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