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