Test for 0022778: Bug in BRepMesh
[occt.git] / src / ViewerTest / ViewerTest_ObjectCommands.cxx
CommitLineData
b311480e 1// Created on: 1998-11-12
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23//===============================================
7fd59977 24// AIS Objects Creation : Datums (axis,trihedrons,lines,planes)
7fd59977 25//===============================================
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31#include <ViewerTest.hxx>
32
33#include <string.h>
34
35#include <Quantity_NameOfColor.hxx>
36#include <Draw_Interpretor.hxx>
37#include <Draw.hxx>
38#include <Draw_Appli.hxx>
39#include <DBRep.hxx>
40
161c4476 41#include <OSD_Chronometer.hxx>
7fd59977 42#include <TCollection_AsciiString.hxx>
4952a30a 43#include <Visual3d_View.hxx>
7fd59977 44#include <V3d_Viewer.hxx>
45#include <V3d_View.hxx>
4952a30a 46#include <V3d_Plane.hxx>
7fd59977 47#include <V3d.hxx>
48
49#include <AIS_Shape.hxx>
50#include <AIS_DisplayMode.hxx>
51#include <TColStd_MapOfInteger.hxx>
52#include <AIS_MapOfInteractive.hxx>
53#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
54#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
55#include <ViewerTest_EventManager.hxx>
56
57#include <TopoDS_Solid.hxx>
58#include <BRepTools.hxx>
59#include <BRep_Builder.hxx>
60#include <TopAbs_ShapeEnum.hxx>
61
62#include <TopoDS.hxx>
63#include <BRep_Tool.hxx>
64#include <TopExp_Explorer.hxx>
65
66#include <BRepAdaptor_Curve.hxx>
67#include <BRepAdaptor_Surface.hxx>
68
69#include <TopAbs.hxx>
70#include <TopExp.hxx>
71#include <TopoDS_Vertex.hxx>
72#include <TopoDS_Shape.hxx>
73#include <TopoDS_Face.hxx>
74
75#include <Draw_Window.hxx>
76#include <AIS_ListIteratorOfListOfInteractive.hxx>
77#include <AIS_ListOfInteractive.hxx>
78#include <AIS_DisplayMode.hxx>
79#include <AIS_Shape.hxx>
80
81#include <AIS_InteractiveContext.hxx>
82#include <Geom_Plane.hxx>
83#include <gp_Pln.hxx>
84#include <AIS_AngleDimension.hxx>
85#include <TCollection_ExtendedString.hxx>
86#include <GC_MakePlane.hxx>
87#include <gp_Circ.hxx>
88#include <AIS_Axis.hxx>
89#include <Geom_Axis2Placement.hxx>
90#include <Geom_Axis1Placement.hxx>
91#include <AIS_Trihedron.hxx>
92#include <AIS_Axis.hxx>
29d43f9c
A
93#include <gp_Trsf.hxx>
94#include <TopLoc_Location.hxx>
3fc57801 95
96#include <HLRAlgo_Projector.hxx>
97#include <HLRBRep_PolyAlgo.hxx>
98#include <HLRBRep_PolyHLRToShape.hxx>
99#include <Aspect_Window.hxx>
100
9558a876
A
101#include <Graphic3d_ArrayOfPoints.hxx>
102#include <Graphic3d_ArrayOfSegments.hxx>
103#include <Graphic3d_ArrayOfPolylines.hxx>
104#include <Graphic3d_ArrayOfTriangles.hxx>
105#include <Graphic3d_ArrayOfTriangleFans.hxx>
106#include <Graphic3d_ArrayOfTriangleStrips.hxx>
107#include <Graphic3d_ArrayOfQuadrangles.hxx>
108#include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
109#include <Graphic3d_ArrayOfPolygons.hxx>
110#include <Graphic3d_Group.hxx>
111#include <Standard_Real.hxx>
112
329843e2
A
113#include <AIS_Circle.hxx>
114#include <AIS_Drawer.hxx>
115#include <BRepBuilderAPI_MakeEdge.hxx>
116#include <BRepBuilderAPI_MakeFace.hxx>
117#include <BRepBuilderAPI_MakeWire.hxx>
118#include <Geom_Circle.hxx>
119#include <GC_MakeCircle.hxx>
120#include <Prs3d_Presentation.hxx>
121#include <Select3D_SensitiveCircle.hxx>
122#include <SelectMgr_EntityOwner.hxx>
123#include <SelectMgr_Selection.hxx>
124#include <StdFail_NotDone.hxx>
125#include <StdPrs_ShadedShape.hxx>
a2d5ab2e 126#include <TopoDS_Wire.hxx>
ac04d101
SA
127
128#include <AIS_ConnectedShape.hxx>
792c785c 129#include <AIS_MultipleConnectedInteractive.hxx>
130#include <AIS_MultipleConnectedShape.hxx>
ac04d101
SA
131#include <TopLoc_Location.hxx>
132#include <TColStd_ListOfInteger.hxx>
133#include <TColStd_ListIteratorOfListOfInteger.hxx>
329843e2 134
ceae62f0
A
135#include <Select3D_SensitiveTriangle.hxx>
136#include <Select3D_SensitiveCurve.hxx>
137#include <BRepAdaptor_Curve.hxx>
138#include <StdPrs_Curve.hxx>
139
140#include <BRepExtrema_ExtPC.hxx>
141#include <BRepExtrema_ExtPF.hxx>
142
a2d5ab2e 143#include <Prs3d_LineAspect.hxx>
144
7fd59977 145#ifdef HAVE_STRINGS_H
146#include <strings.h>
147#endif
148
149#ifdef WNT
150#define _CRT_SECURE_NO_DEPRECATE
151#pragma warning (disable:4996)
152#endif
153
154extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
9558a876
A
155extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
156 const Handle(AIS_InteractiveObject)& theAISObj,
157 Standard_Boolean theReplaceIfExists = Standard_True);
7fd59977 158Standard_IMPORT int ViewerMainLoop(Standard_Integer argc, const char** argv);
159extern Handle(AIS_InteractiveContext)& TheAISContext();
160
161
162//==============================================================================
163//function : Vtrihedron 2d
164//purpose : Create a plane with a 2D trihedron from a faceselection
161c4476 165//Draw arg : vtri2d name
7fd59977 166//==============================================================================
167#include <AIS_PlaneTrihedron.hxx>
168
169
170
171static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
172
173{
174 // Verification des arguments
175 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
176
177 // Declarations
178 Standard_Integer myCurrentIndex;
161c4476 179 // Fermeture des contextes
7fd59977 180 TheAISContext()->CloseAllContexts();
181 // Ouverture d'un contexte local et recuperation de son index.
182 TheAISContext()->OpenLocalContext();
183 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
184 // On active les modes de selections faces.
185 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
186 di<<" Select a face ."<<"\n";
187
188 // Boucle d'attente waitpick.
189 Standard_Integer argccc = 5;
190 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
191 const char **argvvv = (const char **) bufff;
192 while (ViewerMainLoop( argccc, argvvv) ) { }
193 // fin de la boucle
194
195 TopoDS_Shape ShapeB;
196 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
197 ShapeB = TheAISContext()->SelectedShape();
198 }
199
200 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
201
202 // Construction du Plane
203 // recuperation des edges des faces.
204 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
205
206 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
161c4476 207 // declarations
7fd59977 208 gp_Pnt A,B,C;
209
210 // si il y a plusieurs edges
211 if (FaceExpB.More() ) {
212 FaceExpB.Next();
213 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
214 BRepAdaptor_Curve theCurveB(EdgeB);
215 BRepAdaptor_Curve theCurveC(EdgeC);
216 A=theCurveC.Value(0.1);
217 B=theCurveC.Value(0.9);
218 C=theCurveB.Value(0.5);
219 }
220 else {
221 // FaceB a 1 unique edge courbe
222 BRepAdaptor_Curve theCurveB(EdgeB);
223 A=theCurveB.Value(0.1);
224 B=theCurveB.Value(0.9);
225 C=theCurveB.Value(0.5);
226 }
227 // Construction du Geom_Plane
228 GC_MakePlane MkPlane(A,B,C);
229 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
230
231 // Construction de l'AIS_PlaneTrihedron
232 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
233
234 // Fermeture du contexte local.
235 TheAISContext()->CloseLocalContext(myCurrentIndex);
236
237 // on le display & bind
238 TheAISContext()->Display(theAISPlaneTri );
239 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
240
161c4476 241 return 0;
7fd59977 242}
243
244
245
246//==============================================================================
247//function : VTriherdron
7fd59977 248//purpose : Create a trihedron. If no arguments are set, the default
249// trihedron (Oxyz) is created.
250//Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
251//==============================================================================
252
dc9b6d23 253static int VTrihedron (Draw_Interpretor& theDi,
254 Standard_Integer theArgsNb,
255 const char** theArgVec)
7fd59977 256{
dc9b6d23 257 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
258 {
259 theDi << theArgVec[0] << " Syntax error\n";
260 return 1;
7fd59977 261 }
7fd59977 262
dc9b6d23 263 gp_Pnt anOrigin (0.0, 0.0, 0.0);
264 gp_Dir aDirZ = gp::DZ();
265 gp_Dir aDirX = gp::DX();
266 Standard_Integer anArgIter = 2; // 1st is an IO name
267 if (anArgIter < theArgsNb)
268 {
269 anOrigin.SetX (atof (theArgVec[anArgIter++]));
270 anOrigin.SetY (atof (theArgVec[anArgIter++]));
271 anOrigin.SetZ (atof (theArgVec[anArgIter++]));
272 if (anArgIter < theArgsNb)
273 {
274 Standard_Real aX = atof (theArgVec[anArgIter++]);
275 Standard_Real aY = atof (theArgVec[anArgIter++]);
276 Standard_Real aZ = atof (theArgVec[anArgIter++]);
277 aDirZ.SetCoord (aX, aY, aZ);
278
279 aX = atof (theArgVec[anArgIter++]);
280 aY = atof (theArgVec[anArgIter++]);
281 aZ = atof (theArgVec[anArgIter++]);
282 aDirX.SetCoord (aX, aY, aZ);
283 }
284 }
7fd59977 285
dc9b6d23 286 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
287 {
288 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
289 return 1;
290 }
7fd59977 291
dc9b6d23 292 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
293 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
294 VDisplayAISObject (theArgVec[1], aShape);
161c4476 295 return 0;
7fd59977 296}
297
7fd59977 298//==============================================================================
299//function : VSize
300//author : ege
301//purpose : Change the size of a named or selected trihedron
302// if no name : it affects the trihedrons witch are selected otherwise nothing is donne
303// if no value, the value is set at 100 by default
304//Draw arg : vsize [name] [size]
305//==============================================================================
306
307static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
308
309{
310 // Declaration de booleens
311 Standard_Boolean ThereIsName;
312 Standard_Boolean ThereIsCurrent;
313 Standard_Real value;
161c4476 314 Standard_Boolean hascol;
7fd59977 315#ifdef DEB
316 Quantity_NameOfColor col;
317#else
318 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
319#endif
320
321 // Verification des arguments
322 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
323
324 // Verification du nombre d'arguments
325 if (argc==1) {ThereIsName=Standard_False;value=100;}
326 else if (argc==2) {ThereIsName=Standard_False;value=atof(argv[1]);}
327 else {ThereIsName=Standard_True;value=atof(argv[2]);}
328
329 // On ferme le contexte local pour travailler dans le contexte global
161c4476 330 if(TheAISContext()->HasOpenedContext())
7fd59977 331 TheAISContext()->CloseLocalContext();
332
333 // On set le booleen ThereIsCurrent
334 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
335 else {ThereIsCurrent=Standard_False;}
336
337
338
339 //===============================================================
340 // Il n'y a pas de nom mais des objets selectionnes
341 //===============================================================
161c4476 342 if (!ThereIsName && ThereIsCurrent)
7fd59977 343 {
344
345 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
346 it (GetMapOfAIS());
347
348 while ( it.More() ) {
349
350 Handle(AIS_InteractiveObject) aShape=
351 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
352
353 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
354 {
355
161c4476 356 // On verifie que l'AIS InteraciveObject selectionne est bien
7fd59977 357 // un AIS_Trihedron
358 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
359
360 if (aShape->HasColor()) {
361 hascol=Standard_True;
362
363 // On recupere la couleur de aShape
364 col=aShape->Color();}
365
366 else hascol=Standard_False;
367
368 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
369 // pour lui appliquer la methode SetSize()
370 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
371
372 // C'est bien un triedre,on chage sa valeur!
373 aTrihedron->SetSize(value);
374
375 // On donne la couleur au Trihedron
376 if(hascol) aTrihedron->SetColor(col);
377 else aTrihedron->UnsetColor();
378
379
380 // The trihedron hasn't be errased from the map
381 // so you just have to redisplay it
382 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
383
384 }
385
386 }
387
388 it.Next();
389 }
390
391 TheAISContext() ->UpdateCurrentViewer();
392 }
393
394 //===============================================================
395 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
396 //===============================================================
397
398
399
400 //===============================================================
401 // Il y a un nom de triedre passe en argument
402 //===============================================================
403 if (ThereIsName) {
404 TCollection_AsciiString name=argv[1];
405
406 // on verifie que ce nom correspond bien a une shape
407 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
408
409 if (IsBound) {
410
411 // on recupere la shape dans la map des objets displayes
412 Handle(AIS_InteractiveObject) aShape =
413 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
414
161c4476 415 // On verifie que l'AIS InteraciveObject est bien
7fd59977 416 // un AIS_Trihedron
417 if (!aShape.IsNull() &&
418 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
419 {
420
421 if (aShape->HasColor()) {
422 hascol=Standard_True;
423
424 // On recupere la couleur de aShape
425 col=aShape->Color();}
426
427 else hascol=Standard_False;
428
429 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
430 // pour lui appliquer la methode SetSize()
431 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
432
433 // C'est bien un triedre,on chage sa valeur
434 aTrihedron->SetSize(value);
435
436 // On donne la couleur au Trihedron
437 if(hascol) aTrihedron->SetColor(col);
438 else aTrihedron->UnsetColor();
439
440 // The trihedron hasn't be errased from the map
441 // so you just have to redisplay it
442 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
443
444 TheAISContext() ->UpdateCurrentViewer();
445 }
446 }
447 }
161c4476 448 return 0;
7fd59977 449}
450
451
452//==============================================================================
453
454//==============================================================================
455//function : VPlaneTrihedron
456//purpose : Create a plane from a trihedron selection. If no arguments are set, the default
161c4476 457//Draw arg : vplanetri name
7fd59977 458//==============================================================================
459#include <AIS_Plane.hxx>
460
461
462
463static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
464
465{
466 // Verification des arguments
467 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
468
469 // Declarations
470 Standard_Integer myCurrentIndex;
471 // Fermeture des contextes locaux
472 TheAISContext()->CloseAllContexts();
473
161c4476 474 // On recupere tous les trihedrons de la GetMapOfAIS()
7fd59977 475 // et on active le mode de selection par face.
476 // =================================================
477
478 // Ouverture d'un contexte local et recuperation de son index.
479 TheAISContext()->OpenLocalContext(Standard_False);
480 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
481
482 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
483 it (GetMapOfAIS());
484 while(it.More()){
485 Handle(AIS_InteractiveObject) ShapeA =
486 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
487 // On verifie que c'est bien un trihedron
488 if (!ShapeA.IsNull() &&
489 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
490 // on le downcast
491 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
492 // on le charge dans le contexte et on active le mode Plane.
493 TheAISContext()->Load(TrihedronA,0,Standard_False);
494 TheAISContext()->Activate(TrihedronA,3);
495 }
496 it.Next();
497 }
498
499 di<<" Select a plane."<<"\n";
500 // Boucle d'attente waitpick.
501 Standard_Integer argccc = 5;
502 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
503 const char **argvvv = (const char **) bufff;
504 while (ViewerMainLoop( argccc, argvvv) ) { }
505 // fin de la boucle
506
507 Handle(AIS_InteractiveObject) theIOB;
508 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
509 theIOB = TheAISContext()->Interactive();
510 }
511 // on le downcast
512 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
513
514 // Fermeture du contexte local.
515 TheAISContext()->CloseLocalContext(myCurrentIndex);
516
517 // on le display & bind
518 TheAISContext()->Display(PlaneB );
519 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
520
161c4476 521 return 0;
7fd59977 522}
523
524
525
526//==============================================================================
527// Fonction First click 2de click
161c4476 528//
7fd59977 529// vaxis vertex vertex
530// edge None
531// vaxispara edge vertex
532// vaxisortho edge Vertex
533// vaxisinter Face Face
534//==============================================================================
535
536//==============================================================================
537//function : VAxisBuilder
161c4476 538//purpose :
7fd59977 539//Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
540//==============================================================================
541#include <TopoDS_Edge.hxx>
542#include <TopoDS_Vertex.hxx>
543#include <TopExp.hxx>
544#include <Geom_Line.hxx>
545
161c4476 546static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 547{
548 // Declarations
549 Standard_Boolean HasArg;
550 TCollection_AsciiString name;
551 Standard_Integer MyCurrentIndex;
552
553 // Verification
554 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
555 if (argc==8) HasArg=Standard_True;
556 else HasArg=Standard_False;
557
558 name=argv[1];
559 // Fermeture des contextes
560 TheAISContext()->CloseAllContexts();
561
562 // Cas ou il y a des arguments
563 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
564 if (HasArg) {
565 Standard_Real coord[6];
566 for(Standard_Integer i=0;i<=5;i++){
567 coord[i]=atof(argv[2+i]);
568 }
569 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
570
571 gp_Vec myVect (p1,p2);
572 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
573 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
574 GetMapOfAIS().Bind (TheAxis,name);
575 TheAISContext()->Display(TheAxis);
576 }
577
578 // Pas d'arguments
579 else {
580 // fonction vaxis
581 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
582 if ( !strcasecmp(argv[0], "vaxis")) {
583 TheAISContext()->OpenLocalContext();
584 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
585
586 // Active le mode edge et le mode vertex
587 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
588 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
589 di<<" Select an edge or a vertex."<<"\n";
590
591 // Boucle d'attente waitpick.
592 Standard_Integer argcc = 5;
593 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
594 const char **argvv = (const char **) buff;
595 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 596 // fin de la boucle
7fd59977 597
598 // recuperation de la shape.
599 TopoDS_Shape ShapeA;
600 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
601 ShapeA = TheAISContext()->SelectedShape();
602 }
603 // recuperation de l'AIS_InteractiveObject
604 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
605 // down cast en AIS_Point si sig et type
606 // AIS_Point -> Geom_Pnt ....
607
608 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
609 // on desactive le mode edge
610 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
611 di<<" Select a different vertex."<<"\n";
612
613 TopoDS_Shape ShapeB;
614 do {
615 // Boucle d'attente waitpick.
616 Standard_Integer argccc = 5;
617 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
618 const char **argvvv = (const char **) bufff;
619 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 620 // fin de la boucle
7fd59977 621 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
622 ShapeB = TheAISContext()->SelectedShape();
623 }
624
625
626 } while(ShapeB.IsSame(ShapeA) );
627
628 // Fermeture du context local
629 TheAISContext()->CloseLocalContext(MyCurrentIndex);
630
161c4476 631 // Construction de l'axe
7fd59977 632 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
633 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
634 gp_Vec V (A,B);
635 gp_Dir D (V);
636 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
637 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
638 GetMapOfAIS().Bind (TheAxis,name);
639 TheAISContext()->Display(TheAxis);
161c4476 640 }
7fd59977 641 else {
642 // Un unique edge (ShapeA) a ete picke
643 // Fermeture du context local
644 TheAISContext()->CloseLocalContext(MyCurrentIndex);
161c4476 645 // Constuction de l'axe
7fd59977 646 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
647 TopoDS_Vertex Va,Vb;
648 TopExp::Vertices(ed,Va,Vb );
649 gp_Pnt A=BRep_Tool::Pnt(Va);
650 gp_Pnt B=BRep_Tool::Pnt(Vb);
651 gp_Vec V (A,B);
652 gp_Dir D (V);
653 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
654 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
655 GetMapOfAIS().Bind (TheAxis,name);
656 TheAISContext()->Display(TheAxis);
657 }
658
659 }
660
661 // Fonction axispara
662 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
663 else if ( !strcasecmp(argv[0], "vaxispara")) {
664
665 TheAISContext()->OpenLocalContext();
666 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
667
161c4476 668 // Active le mode edge
7fd59977 669 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
670 di<<" Select an edge."<<"\n";
671
672 // Boucle d'attente waitpick.
673 Standard_Integer argcc = 5;
674 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
675 const char **argvv = (const char **) buff;
676 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 677 // fin de la boucle
7fd59977 678
679 TopoDS_Shape ShapeA;
680 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
681 ShapeA = TheAISContext()->SelectedShape();
682 }
683 // Active le mode vertex et deactive edges
684 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
685 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
686 di<<" Select a vertex."<<"\n";
687
688 // Boucle d'attente waitpick.
689 Standard_Integer argccc = 5;
690 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
691 const char **argvvv = (const char **) bufff;
692 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 693 // fin de la boucle
7fd59977 694
695 // On peut choisir un pnt sur l'edge
696 TopoDS_Shape ShapeB;
697 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
698 ShapeB = TheAISContext()->SelectedShape();
699 }
700 // Fermeture du context local
701 TheAISContext()->CloseLocalContext(MyCurrentIndex);
702
703 // Construction de l'axe
704 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
705 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
706 TopoDS_Vertex Va,Vc;
707 TopExp::Vertices(ed,Va,Vc );
708 gp_Pnt A=BRep_Tool::Pnt(Va);
709 gp_Pnt C=BRep_Tool::Pnt(Vc);
710 gp_Vec V (A,C);
711 gp_Dir D (V);
712 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
713 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
714 GetMapOfAIS().Bind (TheAxis,name);
715 TheAISContext()->Display(TheAxis);
716
717 }
718
719 // Fonction axisortho
720 else {
721 TheAISContext()->OpenLocalContext();
722 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
723
161c4476 724 // Active le mode edge
7fd59977 725 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
726 di<<" Select an edge."<<"\n";
727
728 // Boucle d'attente waitpick.
729 Standard_Integer argcc = 5;
730 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
731 const char **argvv = (const char **) buff;
732 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 733 // fin de la boucle
7fd59977 734
735 TopoDS_Shape ShapeA;
736 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
737 ShapeA = TheAISContext()->SelectedShape();
738 }
739 // Active le mode vertex et deactive edges
740 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
741 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
742 di<<" Slect a vertex."<<"\n";
743
744 // Boucle d'attente waitpick.
745 Standard_Integer argccc = 5;
746 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
747 const char **argvvv = (const char **) bufff;
748 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 749 // fin de la boucle
7fd59977 750
751 // On peut choisir un pnt sur l'edge
752 TopoDS_Shape ShapeB;
753 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
754 ShapeB = TheAISContext()->SelectedShape();
755 }
756 // Fermeture du context local
757 TheAISContext()->CloseLocalContext(MyCurrentIndex);
758
759 // Construction de l'axe
760 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
761 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
762 TopoDS_Vertex Va,Vc;
763 TopExp::Vertices(ed,Va,Vc );
764 gp_Pnt A=BRep_Tool::Pnt(Va);
765 gp_Pnt C=BRep_Tool::Pnt(Vc);
766 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
767 gp_Vec V (A,E);
768 gp_Dir D (V);
769 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
770 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
771 GetMapOfAIS().Bind (TheAxis,name);
772 TheAISContext()->Display(TheAxis);
773
774 }
775
776 }
777 return 0;
778}
779
780
781//==============================================================================
782// Fonction First click Result
161c4476 783//
7fd59977 784// vpoint vertex AIS_Point=Vertex
785// edge AIS_Point=Middle of the edge
786//==============================================================================
787
788//==============================================================================
789//function : VPointBuilder
790//purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
791//Draw arg : vpoint PoinName [Xa] [Ya] [Za]
792//==============================================================================
793#include <TopoDS_Edge.hxx>
794#include <TopoDS_Vertex.hxx>
795#include <TopExp.hxx>
796#include <AIS_Point.hxx>
797#include <Geom_CartesianPoint.hxx>
798
161c4476 799static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 800{
801 // Declarations
802 Standard_Boolean HasArg;
803 TCollection_AsciiString name;
804 Standard_Integer myCurrentIndex;
805
806 // Verification
807 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
808 if (argc==5) HasArg=Standard_True;
809 else HasArg=Standard_False;
810
811 name=argv[1];
812 // Fermeture des contextes
813 TheAISContext()->CloseAllContexts();
814
815 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
816 if (HasArg) {
817 Standard_Real thecoord[3];
818 for(Standard_Integer i=0;i<=2;i++)
819 thecoord[i]=atof(argv[2+i]);
820 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
821 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
822 GetMapOfAIS().Bind (myAISPoint,name);
823 TheAISContext()->Display(myAISPoint);
824 }
825
826 // Il n'a pas d'arguments
827 else {
828 TheAISContext()->OpenLocalContext();
829 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
830
831 // Active le mode Vertex et Edges
832 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
833 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
834 di<<" Select a vertex or an edge(build the middle)"<<"\n";
835
836 // Boucle d'attente waitpick.
837 Standard_Integer argcc = 5;
838 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
839 const char **argvv = (const char **) buff;
840 while (ViewerMainLoop( argcc, argvv) ) { }
841 // fin de la boucle
842
843 TopoDS_Shape ShapeA;
844 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
845 ShapeA= TheAISContext()->SelectedShape();
846 }
847
848 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
849 // Un vertex a ete selectionne
850 // Fermeture du context local
851 TheAISContext()->CloseLocalContext(myCurrentIndex);
852
853 // Construction du point
854 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
855 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
856 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
857 GetMapOfAIS().Bind(myAISPoint,name);
858 TheAISContext()->Display(myAISPoint);
859 }
860 else {
861 // Un Edge a ete selectionne
862 // Fermeture du context local
863 TheAISContext()->CloseLocalContext(myCurrentIndex);
864
865 // Construction du point milieu de l'edge
866 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
867 TopoDS_Vertex myVertexA,myVertexB;
868 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
869 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
870 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
871 // M est le milieu de [AB]
872 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
873 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
874 GetMapOfAIS().Bind(myAISPointM,name);
875 TheAISContext()->Display(myAISPointM);
876 }
877
878 }
879 return 0;
880
881}
882
883//==============================================================================
ceae62f0 884// Function 1st click 2de click 3de click
7fd59977 885// vplane Vertex Vertex Vertex
886// Vertex Edge
887// Edge Vertex
888// Face
889// vplanepara Face Vertex
890// Vertex Face
891// vplaneortho Face Edge
892// Edge Face
893//==============================================================================
894
895//==============================================================================
896//function : VPlaneBuilder
ceae62f0 897//purpose : Build an AIS_Plane from selected entities or Named AIS components
7fd59977 898//Draw arg : vplane PlaneName [AxisName] [PointName]
899// [PointName] [PointName] [PointName]
900// [PlaneName] [PointName]
901//==============================================================================
902
ceae62f0
A
903static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
904 Standard_Integer argc,
905 const char** argv)
7fd59977 906{
907 // Declarations
ceae62f0
A
908 Standard_Boolean hasArg;
909 TCollection_AsciiString aName;
910 Standard_Integer aCurrentIndex;
7fd59977 911
912 // Verification
ceae62f0
A
913 if (argc<2 || argc>5 )
914 {
915 std::cout<<" Syntax error\n";
916 return 1;
917 }
918 if (argc==5 || argc==4)
919 hasArg=Standard_True;
920 else
921 hasArg=Standard_False;
7fd59977 922
ceae62f0
A
923 aName=argv[1];
924 // Close all contexts
7fd59977 925 TheAISContext()->CloseAllContexts();
926
ceae62f0
A
927 // There are some arguments
928 if (hasArg)
929 {
930 if (!GetMapOfAIS().IsBound2(argv[2] ))
931 {
932 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
933 return 1;
934 }
935 // Get shape from map
936 Handle(AIS_InteractiveObject) aShapeA =
7fd59977 937 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
938
ceae62f0
A
939 // The first argument is an AIS_Point
940 if (!aShapeA.IsNull() &&
941 aShapeA->Type()==AIS_KOI_Datum &&
942 aShapeA->Signature()==1)
943 {
944 // The second argument must also be an AIS_Point
945 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
946 {
947 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
948 return 1;
949 }
950 // Get shape from map
951 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 952 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
953 // If B is not an AIS_Point
954 if (aShapeB.IsNull() ||
955 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 956 {
ceae62f0 957 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
7fd59977 958 return 1;
959 }
ceae62f0
A
960 // The third object is an AIS_Point
961 if (!GetMapOfAIS().IsBound2(argv[4]) )
962 {
963 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
964 return 1;
965 }
966 // Get shape from map
967 Handle(AIS_InteractiveObject) aShapeC =
7fd59977 968 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
ceae62f0
A
969 // If C is not an AIS_Point
970 if (aShapeC.IsNull() ||
971 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
7fd59977 972 {
ceae62f0 973 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
7fd59977 974 return 1;
975 }
976
ceae62f0
A
977 // Treatment of objects A, B, C
978 // Downcast an AIS_IO to AIS_Point
979 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
980 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
981 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
7fd59977 982
ceae62f0
A
983 Handle(Geom_CartesianPoint ) aCartPointA =
984 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
7fd59977 985
ceae62f0
A
986 Handle(Geom_CartesianPoint ) aCartPointB =
987 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
7fd59977 988
ceae62f0
A
989 Handle(Geom_CartesianPoint ) aCartPointC =
990 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
7fd59977 991
ceae62f0
A
992 // Verification that the three points are different
993 if(abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
994 abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
995 abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
996 {
7fd59977 997 // B=A
ceae62f0 998 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 999 }
ceae62f0
A
1000 if(abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1001 abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1002 abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1003 {
7fd59977 1004 // C=A
ceae62f0 1005 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 1006 }
ceae62f0
A
1007 if(abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1008 abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1009 abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1010 {
7fd59977 1011 // C=B
ceae62f0 1012 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 1013 }
1014
ceae62f0
A
1015 gp_Pnt A = aCartPointA->Pnt();
1016 gp_Pnt B = aCartPointB->Pnt();
1017 gp_Pnt C = aCartPointC->Pnt();
7fd59977 1018
ceae62f0 1019 // Construction of AIS_Plane
7fd59977 1020 GC_MakePlane MkPlane (A,B,C);
ceae62f0
A
1021 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1022 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1023 GetMapOfAIS().Bind (anAISPlane,aName );
1024 TheAISContext()->Display(anAISPlane);
7fd59977 1025 }
1026
ceae62f0
A
1027 // The first argument is an AIS_Axis
1028 // Creation of a plane orthogonal to the axis through a point
1029 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1030 // The second argument should be an AIS_Point
7fd59977 1031 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1032 {
ceae62f0 1033 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
7fd59977 1034 return 1;
1035 }
ceae62f0
A
1036 // Get shape from map
1037 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 1038 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
1039 // If B is not an AIS_Point
1040 if (aShapeB.IsNull() ||
1041 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1042 {
ceae62f0 1043 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
7fd59977 1044 return 1;
1045 }
1046
ceae62f0
A
1047 // Treatment of objects A and B
1048 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1049 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
7fd59977 1050
ceae62f0
A
1051 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1052 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
7fd59977 1053
ceae62f0
A
1054 gp_Ax1 anAxis = aGeomLineA->Position();
1055 Handle(Geom_CartesianPoint) aCartPointB =
1056 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
7fd59977 1057
ceae62f0
A
1058 gp_Dir D =anAxis.Direction();
1059 gp_Pnt B = aCartPointB->Pnt();
7fd59977 1060
ceae62f0
A
1061 // Construction of AIS_Plane
1062 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1063 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1064 GetMapOfAIS().Bind (anAISPlane,aName );
1065 TheAISContext()->Display(anAISPlane);
7fd59977 1066
1067 }
ceae62f0
A
1068 // The first argumnet is an AIS_Plane
1069 // Creation of a plane parallel to the plane passing through the point
1070 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1071 {
1072 // The second argument should be an AIS_Point
1073 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1074 {
1075 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
7fd59977 1076 return 1;
1077 }
ceae62f0
A
1078 // Get shape from map
1079 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 1080 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
1081 // B should be an AIS_Point
1082 if (aShapeB.IsNull() ||
1083 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1084 {
ceae62f0 1085 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
7fd59977 1086 return 1;
1087 }
1088
ceae62f0
A
1089 // Treatment of objects A and B
1090 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1091 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
7fd59977 1092
ceae62f0
A
1093 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1094 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
7fd59977 1095
ceae62f0
A
1096 Handle(Geom_CartesianPoint) aCartPointB =
1097 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1098 gp_Pnt B= aCartPointB->Pnt();
7fd59977 1099
ceae62f0
A
1100 // Construction of an AIS_Plane
1101 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1102 GetMapOfAIS().Bind (anAISPlane, aName);
1103 TheAISContext()->Display(anAISPlane);
1104 }
1105 // Error
1106 else
1107 {
1108 std::cout<<"vplane: error 1st object is not an AIS\n";
1109 return 1;
7fd59977 1110 }
7fd59977 1111 }
ceae62f0
A
1112 // There are no arguments
1113 else
1114 {
1115 // Function vplane
1116 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1117 if (!strcasecmp(argv[0], "vplane"))
1118 {
7fd59977 1119 TheAISContext()->OpenLocalContext();
ceae62f0 1120 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
7fd59977 1121
ceae62f0
A
1122 // Active modes Vertex, Edge and Face
1123 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1124 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1125 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1126 std::cout<<"Select a vertex, a face or an edge\n";
7fd59977 1127
ceae62f0 1128 // Wait for picking
7fd59977 1129 Standard_Integer argcc = 5;
1130 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1131 const char **argvv = (const char **) buff;
1132 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1133 // end of the loop
7fd59977 1134
ceae62f0
A
1135 TopoDS_Shape aShapeA;
1136 for (TheAISContext()->InitSelected();
1137 TheAISContext()->MoreSelected();
1138 TheAISContext()->NextSelected())
1139 {
1140 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1141 }
1142
ceae62f0
A
1143 // aShapeA is a Vertex
1144 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1145 {
1146 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1147 std::cout<<" Select an edge or a different vertex\n";
7fd59977 1148
ceae62f0 1149 // Wait for picking
7fd59977 1150 Standard_Integer argccc = 5;
1151 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1152 const char **argvvv = (const char **) bufff;
1153 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1154 // end of the loop
7fd59977 1155
ceae62f0
A
1156 TopoDS_Shape aShapeB;
1157 for (TheAISContext()->InitSelected();
1158 TheAISContext()->MoreSelected();
1159 TheAISContext()->NextSelected())
1160 {
1161 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1162 }
ceae62f0
A
1163 // aShapeB is a Vertex
1164 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1165 {
1166 // A and B are the same
1167 if (aShapeB.IsSame(aShapeA))
1168 {
1169 std::cout<<" vplane: error, same points selected\n";
1170 return 1;
1171 }
1172 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1173 std::cout<<" Select a different vertex\n";
7fd59977 1174
ceae62f0 1175 // Wait for picking
7fd59977 1176 Standard_Integer argcccc = 5;
1177 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1178 const char **argvvvv = (const char **) buffff;
1179 while (ViewerMainLoop( argcccc, argvvvv) ) { }
ceae62f0 1180 // end of the loop
7fd59977 1181
ceae62f0
A
1182 TopoDS_Shape aShapeC;
1183 for (TheAISContext()->InitSelected();
1184 TheAISContext()->MoreSelected();
1185 TheAISContext()->NextSelected())
1186 {
1187 aShapeC = TheAISContext()->SelectedShape();
1188 }
1189 // aShapeC is the same as A or B
1190 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1191 {
1192 std::cout<<" vplane: error, same points selected\n";
1193 return 1;
7fd59977 1194 }
7fd59977 1195
ceae62f0
A
1196 // Close the local context
1197 TheAISContext()->CloseLocalContext(aCurrentIndex);
1198
1199 // Construction of plane
1200 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1201 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1202 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1203 GC_MakePlane MkPlane(A, B, C);
1204 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1205 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1206 GetMapOfAIS().Bind (anAISPlane, aName);
1207 TheAISContext()->Display(anAISPlane);
7fd59977 1208 }
ceae62f0
A
1209 // ShapeB is an edge
1210 else
1211 {
1212 // Verify that the vertex is not on the edge ShapeB
1213 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1214 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
7fd59977 1215
ceae62f0
A
1216 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1217 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1218 {
1219 // The vertex is on the edge
1220 std::cout<<" vplane: error point is on the edge\n";
1221 return 1;
1222 }
1223 else
1224 {
1225 // Close the local context
1226 TheAISContext()->CloseLocalContext(aCurrentIndex);
1227 // Construction of plane
1228 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1229 TopoDS_Vertex aVBa, aVBb;
1230 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1231 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1232 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1233 GC_MakePlane MkPlane (A, aBa, aBb);
1234 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1235 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1236 GetMapOfAIS().Bind (anAISPlane, aName);
1237 TheAISContext()->Display(anAISPlane);
7fd59977 1238 }
7fd59977 1239 }
7fd59977 1240 }
ceae62f0
A
1241 // aShapeA is an edge
1242 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1243 {
1244 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1245 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1246 std::cout<<" Select a vertex that don't belong to the edge\n";
7fd59977 1247
ceae62f0 1248 // Wait for picking
7fd59977 1249 Standard_Integer argccc = 5;
1250 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1251 const char **argvvv = (const char **) bufff;
1252 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1253 // end of the loop
7fd59977 1254
ceae62f0
A
1255 TopoDS_Shape aShapeB;
1256 for (TheAISContext()->InitSelected();
1257 TheAISContext()->MoreSelected();
1258 TheAISContext()->NextSelected())
1259 {
1260 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1261 }
ceae62f0
A
1262 // aShapeB should be a Vertex
1263 // Check that the vertex aShapeB is not on the edge
1264 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1265 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1266
1267 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1268 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1269 {
1270 // The vertex is on the edge
1271 std::cout<<" vplane: error point is on the edge\n";
1272 return 1;
7fd59977 1273 }
ceae62f0
A
1274 else
1275 {
1276 // Close the local context
1277 TheAISContext()->CloseLocalContext(aCurrentIndex);
1278 // Construction of plane
1279 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1280 TopoDS_Vertex aVAa, aVAb;
1281 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1282 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1283 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
7fd59977 1284 GC_MakePlane MkPlane (B,Aa,Ab);
ceae62f0
A
1285 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1286 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1287 GetMapOfAIS().Bind (anAISPlane ,aName);
1288 TheAISContext()->Display(anAISPlane);
7fd59977 1289 }
7fd59977 1290 }
ceae62f0
A
1291 // aShapeA is a Face
1292 else
1293 {
1294 // Close the local context: nothing to select
1295 TheAISContext()->CloseLocalContext(aCurrentIndex);
1296 // Construction of plane
1297 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1298 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1299 if (aSurface.GetType()==GeomAbs_Plane)
1300 {
1301 gp_Pln aPlane = aSurface.Plane();
1302 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1303 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1304 GetMapOfAIS().Bind (anAISPlane, aName);
1305 TheAISContext()->Display(anAISPlane);
7fd59977 1306 }
ceae62f0
A
1307 else
1308 {
1309 std::cout<<" vplane: error\n";
1310 return 1;
7fd59977 1311 }
7fd59977 1312 }
7fd59977 1313 }
1314
ceae62f0 1315 // Function vPlanePara
7fd59977 1316 // ===================
ceae62f0
A
1317 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1318 else if (!strcasecmp(argv[0], "vplanepara"))
1319 {
7fd59977 1320 TheAISContext()->OpenLocalContext();
ceae62f0 1321 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 1322
ceae62f0
A
1323 // Activate modes Vertex and Face
1324 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1325 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1326 std::cout<<" Select a vertex or a face\n";
7fd59977 1327
ceae62f0 1328 // Wait for picking
7fd59977 1329 Standard_Integer argcc = 5;
1330 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1331 const char **argvv = (const char **) buff;
1332 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1333 // end of the loop
7fd59977 1334
ceae62f0
A
1335 TopoDS_Shape aShapeA;
1336 for (TheAISContext()->InitSelected();
1337 TheAISContext()->MoreSelected();
1338 TheAISContext()->NextSelected())
1339 {
1340 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1341 }
1342
ceae62f0
A
1343 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1344 {
1345 // aShapeA is a vertex
1346 // Deactivate the mode Vertex
1347 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1348 std::cout<<" Select a face\n";
7fd59977 1349
ceae62f0 1350 // Wait for picking
7fd59977 1351 Standard_Integer argccc = 5;
1352 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1353 const char **argvvv = (const char **) bufff;
1354 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1355 // end of the loop
7fd59977 1356
ceae62f0
A
1357 TopoDS_Shape aShapeB;
1358 for (TheAISContext()->InitSelected();
1359 TheAISContext()->MoreSelected();
1360 TheAISContext()->NextSelected())
1361 {
1362 // A vertex ShapeA can be on Face ShapeB
1363 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1364 }
1365
ceae62f0
A
1366 // Close the local context
1367 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1368
ceae62f0
A
1369 // Construction of plane
1370 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1371
1372 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1373 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1374 if (aSurface.GetType()==GeomAbs_Plane )
1375 {
1376 gp_Pln aPlane = aSurface.Plane();
1377 // Construct a plane parallel to aGeomPlane through A
1378 aPlane.SetLocation(A);
1379 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1380 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1381 GetMapOfAIS().Bind (aAISPlane ,aName);
1382 TheAISContext()->Display(aAISPlane);
7fd59977 1383 }
ceae62f0
A
1384 else
1385 {
1386 std::cout<<" vplanepara: error\n";
1387 return 1;
7fd59977 1388 }
7fd59977 1389 }
ceae62f0
A
1390 else
1391 {
1392 // ShapeA is a Face
1393 // Deactive the mode Face
1394 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1395 std::cout<<" Select a vertex\n";
7fd59977 1396
ceae62f0 1397 // Wait for picking
7fd59977 1398 Standard_Integer argccc = 5;
1399 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1400 const char **argvvv = (const char **) bufff;
1401 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1402 // end of the loop
7fd59977 1403
ceae62f0
A
1404 TopoDS_Shape aShapeB;
1405 for (TheAISContext()->InitSelected();
1406 TheAISContext()->MoreSelected();
1407 TheAISContext()->NextSelected())
1408 {
1409 // A vertex ShapeB can be on Face ShapeA
1410 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1411 }
ceae62f0
A
1412 // Close the local context
1413 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1414
ceae62f0
A
1415 // Construction of plane
1416 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1417
1418 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1419 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1420 if (aSurface.GetType()==GeomAbs_Plane )
1421 {
1422 gp_Pln aPlane = aSurface.Plane();
1423 aPlane.SetLocation(B);
1424 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1425 // Construct a plane parallel to aGeomPlane through B
1426 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1427 GetMapOfAIS().Bind (anAISPlane, aName);
1428 TheAISContext()->Display(anAISPlane);
7fd59977 1429 }
ceae62f0
A
1430 else
1431 {
1432 std::cout<<" vplanepara: error"<<"\n";return 1;
7fd59977 1433 }
7fd59977 1434 }
7fd59977 1435 }
1436
ceae62f0 1437 // Function vplaneortho
7fd59977 1438 // ====================
ceae62f0
A
1439 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1440 else
1441 {
7fd59977 1442 TheAISContext()->OpenLocalContext();
ceae62f0 1443 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 1444
ceae62f0
A
1445 // Activate the modes Edge and Face
1446 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1447 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1448 std::cout<<" Select a face and an edge coplanar\n";
7fd59977 1449
ceae62f0 1450 // Wait for picking
7fd59977 1451 Standard_Integer argcc = 5;
1452 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1453 const char **argvv = (const char **) buff;
1454 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1455 // end of the loop
7fd59977 1456
ceae62f0
A
1457 TopoDS_Shape aShapeA;
1458 for (TheAISContext()->InitSelected();
1459 TheAISContext()->MoreSelected();
1460 TheAISContext()->NextSelected())
1461 {
1462 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1463 }
1464
ceae62f0
A
1465 if (aShapeA.ShapeType()==TopAbs_EDGE )
1466 {
1467 // ShapeA is an edge, deactivate the mode Edge...
1468 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1469 std::cout<<" Select a face\n";
7fd59977 1470
ceae62f0 1471 // Wait for picking
7fd59977 1472 Standard_Integer argccc = 5;
1473 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1474 const char **argvvv = (const char **) bufff;
1475 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1476 // end of the loop
7fd59977 1477
ceae62f0
A
1478 TopoDS_Shape aShapeB;
1479 for (TheAISContext()->InitSelected();
1480 TheAISContext()->MoreSelected();
1481 TheAISContext()->NextSelected())
1482 {
1483 // Edge ShapeA can be on Face ShapeB
1484 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1485 }
1486
ceae62f0
A
1487 // Close the local context
1488 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1489
ceae62f0
A
1490 // Construction of plane
1491 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1492 TopoDS_Vertex aVAa, aVAb;
1493 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1494 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1495 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1496 gp_Vec ab (Aa,Ab);
7fd59977 1497
1498 gp_Dir Dab (ab);
ceae62f0
A
1499 // Creation of rotation axis
1500 gp_Ax1 aRotAxis (Aa,Dab);
1501
1502 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1503 // The edge must be parallel to the face
1504 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1505 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1506 // Compare to heights
1507 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1508 >Precision::Confusion())
1509 {
1510 // the edge is not parallel to the face
1511 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1512 return 1;
7fd59977 1513 }
ceae62f0
A
1514 // the edge is OK
1515 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1516 if (aSurface.GetType()==GeomAbs_Plane)
1517 {
1518 gp_Pln aPlane = aSurface.Plane();
1519 // It rotates a half turn round the axis of rotation
1520 aPlane.Rotate(aRotAxis , M_PI/2);
1521
1522 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1523 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1524 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1525 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1526 GetMapOfAIS().Bind (anAISPlane, aName);
1527 TheAISContext()->Display(anAISPlane);
7fd59977 1528 }
ceae62f0
A
1529 else
1530 {
1531 std::cout<<" vplaneortho: error\n";
1532 return 1;
7fd59977 1533 }
7fd59977 1534 }
ceae62f0
A
1535 else
1536 {
1537 // ShapeA is a Face, deactive the mode Face.
1538 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1539 std::cout<<" Select an edge\n";
7fd59977 1540
ceae62f0 1541 // Wait for picking
7fd59977 1542 Standard_Integer argccc = 5;
1543 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1544 const char **argvvv = (const char **) bufff;
1545 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1546 // end of the loop
7fd59977 1547
ceae62f0
A
1548 TopoDS_Shape aShapeB;
1549 for (TheAISContext()->InitSelected();
1550 TheAISContext()->MoreSelected();
1551 TheAISContext()->NextSelected())
1552 {
1553 // Edge ShapeB can be on Face ShapeA
1554 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1555 }
ceae62f0
A
1556 // Close the local context
1557 TheAISContext()->CloseLocalContext(aCurrentIndex);
1558
1559 // Construction of plane
1560 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1561 TopoDS_Vertex aVBa, aVBb;
1562 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1563 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1564 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1565 gp_Vec ab (aBa,aBb);
7fd59977 1566 gp_Dir Dab (ab);
ceae62f0
A
1567 // Creation of rotation axe
1568 gp_Ax1 aRotAxis (aBa,Dab);
1569
1570 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1571 // The edge must be parallel to the face
1572 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1573 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1574 // Comparing the two heights
1575 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1576 >Precision::Confusion())
1577 {
1578 // the edge is not parallel to the face
1579 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1580 return 1;
7fd59977 1581 }
ceae62f0
A
1582 // The edge is OK
1583 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1584 if (aSurface.GetType()==GeomAbs_Plane)
1585 {
1586 gp_Pln aPlane = aSurface.Plane();
1587 // It rotates a half turn round the axis of rotation
1588 aPlane.Rotate(aRotAxis , M_PI/2);
1589 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1590 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1591 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1592 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1593 GetMapOfAIS().Bind (anAISPlane ,aName);
1594 TheAISContext()->Display(anAISPlane);
7fd59977 1595 }
ceae62f0
A
1596 else
1597 {
1598 std::cout<<" vplaneortho: error\n";
1599 return 1;
7fd59977 1600 }
7fd59977 1601 }
7fd59977 1602 }
7fd59977 1603 }
1604 return 0;
7fd59977 1605}
1606
1607
1608//==============================================================================
1609// Fonction vline
1610// --------------- Uniquement par parametre. Pas de selection dans le viewer.
1611//==============================================================================
1612
1613//==============================================================================
1614//function : VLineBuilder
161c4476 1615//purpose : Build an AIS_Line
7fd59977 1616//Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1617// [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1618//==============================================================================
1619#include <Geom_CartesianPoint.hxx>
1620#include <AIS_Line.hxx>
1621
1622
161c4476 1623static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 1624{
1625 Standard_Integer myCurrentIndex;
1626 // Verifications
1627 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1628 // Fermeture des contextes
1629 TheAISContext()->CloseAllContexts();
1630
1631 // On recupere les parametres
1632 Handle(AIS_InteractiveObject) theShapeA;
1633 Handle(AIS_InteractiveObject) theShapeB;
1634
1635 // Parametres: AIS_Point AIS_Point
1636 // ===============================
1637 if (argc==4) {
1638 theShapeA=
1639 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1640 // On verifie que c'est bien une AIS_Point
1641 if (!theShapeA.IsNull() &&
1642 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1643 // on recupere le deuxieme AIS_Point
1644 theShapeB=
1645 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1646 if (theShapeA.IsNull() ||
1647 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1648 {
1649 di <<"vline error: wrong type of 2de argument."<<"\n";
1650 return 1;
1651 }
1652 }
161c4476 1653 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
7fd59977 1654 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1655 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1656 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1657
1658 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1659 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1660 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1661
1662 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1663 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1664 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1665
1666 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1667 // B=A
1668 di<<"vline error: same points"<<"\n";return 1;
1669 }
1670 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1671 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1672 GetMapOfAIS().Bind(theAISLine,argv[1] );
1673 TheAISContext()->Display(theAISLine );
1674
1675 }
1676
1677 // Parametres 6 Reals
1678 // ==================
1679
1680 else if (argc==8) {
161c4476 1681 // On verifie que les deux points ne sont pas confondus
7fd59977 1682
1683 Standard_Real coord[6];
1684 for(Standard_Integer i=0;i<=2;i++){
1685 coord[i]=atof(argv[2+i]);
1686 coord[i+3]=atof(argv[5+i]);
1687 }
1688
1689 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1690 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1691
1692 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1693 GetMapOfAIS().Bind(theAISLine,argv[1] );
1694 TheAISContext()->Display(theAISLine );
1695
1696 }
1697
1698 // Pas de parametres: Selection dans le viewer.
1699 // ============================================
1700
1701 else {
1702 TheAISContext()->OpenLocalContext();
1703 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1704
1705 // Active le mode Vertex.
1706 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1707 di<<" Select a vertex "<<"\n";
1708
1709 // Boucle d'attente waitpick.
1710 Standard_Integer argcc = 5;
1711 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1712 const char **argvv = (const char **) buff;
1713 while (ViewerMainLoop( argcc, argvv) ) { }
1714 // fin de la boucle
1715
1716 TopoDS_Shape ShapeA;
1717 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1718 ShapeA = TheAISContext()->SelectedShape();
1719 }
1720
1721 // ShapeA est un Vertex
1722 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1723
1724 di<<" Select a different vertex."<<"\n";
1725
1726 TopoDS_Shape ShapeB;
1727 do {
1728
1729 // Boucle d'attente waitpick.
1730 Standard_Integer argccc = 5;
1731 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1732 const char **argvvv = (const char **) bufff;
1733 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 1734 // fin de la boucle
7fd59977 1735
1736 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1737 ShapeB = TheAISContext()->SelectedShape();
1738 }
1739
1740
1741 } while(ShapeB.IsSame(ShapeA) );
1742
1743 // Fermeture du context local
1744 TheAISContext()->CloseLocalContext(myCurrentIndex);
1745
1746 // Construction de la line
1747 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1748 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1749
1750 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1751 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1752
1753 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1754 GetMapOfAIS().Bind(theAISLine,argv[1] );
1755 TheAISContext()->Display(theAISLine );
1756
1757 }
1758 else {
1759 di<<"vline error."<<"\n";
1760 }
1761
1762 }
1763
1764 return 0;
1765}
1766
329843e2
A
1767//==============================================================================
1768// class : FilledCircle
1769// purpose : creates filled circle based on AIS_InteractiveObject
1770// and Geom_Circle.
1771// This class is used to check method Matches() of class
1772// Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1773// because none of AIS classes provides creation of
1774// Select3D_SensitiveCircle with member myFillStatus = Standard_True
1775// (look method ComputeSelection() )
1776//==============================================================================
1777
1778Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1779{
1780 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1781 gp_Circ aCirc(anAxes, theRadius);
1782 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1783 return aCircle;
1784}
1785
1786DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1787
1788class FilledCircle : public AIS_InteractiveObject
1789{
1790public:
1791 // CASCADE RTTI
1792 DEFINE_STANDARD_RTTI(FilledCircle);
1793
1794 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1795 FilledCircle(Handle(Geom_Circle) theCircle);
1796
1797private:
1798 TopoDS_Face ComputeFace();
1799
1800 // Virtual methods implementation
1801 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1802 const Handle(Prs3d_Presentation)& thePresentation,
1803 const Standard_Integer theMode);
1804
1805 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1806 const Standard_Integer theMode);
1807
1808protected:
1809 Handle(Geom_Circle) myCircle;
1810 Standard_Boolean myFilledStatus;
1811
1812};
1813
1814IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1815IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1816
1817FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1818{
1819 myCircle = CreateCircle(theCenter, theRadius);
1820 myFilledStatus = Standard_True;
1821}
1822
1823FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1824{
1825 myCircle = theCircle;
1826 myFilledStatus = Standard_True;
1827}
1828
1829TopoDS_Face FilledCircle::ComputeFace()
1830{
1831 // Create edge from myCircle
1832 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1833 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1834
1835 // Create wire from anEdge
1836 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1837 TopoDS_Wire aWire = aWireMaker.Wire();
1838
1839 // Create face from aWire
1840 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1841 TopoDS_Face aFace = aFaceMaker.Face();
1842
1843 return aFace;
1844}
1845
1846void FilledCircle::Compute(const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
1847 const Handle_Prs3d_Presentation &thePresentation,
1848 const Standard_Integer theMode)
1849{
1850 thePresentation->Clear();
1851
1852 TopoDS_Face aFace = ComputeFace();
1853
1854 if (aFace.IsNull()) return;
1855 if (theMode != 0) return;
1856
1857 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1858}
1859
1860void FilledCircle::ComputeSelection(const Handle_SelectMgr_Selection &theSelection,
1861 const Standard_Integer theMode)
1862{
1863 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1864 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
1865 myCircle, myFilledStatus);
1866 theSelection->Add(aSensitiveCircle);
1867}
7fd59977 1868
1869//==============================================================================
1870// Fonction vcircle
1871// ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1872//==============================================================================
1873
1874//==============================================================================
1875//function : VCircleBuilder
161c4476 1876//purpose : Build an AIS_Circle
329843e2
A
1877//Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1878// PointName PointName PointName IsFilled
7fd59977 1879//==============================================================================
329843e2
A
1880
1881void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1882 TCollection_AsciiString theName,
1883 Standard_Boolean isFilled)
1884{
1885 Handle(AIS_InteractiveObject) aCircle;
1886 if (isFilled)
1887 {
1888 aCircle = new FilledCircle(theGeomCircle);
1889 }
1890 else
1891 {
1892 aCircle = new AIS_Circle(theGeomCircle);
1893 }
1894
1895 // Check if there is an object with given name
1896 // and remove it from context
1897 if (GetMapOfAIS().IsBound2(theName))
1898 {
1899 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
1900 Handle(AIS_InteractiveObject) anInterObj =
1901 Handle(AIS_InteractiveObject)::DownCast(anObj);
1902 TheAISContext()->Remove(anInterObj, Standard_False);
1903 GetMapOfAIS().UnBind2(theName);
1904 }
1905
1906 // Bind the circle to its name
1907 GetMapOfAIS().Bind(aCircle, theName);
1908
1909 // Display the circle
1910 TheAISContext()->Display(aCircle);
1911
1912}
7fd59977 1913
161c4476 1914static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 1915{
1916 Standard_Integer myCurrentIndex;
329843e2
A
1917 // Verification of the arguments
1918 if (argc>6 || argc<2)
1919 {
1920 std::cout << "vcircle error: expect 4 arguments.\n";
1921 return 1; // TCL_ERROR
1922 }
7fd59977 1923 TheAISContext()->CloseAllContexts();
1924
329843e2
A
1925 // There are all arguments
1926 if (argc == 6)
1927 {
1928 // Get arguments
1929 TCollection_AsciiString aName(argv[1]);
1930 Standard_Boolean isFilled = (Standard_Boolean)atoi(argv[5]);
1931
7fd59977 1932 Handle(AIS_InteractiveObject) theShapeA;
1933 Handle(AIS_InteractiveObject) theShapeB;
1934
329843e2
A
1935 theShapeA =
1936 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
1937 theShapeB =
1938 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
1939
7fd59977 1940
1941 // Arguments: AIS_Point AIS_Point AIS_Point
1942 // ========================================
329843e2 1943 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
7fd59977 1944 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
1945 {
329843e2
A
1946 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
1947 {
1948 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
1949 return 1; // TCL_ERROR
7fd59977 1950 }
329843e2 1951 // The third object must be a point
7fd59977 1952 Handle(AIS_InteractiveObject) theShapeC =
329843e2 1953 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
7fd59977 1954 if (theShapeC.IsNull() ||
329843e2
A
1955 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
1956 {
1957 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
1958 return 1; // TCL_ERROR
1959 }
7fd59977 1960 // tag
329843e2
A
1961 // Verify that the three points are different
1962 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
1963 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
1964 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
1965
1966 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
1967 Handle(Geom_CartesianPoint) myCartPointA =
1968 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
1969
1970 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
1971 Handle(Geom_CartesianPoint) myCartPointB =
1972 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
1973
1974 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
1975 Handle(Geom_CartesianPoint) myCartPointC =
1976 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
7fd59977 1977
1978 // Test A=B
329843e2
A
1979 if (abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
1980 abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
1981 abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
1982 {
1983 std::cout << "vcircle error: Same points.\n";
1984 return 1; // TCL_ERROR
7fd59977 1985 }
1986 // Test A=C
329843e2
A
1987 if (abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
1988 abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1989 abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1990 {
1991 std::cout << "vcircle error: Same points.\n";
1992 return 1; // TCL_ERROR
7fd59977 1993 }
1994 // Test B=C
329843e2
A
1995 if (abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
1996 abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1997 abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1998 {
1999 std::cout << "vcircle error: Same points.\n";
2000 return 1;// TCL_ERROR
7fd59977 2001 }
329843e2
A
2002 // Construction of the circle
2003 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2004 myCartPointB->Pnt(), myCartPointC->Pnt() );
2005 Handle (Geom_Circle) theGeomCircle;
2006 try
2007 {
2008 theGeomCircle = Cir.Value();
2009 }
2010 catch (StdFail_NotDone)
2011 {
2012 std::cout << "vcircle error: can't create circle\n";
2013 return -1; // TCL_ERROR
2014 }
2015
2016 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2017 }
2018
329843e2 2019 // Arguments: AIS_Plane AIS_Point Real
7fd59977 2020 // ===================================
329843e2
A
2021 else if (theShapeA->Type() == AIS_KOI_Datum &&
2022 theShapeA->Signature() == 7 )
2023 {
2024 if (theShapeB->Type() != AIS_KOI_Datum ||
2025 theShapeB->Signature() != 1 )
2026 {
2027 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2028 return 1; // TCL_ERROR
2029 }
2030