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