summaryrefslogtreecommitdiff
path: root/src/SWDRAW/SWDRAW.cxx
blob: dfd1a493a5331a0cfeeb79462dec6b9548c9bc6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include <SWDRAW.ixx>

#include <DBRep.hxx>
// CKY 4-AOUT-1998 : pb avec GeomFill
//#include <GeometryTest.hxx>
//#include <BRepTest.hxx>
//#include <MeshTest.hxx>

#include <SWDRAW_ShapeTool.hxx>
#include <SWDRAW_ShapeAnalysis.hxx>
#include <SWDRAW_ShapeBuild.hxx>
#include <SWDRAW_ShapeConstruct.hxx>
#include <SWDRAW_ShapeCustom.hxx>
#include <SWDRAW_ShapeExtend.hxx>
#include <SWDRAW_ShapeFix.hxx>
#include <SWDRAW_ShapeUpgrade.hxx>
#include <SWDRAW_ShapeProcess.hxx>
#include <SWDRAW_ShapeProcessAPI.hxx>

//  tovrml
#include <TopoDS_Shape.hxx>
#include <SWDRAW_ToVRML.hxx>
//#72 rln 09.03.99 Packaging of SWDRAW

#include <ShapeProcess_OperLibrary.hxx>
#include <BRepTools.hxx>
#include <Draw_Window.hxx>
#include <BRep_Builder.hxx>
#include <gp_Trsf.hxx>
  
//  for NSPApply -- CKY 12 JUL 2001
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>

static int dejadraw = 0;

//=======================================================================
//function : cpulimit (WNT)
//purpose  : 
//=======================================================================

#ifdef WNT
#include "cpulimit.pc"

static Standard_Integer cpulimit_draw(Draw_Interpretor& di, Standard_Integer n, const char** a)
{
  if (n < 2) { di<<"Give a value"<<"\n"; return 1; }
  int nn = atoi(a[1]);
  di<<"LIMIT ELASPED TIME = "<<nn<<" seconds"<<"\n";
  limitelapsed(nn);

  return 0;
}
#endif

//#72 rln 09.03.99 Packaging of SWDRAW

//=======================================================================
//function : tovrml
//purpose  : 
//=======================================================================

static Standard_Integer tovrml(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
{
  if (n < 3) return 1;
  SWDRAW_ToVRML avrml;
  TopoDS_Shape sh = DBRep::Get (a[1]);
  const char* filename = a[2];
  if (!avrml.Write (sh,filename)) return 1;
  return 0;
}

//=======================================================================
//function : LocSet
//purpose  : 
//=======================================================================

static Standard_Integer LocSet (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
  if (argc < 2) {
    di << argv[0] << "LocSet a [b [c]]: set location for shape \"a\":" << "\n";
    di << "- to Null if one argument is given" << "\n";
    di << "- to location of shape b if two arguments are given" << "\n";
    di << "- to difference of locations of shapes b and c if three arguments are given" << "\n";
    return 1;
  }

  TopoDS_Shape a = DBRep::Get ( argv[1] );
  if ( a.IsNull() ) {
    di << "No shape named \"" << argv[1] << "\" found" << "\n";
    return 1;
  }
  TopLoc_Location L;
  if ( argc >2 ) {
    TopoDS_Shape b = DBRep::Get ( argv[2] );
    if ( b.IsNull() ) {
      di << "No shape named \"" << argv[2] << "\" found" << "\n";
      return 1;
    }
    if ( argc >3 ) {
      TopoDS_Shape c = DBRep::Get ( argv[3] );
      if ( c.IsNull() ) {
	di << "No shape named \"" << argv[3] << "\" found" << "\n";
	return 1;
      }
      L = b.Location().Multiplied ( c.Location().Inverted() );
    }
    else L = b.Location();
  }
  a.Location ( L );
  DBRep::Set ( argv[1], a );
  
  return 0; 
}

//=======================================================================
//function : LocDump
//purpose  : 
//=======================================================================

static Standard_Integer LocDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
  if (argc < 2) {
    di << argv[0] << "LocDump a: dump location of shape \"a\"" << "\n";
    return 1;
  }

  TopoDS_Shape a = DBRep::Get ( argv[1] );
  if ( a.IsNull() ) {
    di << "No shape named \"" << argv[1] << "\" found" << "\n";
    return 1;
  }

  TopLoc_Location L = a.Location();
  di << "Location of shape " << argv[1] << ":" << "\n";
//  L.ShallowDump ( di );
  di << "Results in:" << "\n";
  gp_Trsf T = L.Transformation();
  TopLoc_Location l ( T );
  //l.ShallowDump ( di );
  Standard_SStream aSStream;
  l.ShallowDump ( aSStream );
  di << aSStream;
  
  return 0; 
}

//=======================================================================
//function : NSPApply
//purpose  : CKY , 12 JUL 2001
//=======================================================================

static Standard_Integer NSPApply (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
  if ( argc < 6) {
    di<<"NSPApply result(new shape) shape(initial shape) rscfile sequence tol [maxtol, default=1]"<<"\n";
    return 1;
  }
  TopoDS_Shape shape = DBRep::Get ( argv[2] );
  if (shape.IsNull()) {
    di << "No shape named \"" << argv[1] << "\" found" << "\n";
    return 1;
  }
  TopoDS_Shape newshape;
  Standard_Real tol = atof(argv[5]);
  Standard_Real maxtol = 1.;
  if (argc > 6) maxtol = atof(argv[6]);

  XSAlgo::AlgoContainer()->PrepareForTransfer();
  Handle(Standard_Transient) info;  // reserved for special uses
  newshape = XSAlgo::AlgoContainer()->ProcessShape
    ( shape, tol, maxtol, argv[3] , argv[4] , info);
//    WHAT IS MISSING HERE IS MERGING with starting transfer map

  if (newshape.IsNull()) {
    di<<"No result produced"<<"\n";
  }
  else
    DBRep::Set ( argv[1], newshape );
  return 0;
}

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void  SWDRAW::Init (Draw_Interpretor& theCommands)
{
  if (!dejadraw) {
    dejadraw = 1;
//    DBRep::BasicCommands(theCommands);
// CKY 4-AOUT-1998 : pb avec GeomFill
//    GeometryTest::AllCommands(theCommands);
//    BRepTest::AllCommands(theCommands);
//    MeshTest::Commands(theCommands);
  }

  SWDRAW_ShapeTool::InitCommands (theCommands);
  SWDRAW_ShapeAnalysis::InitCommands (theCommands);
  SWDRAW_ShapeBuild::InitCommands (theCommands);
  SWDRAW_ShapeConstruct::InitCommands (theCommands);
  SWDRAW_ShapeCustom::InitCommands (theCommands);
  SWDRAW_ShapeExtend::InitCommands (theCommands);
  SWDRAW_ShapeFix::InitCommands (theCommands);
  SWDRAW_ShapeUpgrade::InitCommands (theCommands);
  SWDRAW_ShapeProcess::InitCommands (theCommands);
  SWDRAW_ShapeProcessAPI::InitCommands (theCommands);

#ifdef WNT
  theCommands.Add("limitelapsed", "nn seconds",__FILE__, cpulimit_draw, "essai");
#endif

  // locations
  theCommands.Add("LocSet", "a [b [c]]: set loc b->a; use no args to get help",__FILE__,LocSet,"essai");
  theCommands.Add("LocDump", "a: dump location of a",__FILE__,LocDump,"essai");

  //tovrml
  theCommands.Add("tovrml", "shape filename",__FILE__, tovrml, "essai");

  // register operators for ShapeProcessing
  ShapeProcess_OperLibrary::Init();

  // new shape processing
  theCommands.Add ("NSPApply","NSPApply result shape rscfilename sequence tol [maxtol, default=1]",
                   __FILE__,NSPApply,"essai");
}

//=======================================================================
//function : GroupName
//purpose  : 
//=======================================================================

Standard_CString SWDRAW::GroupName()
{
  return "Shape Healing";
}