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