Panda3D
 All Classes Functions Variables Enumerations
dxfPoints.cxx
1 // Filename: dxfPoints.cxx
2 // Created by: drose (04May04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "dxfPoints.h"
16 #include "pystub.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: DXFPoints::Constructor
20 // Access: Public
21 // Description:
22 ////////////////////////////////////////////////////////////////////
23 DXFPoints::
24 DXFPoints() :
25  WithOutputFile(true, true, false)
26 {
27  // Indicate the extension name we expect the user to supply for
28  // output files.
29  _preferred_extension = ".txt";
30 
31  set_program_brief("extract points from AutoCAD .dxf files");
32  set_program_description
33  ("This program reads an AutoCAD .dxf file and generates a simple "
34  "list of all the points contained within it, one per line, to a "
35  "text file, or to standard output.");
36 
37  clear_runlines();
38  add_runline("[opts] input.dxf > output.txt");
39  add_runline("[opts] -o output.txt input.dxf");
40  add_runline("[opts] input.dxf output.txt");
41 }
42 
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: DXFPoints::run
46 // Access: Public
47 // Description:
48 ////////////////////////////////////////////////////////////////////
49 void DXFPoints::
50 run() {
51  // Invoke the DXFFile base class to process the input file.
52  process(_input_filename);
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: DXFPoints::done_entity
57 // Access: Public, Virtual
58 // Description: This is inherited from DXFFile, and gets called as
59 // each entity (face, line, whatever) has finished
60 // processing.
61 ////////////////////////////////////////////////////////////////////
62 void DXFPoints::
64  if (_entity == EN_point) {
65  get_output() << _p << "\n";
66 
67  } else if (_entity == EN_insert) {
68  ocs_2_wcs();
69  get_output() << _p << "\n";
70  }
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: DXFPoints::handle_args
75 // Access: Protected, Virtual
76 // Description:
77 ////////////////////////////////////////////////////////////////////
78 bool DXFPoints::
79 handle_args(ProgramBase::Args &args) {
80  if (args.empty()) {
81  nout << "You must specify the .dxf file to read on the command line.\n";
82  return false;
83 
84  } else if (args.size() != 1) {
85  nout << "You must specify only one .dxf file to read on the command line.\n";
86  return false;
87  }
88 
89  _input_filename = args[0];
90 
91  return true;
92 }
93 
94 
95 int main(int argc, char *argv[]) {
96  // A call to pystub() to force libpystub.so to be linked in.
97  pystub();
98 
99  DXFPoints prog;
100  prog.parse_command_line(argc, argv);
101  prog.run();
102  return 0;
103 }
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
virtual void done_entity()
This is inherited from DXFFile, and gets called as each entity (face, line, whatever) has finished pr...
Definition: dxfPoints.cxx:63
A simple program to read a dxf file and list the points contained within it to a text file...
Definition: dxfPoints.h:29
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
ostream & get_output()
Returns an output stream that corresponds to the user&#39;s intended egg file output–either stdout...
void ocs_2_wcs()
Assuming the current entity is a planar-based entity, for instance, a 2-d polygon (as opposed to a 3-...
Definition: dxfFile.cxx:518
void process(Filename filename)
Opens the indicated filename and reads it as a DXF file.
Definition: dxfFile.cxx:314