0024757: DRAW: Move commands fixshape, tolerance, and similar to MODELING
[occt.git] / src / SWDRAW / SWDRAW.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <SWDRAW.ixx>
15
16 #include <Draw.hxx>
17 #include <DBRep.hxx>
18
19 #include <SWDRAW_ShapeTool.hxx>
20 #include <SWDRAW_ShapeAnalysis.hxx>
21 #include <SWDRAW_ShapeCustom.hxx>
22 #include <SWDRAW_ShapeExtend.hxx>
23 #include <SWDRAW_ShapeFix.hxx>
24 #include <SWDRAW_ShapeUpgrade.hxx>
25 #include <SWDRAW_ShapeProcess.hxx>
26 #include <SWDRAW_ShapeProcessAPI.hxx>
27
28 //#72 rln 09.03.99 Packaging of SWDRAW
29
30 #include <ShapeProcess_OperLibrary.hxx>
31 #include <BRepTools.hxx>
32 #include <Draw_Window.hxx>
33 #include <BRep_Builder.hxx>
34 #include <gp_Trsf.hxx>
35
36 //  for NSPApply -- CKY 12 JUL 2001
37 #include <XSAlgo.hxx>
38 #include <XSAlgo_AlgoContainer.hxx>
39
40 #include <Draw_ProgressIndicator.hxx>
41
42 static int dejadraw = 0;
43
44 //#72 rln 09.03.99 Packaging of SWDRAW
45
46 //=======================================================================
47 //function : LocSet
48 //purpose  : 
49 //=======================================================================
50
51 static Standard_Integer LocSet (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
52 {
53   if (argc < 2) {
54     di << argv[0] << "LocSet a [b [c]]: set location for shape \"a\":" << "\n";
55     di << "- to Null if one argument is given" << "\n";
56     di << "- to location of shape b if two arguments are given" << "\n";
57     di << "- to difference of locations of shapes b and c if three arguments are given" << "\n";
58     return 1;
59   }
60
61   TopoDS_Shape a = DBRep::Get ( argv[1] );
62   if ( a.IsNull() ) {
63     di << "No shape named \"" << argv[1] << "\" found" << "\n";
64     return 1;
65   }
66   TopLoc_Location L;
67   if ( argc >2 ) {
68     TopoDS_Shape b = DBRep::Get ( argv[2] );
69     if ( b.IsNull() ) {
70       di << "No shape named \"" << argv[2] << "\" found" << "\n";
71       return 1;
72     }
73     if ( argc >3 ) {
74       TopoDS_Shape c = DBRep::Get ( argv[3] );
75       if ( c.IsNull() ) {
76         di << "No shape named \"" << argv[3] << "\" found" << "\n";
77         return 1;
78       }
79       L = b.Location().Multiplied ( c.Location().Inverted() );
80     }
81     else L = b.Location();
82   }
83   a.Location ( L );
84   DBRep::Set ( argv[1], a );
85   
86   return 0; 
87 }
88
89 //=======================================================================
90 //function : LocDump
91 //purpose  : 
92 //=======================================================================
93
94 static Standard_Integer LocDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
95 {
96   if (argc < 2) {
97     di << argv[0] << "LocDump a: dump location of shape \"a\"" << "\n";
98     return 1;
99   }
100
101   TopoDS_Shape a = DBRep::Get ( argv[1] );
102   if ( a.IsNull() ) {
103     di << "No shape named \"" << argv[1] << "\" found" << "\n";
104     return 1;
105   }
106
107   TopLoc_Location L = a.Location();
108   di << "Location of shape " << argv[1] << ":" << "\n";
109 //  L.ShallowDump ( di );
110   di << "Results in:" << "\n";
111   gp_Trsf T = L.Transformation();
112   TopLoc_Location l ( T );
113   //l.ShallowDump ( di );
114   Standard_SStream aSStream;
115   l.ShallowDump ( aSStream );
116   di << aSStream;
117   
118   return 0; 
119 }
120
121 //=======================================================================
122 //function : Init
123 //purpose  : 
124 //=======================================================================
125
126 void  SWDRAW::Init (Draw_Interpretor& theCommands)
127 {
128   if (!dejadraw) {
129     dejadraw = 1;
130 //    DBRep::BasicCommands(theCommands);
131 // CKY 4-AOUT-1998 : pb avec GeomFill
132 //    GeometryTest::AllCommands(theCommands);
133 //    BRepTest::AllCommands(theCommands);
134 //    MeshTest::Commands(theCommands);
135   }
136
137   SWDRAW_ShapeTool::InitCommands (theCommands);
138   SWDRAW_ShapeAnalysis::InitCommands (theCommands);
139   SWDRAW_ShapeCustom::InitCommands (theCommands);
140   SWDRAW_ShapeExtend::InitCommands (theCommands);
141   SWDRAW_ShapeFix::InitCommands (theCommands);
142   SWDRAW_ShapeUpgrade::InitCommands (theCommands);
143   SWDRAW_ShapeProcess::InitCommands (theCommands);
144   SWDRAW_ShapeProcessAPI::InitCommands (theCommands);
145
146   // locations
147   theCommands.Add("LocSet", "a [b [c]]: set loc b->a; use no args to get help",__FILE__,LocSet,"essai");
148   theCommands.Add("LocDump", "a: dump location of a",__FILE__,LocDump,"essai");
149
150   // register operators for ShapeProcessing
151   ShapeProcess_OperLibrary::Init();
152
153 }
154
155 //=======================================================================
156 //function : GroupName
157 //purpose  : 
158 //=======================================================================
159
160 Standard_CString SWDRAW::GroupName()
161 {
162   return "Shape Healing";
163 }