Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: SWDRAW_ShapeFix.cxx |
2 | // Created: Tue Mar 9 15:49:13 1999 | |
3 | // Author: data exchange team | |
4 | // <det@kinox.nnov.matra-dtv.fr> | |
5 | ||
6 | ||
7 | #include <SWDRAW_ShapeFix.ixx> | |
8 | #include <DBRep.hxx> | |
9 | #include <SWDRAW.hxx> | |
10 | #include <gp_XYZ.hxx> | |
11 | #include <gp_Pnt2d.hxx> | |
12 | #include <TopoDS.hxx> | |
13 | #include <TopoDS_Shape.hxx> | |
14 | #include <TopoDS_Edge.hxx> | |
15 | #include <TopoDS_Wire.hxx> | |
16 | #include <TopoDS_Face.hxx> | |
17 | #include <TopoDS_Iterator.hxx> | |
18 | #include <TopExp_Explorer.hxx> | |
19 | #include <BRep_Tool.hxx> | |
999d2599 | 20 | #include <BRep_Builder.hxx> |
7fd59977 | 21 | #include <BRepBuilderAPI.hxx> |
22 | #include <BRepTopAdaptor_FClass2d.hxx> | |
23 | ||
24 | #include <ShapeBuild_ReShape.hxx> | |
25 | #include <ShapeAnalysis_Edge.hxx> | |
26 | #include <ShapeAnalysis_WireOrder.hxx> | |
27 | #include <ShapeAnalysis_WireVertex.hxx> | |
28 | #include <ShapeAnalysis_Wire.hxx> | |
29 | #include <ShapeExtend_WireData.hxx> | |
30 | #include <ShapeFix.hxx> | |
31 | #include <ShapeFix_ShapeTolerance.hxx> | |
32 | #include <ShapeFix_Wire.hxx> | |
33 | #include <ShapeFix_WireVertex.hxx> | |
34 | #include <ShapeFix_Wireframe.hxx> | |
35 | #include <ShapeFix_Face.hxx> | |
36 | #include <ShapeFix_Shape.hxx> | |
37 | #include <Precision.hxx> | |
38 | #include <ShapeExtend_DataMapOfShapeListOfMsg.hxx> | |
39 | #include <ShapeExtend_MsgRegistrator.hxx> | |
40 | #include <ShapeExtend_DataMapIteratorOfDataMapOfShapeListOfMsg.hxx> | |
41 | #include <Message_ListIteratorOfListOfMsg.hxx> | |
42 | #include <Message_Msg.hxx> | |
43 | #include <TCollection_AsciiString.hxx> | |
999d2599 D |
44 | #include <TColStd_DataMapIteratorOfDataMapOfAsciiStringInteger.hxx> |
45 | #include <TColStd_DataMapOfAsciiStringInteger.hxx> | |
7fd59977 | 46 | #include <TopTools_MapOfShape.hxx> |
47 | #include <TopTools_DataMapOfShapeListOfShape.hxx> | |
48 | #include <TopAbs_State.hxx> | |
49 | ||
b485ee79 | 50 | #include <Draw_ProgressIndicator.hxx> |
974c25ed G |
51 | #include <ShapeAnalysis_FreeBounds.hxx> |
52 | #include <TopTools_HSequenceOfShape.hxx> | |
53 | #include <BRep_Builder.hxx> | |
54 | #include <TopTools_IndexedMapOfShape.hxx> | |
55 | #include <TopExp.hxx> | |
b485ee79 | 56 | |
7fd59977 | 57 | #ifdef AIX |
58 | #include <strings.h> | |
59 | #endif | |
60 | #include <stdio.h> | |
61 | #include <ShapeExtend_WireData.hxx> | |
62 | ||
63 | //======================================================================= | |
64 | //function : edgesameparam | |
65 | //purpose : | |
66 | //======================================================================= | |
67 | ||
68 | static Standard_Integer edgesameparam (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
69 | { | |
70 | // const Standard_CString arg1 = argv[1]; | |
71 | const Standard_CString arg2 (argc > 2 ? argv[2] : NULL); | |
72 | // **** Edge:SameParameter **** | |
73 | if (argc < 2) { di<<"shapename , option f to force, else only Edges not-SameParameter are computed"<<"\n"; return 1 /* Error */; } | |
74 | TopoDS_Shape Shape = DBRep::Get(argv[1]); | |
75 | ||
76 | if (!ShapeFix::SameParameter(Shape, (argc > 2 && arg2[0] == 'f') , BRepBuilderAPI::Precision()) ) | |
77 | di<<"Some edges were not processed"<<"\n"; | |
78 | di<<"\n"; | |
79 | return 0; // Done | |
80 | } | |
81 | ||
82 | //======================================================================= | |
83 | //function : settolerance | |
84 | //purpose : | |
85 | //======================================================================= | |
86 | ||
87 | static Standard_Integer settolerance (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
88 | { | |
89 | if (argc < 3) { | |
90 | di<< "myshape val : forces tolerances at <val>"<<"\n" | |
91 | << "myshape < max : sets maximum tolerance to <max>"<<"\n" | |
92 | << "myshape > min : sets minimum tolerance to <min>"<<"\n" | |
93 | << "myshape min max : bounds tolerances between <min> and <max>"<<"\n" | |
94 | <<"myshape mode=v-e-f other args : idem but only on vertex-edge-face"<<"\n"; | |
95 | return (argc < 2 ? 0 : 1 /* Error */); | |
96 | } | |
97 | Standard_CString arg1 = argv[1]; | |
98 | Standard_CString arg2 = argv[2]; | |
99 | TopoDS_Shape Shape = DBRep::Get(arg1); | |
100 | if (Shape.IsNull()) { di<<"Shape unknown : "<<arg1<<"\n"; return 1 /* Error */; } | |
101 | char mod2 = arg2[0]; | |
102 | Standard_Integer premarg = 2; | |
103 | TopAbs_ShapeEnum styp = TopAbs_SHAPE; | |
104 | if (mod2 == 'v') { styp = TopAbs_VERTEX; premarg = 3; } | |
105 | if (mod2 == 'e') { styp = TopAbs_EDGE; premarg = 3; } | |
106 | if (mod2 == 'w') { styp = TopAbs_WIRE; premarg = 3; } | |
107 | if (mod2 == 'f') { styp = TopAbs_FACE; premarg = 3; } | |
108 | if (mod2 == 'a') { styp = TopAbs_SHAPE; premarg = 3; } | |
109 | ||
110 | Standard_Real tmin,tmax; | |
111 | mod2 = argv[premarg][0]; | |
112 | if (mod2 == '=') tmin = tmax = atof (argv[argc-1]); | |
113 | else if (mod2 == '<') { tmin = 0; tmax = atof (argv[argc-1]); } | |
114 | else if (mod2 == '>') { tmin = atof (argv[argc-1]); tmax = 0; } | |
115 | else { tmin = atof (argv[premarg]); tmax = atof (argv[argc-1]); } | |
116 | ||
117 | if (argc == premarg + 1 || tmin == tmax) di<<"Setting Tolerance to "<<tmin<<"\n"; | |
118 | else if (tmax < tmin) di<<"Minimum Tolerance to "<<tmin<<"\n"; | |
119 | else if (tmin <= 0) di<<"Maximum Tolerance to "<<tmax<<"\n"; | |
120 | else di<<"Tolerance Limited between "<<tmin<<" and "<<tmax<<"\n"; | |
121 | ShapeFix_ShapeTolerance sat; | |
122 | sat.LimitTolerance (Shape,tmin,tmax,styp); | |
123 | return 0; // Done | |
124 | } | |
125 | ||
126 | //======================================================================= | |
127 | //function : stwire | |
128 | //purpose : | |
129 | //======================================================================= | |
130 | ||
131 | static Standard_Integer stwire (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
132 | { | |
133 | if (argc < 2) { // help | |
134 | di<<"Donner nom shape depart + nom shape resultat + option"<<"\n"; | |
135 | di<<"Options de chargement : x add connected (sinon add simple)\n" | |
136 | << "Options de traitement : l fix little/BRepBuilderAPI\n" | |
137 | <<"Options de sortie : aucune make simple\n" | |
138 | <<" m MakeAPI r avec reorder v vertex\n" | |
139 | <<"Autres (se cumulent) : q quid(stats)"<<"\n"; | |
140 | return 0; | |
141 | } | |
142 | if (argc < 4) { di<<"stwire tout court pour help"<<"\n"; return 1 /* Error */; } | |
143 | Standard_CString arg1 = argv[1]; | |
144 | Standard_CString arg2 = argv[2]; | |
145 | ||
146 | // Options | |
147 | Standard_Integer i; int ox,ol,om,orint,oq,ov; ox=ol=om=orint=oq=ov=0; | |
148 | for (i = 3; i < argc; i ++) { | |
149 | int valopt = 1; | |
150 | char opt = argv[i][0]; | |
151 | if (opt == '+') opt = argv[i][1]; | |
152 | if (opt == '-') { opt = argv[i][1]; valopt = 0; } | |
153 | switch (opt) { | |
154 | case 'l' : ol = valopt; break; | |
155 | case 'm' : om = valopt; break; | |
156 | case 'q' : oq = valopt; break; | |
157 | case 'r' : orint = valopt; break; | |
158 | case 'v' : ov = valopt; break; | |
159 | case 'x' : ox = valopt; break; | |
160 | default : break; | |
161 | } | |
162 | } | |
163 | TopoDS_Shape Shape = DBRep::Get(arg1); | |
164 | if (Shape.IsNull()) { di<<arg1<<" inconnu"<<"\n"; return 1 /* Error */; } | |
165 | ||
166 | // On y va | |
167 | Handle(ShapeExtend_WireData) sbwd = new ShapeExtend_WireData; | |
168 | Handle(ShapeAnalysis_Wire) saw = new ShapeAnalysis_Wire; | |
169 | saw->Load ( sbwd ); | |
170 | ||
171 | TopoDS_Shape awire; // en principe un Wire | |
172 | if (Shape.ShapeType() == TopAbs_WIRE) { | |
173 | awire = Shape; | |
174 | } else if (Shape.ShapeType() == TopAbs_FACE) { | |
175 | saw->SetFace (TopoDS::Face(Shape)); | |
176 | TopExp_Explorer expw(Shape,TopAbs_WIRE); | |
177 | if (expw.More()) awire = expw.Current(); | |
178 | saw->SetPrecision (BRepBuilderAPI::Precision()); | |
179 | } | |
180 | if (awire.IsNull()) { | |
181 | di<<"Neither FACE nor WIRE : "<<arg1<<"\n"; | |
182 | di<<"Considering as list of edges ..."<<"\n"; | |
183 | awire = Shape; | |
184 | // return 1 /* Error */; | |
185 | } | |
186 | ||
187 | // Chargement : normal ou par connected(oriented) | |
188 | // if (ox) { | |
189 | for (TopExp_Explorer exp(Shape,TopAbs_EDGE); exp.More(); exp.Next()) { | |
190 | TopoDS_Edge E = TopoDS::Edge (exp.Current()); | |
191 | Standard_Integer orient = saw->CheckShapeConnect (E); | |
192 | di<<"Orientation : "<<orient<<" LowerDist : "<< saw->MinDistance3d() << "\n"; | |
193 | if (ox) sbwd->AddOriented (E,orient); | |
194 | else sbwd->Add (E); | |
195 | } | |
196 | // } | |
197 | // else sbwd->Init (awire); | |
198 | ||
199 | Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire; | |
200 | sfw->Init ( saw ); | |
201 | ||
202 | // Traitement en cours | |
203 | if (ol) { | |
204 | Standard_Integer nb = sfw->NbEdges(); | |
205 | for (i = 1; i <= nb; i ++) { | |
206 | Standard_Boolean stat = sfw->FixSmall (i, Standard_True, 0.0); | |
207 | //cout<<"FixSmall for"<<i<<(stat ? " done" : " not done"); //:sw <<" StatusFix="<<STW.StatusFix()<<"\n"; | |
208 | di<<"FixSmall for"<<i; | |
209 | if (!stat) { | |
210 | di<<" not done"; | |
211 | } else { | |
212 | di<<" done"; | |
213 | } | |
214 | if ( sfw->LastFixStatus ( ShapeExtend_FAIL ) ) di << " (failed)"; | |
215 | di << "\n"; | |
216 | } | |
217 | } | |
218 | ||
219 | // Traitement | |
220 | if (orint) { // reorder ? | |
221 | ShapeAnalysis_WireOrder WO ( (Shape.ShapeType() != TopAbs_FACE), BRepBuilderAPI::Precision()); | |
222 | ||
223 | Standard_Integer stwo = saw->CheckOrder (WO); | |
224 | Standard_Integer nb = WO.NbEdges(); | |
225 | di<<"Reorder status : "<<stwo<<" NbEdges="<<nb<<"\n"; | |
226 | for (i = 1; i <= nb; i ++) { | |
227 | Standard_Integer iord = WO.Ordered(i); | |
228 | di<<"Edge n0 "<<i; | |
229 | if ( sbwd->Edge(iord).Orientation() == TopAbs_REVERSED) di<<" REV"; | |
230 | else di<<" FWD"; | |
231 | di<<" ordered to "<<iord<<" Gap="<<WO.Gap(i)<<"\n"; | |
232 | } | |
233 | di<<"Reorder not yet done"<<"\n"; | |
234 | sfw->FixReorder (WO); | |
235 | // Mais on n execute pas | |
236 | } | |
237 | ||
238 | // Statistiques | |
239 | if (oq) { | |
240 | ShapeAnalysis_Edge sae; | |
241 | Standard_Integer nb = sbwd->NbEdges(); | |
242 | di<<"NbEdges : "<<nb<<"\n"; | |
243 | for (i = 1; i <= nb; i ++) { | |
244 | TopoDS_Edge E = sbwd->Edge(i); | |
245 | di<<"Edge "<<i; | |
246 | if (E.Orientation() == TopAbs_REVERSED) di<<" REV"; | |
247 | else di<<" FWD"; | |
248 | if (BRep_Tool::Degenerated(E)) di<<" DGNR"; | |
249 | if (sbwd->IsSeam(i)) di<<" SEAM_WIRE"; | |
250 | if (Shape.ShapeType() == TopAbs_FACE && | |
251 | sae.IsSeam(E,TopoDS::Face(Shape))) di<<" SEAM_FACE"; | |
252 | if (Shape.ShapeType() == TopAbs_FACE ) | |
253 | if (sae.HasPCurve(E,TopoDS::Face(Shape))) di<<" PCU"; | |
254 | else di<<" NO_PCU"; | |
255 | if (sae.HasCurve3d(E)) di<<" C3D"; | |
256 | else di<<" NO_C3D"; | |
257 | if (sae.IsClosed3d(E)) di<<" CLOSED"; | |
258 | di<<"\n"; | |
259 | } | |
260 | } | |
261 | ||
262 | // Resultat | |
263 | TopoDS_Wire result; | |
264 | if (ov) { | |
265 | ShapeAnalysis_WireVertex sawv; | |
266 | sawv.Init ( sbwd, saw->Precision() ); | |
267 | sawv.Analyze(); | |
268 | Standard_Integer nb = sbwd->NbEdges(); | |
269 | di<<"Nb(End)Vertex : "<<nb<<"\n"; | |
270 | for (i = 1; i <= nb; i ++) { | |
271 | gp_XYZ pos; Standard_Real upre,ufol; | |
272 | Standard_Integer stat = sawv.Data (i,pos,upre,ufol); | |
273 | di<<i<<" : "; | |
274 | switch (stat) { | |
275 | case 0 : di<<"Same Vertex"<<"\n"; break; | |
276 | case 1 : di<<"Same Coords with recorded precisions (but not Same Vertex)"<<"\n"; break; | |
277 | case 2 : di<<"Close (with preci="<< saw->Precision()<<")"<<"\n"; break; | |
278 | case 3 : di<<"End of "<<i<<" OK, Start of "<<(i == nb ? 1 : i+1)<<" at U="<<ufol; break; | |
279 | case 4 : di<<"End of "<<i<<" at U="<<upre<<", Start of "<<(i == nb ? 1 : i+1)<<" OK"; break; | |
280 | case 5 : di<<"Intersection, End of "<<i<<" at U="<<upre<<", Start of "<<(i == nb ? 1 : i+1)<<" at U="<<ufol; break; | |
281 | default : di<<"Disjoined"<<"\n"; | |
282 | } | |
283 | if (stat >= 3 && stat <= 5) di<<"\n - Position : "<<pos.X()<<" "<<pos.Y()<<" "<<pos.Z()<<"\n"; | |
284 | } | |
285 | ShapeFix_WireVertex sfwv; | |
286 | sfwv.Init ( sawv ); | |
287 | di<<"Nb Fixed Vertex : "<< sfwv.Fix() <<"\n"; | |
288 | } | |
289 | /* | |
290 | if (oc) { | |
291 | if ( Shape.ShapeType() == TopAbs_FACE ) { | |
292 | Correct_Wire CW ( TopoDS::Face(Shape) ); | |
293 | Standard_Integer i, nb = sbwd->NbEdges(); | |
294 | Standard_Integer num = 1; | |
295 | for (i = 1; i <= nb; i ++) CW.Add (sbwd->Edge(i)); | |
296 | CW.Perform ( saw->Precision() ); | |
297 | nb = CW.NbWires(); | |
298 | if (nb != 1) { | |
299 | // On prend celui qui a le plus d edges | |
300 | Standard_Integer nbe, maxe = 0; | |
301 | for (i = 1; i <= nb; i ++) { | |
302 | TopoDS_Wire wir = CW.Wire(i); | |
303 | nbe = 0; | |
304 | for (TopoDS_Iterator ite(wir); ite.More(); ite.Next()) nbe ++; | |
305 | if (nbe > maxe) { num = i; maxe = nbe; } | |
306 | } | |
307 | di<<"Correct_Wire produced "<<nb<<" Wires, taken n0 "<<num<<"\n"; | |
308 | } | |
309 | result = CW.Wire (num); | |
310 | } | |
311 | else di << "Cannot apply Correct_Wire: face not defined" << "\n"; | |
312 | } | |
313 | */ | |
314 | else if (om) result = sbwd->WireAPIMake(); | |
315 | else result = sbwd->Wire(); | |
316 | if (result.IsNull()) { | |
317 | di<<"Pas de resultat, desole"<<"\n"; | |
318 | return 1; // Fail | |
319 | } | |
320 | DBRep::Set (arg2,result); | |
321 | return 0; // Done | |
322 | } | |
323 | ||
324 | //======================================================================= | |
325 | //function : reface | |
326 | //purpose : | |
327 | //======================================================================= | |
328 | ||
329 | static Standard_Integer reface (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
330 | { | |
331 | if (argc < 3) { di<<"Donner un nom de SHAPE (SHELL ou FACE) + un nom de RESULTAT"<<"\n"; return 1 /* Error */; } | |
332 | Standard_CString arg1 = argv[1]; | |
333 | Standard_CString arg2 = argv[2]; | |
334 | TopoDS_Shape Shape = DBRep::Get(arg1); | |
335 | if (Shape.IsNull()) { di<<"Shape unknown : "<<arg1<<"\n"; return 1 /* Error */; } | |
336 | ||
337 | Standard_Boolean rebuild = Standard_False; | |
338 | ||
339 | Handle(ShapeFix_Face) STF = new ShapeFix_Face; | |
340 | // Options ? | |
341 | Standard_Integer i; // svv Jan11 2000 : porting on DEC | |
342 | for (i = 3; i < argc; i ++) { | |
343 | Standard_Boolean valopt = Standard_True; | |
344 | char opt = argv[i][0]; | |
345 | if (opt == '+') opt = argv[i][1]; | |
346 | if (opt == '-') { opt = argv[i][1]; valopt = Standard_False; } | |
347 | //cout<<(valopt ? ".." : ".. NO"); | |
348 | if (!valopt) { | |
349 | di<<".. NO"; | |
350 | } else { | |
351 | di<<".."; | |
352 | } | |
353 | ||
354 | if (opt == 'R') { di<<" REBUILD-ANYWAY .."; rebuild = valopt; } | |
355 | if (opt == 'd') { di<<" fix-dgnr .."; STF->FixWireTool()->FixDegeneratedMode() = valopt; } | |
356 | if (opt == 'r') { di<<" fix-reorder-wire .."; STF->FixWireTool()->FixReorderMode() = valopt; } | |
357 | if (opt == 'k') { | |
358 | } | |
359 | } | |
360 | ||
361 | TopoDS_Face face; | |
362 | ShapeBuild_ReShape resh; | |
363 | ||
364 | Standard_Integer nbf = 0, nbfc = 0; | |
365 | for (TopExp_Explorer EF (Shape,TopAbs_FACE); EF.More(); EF.Next()) { | |
366 | TopoDS_Face F = TopoDS::Face (EF.Current()); face = F; | |
367 | nbf ++; | |
368 | Standard_Boolean newface = Standard_False; | |
369 | // on va voir si ShapeTool_Face trouve qqchose a redire | |
370 | //:sw ShapeTool_Wire STW; | |
371 | //:sw STW.SetFace (F); | |
372 | ||
373 | STF->Init (F); // qui fait tout | |
374 | STF->Perform(); | |
375 | face = STF->Face(); | |
376 | newface = STF->Status(ShapeExtend_DONE) || rebuild; | |
377 | if (newface) { nbfc ++; resh.Replace (F,face); } | |
378 | } | |
379 | if (nbfc > 0) { | |
380 | di<<"Faces reprises par ShapeFix_Face : "<<nbfc<<"\n"; | |
381 | DBRep::Set (arg2,resh.Apply (Shape,TopAbs_FACE,2)); | |
382 | return 0; // Done | |
383 | } | |
384 | else di<<"ShapeFix_Face n a rien trouve a redire"<<"\n"; | |
385 | return 0; | |
386 | } | |
387 | ||
388 | ||
389 | //======================================================================= | |
390 | //function : fixshape | |
391 | //purpose : | |
392 | //======================================================================= | |
393 | ||
394 | static Standard_Integer fixshape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
395 | { | |
396 | Handle(ShapeExtend_MsgRegistrator) msg = new ShapeExtend_MsgRegistrator; | |
397 | Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; | |
398 | sfs->SetMsgRegistrator ( msg ); | |
399 | ||
400 | Standard_CString res = 0; | |
401 | Standard_Integer par = 0, mess=0; | |
402 | for ( Standard_Integer i=1; i < argc; i++ ) { | |
403 | if ( argv[i][0] == '-' || argv[i][0] == '+' || argv[i][0] == '*' ) { | |
404 | Standard_Integer val = ( argv[i][0] == '-' ? 0 : argv[i][0] == '+' ? 1 : -1 ); | |
405 | switch ( argv[i][1] ) { | |
999d2599 D |
406 | case 'l': sfs->FixWireTool()->FixLackingMode() = val; break; |
407 | case 'o': sfs->FixFaceTool()->FixOrientationMode() = val; break; | |
408 | case 'h': sfs->FixWireTool()->FixShiftedMode() = val; break; | |
409 | case 'm': sfs->FixFaceTool()->FixMissingSeamMode() = val; break; | |
410 | case 'd': sfs->FixWireTool()->FixDegeneratedMode() = val; break; | |
411 | case 's': sfs->FixWireTool()->FixSmallMode() = val; break; | |
412 | case 'i': sfs->FixWireTool()->FixSelfIntersectionMode() = val; break; | |
413 | case 'n': sfs->FixWireTool()->FixNotchedEdgesMode() = val; break; | |
414 | case '?': mess = val; break; | |
7fd59977 | 415 | } |
416 | continue; | |
417 | } | |
418 | else { | |
419 | switch ( par ) { | |
420 | case 0: res = argv[i]; break; | |
421 | case 1: { | |
422 | TopoDS_Shape initShape = DBRep::Get(argv[i]); | |
423 | if(initShape.IsNull()) continue; | |
424 | sfs->Init ( initShape ); | |
425 | } break; | |
426 | case 2: sfs->SetPrecision (atof(argv[i])); break; | |
427 | case 3: sfs->SetMaxTolerance(atof(argv[i])); break; | |
428 | } | |
429 | } | |
430 | par++; | |
431 | } | |
432 | ||
433 | if ( par <2 ) { | |
434 | di << "Use: " << argv[0] << " result shape [tolerance [max_tolerance]] [switches]" << "\n"; | |
435 | di << "Switches allow to tune parameters of ShapeFix" << "\n"; | |
436 | di << "The following syntax is used: <symbol><parameter>" << "\n"; | |
437 | di << "- symbol may be - to set parameter off, + to set on or * to set default" << "\n"; | |
438 | di << "- parameters are identified by letters:" << "\n"; | |
439 | di << " l - FixLackingMode" << "\n"; | |
440 | di << " o - FixOrientationMode" << "\n"; | |
441 | di << " h - FixShiftedMode" << "\n"; | |
442 | di << " m - FixMissingSeamMode" << "\n"; | |
443 | di << " d - FixDegeneratedMode" << "\n"; | |
444 | di << " s - FixSmallMode" << "\n"; | |
445 | di << " i - FixSelfIntersectionMode" << "\n"; | |
446 | di << " n - FixNotchedEdgesMode" << "\n"; | |
447 | di << "For enhanced message output, use switch '+?'" << "\n"; | |
448 | return 1; | |
449 | } | |
b485ee79 KD |
450 | |
451 | Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1); | |
452 | sfs->Perform (aProgress); | |
7fd59977 | 453 | DBRep::Set (res,sfs->Shape()); |
b485ee79 | 454 | |
999d2599 D |
455 | if ( mess ) |
456 | { | |
457 | TColStd_DataMapOfAsciiStringInteger aMapOfNumberOfFixes; | |
458 | Standard_SStream aSStream; | |
459 | TopoDS_Compound aCompound; | |
460 | BRep_Builder aBuilder; | |
461 | aBuilder.MakeCompound (aCompound); | |
7fd59977 | 462 | const ShapeExtend_DataMapOfShapeListOfMsg &map = msg->MapShape(); |
999d2599 D |
463 | // Counting the number of each type of fixes. If the switch '*?' store all modified shapes in compound. |
464 | for ( ShapeExtend_DataMapIteratorOfDataMapOfShapeListOfMsg it ( map ); it.More(); it.Next() ) | |
465 | { | |
466 | for ( Message_ListIteratorOfListOfMsg iter ( it.Value() ); iter.More(); iter.Next() ) | |
467 | { | |
468 | if ( aMapOfNumberOfFixes.IsBound ( iter.Value().Value() ) ) | |
469 | { | |
470 | aMapOfNumberOfFixes ( iter.Value().Value() )++; | |
471 | } | |
472 | else | |
473 | { | |
474 | aMapOfNumberOfFixes.Bind ( iter.Value().Value(), 1 ); | |
475 | } | |
7fd59977 | 476 | } |
999d2599 D |
477 | if ( mess < 0 ) |
478 | { | |
479 | aBuilder.Add ( aCompound, it.Key() ); | |
480 | } | |
481 | } | |
482 | ||
483 | aSStream << " Fix" << setw (58) << "Count\n"; | |
484 | aSStream << " ------------------------------------------------------------\n"; | |
485 | for ( TColStd_DataMapIteratorOfDataMapOfAsciiStringInteger anIter ( aMapOfNumberOfFixes ); anIter.More(); anIter.Next() ) | |
486 | { | |
487 | aSStream << " " << anIter.Key() << setw ( 60 - anIter.Key().Length() ) << anIter.Value() << "\n"; | |
488 | } | |
489 | aSStream << " ------------------------------------------------------------\n"; | |
490 | di << aSStream; | |
491 | ||
492 | if ( mess < 0 ) | |
493 | { | |
494 | char buff[256]; | |
495 | sprintf ( buff, "%s_%s", res, "m" ); | |
496 | di << " Modified shapes saved in compound: " << buff; | |
497 | DBRep::Set (buff, aCompound); | |
7fd59977 | 498 | } |
499 | } | |
500 | ||
501 | return 0; // Done | |
502 | } | |
503 | ||
504 | //======================================================================= | |
505 | //function : fixgaps | |
506 | //purpose : | |
507 | //======================================================================= | |
508 | ||
509 | Standard_Integer fixgaps(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
510 | { | |
511 | if (n < 3) return 1; | |
512 | ||
513 | TopoDS_Shape S = DBRep::Get(a[2]); | |
514 | if (S.IsNull()) { | |
515 | di << " Shape is null" << "\n"; | |
516 | return 1; | |
517 | } | |
518 | ||
519 | Handle(ShapeFix_Wireframe) SFWF = new ShapeFix_Wireframe(S); | |
520 | Standard_Real prec = ( n >3 ? atof(a[3]) : 0. ); | |
521 | SFWF->SetPrecision(prec); | |
522 | if ( SFWF->FixWireGaps() ) { | |
523 | DBRep::Set(a[1],SFWF->Shape()); | |
524 | di<<" Wireframe gaps fixed on shape"<<"\n"; | |
525 | } | |
526 | ||
527 | return 0; | |
528 | } | |
529 | ||
530 | //======================================================================= | |
531 | //function : fixsmall | |
532 | //purpose : | |
533 | //======================================================================= | |
534 | ||
535 | Standard_Integer fixsmall(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
536 | { | |
537 | if (n < 3) return 1; | |
538 | ||
539 | TopoDS_Shape S = DBRep::Get(a[2]); | |
540 | if (S.IsNull()) { | |
541 | di << " Shape is null" << "\n"; | |
542 | return 1; | |
543 | } | |
544 | ||
545 | Standard_Real prec = (n == 4)? atof(a[3]) : 1.; | |
546 | ShapeFix_Wireframe SFWF(S); | |
547 | SFWF.SetPrecision(prec); | |
548 | ||
549 | if (SFWF.FixSmallEdges()) { | |
550 | DBRep::Set(a[1],SFWF.Shape()); | |
551 | di<<" Small edges fixed on shape"<<"\n"; | |
552 | } | |
553 | ||
554 | return 0; | |
555 | } | |
556 | ||
557 | //======================================================================= | |
558 | //function : fixsmalledges | |
559 | //purpose : | |
560 | //======================================================================= | |
561 | ||
562 | static Standard_Integer fixsmalledges(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
563 | { | |
564 | if( n < 3) { | |
565 | di<<"Invalid number of arguments"<<"\n"; | |
566 | return 1; | |
567 | } | |
568 | TopoDS_Shape Sh = DBRep::Get(a[2]); | |
569 | ||
570 | Standard_Integer k = 3; | |
571 | Standard_Real tol = 100000; | |
572 | Standard_Integer mode = 2; | |
c6541a0c | 573 | Standard_Real tolang = M_PI/2; |
7fd59977 | 574 | if(n > k) |
575 | tol = atof(a[k++]); | |
576 | ||
577 | if(n > k) | |
578 | mode= atoi(a[k++]); | |
579 | ||
580 | if(n > k) | |
581 | tolang = atof(a[k++]); | |
582 | ||
583 | Handle(ShapeFix_Wireframe) aSfwr = new ShapeFix_Wireframe(); | |
584 | Handle(ShapeBuild_ReShape) aReShape = new ShapeBuild_ReShape; | |
585 | aSfwr->SetContext(aReShape); | |
586 | aSfwr->Load(Sh); | |
587 | aSfwr->SetPrecision(tol); | |
588 | Standard_Boolean aModeDrop = Standard_True; | |
589 | if(mode == 2) | |
590 | aModeDrop = Standard_False; | |
591 | ||
592 | TopTools_MapOfShape theSmallEdges, theMultyEdges; | |
593 | TopTools_DataMapOfShapeListOfShape theEdgeToFaces,theFaceWithSmall; | |
594 | aSfwr->CheckSmallEdges(theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges); | |
595 | aSfwr->MergeSmallEdges (theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges, aModeDrop,tolang); | |
596 | //aSfwr->FixSmallEdges(); | |
597 | TopoDS_Shape resShape = aSfwr->Shape();; | |
598 | DBRep::Set ( a[1], resShape ); | |
599 | return 0; | |
600 | } | |
601 | ||
602 | //======================================================================= | |
603 | //function : checkoverlapedges | |
604 | //purpose : | |
605 | //======================================================================= | |
606 | ||
607 | static Standard_Integer checkoverlapedges(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
608 | { | |
609 | if( n < 3) { | |
610 | di<<"Invalid number of arguments"<<"\n"; | |
611 | return 1; | |
612 | } | |
613 | TopoDS_Shape Sh1 = DBRep::Get(a[1]); | |
614 | TopoDS_Shape Sh2 = DBRep::Get(a[2]); | |
615 | if(Sh1.IsNull() || Sh2.IsNull()) { | |
616 | di<<"Invalid arguments"<<"\n"; | |
617 | return 1; | |
618 | } | |
619 | TopoDS_Edge e1 = TopoDS::Edge(Sh1); | |
620 | TopoDS_Edge e2 = TopoDS::Edge(Sh2); | |
621 | if(e1.IsNull() || e2.IsNull()) { | |
622 | di<<"Invalid type of arguments"<<"\n"; | |
623 | return 1; | |
624 | } | |
625 | Standard_Real aTol = Precision::Confusion(); | |
626 | Standard_Real aDistDomain = 0.0; | |
627 | Standard_Integer k = 3; | |
628 | if(k < n) | |
629 | aTol = atof(a[k++]); | |
630 | if(k < n) | |
631 | aDistDomain = atof(a[k++]); | |
632 | ||
633 | ShapeAnalysis_Edge sae; | |
634 | if(sae.CheckOverlapping(e1,e2,aTol,aDistDomain)) { | |
635 | if(aDistDomain ==0.0) | |
636 | di<<"Edges is overlaping comletly"<<"\n"; | |
637 | else { | |
638 | di<<"Edges is overlaped"<<"\n"; | |
639 | di<<"with tolerance = "<<aTol<<"\n"; | |
640 | di<<"on segment length = "<<aDistDomain<<"\n"; | |
641 | } | |
642 | } | |
643 | else di<<"Edges is not overlaped"<<"\n"; | |
644 | return 0; | |
645 | } | |
646 | ||
647 | //======================================================================= | |
648 | //function : checkfclass2d | |
649 | //purpose : | |
650 | //======================================================================= | |
651 | ||
652 | static Standard_Integer checkfclass2d(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
653 | { | |
654 | if( n < 4) { | |
655 | di<<"Invalid number of arguments"<<"\n"; | |
656 | return 1; | |
657 | } | |
658 | TopoDS_Shape Sh1 = DBRep::Get(a[1]); | |
659 | Standard_Real ucoord = atof(a[2]); | |
660 | Standard_Real vcoord = atof(a[3]); | |
661 | if(Sh1.IsNull() || Sh1.ShapeType()!= TopAbs_FACE) { | |
662 | di<<"Invalid arguments"<<"\n"; | |
663 | return 1; | |
664 | } | |
665 | TopoDS_Face aFace = TopoDS::Face(Sh1); | |
666 | gp_Pnt2d p2d(ucoord,vcoord); | |
667 | BRepTopAdaptor_FClass2d f2d(aFace,Precision::Confusion()); | |
668 | TopAbs_State stat = f2d.Perform(p2d); | |
669 | if(stat == TopAbs_OUT) | |
670 | di<<"Point is OUT"<<"\n"; | |
671 | else if(stat == TopAbs_IN) | |
672 | di<<"Point is IN"<<"\n"; | |
673 | else if(stat == TopAbs_ON) | |
674 | di<<"Point is ON"<<"\n"; | |
675 | else | |
676 | di<<"Point is UNKNOWN"<<"\n"; | |
677 | return 0; | |
678 | } | |
679 | ||
974c25ed G |
680 | static Standard_Integer connectedges(Draw_Interpretor& di, Standard_Integer n, const char** a) |
681 | { | |
682 | if( n < 3) { | |
683 | di<<"Invalid number of arguments. Should be : result shape [toler shared]"<<"\n"; | |
684 | return 1; | |
685 | } | |
686 | TopoDS_Shape aSh1 = DBRep::Get(a[2]); | |
687 | if(aSh1.IsNull()) { | |
688 | di<<"Shape is null"<<"\n"; | |
689 | return 1; | |
690 | } | |
691 | Standard_Real aTol = Precision::Confusion(); | |
692 | if( n > 3) | |
693 | aTol = atof(a[3]); | |
694 | ||
695 | Standard_Boolean shared = Standard_True; | |
696 | if( n > 4) | |
697 | shared = (atoi(a[4]) == 1); | |
698 | TopExp_Explorer aExpE(aSh1,TopAbs_EDGE); | |
699 | Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape; | |
700 | Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape; | |
701 | TopTools_IndexedMapOfShape aMapEdges; | |
702 | for( ; aExpE.More(); aExpE.Next()) | |
703 | { | |
704 | aSeqEdges->Append(aExpE.Current()); | |
705 | aMapEdges.Add(aExpE.Current()); | |
706 | } | |
707 | ||
708 | ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,aTol,shared,aSeqWires ); | |
709 | TopoDS_Compound aComp; | |
710 | BRep_Builder aB; | |
711 | aB.MakeCompound(aComp); | |
712 | Standard_Integer i = 1; | |
713 | for( ; i <= aSeqWires->Length() ; i++) | |
714 | { | |
715 | TopoDS_Shape aW = aSeqWires->Value(i); | |
716 | di<<"Wire - "<<i<<" : "<<"\n"; | |
717 | ||
718 | TopExp_Explorer aExp1(aW, TopAbs_EDGE); | |
719 | for( ; aExp1.More(); aExp1.Next()) | |
720 | { | |
721 | if(shared) | |
722 | { | |
723 | Standard_Integer ind = aMapEdges.FindIndex(aExp1.Current()); | |
724 | di<<ind<<" "; | |
725 | } | |
726 | else | |
727 | { | |
728 | TopoDS_Vertex aV1, aV2; | |
729 | TopExp::Vertices(TopoDS::Edge(aExp1.Current()), aV1,aV2); | |
730 | gp_Pnt aP = BRep_Tool::Pnt(aV1); | |
731 | di<<aP.X()<<" "<<aP.Y()<<" "<<aP.Z()<<"\n"; | |
732 | } | |
733 | } | |
734 | ||
735 | di<<"\n"; | |
736 | aB.Add( aComp,aSeqWires->Value(i)); | |
737 | } | |
738 | DBRep::Set(a[1],aComp); | |
739 | return 0; | |
740 | ||
741 | } | |
742 | ||
7fd59977 | 743 | //======================================================================= |
744 | //function : InitCommands | |
745 | //purpose : | |
746 | //======================================================================= | |
747 | ||
748 | void SWDRAW_ShapeFix::InitCommands(Draw_Interpretor& theCommands) | |
749 | { | |
750 | static Standard_Integer initactor = 0; | |
751 | if (initactor) return; initactor = 1; | |
752 | ||
753 | Standard_CString g = SWDRAW::GroupName(); | |
754 | ||
755 | theCommands.Add ("edgesameparam","nom shape draw ou * [+ option force]", | |
756 | __FILE__,edgesameparam,g); | |
757 | theCommands.Add ("settolerance","shape [mode=v-e-f-a] val(fix value) or tolmin tolmax", | |
758 | __FILE__,settolerance,g); | |
759 | theCommands.Add ("stwire","stwire tout court pour help complet", | |
760 | __FILE__,stwire,g); | |
761 | theCommands.Add ("reface","shape result : controle sens wire", | |
762 | __FILE__,reface,g); | |
763 | theCommands.Add ("fixshape","res shape [preci [maxpreci]] [{switches}]", | |
764 | __FILE__,fixshape,g); | |
765 | // theCommands.Add ("testfill","result edge1 edge2", | |
766 | // __FILE__,XSHAPE_testfill,g); | |
767 | theCommands.Add ("fixwgaps","result shape [toler=0]", | |
768 | __FILE__,fixgaps,g); | |
769 | theCommands.Add ("fixsmall","result shape [toler=1.]", | |
770 | __FILE__,fixsmall,g); | |
771 | theCommands.Add ("fixsmalledges","result shape [toler mode amxangle]", | |
772 | __FILE__,fixsmalledges,g); | |
773 | theCommands.Add ("checkoverlapedges","edge1 edge2 [toler domaindist]", | |
774 | __FILE__,checkoverlapedges,g); | |
775 | theCommands.Add ("checkfclass2d","face ucoord vcoord", | |
776 | __FILE__,checkfclass2d,g); | |
974c25ed G |
777 | theCommands.Add ("connectedges","res shape [toler shared]", |
778 | __FILE__,connectedges,g); | |
779 | ||
7fd59977 | 780 | } |
781 |