b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | |
19 | //=============================================== |
7fd59977 |
20 | // AIS2D Objects Creation : Datums (axis,trihedrons,lines,planes) |
7fd59977 |
21 | //=============================================== |
22 | |
23 | #ifdef HAVE_CONFIG_H |
24 | # include <config.h> |
25 | #endif |
26 | |
27 | #include <Viewer2dTest.hxx> |
28 | |
29 | #include <string.h> |
30 | |
31 | #include <Quantity_NameOfColor.hxx> |
32 | |
33 | #include <Draw_Interpretor.hxx> |
34 | #include <Draw.hxx> |
35 | #include <Draw_Appli.hxx> |
36 | #include <DBRep.hxx> |
37 | |
38 | #include <TCollection_AsciiString.hxx> |
39 | #include <TCollection_ExtendedString.hxx> |
40 | #include <TColStd_MapOfInteger.hxx> |
41 | |
42 | #include <V2d_Viewer.hxx> |
43 | #include <V2d_View.hxx> |
44 | #include <V2d.hxx> |
45 | |
46 | #include <Viewer2dTest_DoubleMapOfInteractiveAndName.hxx> |
47 | #include <Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
48 | #include <Viewer2dTest_EventManager.hxx> |
49 | |
50 | #include <BRepTools.hxx> |
51 | #include <BRep_Tool.hxx> |
52 | #include <BRep_Builder.hxx> |
53 | #include <BRepAdaptor_Curve.hxx> |
54 | #include <BRepAdaptor_Surface.hxx> |
55 | |
56 | #include <TopoDS.hxx> |
57 | #include <TopoDS_Solid.hxx> |
58 | #include <TopoDS_Vertex.hxx> |
59 | #include <TopoDS_Shape.hxx> |
60 | #include <TopoDS_Face.hxx> |
61 | #include <TopoDS_Edge.hxx> |
62 | |
63 | #include <TopAbs.hxx> |
64 | #include <TopAbs_ShapeEnum.hxx> |
65 | #include <TopExp.hxx> |
66 | #include <TopExp_Explorer.hxx> |
67 | |
68 | #include <Draw_Window.hxx> |
69 | |
70 | #include <AIS2D_ProjShape.hxx> |
71 | #include <AIS2D_InteractiveContext.hxx> |
72 | |
73 | #include <Graphic2d_InfiniteLine.hxx> |
74 | #include <Graphic2d_Circle.hxx> |
75 | |
76 | #include <Geom2d_Line.hxx> |
77 | #include <Geom2d_CartesianPoint.hxx> |
78 | |
79 | #include <Geom_Line.hxx> |
80 | #include <Geom_Plane.hxx> |
81 | #include <Geom_Axis2Placement.hxx> |
82 | #include <Geom_Axis1Placement.hxx> |
83 | #include <Geom_CartesianPoint.hxx> |
84 | |
85 | #include <gp_Pln.hxx> |
86 | #include <gp_Circ.hxx> |
87 | |
88 | #include <GC_MakePlane.hxx> |
89 | |
90 | extern Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D(); |
91 | Standard_IMPORT int ViewerMainLoop2d (Standard_Integer argc, const char** argv); |
92 | extern Handle(AIS2D_InteractiveContext)& TheAIS2DContext(); |
93 | |
94 | //============================================================================== |
95 | //function : SelectShape2d |
96 | //purpose : |
97 | //============================================================================== |
98 | TopoDS_Shape SelectShape2d (int theSelType) |
99 | { |
100 | TopoDS_Shape ShapeA; |
101 | |
102 | // if (theSelType != 5) |
103 | // TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(theSelType)); |
104 | |
105 | switch (theSelType) |
106 | { |
107 | case 1: |
108 | cout << " Select a vertex ..." << endl; |
109 | break; |
110 | case 2: |
111 | cout << " Select an edge ..." << endl; |
112 | break; |
113 | case 4: |
114 | cout << " Select a face ..." << endl; |
115 | break; |
116 | case 5: // user defined text |
117 | break; |
118 | default: |
119 | cout << " Incorrect selection mode" << endl; |
120 | break; |
121 | } |
122 | |
123 | Standard_Integer argcc = 5; |
124 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
125 | const char **argvv = (const char **) buff; |
126 | while (ViewerMainLoop2d(argcc, argvv)) {} |
127 | |
128 | /* for (TheAIS2DContext()->InitSelected(); |
129 | TheAIS2DContext()->MoreSelected(); |
130 | TheAIS2DContext()->NextSelected()) |
131 | { |
132 | ShapeA = TheAIS2DContext()->SelectedShape(); |
133 | }*/ |
134 | |
135 | // if (theSelType != 5) |
136 | // TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(theSelType)); |
137 | |
138 | return ShapeA; |
139 | } |
140 | #if 0 |
141 | //============================================================================== |
142 | //function : V2dTrihedron2D |
143 | //purpose : Create a plane with a 2D trihedron from a faceselection |
144 | //Draw arg : v2dtri2d name |
145 | //============================================================================== |
146 | static int V2dTrihedron2D (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
147 | { |
148 | if (argc != 2) |
149 | { |
150 | cout << argv[0] << " wrong arguments number" << endl; |
151 | return 1; |
152 | } |
153 | |
154 | // Declarations |
155 | Standard_Integer myCurrentIndex; |
156 | |
157 | // Fermeture des contextes |
158 | TheAIS2DContext()->CloseAllContext(); |
159 | |
160 | // Ouverture d'un contexte local et recuperation de son index. |
161 | TheAIS2DContext()->OpenLocalContext(); |
162 | myCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
163 | |
164 | TopoDS_Shape ShapeB = SelectShape2d(4); // Face |
165 | TopoDS_Face FaceB = TopoDS::Face(ShapeB); |
166 | |
167 | // Construction du Plane |
168 | // recuperation des edges des faces. |
169 | TopExp_Explorer FaceExpB (FaceB, TopAbs_EDGE); |
170 | |
171 | TopoDS_Edge EdgeB = TopoDS::Edge(FaceExpB.Current()); |
172 | |
173 | // declarations |
174 | gp_Pnt A,B,C; |
175 | |
176 | // si il y a plusieurs edges |
177 | if (FaceExpB.More()) |
178 | { |
179 | FaceExpB.Next(); |
180 | TopoDS_Edge EdgeC = TopoDS::Edge(FaceExpB.Current()); |
181 | BRepAdaptor_Curve theCurveB (EdgeB); |
182 | BRepAdaptor_Curve theCurveC (EdgeC); |
183 | A = theCurveC.Value(0.1); |
184 | B = theCurveC.Value(0.9); |
185 | C = theCurveB.Value(0.5); |
186 | } |
187 | else |
188 | { |
189 | // FaceB a 1 unique edge courbe |
190 | BRepAdaptor_Curve theCurveB (EdgeB); |
191 | A = theCurveB.Value(0.1); |
192 | B = theCurveB.Value(0.9); |
193 | C = theCurveB.Value(0.5); |
194 | } |
195 | // Construction du Geom_Plane |
196 | GC_MakePlane MkPlane (A,B,C); |
197 | Handle(Geom_Plane) theGeomPlane = MkPlane.Value(); |
198 | |
199 | // Construction de l'AIS2D_PlaneTrihedron |
200 | // Handle(AIS2D_PlaneTrihedron) theAIS2DPlaneTri = new AIS2D_PlaneTrihedron(theGeomPlane); |
201 | |
202 | // Fermeture du contexte local. |
203 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
204 | |
205 | // on le display & bind |
206 | // TheAIS2DContext()->Display(theAIS2DPlaneTri); |
207 | // GetMapOfAIS2D().Bind(theAIS2DPlaneTri, argv[1]); |
208 | |
209 | return 0; |
210 | } |
211 | #endif |
212 | |
213 | //============================================================================== |
214 | //function : V2dTrihedron |
215 | //purpose : Create a trihedron. If no arguments are set, the default |
216 | // trihedron (Oxyz) is created. |
217 | //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] |
218 | //============================================================================== |
219 | /*static int V2dTrihedron (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
220 | { |
221 | // Verification des arguments |
222 | if (argc < 2 || argc > 11) |
223 | { |
224 | cout << argv[0] << " Syntaxe error" << endl; |
225 | return 1; |
226 | } |
227 | |
228 | TCollection_AsciiString name = argv[1]; |
229 | |
230 | if (argc > 5 && argc != 11) |
231 | { |
232 | cout << argv[0] << " Syntaxe error" << endl; |
233 | return 1; |
234 | } |
235 | |
236 | Standard_Real coord[9] = {0.,0.,0.,0.,0.,1.,1.,0.,0.}; |
237 | if (argc > 2) |
238 | { |
239 | Standard_Integer i; |
240 | for (i = 0; i <= 2; i++) |
241 | coord[i] = atof(argv[2+i]); |
242 | |
243 | if (argc > 5) |
244 | { |
245 | for (i = 0; i <= 2; i++) |
246 | { |
247 | coord[3+i] = atof(argv[6+i]); |
248 | coord[6+i] = atof(argv[8+i]); |
249 | } |
250 | } |
251 | } |
252 | gp_Pnt ThePoint (coord[0],coord[1],coord[2]); |
253 | gp_Dir TheZVector (coord[3],coord[4],coord[5]); |
254 | gp_Dir TheXVector (coord[6],coord[7],coord[8]); |
255 | |
c6541a0c |
256 | if (!TheZVector.IsNormal(TheXVector,M_PI/180)) |
7fd59977 |
257 | { |
258 | cout << argv[0] << " VectorX is not normal to VectorZ" << endl; |
259 | return 1; |
260 | } |
261 | |
262 | Handle(Geom_Axis2Placement) OrigineAndAxii = new Geom_Axis2Placement(ThePoint,TheZVector,TheXVector); |
263 | |
264 | // Creation du triedre |
265 | Handle(AIS2D_Trihedron) aShape = new AIS2D_Trihedron(OrigineAndAxii); |
266 | GetMapOfAIS2D().Bind(aShape,name); |
267 | TheAIS2DContext()->Display(aShape); |
268 | |
269 | return 0; |
270 | }*/ |
271 | #if 0 |
272 | //============================================================================== |
273 | //function : V2dSize |
274 | //purpose : Change the size of a named or selected trihedron |
275 | // if no name : it affects the trihedrons witch are selected otherwise nothing is donne |
276 | // if no value, the value is set at 100 by default |
277 | //Draw arg : v2dsize [name] [size] |
278 | //============================================================================== |
279 | static int V2dSize (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
280 | { |
281 | Standard_Boolean ThereIsName; |
282 | Standard_Real value; |
283 | // Quantity_NameOfColor col = Quantity_NOC_BLACK; |
284 | |
285 | if (argc > 3) |
286 | { |
287 | cout << argv[0] << " Syntaxe error" << endl; |
288 | return 1; |
289 | } |
290 | |
291 | if (argc == 1) |
292 | { |
293 | ThereIsName = Standard_False; |
294 | value = 100; |
295 | } |
296 | else if (argc == 2) |
297 | { |
298 | ThereIsName = Standard_False; |
299 | value = atof(argv[1]); |
300 | } |
301 | else |
302 | { |
303 | ThereIsName = Standard_True; |
304 | value = atof(argv[2]); |
305 | } |
306 | |
307 | if (TheAIS2DContext()->HasOpenedContext()) TheAIS2DContext()->CloseLocalContext(); |
308 | |
309 | if (!ThereIsName) |
310 | { |
311 | // if (TheAIS2DContext()->NbCurrents() <= 0) return -1; |
312 | Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D()); |
313 | |
314 | while (it.More()) |
315 | { |
316 | Handle(AIS2D_InteractiveObject) aShape = it.Key1(); |
317 | |
318 | if (TheAIS2DContext()->IsCurrent(aShape)) |
319 | { |
320 | /* if (aShape->Type() == AIS2D_KOI_Datum && aShape->Signature() == 3) |
321 | { |
322 | if (aShape->HasColor()) |
323 | { |
324 | hascol = Standard_True; |
325 | col = aShape->Color(); |
326 | } |
327 | else hascol = Standard_False; |
328 | |
329 | Handle(AIS2D_Trihedron) aTrihedron = *(Handle(AIS2D_Trihedron)*) &aShape; |
330 | |
331 | aTrihedron->SetSize(value); |
332 | |
333 | if (hascol) aTrihedron->SetColor(col); |
334 | else aTrihedron->UnsetColor(); |
335 | |
336 | // The trihedron hasn't be errased from the map |
337 | // so you just have to redisplay it |
338 | TheAIS2DContext()->Redisplay(aTrihedron, Standard_False); |
339 | }*/ |
340 | } |
341 | it.Next(); |
342 | } |
343 | TheAIS2DContext()->UpdateCurrentViewer(); |
344 | } |
345 | else |
346 | { |
347 | TCollection_AsciiString name = argv[1]; |
348 | |
349 | if (GetMapOfAIS2D().IsBound2(name)) |
350 | { |
351 | Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name); |
352 | |
353 | /* if (aShape->Type() == AIS2D_KOI_Datum && aShape->Signature() == 3) |
354 | { |
355 | if (aShape->HasColor()) |
356 | { |
357 | hascol = Standard_True; |
358 | col = aShape->Color(); |
359 | } |
360 | else hascol = Standard_False; |
361 | |
362 | // On downcast aShape de AIS2D_InteractiveObject a AIS2D_Trihedron |
363 | // pour lui appliquer la methode SetSize() |
364 | Handle(AIS2D_Trihedron) aTrihedron = *(Handle(AIS2D_Trihedron)*) &aShape; |
365 | |
366 | aTrihedron->SetSize(value); |
367 | |
368 | if (hascol) aTrihedron->SetColor(col); |
369 | else aTrihedron->UnsetColor(); |
370 | |
371 | // The trihedron hasn't be errased from the map |
372 | // so you just have to redisplay it |
373 | TheAIS2DContext()->Redisplay(aTrihedron, Standard_False); |
374 | |
375 | TheAIS2DContext()->UpdateCurrentViewer(); |
376 | }*/ |
377 | } |
378 | } |
379 | return 0; |
380 | } |
381 | #endif |
382 | |
383 | //============================================================================== |
384 | //function : V2dPlaneTrihedron |
385 | //purpose : Create a plane from a trihedron selection. If no arguments are set, the default |
386 | //Draw arg : v2dplanetri name |
387 | //============================================================================== |
388 | /*static int V2dPlaneTrihedron (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
389 | { |
390 | if (argc != 2) |
391 | { |
392 | cout << argv[0] << " error" << endl; |
393 | return 1; |
394 | } |
395 | |
396 | Standard_Integer myCurrentIndex; |
397 | TheAIS2DContext()->CloseAllContexts(); |
398 | TheAIS2DContext()->OpenLocalContext(Standard_False); |
399 | myCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
400 | |
401 | Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D()); |
402 | while (it.More()) |
403 | { |
404 | Handle(AIS2D_InteractiveObject) ShapeA = it.Key1(); |
405 | if (ShapeA->Type() == AIS2D_KOI_Datum && ShapeA->Signature() == 3) |
406 | { |
407 | Handle(AIS2D_Trihedron) TrihedronA = ((*(Handle(AIS2D_Trihedron)*)&ShapeA)); |
408 | TheAIS2DContext()->Load(TrihedronA,0,Standard_False); |
409 | TheAIS2DContext()->Activate(TrihedronA,3); |
410 | } |
411 | it.Next(); |
412 | } |
413 | |
414 | cout<<" Select a plane."<<endl; |
415 | Standard_Integer argccc = 5; |
416 | char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
417 | char **argvvv = bufff; |
418 | while (ViewerMainLoop2d(argccc, argvvv)) {} |
419 | |
420 | Handle(AIS2D_InteractiveObject) theIOB; |
421 | for (TheAIS2DContext()->InitSelected(); |
422 | TheAIS2DContext()->MoreSelected(); TheAIS2DContext()->NextSelected()) |
423 | { |
424 | theIOB = TheAIS2DContext()->Interactive(); |
425 | } |
426 | Handle(AIS2D_Plane) PlaneB = ((*(Handle(AIS2D_Plane)*)&theIOB)); |
427 | |
428 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
429 | |
430 | // Construction de l'AIS2D_Plane |
431 | //gp_Pnt A,B,C; |
432 | //Handle(Geom_Plane) theGeomPlane; |
433 | //PlaneB->PlaneAttributes(theGeomPlane,A,B,C); |
434 | //Handle(AIS2D_PlaneTrihedron) theAIS2DPlaneTri= new AIS2D_PlaneTrihedron(theGeomPlane ); |
435 | |
436 | // on le display & bind |
437 | TheAIS2DContext()->Display(PlaneB); |
438 | GetMapOfAIS2D().Bind(PlaneB, argv[1]); |
439 | |
440 | return 0; |
441 | }*/ |
442 | |
443 | //============================================================================== |
444 | // Fonction First click 2de click |
445 | // |
446 | // v2daxis vertex vertex |
447 | // edge None |
448 | // v2daxispara edge vertex |
449 | // v2daxisortho edge Vertex |
450 | // v2daxisinter Face Face |
451 | //============================================================================== |
452 | |
453 | //============================================================================== |
454 | //function : V2dAxisBuilder |
455 | //purpose : |
456 | //Draw arg : v2daxis AxisName Xa Ya Xb Yb |
457 | //============================================================================== |
458 | static int V2dAxisBuilder (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
459 | { |
460 | Standard_Boolean HasArg; |
461 | TCollection_AsciiString name; |
462 | Standard_Integer MyCurrentIndex; |
463 | |
464 | if (argc < 2 || argc > 6) |
465 | { |
466 | cout << " Syntaxe error" << endl; |
467 | return 1; |
468 | } |
469 | if (argc == 6) HasArg = Standard_True; |
470 | else HasArg = Standard_False; |
471 | |
472 | name = argv[1]; |
473 | TheAIS2DContext()->CloseAllContext(); |
474 | |
475 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
476 | |
477 | if (HasArg) |
478 | { |
479 | Standard_Real coord [4]; |
480 | for (Standard_Integer i = 0; i <= 3; i++) |
481 | { |
482 | coord[i] = atof(argv[2+i]); |
483 | } |
484 | // gp_Pnt2d p1 (coord[0],coord[1]); |
485 | // gp_Pnt2d p2 (coord[2],coord[3]); |
486 | |
487 | Handle(Graphic2d_GraphicObject) obj = |
488 | new Graphic2d_GraphicObject(V->View()); |
489 | |
490 | Handle(Graphic2d_InfiniteLine) line = new Graphic2d_InfiniteLine |
491 | (obj, coord[0], coord[1], coord[2] - coord[0], coord[3] - coord[1]); |
492 | |
493 | obj->Display(); |
494 | V->Viewer()->Update(); |
495 | // gp_Vec2d myVect (p1, p2); |
496 | // Handle(Geom2d_Line) myLine = new Geom2d_Line(p1, myVect); |
497 | // Handle(AIS2D_Axis) TheAxis = new AIS2D_Axis(myLine); |
498 | // GetMapOfAIS2D().Bind(TheAxis,name); |
499 | // TheAIS2DContext()->Display(TheAxis); |
500 | } |
501 | else |
502 | { |
503 | // fonction vaxis |
504 | // Purpose: Teste le constructeur AIS2D_Axis::AIS2D_Axis (x:Axis1Placement from Geom) |
505 | if (!strcasecmp(argv[0], "v2daxis")) |
506 | { |
507 | TheAIS2DContext()->OpenLocalContext(); |
508 | MyCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
509 | |
510 | // Active le mode edge et le mode vertex |
511 | // TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(1)); |
512 | // TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(2)); |
513 | cout << " Select an edge or a vertex." << endl; |
514 | |
515 | TopoDS_Shape ShapeA = SelectShape2d(5); |
516 | |
517 | if (ShapeA.ShapeType() == TopAbs_VERTEX) |
518 | { |
519 | // TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(2)); |
520 | cout << " Select a different vertex." << endl; |
521 | |
522 | TopoDS_Shape ShapeB; |
523 | do |
524 | { |
525 | ShapeB = SelectShape2d(5); |
526 | } while (ShapeB.IsSame(ShapeA)); |
527 | |
528 | TheAIS2DContext()->CloseLocalContext(MyCurrentIndex); |
529 | |
530 | // Construction de l'axe |
531 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)); |
532 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); |
533 | gp_Vec aV (A,B); |
534 | gp_Dir D (aV); |
535 | Handle(Geom_Axis1Placement) OrigineAndVect = new Geom_Axis1Placement(A,D); |
536 | // Handle(AIS2D_Axis) TheAxis = new AIS2D_Axis(OrigineAndVect); |
537 | // GetMapOfAIS2D().Bind(TheAxis,name); |
538 | // TheAIS2DContext()->Display(TheAxis); |
539 | } |
540 | else |
541 | { |
542 | // Un unique edge (ShapeA) a ete picke |
543 | // Fermeture du context local |
544 | TheAIS2DContext()->CloseLocalContext(MyCurrentIndex); |
545 | // Constuction de l'axe |
546 | TopoDS_Edge ed = TopoDS::Edge(ShapeA); |
547 | TopoDS_Vertex Va,Vb; |
548 | TopExp::Vertices(ed,Va,Vb ); |
549 | gp_Pnt A = BRep_Tool::Pnt(Va); |
550 | gp_Pnt B = BRep_Tool::Pnt(Vb); |
551 | gp_Vec aV (A,B); |
552 | gp_Dir D (aV); |
553 | Handle(Geom_Axis1Placement) OrigineAndVect = new Geom_Axis1Placement(A,D); |
554 | // Handle(AIS2D_Axis) TheAxis = new AIS2D_Axis(OrigineAndVect); |
555 | // GetMapOfAIS2D().Bind(TheAxis,name); |
556 | // TheAIS2DContext()->Display(TheAxis); |
557 | } |
558 | } |
559 | |
560 | // Fonction axispara |
561 | // Purpose: Teste le constructeur AIS2D_Axis::AIS2D_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS2D) |
562 | else if (!strcasecmp(argv[0], "v2daxispara")) |
563 | { |
564 | TheAIS2DContext()->OpenLocalContext(); |
565 | MyCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
566 | |
567 | TopoDS_Shape ShapeA = SelectShape2d(2); // Edge |
568 | TopoDS_Shape ShapeB = SelectShape2d(1); // Vertex |
569 | |
570 | // Fermeture du context local |
571 | TheAIS2DContext()->CloseLocalContext(MyCurrentIndex); |
572 | |
573 | // Construction de l'axe |
574 | TopoDS_Edge ed = TopoDS::Edge(ShapeA); |
575 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); |
576 | TopoDS_Vertex Va,Vc; |
577 | TopExp::Vertices(ed,Va,Vc); |
578 | gp_Pnt A = BRep_Tool::Pnt(Va); |
579 | gp_Pnt C = BRep_Tool::Pnt(Vc); |
580 | gp_Vec aV (A,C); |
581 | gp_Dir D (aV); |
582 | Handle(Geom_Axis1Placement) OrigineAndVect = new Geom_Axis1Placement(B,D); |
583 | // Handle(AIS2D_Axis) TheAxis = new AIS2D_Axis(OrigineAndVect); |
584 | // GetMapOfAIS2D().Bind(TheAxis,name); |
585 | // TheAIS2DContext()->Display(TheAxis); |
586 | } |
587 | else // Fonction axisortho |
588 | { |
589 | TheAIS2DContext()->OpenLocalContext(); |
590 | MyCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
591 | |
592 | TopoDS_Shape ShapeA = SelectShape2d(2); // Edge |
593 | TopoDS_Shape ShapeB = SelectShape2d(1); // Vertex |
594 | |
595 | // Fermeture du context local |
596 | TheAIS2DContext()->CloseLocalContext(MyCurrentIndex); |
597 | |
598 | // Construction de l'axe |
599 | TopoDS_Edge ed = TopoDS::Edge(ShapeA); |
600 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); |
601 | TopoDS_Vertex Va,Vc; |
602 | TopExp::Vertices(ed,Va,Vc); |
603 | gp_Pnt A = BRep_Tool::Pnt(Va); |
604 | gp_Pnt C = BRep_Tool::Pnt(Vc); |
605 | gp_Pnt E (A.Y()+A.Z()-C.Y()-C.Z(), C.X()-A.X(), C.X()-A.X()); |
606 | // W = AE est un vecteur orthogonal a AC |
607 | gp_Vec aV (A,E); |
608 | gp_Dir D (aV); |
609 | Handle(Geom_Axis1Placement) OrigineAndVect = new Geom_Axis1Placement(B,D); |
610 | // Handle(AIS2D_Axis) TheAxis = new AIS2D_Axis(OrigineAndVect); |
611 | // GetMapOfAIS2D().Bind(TheAxis,name); |
612 | // TheAIS2DContext()->Display(TheAxis); |
613 | } |
614 | } |
615 | |
616 | return 0; |
617 | } |
618 | |
619 | //============================================================================== |
620 | // Fonction First click Result |
621 | // |
622 | // vpoint vertex AIS2D_Point=Vertex |
623 | // edge AIS2D_Point=Middle of the edge |
624 | //============================================================================== |
625 | |
626 | #if 0 |
627 | //============================================================================== |
628 | //function : V2dPointBuilder |
629 | //purpose : Build an AIS2D_Point from coordinates or with a selected vertex or edge |
630 | //Draw arg : v2dpoint PoinName [Xa] [Ya] |
631 | //============================================================================== |
632 | static int V2dPointBuilder (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
633 | { |
634 | // Declarations |
635 | Standard_Boolean HasArg; |
636 | TCollection_AsciiString name; |
637 | Standard_Integer myCurrentIndex; |
638 | |
639 | // Verification |
640 | if (argc < 2 || argc > 4 ) |
641 | { |
642 | cout << " Syntaxe error" << endl; |
643 | return 1; |
644 | } |
645 | if (argc == 4) HasArg = Standard_True; |
646 | else HasArg = Standard_False; |
647 | |
648 | name = argv[1]; |
649 | // Fermeture des contextes |
650 | TheAIS2DContext()->CloseAllContext(); |
651 | |
652 | // Il y a des arguments: teste l'unique constructeur AIS2D_Pnt::AIS2D_Pnt(Point from Geom) |
653 | if (HasArg) |
654 | { |
655 | Standard_Real thecoord[3]; |
656 | for (Standard_Integer i = 0; i <= 2; i++) thecoord[i] = atof(argv[2+i]); |
657 | Handle(Geom2d_CartesianPoint) myGeomPoint = new Geom2d_CartesianPoint(thecoord[0],thecoord[1]); |
658 | // Handle(AIS2D_Point) myAIS2DPoint = new AIS2D_Point(myGeomPoint); |
659 | // GetMapOfAIS2D().Bind(myAIS2DPoint, name); |
660 | // TheAIS2DContext()->Display(myAIS2DPoint); |
661 | } |
662 | else // Il n'a pas d'arguments |
663 | { |
664 | TheAIS2DContext()->OpenLocalContext(); |
665 | myCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
666 | |
667 | // TheAIS2DContext()->ActivateStandardMode (AIS2D_ProjShape::SelectionType(1)); |
668 | // TheAIS2DContext()->ActivateStandardMode (AIS2D_ProjShape::SelectionType(2)); |
669 | cout << " Select a vertex or an edge (build the middle)" << endl; |
670 | TopoDS_Shape ShapeA = SelectShape2d(5); |
671 | |
672 | if (ShapeA.ShapeType() == TopAbs_VERTEX) |
673 | { |
674 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
675 | |
676 | // Construction du point |
677 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)); |
678 | Handle(Geom_CartesianPoint) myGeomPoint = new Geom_CartesianPoint(A); |
679 | // Handle(AIS2D_Point) myAIS2DPoint = new AIS2D_Point(myGeomPoint); |
680 | // GetMapOfAIS2D().Bind(myAIS2DPoint,name); |
681 | // TheAIS2DContext()->Display(myAIS2DPoint); |
682 | } |
683 | else |
684 | { |
685 | // Un Edge a ete selectionne |
686 | // Fermeture du context local |
687 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
688 | |
689 | // Construction du point milieu de l'edge |
690 | TopoDS_Edge myEdge = TopoDS::Edge(ShapeA); |
691 | TopoDS_Vertex myVertexA,myVertexB; |
692 | TopExp::Vertices (myEdge, myVertexA, myVertexB); |
693 | gp_Pnt A = BRep_Tool::Pnt(myVertexA); |
694 | gp_Pnt B = BRep_Tool::Pnt(myVertexB); |
695 | |
696 | Handle(Geom_CartesianPoint) myGeomPointM = |
697 | new Geom_CartesianPoint((A.X()+B.X())/2, (A.Y()+B.Y())/2, (A.Z()+B.Z())/2); |
698 | // Handle(AIS2D_Point) myAIS2DPointM = new AIS2D_Point(myGeomPointM); |
699 | // GetMapOfAIS2D().Bind(myAIS2DPointM, name); |
700 | // TheAIS2DContext()->Display(myAIS2DPointM); |
701 | } |
702 | } |
703 | |
704 | return 0; |
705 | } |
706 | #endif |
707 | |
708 | //============================================================================== |
709 | // Fonction 1st click 2de click 3de click |
710 | // v2dplane Vertex Vertex Vertex |
711 | // Vertex Edge |
712 | // Edge Vertex |
713 | // Face |
714 | // v2dplanepara Face Vertex |
715 | // Vertex Face |
716 | // v2dplaneortho Face Edge |
717 | // Edge Face |
718 | //============================================================================== |
719 | |
720 | //============================================================================== |
721 | //function : V2dPlaneBuilder |
722 | //purpose : Build an AIS2D_Plane from selected entities or Named AIs components |
723 | //Draw arg : v2dplane PlaneName [AxisName] [PointName] |
724 | // [PointName] [PointName] [PointName] |
725 | // [PlaneName] [PointName] |
726 | //============================================================================== |
727 | /*#include <BRepExtrema_ExtPC.hxx> |
728 | #include <BRepExtrema_ExtPF.hxx> |
729 | #include <BRepAdaptor_Surface.hxx> |
730 | #include <gp_Pln.hxx> |
731 | #include <GC_MakePlane.hxx> |
732 | static int V2dPlaneBuilder (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
733 | { |
734 | Standard_Boolean HasArg; |
735 | TCollection_AsciiString name; |
736 | Standard_Integer myCurrentIndex; |
737 | |
738 | if (argc < 2 || argc > 5) |
739 | { |
740 | cout << " Syntaxe error" << endl; |
741 | return 1; |
742 | } |
743 | |
744 | if (argc == 5 || argc == 4) HasArg = Standard_True; |
745 | else HasArg = Standard_False; |
746 | |
747 | name = argv[1]; |
748 | TheAIS2DContext()->CloseAllContexts(); |
749 | |
750 | if (HasArg) |
751 | { |
752 | if (!GetMapOfAIS2D().IsBound2(argv[2])) |
753 | { |
754 | cout << "v2dplane: error 1st name doesn't exist in the GetMapOfAIS2D()." << endl; |
755 | return 1; |
756 | } |
757 | Handle(AIS2D_InteractiveObject) theShapeA = GetMapOfAIS2D().Find2(argv[2]); |
758 | |
759 | if (theShapeA->Type() == AIS2D_KOI_Datum && theShapeA->Signature() == 1) |
760 | { |
761 | if (argc < 5 || !GetMapOfAIS2D().IsBound2(argv[3])) |
762 | { |
763 | cout << "v2dplane: error 2de name doesn't exist in the GetMapOfAIS2D()." << endl; |
764 | return 1; |
765 | } |
766 | Handle(AIS2D_InteractiveObject) theShapeB = GetMapOfAIS2D().Find2(argv[3]); |
767 | if (!(theShapeB->Type() == AIS2D_KOI_Datum && theShapeB->Signature() == 1)) |
768 | { |
769 | cout << "v2dplane: error 2de object is expected to be an AIS2D_Point. " << endl; |
770 | return 1; |
771 | } |
772 | if (!GetMapOfAIS2D().IsBound2(argv[4])) |
773 | { |
774 | cout << "v2dplane: error 3de name doesn't exist in the GetMapOfAIS2D()." << endl; |
775 | return 1; |
776 | } |
777 | Handle(AIS2D_InteractiveObject) theShapeC = GetMapOfAIS2D().Find2(argv[4]); |
778 | if (!(theShapeC->Type() == AIS2D_KOI_Datum && theShapeC->Signature() == 1)) |
779 | { |
780 | cout << "v2dplane: error 3de object is expected to be an AIS2D_Point. " << endl; |
781 | return 1; |
782 | } |
783 | |
784 | Handle(AIS2D_Point) theAIS2DPointA = *(Handle(AIS2D_Point)*)& theShapeA; |
785 | Handle(AIS2D_Point) theAIS2DPointB = *(Handle(AIS2D_Point)*)& theShapeB; |
786 | Handle(AIS2D_Point) theAIS2DPointC = *(Handle(AIS2D_Point)*)& theShapeC; |
787 | |
788 | Handle(Geom_Point) myGeomPointA = theAIS2DPointA->Component(); |
789 | Handle(Geom_CartesianPoint) myCartPointA = *((Handle(Geom_CartesianPoint)*)& myGeomPointA); |
790 | |
791 | Handle(Geom_Point) myGeomPointB = theAIS2DPointB->Component(); |
792 | Handle(Geom_CartesianPoint) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAIS2DPointB); |
793 | |
794 | Handle(Geom_Point) myGeomPointBC = theAIS2DPointC->Component(); |
795 | Handle(Geom_CartesianPoint) myCartPointC = *((Handle(Geom_CartesianPoint)*)& theAIS2DPointC); |
796 | |
797 | if (myCartPointB->X() == myCartPointA->X() && |
798 | myCartPointB->Y() == myCartPointA->Y() && myCartPointB->Z() == myCartPointA->Z()) |
799 | { |
800 | // B=A |
801 | cout << "v2dplane error: same points" << endl; |
802 | return 1; |
803 | } |
804 | if (myCartPointC->X() == myCartPointA->X() && |
805 | myCartPointC->Y() == myCartPointA->Y() && myCartPointC->Z() == myCartPointA->Z()) |
806 | { |
807 | // C=A |
808 | cout << "v2dplane error: same points" << endl; |
809 | return 1; |
810 | } |
811 | if (myCartPointC->X() == myCartPointB->X() && |
812 | myCartPointC->Y() == myCartPointB->Y() && myCartPointC->Z() == myCartPointB->Z()) |
813 | { |
814 | // C=B |
815 | cout << "v2dplane error: same points" << endl; |
816 | return 1; |
817 | } |
818 | |
819 | gp_Pnt A = myCartPointA->Pnt(); |
820 | gp_Pnt B = myCartPointB->Pnt(); |
821 | gp_Pnt C = myCartPointC->Pnt(); |
822 | |
823 | // Construction de l'AIS2D_Plane |
824 | GC_MakePlane MkPlane (A,B,C); |
825 | Handle(Geom_Plane) myGeomPlane = MkPlane.Value(); |
826 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(myGeomPlane); |
827 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
828 | TheAIS2DContext()->Display(myAIS2DPlane); |
829 | } |
830 | |
831 | else if (theShapeA->Type() == AIS2D_KOI_Datum && theShapeA->Signature() == 2) |
832 | { |
833 | if (argc != 4 || !GetMapOfAIS2D().IsBound2(argv[3])) |
834 | { |
835 | cout << "v2dplane: error 2de name doesn't exist in the GetMapOfAIS2D()." << endl; |
836 | return 1; |
837 | } |
838 | Handle(AIS2D_InteractiveObject) theShapeB = GetMapOfAIS2D().Find2(argv[3]); |
839 | if (!(theShapeB->Type() == AIS2D_KOI_Datum && theShapeB->Signature() == 1)) |
840 | { |
841 | cout << "v2dplane: error 2de object is expected to be an AIS2D_Point." << endl; |
842 | return 1; |
843 | } |
844 | |
845 | Handle(AIS2D_Axis) theAIS2DAxisA = *(Handle(AIS2D_Axis)*)& theShapeA; |
846 | Handle(AIS2D_Point) theAIS2DPointB = *(Handle(AIS2D_Point)*)& theShapeB; |
847 | |
848 | Handle(Geom_Line) myGeomLineA = theAIS2DAxisA->Component(); |
849 | Handle(Geom_Point) myGeomPointB = theAIS2DPointB->Component(); |
850 | |
851 | gp_Ax1 myAxis = myGeomLineA->Position(); |
852 | Handle(Geom_CartesianPoint) myCartPointB = *(Handle(Geom_CartesianPoint)*)& myGeomPointB; |
853 | |
854 | gp_Dir D = myAxis.Direction(); |
855 | gp_Pnt B = myCartPointB->Pnt(); |
856 | |
857 | // Construction de l'AIS2D_Plane |
858 | Handle(Geom_Plane) myGeomPlane = new Geom_Plane(B,D); |
859 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(myGeomPlane,B); |
860 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
861 | TheAIS2DContext()->Display(myAIS2DPlane); |
862 | } |
863 | else if (theShapeA->Type() == AIS2D_KOI_Datum && theShapeA->Signature() == 7) |
864 | { |
865 | if (argc != 4 || !GetMapOfAIS2D().IsBound2(argv[3])) |
866 | { |
867 | cout << "vplane: error 2de name doesn't exist in the GetMapOfAIS2D()." << endl; |
868 | return 1; |
869 | } |
870 | Handle(AIS2D_InteractiveObject) theShapeB = GetMapOfAIS2D().Find2(argv[3]); |
871 | if (!(theShapeB->Type() == AIS2D_KOI_Datum && theShapeB->Signature() == 1)) |
872 | { |
873 | cout << "vplane: error 2de object is expected to be an AIS2D_Point." << endl; |
874 | return 1; |
875 | } |
876 | |
877 | Handle(AIS2D_Plane) theAIS2DPlaneA = *(Handle(AIS2D_Plane)*)& theShapeA; |
878 | Handle(AIS2D_Point) theAIS2DPointB = *(Handle(AIS2D_Point)*)& theShapeB; |
879 | |
880 | Handle(Geom_Plane) theNewGeomPlane = theAIS2DPlaneA->Component(); |
881 | Handle(Geom_Point) myGeomPointB = theAIS2DPointB->Component(); |
882 | |
883 | Handle(Geom_CartesianPoint) myCartPointB = *(Handle(Geom_CartesianPoint)*)& myGeomPointB; |
884 | gp_Pnt B = myCartPointB->Pnt(); |
885 | |
886 | // Construction de l'AIS2D_Plane |
887 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theNewGeomPlane,B); |
888 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
889 | TheAIS2DContext()->Display(myAIS2DPlane); |
890 | } |
891 | else |
892 | { |
893 | cout << "v2dplane: error 1st object is not an AIS2D." << endl; |
894 | return 1; |
895 | } |
896 | } |
897 | else |
898 | { |
899 | if (!strcasecmp(argv[0] ,"v2dplane")) |
900 | { |
901 | TheAIS2DContext()->OpenLocalContext(); |
902 | myCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
903 | |
904 | TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(1)); |
905 | TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(2)); |
906 | cout << "Select a vertex, a face or an edge." << endl; |
907 | ShapeA = SelectShape2d(5); // User-defined mode |
908 | TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
909 | |
910 | if (ShapeA.ShapeType() == TopAbs_VERTEX) |
911 | { |
912 | TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
913 | cout << " Select an edge or a different vertex." << endl; |
914 | TopoDS_Shape ShapeB = SelectShape2d(5); |
915 | |
916 | if (ShapeB.ShapeType() == TopAbs_VERTEX) |
917 | { |
918 | if (ShapeB.IsSame(ShapeA)) |
919 | { |
920 | cout << " v2dplane: error, same points selected" << endl; |
921 | return 1; |
922 | } |
923 | TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(2)); |
924 | cout<<" Select a different vertex."<<endl; |
925 | TopoDS_Shape ShapeC = SelectShape2d(5); |
926 | |
927 | if (ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB)) |
928 | { |
929 | cout << " v2dplane: error, same points selected" << endl; |
930 | return 1; |
931 | } |
932 | |
933 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
934 | |
935 | // Construction du plane |
936 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)); |
937 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); |
938 | gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC)); |
939 | GC_MakePlane MkPlane (A,B,C); |
940 | Handle(Geom_Plane) theGeomPlane = MkPlane.Value(); |
941 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theGeomPlane); |
942 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
943 | TheAIS2DContext()->Display(myAIS2DPlane); |
944 | } |
945 | else // ShapeB est un edge |
946 | { |
947 | TopoDS_Edge EdgeB = TopoDS::Edge(ShapeB); |
948 | TopoDS_Vertex VertA = TopoDS::Vertex(ShapeA); |
949 | |
950 | BRepExtrema_ExtPC OrthoProj (VertA, EdgeB); |
951 | if (OrthoProj.Value(1) < 0.001) |
952 | { |
953 | cout << " v2dplane: error point is on the edge." << endl; |
954 | return 1; |
955 | } |
956 | else |
957 | { |
958 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
959 | // Construction du plane |
960 | gp_Pnt A = BRep_Tool::Pnt(VertA); |
961 | TopoDS_Vertex VBa, VBb; |
962 | TopExp::Vertices(EdgeB, VBa, VBb); |
963 | gp_Pnt Ba = BRep_Tool::Pnt(VBa); |
964 | gp_Pnt Bb = BRep_Tool::Pnt(VBb); |
965 | GC_MakePlane MkPlane (A,Ba,Bb); |
966 | Handle(Geom_Plane) theGeomPlane = MkPlane.Value(); |
967 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theGeomPlane); |
968 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
969 | TheAIS2DContext()->Display(myAIS2DPlane); |
970 | } |
971 | } |
972 | } |
973 | else if (ShapeA.ShapeType() == TopAbs_EDGE) |
974 | { |
975 | TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
976 | TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(2)); |
977 | cout << " Select a vertex that don't belong to the edge." << endl; |
978 | TopoDS_Shape ShapeB = SelectShape2d(5); |
979 | |
980 | TopoDS_Edge EdgeA = TopoDS::Edge(ShapeA); |
981 | TopoDS_Vertex VertB = TopoDS::Vertex(ShapeB); |
982 | |
983 | BRepExtrema_ExtPC OrthoProj (VertB,EdgeA); |
984 | if (OrthoProj.Value(1) < 0.001) |
985 | { |
986 | cout << " v2dplane: error point is on the edge." << endl; |
987 | return 1; |
988 | } |
989 | else |
990 | { |
991 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
992 | // Construction du plane |
993 | gp_Pnt B = BRep_Tool::Pnt(VertB); |
994 | TopoDS_Vertex VAa, VAb; |
995 | TopExp::Vertices(EdgeA, VAa, VAb); |
996 | gp_Pnt Aa = BRep_Tool::Pnt(VAa); |
997 | gp_Pnt Ab = BRep_Tool::Pnt(VAb); |
998 | GC_MakePlane MkPlane (B,Aa,Ab); |
999 | Handle(Geom_Plane) theGeomPlane = MkPlane.Value(); |
1000 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theGeomPlane); |
1001 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
1002 | TheAIS2DContext()->Display(myAIS2DPlane); |
1003 | } |
1004 | } |
1005 | else // ShapeA est une Face |
1006 | { |
1007 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
1008 | // Construction du plane |
1009 | TopoDS_Face myFace = TopoDS::Face(ShapeA); |
1010 | BRepAdaptor_Surface mySurface (myFace, Standard_False); |
1011 | if (mySurface.GetType() == GeomAbs_Plane) |
1012 | { |
1013 | gp_Pln myPlane = mySurface.Plane(); |
1014 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane(myPlane); |
1015 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theGeomPlane); |
1016 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
1017 | TheAIS2DContext()->Display(myAIS2DPlane); |
1018 | } |
1019 | else |
1020 | { |
1021 | cout << " v2dplane: error" << endl; |
1022 | return 1; |
1023 | } |
1024 | } |
1025 | } |
1026 | else if (!strcasecmp(argv[0], "v2dplanepara")) |
1027 | { |
1028 | TheAIS2DContext()->OpenLocalContext(); |
1029 | myCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
1030 | |
1031 | TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(1)); |
1032 | TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
1033 | cout << " Select a vertex or a face." << endl; |
1034 | TopoDS_Shape ShapeA = SelectShape2d(5); |
1035 | |
1036 | if (ShapeA.ShapeType() == TopAbs_VERTEX) |
1037 | { |
1038 | TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(1)); |
1039 | cout<<" Select a face."<<endl; |
1040 | TopoDS_Shape ShapeB = SelectShape2d(5); |
1041 | |
1042 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
1043 | |
1044 | // Construction du plane |
1045 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)); |
1046 | |
1047 | TopoDS_Face myFace = TopoDS::Face(ShapeB); |
1048 | BRepAdaptor_Surface mySurface (myFace, Standard_False); |
1049 | if (mySurface.GetType() == GeomAbs_Plane) |
1050 | { |
1051 | gp_Pln myPlane = mySurface.Plane(); |
1052 | myPlane.SetLocation(A); |
1053 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane(myPlane); |
1054 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theGeomPlane, A); |
1055 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
1056 | TheAIS2DContext()->Display(myAIS2DPlane); |
1057 | } |
1058 | else |
1059 | { |
1060 | cout << " vplane: error" << endl; |
1061 | return 1; |
1062 | } |
1063 | } |
1064 | else |
1065 | { |
1066 | TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
1067 | cout<<" Select a vertex."<<endl; |
1068 | TopoDS_Shape ShapeB = SelectShape2d(5); |
1069 | |
1070 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
1071 | |
1072 | // Construction du plane |
1073 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) ); |
1074 | |
1075 | TopoDS_Face myFace = TopoDS::Face(ShapeA); |
1076 | BRepAdaptor_Surface mySurface (myFace, Standard_False); |
1077 | if (mySurface.GetType() == GeomAbs_Plane) |
1078 | { |
1079 | gp_Pln myPlane = mySurface.Plane(); |
1080 | myPlane.SetLocation(B); |
1081 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane(myPlane); |
1082 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theGeomPlane, B); |
1083 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
1084 | TheAIS2DContext()->Display(myAIS2DPlane); |
1085 | } |
1086 | else |
1087 | { |
1088 | cout << " v2dplane: error" << endl; |
1089 | return 1; |
1090 | } |
1091 | } |
1092 | } |
1093 | else // Fonction v2dplaneortho |
1094 | { |
1095 | TheAIS2DContext()->OpenLocalContext(); |
1096 | myCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
1097 | |
1098 | TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(2)); |
1099 | TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
1100 | cout << " Select a face and an edge coplanar." << endl; |
1101 | TopoDS_Shape ShapeA = SelectShape2d(5); |
1102 | |
1103 | if (ShapeA.ShapeType() == TopAbs_EDGE) |
1104 | { |
1105 | // ShapeA est un edge, on desactive le mode edge... |
1106 | TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(2)); |
1107 | cout<<" Select a face."<<endl; |
1108 | TopoDS_Shape ShapeB = SelectShape2d(5); |
1109 | |
1110 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
1111 | |
1112 | // Construction du plane |
1113 | TopoDS_Edge EdgeA = TopoDS::Edge(ShapeA); |
1114 | TopoDS_Vertex VAa, VAb; |
1115 | |
1116 | TopExp::Vertices(EdgeA, VAa, VAb); |
1117 | gp_Pnt Aa = BRep_Tool::Pnt(VAa); |
1118 | gp_Pnt Ab = BRep_Tool::Pnt(VAb); |
1119 | gp_Vec ab (Aa,Ab); |
1120 | |
1121 | gp_Dir Dab (ab); |
1122 | // Creation de mon axe de rotation |
1123 | gp_Ax1 myRotAxis (Aa,Dab); |
1124 | |
1125 | TopoDS_Face myFace = TopoDS::Face(ShapeB); |
1126 | BRepExtrema_ExtPF myHauteurA (VAa, myFace); |
1127 | BRepExtrema_ExtPF myHauteurB (VAb, myFace); |
1128 | if (fabs(myHauteurA.Value(1) - myHauteurB.Value(1) ) > 0.1) |
1129 | { |
1130 | cout << " v2dplaneOrtho error: l'edge n'est pas parallele a la face." << endl; |
1131 | return 1; |
1132 | } |
1133 | BRepAdaptor_Surface mySurface (myFace, Standard_False); |
1134 | if (mySurface.GetType() == GeomAbs_Plane) |
1135 | { |
1136 | gp_Pln myPlane = mySurface.Plane(); |
c6541a0c |
1137 | myPlane.Rotate(myRotAxis, M_PI/2); |
7fd59977 |
1138 | |
1139 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane(myPlane); |
1140 | gp_Pnt theMiddle ((Aa.X()+Ab.X())/2, (Aa.Y()+Ab.Y())/2, (Aa.Z()+Ab.Z())/2); |
1141 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theGeomPlane, theMiddle); |
1142 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
1143 | TheAIS2DContext()->Display(myAIS2DPlane); |
1144 | |
1145 | } |
1146 | else |
1147 | { |
1148 | cout << " v2dplaneOrtho: error" << endl; |
1149 | return 1; |
1150 | } |
1151 | } |
1152 | else |
1153 | { |
1154 | TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
1155 | cout << " Select an edge." << endl; |
1156 | TopoDS_Shape ShapeB = SelectShape2d(5); |
1157 | |
1158 | // Fermeture du context local |
1159 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
1160 | |
1161 | // Construction du plane |
1162 | TopoDS_Edge EdgeB = TopoDS::Edge(ShapeB); |
1163 | TopoDS_Vertex VBa, VBb; |
1164 | TopExp::Vertices(EdgeB, VBa, VBb); |
1165 | gp_Pnt Ba = BRep_Tool::Pnt(VBa); |
1166 | gp_Pnt Bb = BRep_Tool::Pnt(VBb); |
1167 | gp_Vec ab (Ba,Bb); |
1168 | gp_Dir Dab (ab); |
1169 | // Creation de mon axe de rotation |
1170 | gp_Ax1 myRotAxis (Ba,Dab); |
1171 | |
1172 | TopoDS_Face myFace = TopoDS::Face(ShapeA); |
1173 | BRepExtrema_ExtPF myHauteurA (VBa, myFace); |
1174 | BRepExtrema_ExtPF myHauteurB (VBb, myFace); |
1175 | |
1176 | if (fabs(myHauteurA.Value(1) - myHauteurB.Value(1) ) > 0.1) |
1177 | { |
1178 | cout << " v2dplaneOrtho error: l'edge n'est pas parallele a la face." << endl; |
1179 | return 1; |
1180 | } |
1181 | BRepAdaptor_Surface mySurface (myFace, Standard_False); |
1182 | if (mySurface.GetType() == GeomAbs_Plane) |
1183 | { |
1184 | gp_Pln myPlane = mySurface.Plane(); |
c6541a0c |
1185 | myPlane.Rotate(myRotAxis, M_PI/2); |
7fd59977 |
1186 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane(myPlane); |
1187 | gp_Pnt theMiddle ((Ba.X()+Bb.X())/2, (Ba.Y()+Bb.Y())/2, (Ba.Z()+Bb.Z())/2); |
1188 | Handle(AIS2D_Plane) myAIS2DPlane = new AIS2D_Plane(theGeomPlane, theMiddle); |
1189 | GetMapOfAIS2D().Bind(myAIS2DPlane, name); |
1190 | TheAIS2DContext()->Display(myAIS2DPlane); |
1191 | } |
1192 | else |
1193 | { |
1194 | cout << " v2dplaneOrtho: error" << endl; |
1195 | return 1; |
1196 | } |
1197 | } |
1198 | } |
1199 | } |
1200 | |
1201 | return 0; |
1202 | }*/ |
1203 | |
1204 | //============================================================================== |
1205 | // Fonction vline |
1206 | // --------------- Uniquement par parametre. Pas de selection dans le viewer. |
1207 | //============================================================================== |
1208 | |
1209 | //============================================================================== |
1210 | //function : V2dLineBuilder |
1211 | //purpose : Build a Graphic2d_Line |
1212 | //Draw arg : v2dline LineName [AIS2D_PointName] [AIS2D_PointName] |
1213 | // [Xa] [Ya] [Za] [Xb] [Yb] [Zb] |
1214 | //============================================================================== |
1215 | /*static int V2dLineBuilder(Draw_Interpretor& , Standard_Integer argc, const char** argv) |
1216 | { |
1217 | Standard_Integer myCurrentIndex; |
1218 | if (argc != 4 && argc != 8 && argc != 2) |
1219 | { |
1220 | cout << "vline error: number of arguments not correct " << endl; |
1221 | return 1; |
1222 | } |
1223 | TheAIS2DContext()->CloseAllContext(); |
1224 | |
1225 | // On recupere les parametres |
1226 | Handle(AIS2D_InteractiveObject) theShapeA; |
1227 | Handle(AIS2D_InteractiveObject) theShapeB; |
1228 | |
1229 | // Parametres: AIS2D_Point AIS2D_Point |
1230 | if (argc == 4) |
1231 | { |
1232 | theShapeA = GetMapOfAIS2D().Find2(argv[2] ); |
1233 | if (theShapeA->Type() == AIS2D_KOI_Datum && theShapeA->Signature() == 1) |
1234 | { |
1235 | theShapeB = GetMapOfAIS2D().Find2(argv[3]); |
1236 | if (!(theShapeB->Type() == AIS2D_KOI_Datum && theShapeB->Signature() == 1)) |
1237 | { |
1238 | cout << "v2dline error: wrong type of 2de argument." << endl; |
1239 | return 1; |
1240 | } |
1241 | } |
1242 | else |
1243 | { |
1244 | cout << "v2dline error: wrong type of 1st argument." << endl; |
1245 | return 1; |
1246 | } |
1247 | |
1248 | Handle(AIS2D_Point) theAIS2DPointA = *(Handle(AIS2D_Point)*)& theShapeA; |
1249 | Handle(AIS2D_Point) theAIS2DPointB = *(Handle(AIS2D_Point)*)& theShapeB; |
1250 | |
1251 | Handle(Geom_Point) myGeomPointBA = theAIS2DPointA->Component(); |
1252 | Handle(Geom_CartesianPoint) myCartPointA = *((Handle(Geom_CartesianPoint)*)& myGeomPointBA); |
1253 | |
1254 | Handle(Geom_Point) myGeomPointB = theAIS2DPointB->Component(); |
1255 | Handle(Geom_CartesianPoint) myCartPointB = *((Handle(Geom_CartesianPoint)*)& myGeomPointB); |
1256 | |
1257 | if (myCartPointB->X() == myCartPointA->X() && |
1258 | myCartPointB->Y() == myCartPointA->Y() && myCartPointB->Z() == myCartPointA->Z()) |
1259 | { |
1260 | // B=A |
1261 | cout << "v2dline error: same points" << endl; |
1262 | return 1; |
1263 | } |
1264 | Handle(AIS2D_Line) theAIS2DLine = new AIS2D_Line(myCartPointA, myCartPointB); |
1265 | GetMapOfAIS2D().Bind(theAIS2DLine, argv[1]); |
1266 | TheAIS2DContext()->Display(theAIS2DLine); |
1267 | } |
1268 | else if (argc == 8) // Parametres 6 Reals |
1269 | { |
1270 | Standard_Real coord[6]; |
1271 | for (Standard_Integer i = 0; i <= 2; i++) |
1272 | { |
1273 | coord[i] = atof(argv[2+i]); |
1274 | coord[i+3] = atof(argv[5+i]); |
1275 | } |
1276 | |
1277 | Handle(Geom_CartesianPoint) myCartPointA = new Geom_CartesianPoint(coord[0],coord[1],coord[2]); |
1278 | Handle(Geom_CartesianPoint) myCartPointB = new Geom_CartesianPoint(coord[3],coord[4],coord[5]); |
1279 | |
1280 | Handle(AIS2D_Line) theAIS2DLine = new AIS2D_Line(myCartPointA, myCartPointB); |
1281 | GetMapOfAIS2D().Bind(theAIS2DLine, argv[1]); |
1282 | TheAIS2DContext()->Display(theAIS2DLine); |
1283 | } |
1284 | else |
1285 | { |
1286 | TheAIS2DContext()->OpenLocalContext(); |
1287 | myCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
1288 | |
1289 | // Active le mode Vertex. |
1290 | TopoDS_Shape ShapeA = SelectShape2d(1); |
1291 | |
1292 | if (ShapeA.ShapeType() == TopAbs_VERTEX) |
1293 | { |
1294 | // TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(1)); |
1295 | cout << " Select a different vertex." << endl; |
1296 | |
1297 | TopoDS_Shape ShapeB; |
1298 | do |
1299 | { |
1300 | ShapeB = SelectShape2d(5); |
1301 | } while (ShapeB.IsSame(ShapeA)); |
1302 | |
1303 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
1304 | |
1305 | // Construction de la line |
1306 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)); |
1307 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); |
1308 | |
1309 | Handle(Geom_CartesianPoint) myCartPointA = new Geom_CartesianPoint(A); |
1310 | Handle(Geom_CartesianPoint) myCartPointB = new Geom_CartesianPoint(B); |
1311 | |
1312 | Handle(AIS2D_Line) theAIS2DLine = new AIS2D_Line(myCartPointA, myCartPointB); |
1313 | GetMapOfAIS2D().Bind(theAIS2DLine, argv[1]); |
1314 | TheAIS2DContext()->Display(theAIS2DLine); |
1315 | } |
1316 | else |
1317 | { |
1318 | cout << "v2dline error." << endl; |
1319 | } |
1320 | } |
1321 | |
1322 | return 0; |
1323 | }*/ |
1324 | |
1325 | //============================================================================== |
1326 | //function : V2dCircleBuilder |
1327 | //purpose : Build an Graphic2d_Circle |
1328 | //Draw arg : v2dcircle CircleName X Y Radius [Color_index] |
1329 | //============================================================================== |
1330 | static int V2dCircleBuilder (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
1331 | { |
1332 | Standard_Integer myCurrentIndex; |
1333 | // verification of the arguments |
1334 | if (argc < 2) |
1335 | { |
1336 | cout << "Usage: v2dcircle CircleName X Y Radius [Color_index]" << endl; |
1337 | return 1; |
1338 | } |
1339 | TheAIS2DContext()->CloseAllContext(); |
1340 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1341 | |
1342 | TCollection_AsciiString name = argv[1]; |
1343 | |
1344 | if (argc >= 5) |
1345 | { |
1346 | // Handle(AIS2D_InteractiveObject) theShapeA; |
1347 | // Handle(AIS2D_InteractiveObject) theShapeB; |
1348 | // theShapeA=GetMapOfAIS2D().Find2(argv[2]); |
1349 | // theShapeB=GetMapOfAIS2D().Find2(argv[3]); |
1350 | |
1351 | // Arguments: AIS2D_Point AIS2D_Point AIS2D_Point |
1352 | // ======================================== |
1353 | /* if (theShapeA->Type() == AIS2D_KOI_Datum && theShapeA->Signature() == 1) |
1354 | { |
1355 | if (theShapeB->Type() != AIS2D_KOI_Datum || theShapeB->Signature() != 1) |
1356 | { |
1357 | cout<<"vcircle error: 2de argument is unexpected to be a point."<<endl;return 1; |
1358 | } |
1359 | Handle(AIS2D_InteractiveObject) theShapeC=GetMapOfAIS2D().Find2(argv[4]); |
1360 | if (theShapeC->Type()!=AIS2D_KOI_Datum || theShapeC->Signature()!=1 ) { |
1361 | cout<<"vcircle error: 3de argument is unexpected to be a point."<<endl;return 1; |
1362 | } |
1363 | // tag |
1364 | Handle(AIS2D_Point) theAIS2DPointA = *(Handle(AIS2D_Point)*)& theShapeA; |
1365 | Handle(AIS2D_Point) theAIS2DPointB = *(Handle(AIS2D_Point)*)& theShapeB; |
1366 | Handle(AIS2D_Point) theAIS2DPointC = *(Handle(AIS2D_Point)*)& theShapeC; |
1367 | |
1368 | Handle(Geom_Point) myGeomPointA = theAIS2DPointA->Component(); |
1369 | Handle(Geom_CartesianPoint) myCartPointA = *((Handle(Geom_CartesianPoint)*)& myGeomPointA); |
1370 | |
1371 | Handle(Geom_Point ) myGeomPointB = theAIS2DPointB->Component(); |
1372 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAIS2DPointB); |
1373 | |
1374 | Handle(Geom_Point ) myGeomPointBC= theAIS2DPointC->Component(); |
1375 | Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAIS2DPointC); |
1376 | |
1377 | // Test A=B |
1378 | if (myCartPointA->X()==myCartPointB->X() && myCartPointA->Y()==myCartPointB->Y() && myCartPointA->Z()==myCartPointB->Z() ) { |
1379 | cout<<"vcircle error: Same points."<<endl;return 1; |
1380 | } |
1381 | // Test A=C |
1382 | if (myCartPointA->X()==myCartPointC->X() && myCartPointA->Y()==myCartPointC->Y() && myCartPointA->Z()==myCartPointC->Z() ) { |
1383 | cout<<"vcircle error: Same points."<<endl;return 1; |
1384 | } |
1385 | // Test B=C |
1386 | if (myCartPointB->X()==myCartPointC->X() && myCartPointB->Y()==myCartPointC->Y() && myCartPointB->Z()==myCartPointC->Z() ) { |
1387 | cout<<"vcircle error: Same points."<<endl;return 1; |
1388 | } |
1389 | // Construction du cercle |
1390 | GC_MakeCircle Cir=GC_MakeCircle (myCartPointA->Pnt(),myCartPointB->Pnt(),myCartPointC->Pnt() ); |
1391 | Handle (Geom_Circle) theGeomCircle=Cir.Value(); |
1392 | Handle(AIS2D_Circle) theAIS2DCircle=new AIS2D_Circle(theGeomCircle ); |
1393 | GetMapOfAIS2D().Bind(theAIS2DCircle,argv[1] ); |
1394 | TheAIS2DContext()->Display(theAIS2DCircle ); |
1395 | |
1396 | } |
1397 | // Arguments: ASI_Plane AIS2D_Point Real |
1398 | // =================================== |
1399 | else if (theShapeA->Type()==AIS2D_KOI_Datum && theShapeA->Signature()==7 ) { |
1400 | if (theShapeB->Type()!=AIS2D_KOI_Datum || theShapeB->Signature()!=1 ) { |
1401 | cout<<"vcircle error: 2de element is a unexpected to be a point."<<endl;return 1; |
1402 | } |
1403 | // On verifie que le rayon est bien >=0 |
1404 | if (atof(argv[4])<=0 ) {cout<<"vcircle error: the radius must be >=0."<<endl;return 1; } |
1405 | |
1406 | // On recupere la normale au Plane. |
1407 | Handle(AIS2D_Plane) theAIS2DPlane= *(Handle(AIS2D_Plane)*)& theShapeA; |
1408 | Handle(AIS2D_Point) theAIS2DPointB= *(Handle(AIS2D_Point)*)& theShapeB; |
1409 | |
1410 | |
1411 | // Handle(Geom_Plane ) myGeomPlane= *(Handle(Geom_Plane)*)& (theAIS2DPlane->Component() ); |
1412 | Handle(Geom_Plane ) myGeomPlane= theAIS2DPlane->Component(); |
1413 | Handle(Geom_Point ) myGeomPointB = theAIS2DPointB->Component(); |
1414 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAIS2DPointB); |
1415 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAIS2DPointB->Component() ); |
1416 | |
1417 | //Handle(Geom_Axis2Placement) OrigineAndAxii=myGeomPlane->Axis(); |
1418 | gp_Pln mygpPlane = myGeomPlane->Pln(); |
1419 | gp_Ax1 thegpAxe = mygpPlane.Axis(); |
1420 | gp_Dir theDir = thegpAxe.Direction(); |
1421 | gp_Pnt theCenter=myCartPointB->Pnt(); |
1422 | Standard_Real TheR = atof(argv[4]); |
1423 | GC_MakeCircle Cir=GC_MakeCircle (theCenter, theDir ,TheR); |
1424 | Handle (Geom_Circle) theGeomCircle=Cir.Value(); |
1425 | Handle(AIS2D_Circle) theAIS2DCircle=new AIS2D_Circle(theGeomCircle ); |
1426 | GetMapOfAIS2D().Bind(theAIS2DCircle,argv[1] ); |
1427 | TheAIS2DContext()->Display(theAIS2DCircle ); |
1428 | } |
1429 | else // Error |
1430 | { |
1431 | cout << "v2dcircle error: !st argument is a unexpected type." << endl; |
1432 | return 1; |
1433 | } |
1434 | */ |
1435 | //Draw arg : v2dcircle CircleName X Y Radius [Color_index] |
1436 | if (GetMapOfAIS2D().IsBound2(name)) |
1437 | { |
1438 | cout << "There is already an object with name " << name << endl; |
1439 | return -1; |
1440 | } |
1441 | Handle(AIS2D_InteractiveObject) aisobj = new AIS2D_InteractiveObject(); |
1442 | aisobj->SetView(V->View()); |
1443 | // Handle(Graphic2d_GraphicObject) obj = |
1444 | // new Graphic2d_GraphicObject(V->View()); |
1445 | |
1446 | Handle(Graphic2d_Circle) circle = new Graphic2d_Circle |
1447 | (aisobj, atof(argv[2]), atof(argv[3]), atof(argv[4])); |
1448 | |
1449 | if (argc > 5) |
1450 | { |
1451 | circle->SetTypeOfPolygonFilling(Graphic2d_TOPF_FILLED); |
1452 | circle->SetInteriorColorIndex(atoi(argv[5])); |
1453 | } |
1454 | |
1455 | // obj->Display(); |
1456 | GetMapOfAIS2D().Bind(aisobj, name); |
1457 | // TheAIS2DContext()->Display(aisobj, Standard_False); |
1458 | aisobj->Display(); |
1459 | |
1460 | V->Viewer()->Update(); |
1461 | } |
1462 | else |
1463 | { |
1464 | TheAIS2DContext()->OpenLocalContext(); |
1465 | myCurrentIndex = TheAIS2DContext()->IndexOfCurrentLocal(); |
1466 | |
1467 | // Active le mode Vertex et face. |
1468 | // TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(1)); |
1469 | // TheAIS2DContext()->ActivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
1470 | cout << " Select a vertex or a face." << endl; |
1471 | TopoDS_Shape ShapeA = SelectShape2d(5); |
1472 | |
1473 | if (ShapeA.ShapeType() == TopAbs_VERTEX) |
1474 | { |
1475 | // TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
1476 | cout << " Select a different vertex." << endl; |
1477 | |
1478 | TopoDS_Shape ShapeB; |
1479 | do |
1480 | { |
1481 | ShapeB = SelectShape2d(5); |
1482 | } while (ShapeB.IsSame(ShapeA)); |
1483 | |
1484 | // Selection de ShapeC |
1485 | cout << " Select the last vertex." << endl; |
1486 | TopoDS_Shape ShapeC; |
1487 | do |
1488 | { |
1489 | ShapeC = SelectShape2d(5); |
1490 | } while (ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB)); |
1491 | |
1492 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
1493 | |
1494 | // Construction du cercle |
1495 | /* |
1496 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)); |
1497 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); |
1498 | gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC)); |
1499 | |
1500 | GC_MakeCircle Cir = GC_MakeCircle(A,B,C); |
1501 | Handle(Geom_Circle) theGeomCircle = Cir.Value(); |
1502 | Handle(AIS2D_Circle) theAIS2DCircle = new AIS2D_Circle(theGeomCircle); |
1503 | GetMapOfAIS2D().Bind(theAIS2DCircle,argv[1]); |
1504 | TheAIS2DContext()->Display(theAIS2DCircle);*/ |
1505 | } |
1506 | // ShapeA est une face. |
1507 | else |
1508 | { |
1509 | cout << " Select a vertex (in your face)." << endl; |
1510 | // TheAIS2DContext()->DeactivateStandardMode(AIS2D_ProjShape::SelectionType(4)); |
1511 | TopoDS_Shape ShapeB = SelectShape2d(5); |
1512 | |
1513 | Standard_Integer theRad; |
1514 | do |
1515 | { |
1516 | cout << " Enter the value of the radius:" << endl; |
1517 | cin >> theRad; |
1518 | } while (theRad <= 0); |
1519 | |
1520 | TheAIS2DContext()->CloseLocalContext(myCurrentIndex); |
1521 | |
1522 | // Construction du cercle. |
1523 | |
1524 | // On recupere la normale au Plane. tag |
1525 | /* TopoDS_Face myFace = TopoDS::Face(ShapeA); |
1526 | BRepAdaptor_Surface mySurface (myFace, Standard_False); |
1527 | gp_Pln myPlane = mySurface.Plane(); |
1528 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane ); |
1529 | gp_Pln mygpPlane = theGeomPlane->Pln(); |
1530 | gp_Ax1 thegpAxe = mygpPlane.Axis(); |
1531 | gp_Dir theDir = thegpAxe.Direction(); |
1532 | |
1533 | // On recupere le centre. |
1534 | gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); |
1535 | |
1536 | // On construit l'AIS2D_Circle |
1537 | GC_MakeCircle Cir = GC_MakeCircle(theCenter, theDir ,theRad); |
1538 | Handle(Geom_Circle) theGeomCircle = Cir.Value(); |
1539 | Handle(AIS2D_Circle) theAIS2DCircle = new AIS2D_Circle(theGeomCircle); |
1540 | GetMapOfAIS2D().Bind(theAIS2DCircle,argv[1] ; |
1541 | TheAIS2DContext()->Display(theAIS2DCircle);*/ |
1542 | } |
1543 | } |
1544 | |
1545 | return 0; |
1546 | } |
1547 | |
1548 | //======================================================================= |
1549 | //function : ObjectCommands |
1550 | //purpose : |
1551 | //======================================================================= |
1552 | void Viewer2dTest::ObjectCommands (Draw_Interpretor& theCommands) |
1553 | { |
1554 | const char *group = "2D AIS Viewer - Primitives Creation"; |
1555 | |
1556 | // theCommands.Add("v2dtrihedron", |
1557 | // "v2dtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]", |
1558 | // __FILE__,V2dTrihedron,group); |
1559 | |
1560 | /* theCommands.Add("v2dtri2d", |
1561 | "v2dtri2d Name (Selection in the viewer only)", |
1562 | __FILE__, V2dTrihedron2D, group); |
1563 | |
1564 | // theCommands.Add("v2dplanetri", |
1565 | // "v2dplanetri Name (Selection in the viewer only)", |
1566 | // __FILE__, V2dPlaneTrihedron, group); |
1567 | |
1568 | theCommands.Add("v2dsize", |
1569 | "v2dsize [name(Default=Current)] [size(Default=100)] ", |
1570 | __FILE__, V2dSize, group); |
1571 | */ |
1572 | theCommands.Add("v2daxis", |
1573 | "v2daxis nom [Xa] [Ya] [Xb] [Yb]", |
1574 | __FILE__, V2dAxisBuilder, group); |
1575 | |
1576 | /* theCommands.Add("v2daxispara", |
1577 | "v2daxispara nom ", |
1578 | __FILE__, V2dAxisBuilder, group); |
1579 | |
1580 | theCommands.Add("v2daxisortho", |
1581 | "v2daxisotho nom ", |
1582 | __FILE__, V2dAxisBuilder, group); |
1583 | |
1584 | theCommands.Add("v2dpoint", |
1585 | "v2dpoint PointName [Xa] [Ya]", |
1586 | __FILE__, V2dPointBuilder, group); |
1587 | */ |
1588 | /* theCommands.Add("v2dplane", |
1589 | "v2dplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ", |
1590 | __FILE__,V2dPlaneBuilder,group); |
1591 | |
1592 | theCommands.Add("v2dplanepara", |
1593 | "v2dplanepara PlaneName ", |
1594 | __FILE__,V2dPlaneBuilder,group); |
1595 | |
1596 | theCommands.Add("v2dplaneortho", |
1597 | "v2dplaneortho PlaneName ", |
1598 | __FILE__,V2dPlaneBuilder,group); |
1599 | */ |
1600 | // theCommands.Add("v2dline", |
1601 | // "v2dline LineName [Xa/PointName] [Ya/PointName] [Xb] [Yb]", |
1602 | // __FILE__,V2dLineBuilder,group); |
1603 | |
1604 | theCommands.Add("v2dcircle", |
1605 | "v2dcircle CircleName X Y Radius [color_index]", |
1606 | __FILE__, V2dCircleBuilder, group); |
1607 | } |