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