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
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.
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.
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.
23 #include <ViewerTest.hxx>
28 #include <AIS_InteractiveContext.hxx>
30 #include <Draw_Interpretor.hxx>
32 #include <Draw_Appli.hxx>
36 #include <TCollection_AsciiString.hxx>
37 #include <V3d_Viewer.hxx>
38 #include <V3d_View.hxx>
41 #include <AIS_InteractiveContext.hxx>
42 #include <AIS_Shape.hxx>
43 #include <AIS_Point.hxx>
44 #include <AIS_DisplayMode.hxx>
45 #include <TColStd_MapOfInteger.hxx>
46 #include <AIS_MapOfInteractive.hxx>
47 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
48 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
49 #include <ViewerTest_EventManager.hxx>
51 #include <TopoDS_Solid.hxx>
52 #include <BRepTools.hxx>
53 #include <BRep_Builder.hxx>
54 #include <TopAbs_ShapeEnum.hxx>
57 #include <BRep_Tool.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <TopoDS_Face.hxx>
64 #include <Draw_Window.hxx>
65 #include <AIS_ListIteratorOfListOfInteractive.hxx>
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_DisplayMode.hxx>
69 #include <Geom_CartesianPoint.hxx>
70 #include <StdSelect.hxx>
73 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
74 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
75 extern Handle(AIS_InteractiveContext)& TheAISContext ();
78 #include <Geom_Plane.hxx>
80 #include <AIS_AngleDimension.hxx>
81 #include <TCollection_ExtendedString.hxx>
82 #include <GC_MakePlane.hxx>
83 #include <IntAna_IntConicQuad.hxx>
84 #include <Select3D_Projector.hxx>
85 #include <Precision.hxx>
86 #include <IntAna_Quadric.hxx>
94 #define VertexMask 0x01
99 static Standard_Boolean ComputeIntersection(const gp_Lin& L,const gp_Pln& ThePl, gp_Pnt& TheInter)
101 static IntAna_Quadric TheQuad;
102 TheQuad.SetQuadric(ThePl);
103 static IntAna_IntConicQuad QQ;
104 QQ.Perform(L,TheQuad);
107 TheInter = QQ.Point(1);
108 return Standard_True;
111 return Standard_False;
114 //=======================================================================
115 //function : Get3DPointAtMousePosition
116 //purpose : calcul du point 3D correspondant a la position souris dans le plan de
118 //=======================================================================
119 static gp_Pnt Get3DPointAtMousePosition(){
120 Handle(V3d_View) aview = ViewerTest::CurrentView();
121 static Select3D_Projector prj;
124 // le plan de la vue...
125 Standard_Real xv,yv,zv;
126 aview->Proj(xv,yv,zv);
127 Standard_Real xat,yat,zat;
128 aview->At(xat,yat,zat);
129 gp_Pln ThePl(gp_Pnt(xat,yat,zat),gp_Dir(xv,yv,zv));
130 Standard_Integer xpix,ypix;
132 ViewerTest::GetMousePosition(xpix,ypix);
133 aview->Convert(xpix,ypix,x,y); // espace reel 2D de la vue...
134 gp_Lin L = prj.Shoot(x,y);
137 ComputeIntersection(L,ThePl,P);
143 //=======================================================================
144 //function : ComputeNewPlaneForDim
146 //=======================================================================
147 static void ComputeNewPlaneForDim(const Handle(AIS_Relation)& R,
160 TopoDS_Shape S1 = R->FirstShape();
161 TopoDS_Shape S2 = R->SecondShape();
162 TopAbs_ShapeEnum Typ1 = S1.ShapeType();
163 TopAbs_ShapeEnum Typ2 = S2.ShapeType();
166 thepoint[0] = Get3DPointAtMousePosition();
168 // on met l'objet le plus petit en 1...
169 if((Standard_Integer)Typ2>(Standard_Integer)Typ1){
171 TopoDS_Shape tmpS = S1;
172 TopAbs_ShapeEnum tmpT = Typ1;
181 thepoint[0] = BRep_Tool::Pnt(S1);
182 if(Typ2==TopAbs_VERTEX)
183 thepoint[1] = BRep_Tool::Pnt(S2);
184 else if(Typ2==TopAbs_EDGE){
186 TopExp::Vertices(S2,Va,Vb);
187 thepoint[1] = BRep_Tool::Pnt(Va);
189 else if(Typ2==TopAbs_FACE){
199 //=======================================================================
200 //function : VAngleDimBuilder
202 //=======================================================================
203 static int VAngleDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
205 Standard_Integer myCurrentIndex;
207 if (argc!=2) {di<<" vangledim error."<<"\n";return 1;}
208 TheAISContext()->CloseAllContexts();
209 TheAISContext()->OpenLocalContext();
210 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
211 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
212 di<<" Select two edges coplanar or not."<<"\n";
213 Standard_Integer argcc = 5;
214 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
215 const char **argvv = (const char **) buff;
216 while (ViewerMainLoop( argcc, argvv) ) { }
219 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
220 ShapeA = TheAISContext()->SelectedShape();
222 // Si ShapeA est un Edge.
223 if (ShapeA.ShapeType()== TopAbs_EDGE ) {
225 // Boucle d'attente waitpick.
226 Standard_Integer argccc = 5;
227 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
228 const char **argvvv = (const char **) bufff;
229 while (ViewerMainLoop( argccc, argvvv) ) { }
233 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
234 ShapeB = TheAISContext()->SelectedShape();
236 // ShapeB doit etre un Edge
237 if (ShapeB.ShapeType()!= TopAbs_EDGE ) {
238 di<<" vangledim error: you shoud have selected an edge."<<"\n";return 1;
241 // on recupere les vertexes de edgeA
243 TopExp::Vertices(TopoDS::Edge(ShapeA),Va ,Vb );
244 // Recuperation des points.
245 gp_Pnt A=BRep_Tool::Pnt(Va);
246 gp_Pnt B=BRep_Tool::Pnt(Vb);
247 gp_Pnt C(A.X()+5 ,A.Y()+5 ,A.Z()+5 );
250 // Construction du plane. Methode pas orthodoxe!
251 GC_MakePlane MkPlane(A ,B ,C );
252 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
254 // Construction du texte.
255 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString( 90 ) );
257 // Fermeture du context local.
258 TheAISContext()->CloseLocalContext(myCurrentIndex);
260 // Construction de l'AIS dimension
261 Handle (AIS_AngleDimension) myAISDim= new AIS_AngleDimension (TopoDS::Edge(ShapeA) ,TopoDS::Edge(ShapeB) ,theGeomPlane ,M_PI/2.0 ,TheMessage_Str );
262 GetMapOfAIS().Bind (myAISDim,argv[1]);
263 TheAISContext()->Display(myAISDim );
267 di<<" vangledim error: you must select 2 edges."<<"\n";return 1;
274 //==============================================================================
275 //function : VDiameterDim
276 //purpose : Display the diameter dimension of a face or an edge.
277 //Draw arg : vdiameterdim Name
278 //==============================================================================
279 #include <AIS_DiameterDimension.hxx>
280 #include <TCollection_ExtendedString.hxx>
281 #include <BRepAdaptor_Curve.hxx>
282 #include <gp_Circ.hxx>
285 static int VDiameterDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
288 Standard_Integer myCurrentIndex;
289 Standard_Real theRadius;
292 if (argc!=2) {di<<" vdiameterdim error"<<"\n";return 1;}
293 // Fermeture des contextes locaux
294 TheAISContext()->CloseAllContexts();
295 // Ouverture d'un contexte local et recuperation de son index.
296 TheAISContext()->OpenLocalContext();
297 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
299 // On active les modes de selections Edges et Faces.
300 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
301 di<<" Select an circled edge."<<"\n";
303 // Boucle d'attente waitpick.
304 Standard_Integer argcc = 5;
305 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
306 const char **argvv = (const char **) buff;
307 while (ViewerMainLoop( argcc, argvv) ) { }
311 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
312 ShapeA = TheAISContext()->SelectedShape();
314 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
316 // Recuperation du rayon
317 BRepAdaptor_Curve theCurve(TopoDS::Edge(ShapeA));
318 if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vdiameterdim error: the edge is not a circular one."<<"\n";return 1;}
320 gp_Circ theGpCircle=theCurve.Circle();
321 theRadius=2.*theGpCircle.Radius();
324 // Construction du texte.
325 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theRadius ) );
326 // Construction de L'AIS_AngleDimension.
327 TheAISContext()->CloseLocalContext(myCurrentIndex);
329 Handle (AIS_DiameterDimension) myDiamDim= new AIS_DiameterDimension(ShapeA ,theRadius ,TheMessage_Str );
330 GetMapOfAIS().Bind (myDiamDim,argv[1]);
331 TheAISContext()->Display(myDiamDim );
336 di<<" vdiameterdim error: the selection of a face or an edge was expected."<<"\n";return 1;
344 //==============================================================================
345 // Fonction vconcentric
346 // ----------------- Uniquement par selection dans le viewer.
347 //==============================================================================
349 //==============================================================================
350 //function : VConcentric
351 //purpose : Display the concentric relation between two surfaces.
352 //Draw arg : vconcentric Name
353 //==============================================================================
354 #include <AIS_ConcentricRelation.hxx>
355 #include <Geom_Plane.hxx>
356 #include <gp_Pln.hxx>
357 #include <GC_MakePlane.hxx>
358 #include <BRepAdaptor_Curve.hxx>
359 #include <TopExp_Explorer.hxx>
362 static int VConcentricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
365 Standard_Integer myCurrentIndex;
368 if (argc!=2) {di<<"vconcentric error."<<"\n";return 1;}
369 // Fermeture des contextes locaux
370 TheAISContext()->CloseAllContexts();
371 // Ouverture d'un contexte local et recuperation de son index.
372 TheAISContext()->OpenLocalContext();
373 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
375 // On active les modes de selections Edges et Faces.
376 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
377 di<<" Select a circled edge."<<"\n";
379 // Boucle d'attente waitpick.
380 Standard_Integer argcc = 5;
381 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
382 const char **argvv = (const char **) buff;
383 while (ViewerMainLoop( argcc, argvv) ) { }
387 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
388 ShapeA = TheAISContext()->SelectedShape();
390 // ShapeA est un edge
391 // ==================
392 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
393 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
394 di<<" Select an edge."<<"\n";
396 // Boucle d'attente waitpick.
397 Standard_Integer argccc = 5;
398 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
399 const char **argvvv = (const char **) bufff;
400 while (ViewerMainLoop( argccc, argvvv) ) { }
404 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
405 ShapeB = TheAISContext()->SelectedShape();
407 if (ShapeB.ShapeType()!=TopAbs_EDGE ) {
408 di<<" vconcentric error: select an edge."<<"\n";return 1;
411 // Construction du plane.
412 // On recupere le centre du cercle A.
413 BRepAdaptor_Curve theCurveA(TopoDS::Edge(ShapeA) );
414 gp_Circ theCircleA=theCurveA.Circle();
415 gp_Pnt theCenterA=theCircleA.Location();
416 // On recupere deux points sur le cercle A
417 gp_Pnt B= theCurveA.Value(0.25);
418 gp_Pnt C= theCurveA.Value(0.75);
419 // Construction du plane.
420 GC_MakePlane MkPlane(theCenterA ,B ,C );
421 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
423 // Fermeture du context local
424 TheAISContext()->CloseLocalContext(myCurrentIndex);
426 Handle (AIS_ConcentricRelation) myConcentry= new AIS_ConcentricRelation(ShapeA, ShapeB, theGeomPlane );
427 TheAISContext()->Display(myConcentry );
428 GetMapOfAIS().Bind (myConcentry,argv[1]);
433 di<<" vconcentric error: the selection of a face or an edge was expected."<<"\n";return 1;
443 //==============================================================================
444 //function : VEqualDistRelation
446 //Draw arg : vdiameterdim Name DiameterValue
447 //==============================================================================
448 #include <AIS_EqualDistanceRelation.hxx>
449 #include <BRepExtrema_ExtCC.hxx>
450 #include <GC_MakePlane.hxx>
453 static int VEqualDistRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
456 Standard_Integer myCurrentIndex;
459 if (argc!=2) {di<<" vequaldistrelation error: no arguments allowed."<<"\n";return 1;}
461 // Fermeture des contextes locaux
462 TheAISContext()->CloseAllContexts();
464 // Ouverture d'un contexte local et recuperation de son index.
465 TheAISContext()->OpenLocalContext();
466 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
468 // On active les modes de selections Edges et Vertexes.
469 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
470 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
471 di<<" Select an edge or a vertex"<<"\n";
473 // Boucle d'attente waitpick.
474 Standard_Integer argc1 = 5;
475 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
476 const char **argv1 = (const char **) buf1;
477 while (ViewerMainLoop( argc1, argv1) ) { }
481 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
482 ShapeA = TheAISContext()->SelectedShape();
485 di<<" Select an edge or a vertex"<<"\n";
486 // Boucle d'attente waitpick.
487 Standard_Integer argc2 = 5;
488 const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
489 const char **argv2 = (const char **) buf2;
490 while (ViewerMainLoop( argc2, argv2) ) { }
494 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
495 ShapeB = TheAISContext()->SelectedShape();
498 // Verification des resultats.
499 if (ShapeA.ShapeType()==TopAbs_EDGE && ShapeB.ShapeType()==TopAbs_EDGE ) {
500 // A et B sont des edges ils doivent etre paralleles
501 BRepExtrema_ExtCC myDeltaEdge (TopoDS::Edge(ShapeA) ,TopoDS::Edge(ShapeB) );
502 // on verifie qu'ils sont pas paralleles.
503 if (!myDeltaEdge.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; }
508 di<<" Select an edge or a vertex"<<"\n";
509 // Boucle d'attente waitpick.
510 Standard_Integer argc3 = 5;
511 const char *buf3[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
512 const char **argv3 = (const char **) buf3;
513 while (ViewerMainLoop( argc3, argv3) ) { }
517 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
518 ShapeC = TheAISContext()->SelectedShape();
521 di<<" Select an edge or a vertex"<<"\n";
522 // Boucle d'attente waitpick.
523 Standard_Integer argc4 = 5;
524 const char *buf4[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
525 const char **argv4 = (const char **) buf4;
526 while (ViewerMainLoop( argc4, argv4) ) { }
530 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
531 ShapeD = TheAISContext()->SelectedShape();
533 // Verification des resultats.
534 if (ShapeC.ShapeType()==TopAbs_EDGE && ShapeD.ShapeType()==TopAbs_EDGE ) {
535 // C et D sont des edges ils doivent etre paralleles
536 BRepExtrema_ExtCC myDeltaEdge2 (TopoDS::Edge(ShapeC) ,TopoDS::Edge(ShapeD) );
537 // on verifie qu'ils sont pas paralleles.
538 if (!myDeltaEdge2.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; }
542 // Creation du plan porteur de la contrainte.Methode lourde!
544 if (ShapeA.ShapeType()==TopAbs_EDGE) {
547 TopExp::Vertices (TopoDS::Edge(ShapeA) ,Va ,Vb );
548 A=BRep_Tool::Pnt(Va);
549 B=BRep_Tool::Pnt(Vb);
551 if (ShapeB.ShapeType()==TopAbs_EDGE) {
552 // B est un edge aussi
554 TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vc ,Vd );
555 // besoin que de 1 point.
556 C=BRep_Tool::Pnt(Vc);
561 C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
566 A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
568 if (ShapeB.ShapeType()==TopAbs_EDGE ) {
571 TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vb ,Vc );
572 // besoin que de 2 points.
573 B=BRep_Tool::Pnt(Vb);
574 C=BRep_Tool::Pnt(Vc);
579 B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
587 // Fermeture du context local.
588 TheAISContext()->CloseLocalContext(myCurrentIndex);
590 // construction du plane
591 GC_MakePlane MkPlane(A ,B ,C );
592 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
594 // Construction de l'AIS_EqualDistanceRelation
595 Handle (AIS_EqualDistanceRelation ) myRelation= new AIS_EqualDistanceRelation (ShapeA, ShapeB, ShapeC ,ShapeD , theGeomPlane );
596 TheAISContext()->Display(myRelation );
597 GetMapOfAIS().Bind (myRelation,argv[1]);
605 //==============================================================================
606 //function : VEqualRadiusRelation
608 //Draw arg : vdiameterdim Name DiameterValue
609 //==============================================================================
610 #include <AIS_EqualRadiusRelation.hxx>
611 #include <GC_MakePlane.hxx>
612 #include <BRepAdaptor_Curve.hxx>
615 static int VEqualRadiusRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
618 Standard_Integer myCurrentIndex;
621 if (argc!=2) {di<<" vequalrad error: no arguments allowed."<<"\n";return 1;}
623 // Fermeture des contextes locaux
624 TheAISContext()->CloseAllContexts();
626 // Ouverture d'un contexte local et recuperation de son index.
627 TheAISContext()->OpenLocalContext();
628 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
630 // On active les modes de selections Edges.
631 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
632 di<<" Select an circled edge "<<"\n";
634 // Boucle d'attente waitpick.
635 Standard_Integer argc1 = 5;
636 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
637 const char **argv1 = (const char **) buf1;
638 while (ViewerMainLoop( argc1, argv1) ) { }
642 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
643 ShapeA = TheAISContext()->SelectedShape();
646 di<<" Select the last circled edge."<<"\n";
647 // Boucle d'attente waitpick.
648 Standard_Integer argc2 = 5;
649 const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
650 const char **argv2 = (const char **) buf2;
651 while (ViewerMainLoop( argc2, argv2) ) { }
655 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
656 ShapeB = TheAISContext()->SelectedShape();
658 // creation du plan qui contient la contrainte.
659 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
660 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
661 BRepAdaptor_Curve theCurveA(EdgeA);
662 // On recupere 3 points A,B,C de la curve.
663 gp_Pnt A=theCurveA.Value(0.1);
664 gp_Pnt B=theCurveA.Value(0.5);
665 gp_Pnt C=theCurveA.Value(0.9);
667 // fermeture du contexte local.
668 TheAISContext()->CloseLocalContext(myCurrentIndex);
670 // Creation du plane.
671 GC_MakePlane MkPlane (A ,B ,C );
672 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
673 // Construction de l'AIS_EqualRadiusRelation
674 Handle (AIS_EqualRadiusRelation ) myRelation= new AIS_EqualRadiusRelation (EdgeA,EdgeB, theGeomPlane );
675 TheAISContext()->Display(myRelation );
676 GetMapOfAIS().Bind (myRelation,argv[1]);
683 //==============================================================================
684 //function : VFixRelation
686 //Draw arg : vdiameterdim Name DiameterValue
687 //==============================================================================
688 #include <AIS_FixRelation.hxx>
689 #include <GC_MakePlane.hxx>
690 #include <BRepAdaptor_Curve.hxx>
692 static int VFixRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
695 Standard_Integer myCurrentIndex;
698 if (argc!=2) {di<<" vfix error: no arguments allowed."<<"\n";return 1;}
700 // Fermeture des contextes locaux
701 TheAISContext()->CloseAllContexts();
703 // Ouverture d'un contexte local et recuperation de son index.
704 TheAISContext()->OpenLocalContext();
705 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
707 // On active les modes de selections edge.
708 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
709 di<<" Select an edge. "<<"\n";
711 // Boucle d'attente waitpick.
712 Standard_Integer argc1 = 5;
713 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
714 const char **argv1 = (const char **) buf1;
715 while (ViewerMainLoop( argc1, argv1) ) { }
719 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
720 ShapeA = TheAISContext()->SelectedShape();
723 // creation du plan qui contient la contrainte.
724 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
725 BRepAdaptor_Curve theCurveA(EdgeA);
726 // On recupere 3 points A,B,C de la curve.
727 gp_Pnt A=theCurveA.Value(0.1);
728 gp_Pnt B=theCurveA.Value(0.5);
729 gp_Pnt D=theCurveA.Value(0.9);
730 gp_Pnt C(B.X()+5,B.Y()+5,B.Z()+5);
732 // fermeture du contexte local.
733 TheAISContext()->CloseLocalContext(myCurrentIndex);
735 // Creation du plane.
736 GC_MakePlane MkPlane (A ,D ,C );
737 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
738 // Construction de l'AIS_EqualRadiusRelation
739 Handle (AIS_FixRelation) myRelation= new AIS_FixRelation (EdgeA,theGeomPlane );
740 TheAISContext()->Display(myRelation );
741 GetMapOfAIS().Bind (myRelation,argv[1]);
748 //==============================================================================
749 //function : VIdenticRelation
751 //Draw arg : vdiameterdim Name DiameterValue
752 //==============================================================================
753 #include <AIS_IdenticRelation.hxx>
754 #include <BRepAdaptor_Curve.hxx>
755 #include <TopExp_Explorer.hxx>
758 static int VIdenticRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
761 Standard_Integer myCurrentIndex;
764 if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;}
766 // Fermeture des contextes locaux
767 TheAISContext()->CloseAllContexts();
769 // Ouverture d'un contexte local et recuperation de son index.
770 TheAISContext()->OpenLocalContext();
771 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
773 // On active les modes de selections vertex et face.
774 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
775 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
776 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
777 di<<" Select an edge, a face or a vertex. "<<"\n";
779 // Boucle d'attente waitpick.
780 Standard_Integer argc1 = 5;
781 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
782 const char **argv1 = (const char **) buf1;
783 while (ViewerMainLoop( argc1, argv1) ) { }
787 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
788 ShapeA = TheAISContext()->SelectedShape();
791 di<<" Select an edge, a face or a vertex. "<<"\n";
792 // Boucle d'attente waitpick.
793 Standard_Integer argc2 = 5;
794 const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
795 const char **argv2 = (const char **) buf2;
796 while (ViewerMainLoop( argc2, argv2) ) { }
800 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
801 ShapeB = TheAISContext()->SelectedShape();
804 // Recuperation de points pour construir le Geom_Plnae.
806 if (ShapeA.ShapeType()==TopAbs_EDGE) {
807 // A est un edge; on peut supposer qu'il sera element d'une face ou possesseur d'un vertex ou identic a un autre edge.
808 // on recupere deux points sur l'edge (il peut etre rectiligne)
809 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
810 BRepAdaptor_Curve theCurveA(EdgeA);
811 // Creation des 3 points.
812 A=theCurveA.Value(0.1);
813 B=theCurveA.Value(0.9);
818 else if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
819 // SahpeA est un Vertex
820 // On va utiliser ShapeB
821 if (ShapeB.ShapeType()==TopAbs_EDGE) {
823 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
824 BRepAdaptor_Curve theCurveB(EdgeB);
825 // Creation des 3 points.
826 A=theCurveB.Value(0.1);
827 B=theCurveB.Value(0.9);
833 else if (ShapeB.ShapeType()==TopAbs_FACE ) {
834 // Shape B est une face
835 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
836 // On recupere 1 edge de FaceB(la face n'a pas forcement de vertex) (l'element A est forcement dans B).
837 TopExp_Explorer FaceExp(FaceB,TopAbs_EDGE);
838 TopoDS_Edge EdgeFromB=TopoDS::Edge(FaceExp.Current() );
839 // On recupere les 3 points de l'edge de face B
840 BRepAdaptor_Curve theCurveB(EdgeFromB);
841 // On recupere 3 points A,B,C de la curve.
842 A=theCurveB.Value(0.1);
843 B=theCurveB.Value(0.5);
844 C=theCurveB.Value(0.9);
848 // B ets un vetex aussi
849 A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
850 B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
860 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
861 // On recupere 1 edge de FaceA
862 TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE);
863 TopoDS_Edge EdgeFromA=TopoDS::Edge(FaceExp.Current() );
864 // On recupere les 3 points de l'edge
865 BRepAdaptor_Curve theCurveA(EdgeFromA);
866 // On recupere 3 points A,B,C de la curve.
867 A=theCurveA.Value(0.1);
868 B=theCurveA.Value(0.5);
869 C=theCurveA.Value(0.9);
873 // Fermeture du context local.
874 TheAISContext()->CloseLocalContext(myCurrentIndex);
875 // On construit le plane
876 GC_MakePlane MkPlane (A ,B ,C );
877 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
879 // Construction de l'AIS_IdenticRelation
880 Handle ( AIS_IdenticRelation ) myRelation= new AIS_IdenticRelation (ShapeA ,ShapeB, theGeomPlane );
881 TheAISContext()->Display(myRelation );
882 GetMapOfAIS().Bind (myRelation,argv[1]);
889 //==============================================================================
890 //function : VLengthDimension
891 //purpose : Display the diameter dimension of a face or an edge.
892 //Draw arg : vdiameterdim Name DiameterValue
893 //==============================================================================
894 #include <AIS_LengthDimension.hxx>
895 #include <BRepExtrema_ExtCC.hxx>
896 #include <BRepExtrema_ExtPC.hxx>
897 #include <BRepExtrema_ExtCF.hxx>
898 #include <BRepExtrema_ExtPF.hxx>
899 #include <BRepExtrema_ExtFF.hxx>
900 #include <TCollection_ExtendedString.hxx>
901 #include <BRepExtrema_DistShapeShape.hxx>
902 #include <GC_MakePlane.hxx>
903 #include <TopExp_Explorer.hxx>
904 #include <BRepBuilderAPI_MakeVertex.hxx>
905 static int VLenghtDimension(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
908 Standard_Integer myCurrentIndex;
909 Standard_Real theDist;
912 if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;}
914 // Fermeture des contextes locaux
915 TheAISContext()->CloseAllContexts();
917 // Ouverture d'un contexte local et recuperation de son index.
918 myCurrentIndex = TheAISContext()->OpenLocalContext();
919 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
920 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
921 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
922 di<<" Select an edge, a face or a vertex. "<<"\n";
924 // Boucle d'attente waitpick.
925 Standard_Integer argc1 = 5;
926 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
927 const char **argv1 = (const char **) buf1;
928 while (ViewerMainLoop( argc1, argv1) ) { }
932 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
933 ShapeA = TheAISContext()->SelectedShape();
935 di<<" Select an edge, a face or a vertex. "<<"\n";
936 // Boucle d'attente waitpick.
937 Standard_Integer argc2 = 5;
938 const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
939 const char **argv2 = (const char **) buf2;
940 while (ViewerMainLoop( argc2, argv2) ) { }
944 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
945 ShapeB = TheAISContext()->SelectedShape();
947 // ShapeA est un edge.
948 // ===================
949 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
950 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
952 // Si ShapeB est un edge
953 if (ShapeB.ShapeType()==TopAbs_EDGE ) {
954 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
955 BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB );
956 // on verifie qu'ils ne sont pas paralleles.
957 if (!myDeltaEdge.IsParallel() ) {di<<"vlenghtdim error: non parallel edges."<<"\n";return 1; }
959 // On saisit la distance et on l'arrondit!
960 theDist=Round (sqrt(myDeltaEdge.SquareDistance(1))*10. )/10.;
962 // On recupere 3 Points des edges pour construire un plane.
963 TopoDS_Vertex Va,Vb,Vc,Vd;
964 TopExp::Vertices(EdgeA,Va,Vb);
965 TopExp::Vertices(EdgeB,Vc,Vd);
966 gp_Pnt A=BRep_Tool::Pnt(Va);
967 gp_Pnt B=BRep_Tool::Pnt(Vb);
968 gp_Pnt C=BRep_Tool::Pnt(Vc);
970 // Creation du Plane contenant la relation.
971 GC_MakePlane MkPlane(A,B,C);
972 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
974 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
976 // On ferme le contexte local.
977 TheAISContext()->CloseLocalContext(myCurrentIndex);
979 // on construit l'AISLenghtDimension.
980 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeA,EdgeB,theGeomPlane,theDist,TheMessage_Str );
981 TheAISContext()->Display(myLenghtDim );
982 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
985 // Si ShapeB est un vertex.
986 else if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
988 TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB);
989 BRepExtrema_ExtPC myDeltaEdgeVertex (VertexB ,EdgeA );
991 // On saisit la distance et on l'arrondit!
992 theDist=Round (sqrt (myDeltaEdgeVertex.SquareDistance(1))*10. )/10.;
994 // On recupere 2 Points de EdgeA pour construire un plane.
996 TopExp::Vertices(EdgeA,Va,Vb);
997 gp_Pnt A=BRep_Tool::Pnt(Va);
998 gp_Pnt B=BRep_Tool::Pnt(Vb);
999 gp_Pnt C=BRep_Tool::Pnt(VertexB);
1001 GC_MakePlane MkPlane(A,B,C);
1002 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1004 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1005 TheAISContext()->CloseLocalContext(myCurrentIndex);
1006 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeA,VertexB,theGeomPlane,theDist,TheMessage_Str );
1007 TheAISContext()->Display(myLenghtDim );
1008 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1013 // Si ShapeB est une Face
1016 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1017 BRepExtrema_ExtCF myDeltaEdgeFace (EdgeA,FaceB );
1018 // On verifie que l'edge est bien parallele a la face.
1019 if (!myDeltaEdgeFace.IsParallel() ) {di<<"vdistdim error: the edge isn't parallel to the face;can't compute the distance. "<<"\n";return 1; }
1021 // On saisit la distance et on l'arrondit!
1022 theDist=Round (sqrt (myDeltaEdgeFace.SquareDistance(1))*10. )/10.;
1024 // Construction du texte.
1025 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1027 // on construit l'AISLenghtDimension.
1028 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceB,EdgeA,theDist,TheMessage_Str );
1029 TheAISContext()->Display(myLenghtDim );
1030 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1036 // ShapeA est un vertex
1037 // ====================
1038 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1039 TopoDS_Vertex VertexA=TopoDS::Vertex(ShapeA);
1041 // Si ShapeB est un edge.
1042 if (ShapeB.ShapeType()==TopAbs_EDGE ) {
1043 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1044 BRepExtrema_ExtPC myDeltaEdgeVertex (VertexA ,EdgeB );
1045 // On saisit la distance et on l'arrondit!
1046 theDist=Round (sqrt (myDeltaEdgeVertex.SquareDistance(1))*10. )/10.;
1048 // On recupere 2 Points de EdgeB pour construire un plane.
1049 TopoDS_Vertex Va,Vb;
1050 TopExp::Vertices(EdgeB,Va,Vb);
1051 gp_Pnt A=BRep_Tool::Pnt(Va);
1052 gp_Pnt B=BRep_Tool::Pnt(Vb);
1053 gp_Pnt C=BRep_Tool::Pnt(VertexA);
1055 // Creation du Plane contenant la relation.
1056 GC_MakePlane MkPlane(A,B,C);
1057 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1059 // Fermeture du contexte local.
1060 TheAISContext()->CloseLocalContext(myCurrentIndex);
1061 // Construction du texte.
1062 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1064 // on construit l'AISLenghtDimension.
1065 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeB,VertexA,theGeomPlane,theDist,TheMessage_Str );
1066 TheAISContext()->Display(myLenghtDim );
1067 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1071 // Si ShapeB est un vertex.
1072 else if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
1073 TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB);
1074 BRepExtrema_DistShapeShape myDeltaVertexVertex (VertexA ,VertexB );
1075 // On saisit la distance et on l'arrondit!
1076 theDist=Round (myDeltaVertexVertex.Value()*10. )/10.;
1078 // Les deux premiers points.
1079 gp_Pnt A=BRep_Tool::Pnt(VertexA);
1080 gp_Pnt B=BRep_Tool::Pnt(VertexB);
1081 gp_Pnt C(B.X()+10,B.Y()+10,B.Z()+10);
1083 GC_MakePlane MkPlane(A,B,C);
1084 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1086 // Fermeture du contexte local.
1087 TheAISContext()->CloseLocalContext(myCurrentIndex);
1088 // Construction du texte.
1089 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1091 // on construit l'AISLenghtDimension.
1092 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexA,VertexB,theGeomPlane,theDist,TheMessage_Str );
1093 TheAISContext()->Display(myLenghtDim );
1094 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1101 // Si ShapeB est une Face
1104 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1105 BRepExtrema_ExtPF myDeltaVertexFace (VertexA ,FaceB );
1106 // On saisit la distance et on l'arrondit!
1107 theDist=Round (sqrt (myDeltaVertexFace.SquareDistance(1))*10. )/10.;
1110 gp_Pnt A=BRep_Tool::Pnt(VertexA);
1112 // On recupere 1 edge de FaceB.
1113 TopExp_Explorer FaceExp(FaceB,TopAbs_EDGE);
1114 TopoDS_Edge EdFromB=TopoDS::Edge(FaceExp.Current() );
1115 // On recupere les deux vertexes extremites de l'edge de face B
1116 TopoDS_Vertex Vb,Vc;
1117 TopExp::Vertices(EdFromB,Vb,Vc);
1122 gp_Pnt C=BRep_Tool::Pnt(Vc);
1124 // On projette le point B sur la Face car il
1125 // n'existe pas de constructeurs AIS_LD PointFace
1126 // on est donc oblige de creer un nouveau TopoDS_Vertex.
1127 gp_Pnt theProjA=myDeltaVertexFace.Point(1);
1128 BRepBuilderAPI_MakeVertex theVertexMaker(theProjA);
1129 TopoDS_Vertex VertexAproj=theVertexMaker.Vertex();
1130 // Creation du Plane contenant la relation.
1131 GC_MakePlane MkPlane(A,theProjA,C);
1132 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1134 // Fermeture du contexte local.
1135 TheAISContext()->CloseLocalContext(myCurrentIndex);
1136 // Construction du texte.
1137 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1139 // on construit l'AISLenghtDimension.
1140 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexA,VertexAproj,theGeomPlane,theDist,TheMessage_Str );
1141 TheAISContext()->Display(myLenghtDim );
1142 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1150 // ShapeA est une Face
1151 // ===================
1153 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1154 // Si ShapeB est un edge.
1155 if (ShapeB.ShapeType()==TopAbs_EDGE ) {
1156 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1157 BRepExtrema_ExtCF myDeltaEdgeFace (EdgeB,FaceA );
1158 // On verifie que l'edge est bien parallele a la face.
1159 if (!myDeltaEdgeFace.IsParallel() ) {di<<"vdistdim error: the edge isn't parallel to the face;can't compute the distance. "<<"\n";return 1; }
1161 // On saisit la distance et on l'arrondit!
1162 theDist=Round (sqrt (myDeltaEdgeFace.SquareDistance(1))*10. )/10.;
1164 // Construction du texte.
1165 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1167 // on construit l'AISLenghtDimension.
1168 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceA,EdgeB,theDist,TheMessage_Str );
1169 TheAISContext()->Display(myLenghtDim );
1170 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1174 // Si ShapeB est un vertex.
1175 else if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
1177 TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB);
1178 BRepExtrema_ExtPF myDeltaVertexFace (VertexB ,FaceA );
1179 // On saisit la distance et on l'arrondit!
1180 theDist=Round (sqrt (myDeltaVertexFace.SquareDistance(1))*10. )/10.;
1183 gp_Pnt B=BRep_Tool::Pnt(VertexB);
1185 // On recupere 1 edge de FaceA.
1186 TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE);
1187 TopoDS_Edge EdFromA=TopoDS::Edge(FaceExp.Current() );
1188 // On recupere les deux vertexes extremites de l'edge de face A
1189 TopoDS_Vertex Va,Vc;
1190 TopExp::Vertices(EdFromA,Va,Vc);
1191 gp_Pnt A=BRep_Tool::Pnt(Va);
1197 // On projette le point B sur la Face car il
1198 // n'existe pas de constructeurs AIS_LD PointFace
1199 // on est donc oblige de creer un nouveau TopoDS_Vertex.
1200 gp_Pnt theProjB=myDeltaVertexFace.Point(1);
1201 BRepBuilderAPI_MakeVertex theVertexMaker(theProjB);
1202 TopoDS_Vertex VertexBproj=theVertexMaker.Vertex();
1203 // Creation du Plane contenant la relation.
1204 GC_MakePlane MkPlane(A,B,theProjB);
1205 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1207 // Fermeture du contexte local.
1208 TheAISContext()->CloseLocalContext(myCurrentIndex);
1209 // Construction du texte.
1210 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1212 // on construit l'AISLenghtDimension mais en utilisant le constructeur Vertex Vertex.
1213 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexB,VertexBproj,theGeomPlane,theDist,TheMessage_Str );
1214 TheAISContext()->Display(myLenghtDim );
1215 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1219 // Si ShapeB est une Face
1222 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1223 BRepExtrema_ExtFF myDeltaFaceFace (FaceA ,FaceB );
1224 // On verifie que les deux faces sont bien parelles.
1225 if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1227 // On saisit la distance et on l'arrondit!
1228 theDist=Round (sqrt (myDeltaFaceFace.SquareDistance(1))*10. )/10.;
1229 // Fermeture du contexte local.
1230 TheAISContext()->CloseLocalContext(myCurrentIndex);
1231 // Construction du texte.
1232 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1234 // on construit l'AISLenghtDimension.
1235 Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceA,FaceB,theDist,TheMessage_Str );
1236 TheAISContext()->Display(myLenghtDim );
1237 GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1250 //==============================================================================
1251 //function : VRadiusDim
1252 //purpose : Display the radius dimension of a face or an edge.
1253 //Draw arg : vradiusdim Name
1254 //==============================================================================
1255 #include <AIS_RadiusDimension.hxx>
1256 #include <TCollection_ExtendedString.hxx>
1257 #include <BRepAdaptor_Curve.hxx>
1258 #include <gp_Circ.hxx>
1261 static int VRadiusDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1264 Standard_Integer myCurrentIndex;
1265 Standard_Real theRadius;
1268 if (argc!=2) {di<<" vradiusdim error"<<"\n";return 1;}
1270 // Fermeture des contextes locaux
1271 TheAISContext()->CloseAllContexts();
1273 // Ouverture d'un contexte local et recuperation de son index.
1274 TheAISContext()->OpenLocalContext();
1275 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1277 // On active les modes de selections Edges et Faces.
1278 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1279 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1280 di<<" Select an circled edge or face."<<"\n";
1282 // Boucle d'attente waitpick.
1283 Standard_Integer argcc = 5;
1284 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1285 const char **argvv = (const char **) buff;
1286 while (ViewerMainLoop( argcc, argvv) ) { }
1289 TopoDS_Shape ShapeA;
1290 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1291 ShapeA = TheAISContext()->SelectedShape();
1294 // Shape A est un edge.
1295 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1297 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1298 // Recuperation du rayon
1299 BRepAdaptor_Curve theCurve(TopoDS::Edge(ShapeA));
1300 if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vradiusdim error: the edge is not a circular one."<<"\n";return 1;}
1302 gp_Circ theGpCircle=theCurve.Circle();
1303 theRadius=theGpCircle.Radius();
1304 // On arrondit le rayon
1305 theRadius=Round (theRadius*10. )/10.;
1308 // Construction du texte.
1309 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("r=")+TCollection_ExtendedString(theRadius ) );
1311 // Fermeture du contexte.
1312 TheAISContext()->CloseLocalContext(myCurrentIndex);
1314 // Construction de L'AIS_RadiusDimension.
1315 Handle (AIS_RadiusDimension) myRadDim= new AIS_RadiusDimension(ShapeA ,theRadius ,TheMessage_Str );
1316 GetMapOfAIS().Bind (myRadDim,argv[1]);
1317 TheAISContext()->Display(myRadDim );
1322 // Shape A est une face
1323 else if (ShapeA.ShapeType()==TopAbs_FACE ) {
1325 // on recupere un edge de la face.
1326 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1328 TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE);
1329 TopoDS_Edge EdgeFromA=TopoDS::Edge(FaceExp.Current() );
1331 // Recuperation du rayon
1332 BRepAdaptor_Curve theCurve(EdgeFromA );
1333 if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vradiusdim error: the face is not a circular one."<<"\n";return 1;}
1335 gp_Circ theGpCircle=theCurve.Circle();
1336 theRadius=theGpCircle.Radius();
1337 // On arrondit le rayon
1338 theRadius=Round (theRadius*10. )/10.;
1341 // Construction du texte.
1342 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("r=")+TCollection_ExtendedString(theRadius ) );
1344 // Fermeture du contexte.
1345 TheAISContext()->CloseLocalContext(myCurrentIndex);
1347 // Construction de L'AIS_RadiusDimension.
1348 Handle (AIS_RadiusDimension) myRadDim= new AIS_RadiusDimension(ShapeA ,theRadius ,TheMessage_Str );
1349 //Handle (AIS_MinRadiusDimension) myRadDim= new AIS_MinRadiusDimension(EdgeFromA ,theRadius ,TheMessage_Str );
1350 GetMapOfAIS().Bind (myRadDim,argv[1]);
1351 TheAISContext()->Display(myRadDim );
1357 di<<" vradiusdim error: the selection of a face or an edge was expected."<<"\n";return 1;
1366 //==============================================================================
1367 //function : VOffsetDim
1368 //purpose : Display the offset dimension
1369 //Draw arg : voffsetdim Name
1370 //==============================================================================
1371 #include <AIS_OffsetDimension.hxx>
1372 #include <TCollection_ExtendedString.hxx>
1373 #include <BRepExtrema_ExtFF.hxx>
1376 static int VOffsetDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1379 Standard_Integer myCurrentIndex;
1380 Standard_Real theDist;
1383 if (argc!=2) {di<<" voffsetdim error"<<"\n";return 1;}
1385 // Fermeture des contextes locaux
1386 TheAISContext()->CloseAllContexts();
1388 // Ouverture d'un contexte local et recuperation de son index.
1389 TheAISContext()->OpenLocalContext();
1390 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1392 // On active les modes de selections Faces.
1393 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1394 di<<" Select a face."<<"\n";
1396 // Boucle d'attente waitpick.
1397 Standard_Integer argcc = 5;
1398 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1399 const char **argvv = (const char **) buff;
1400 while (ViewerMainLoop( argcc, argvv) ) { }
1403 TopoDS_Shape ShapeA;
1404 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1405 ShapeA = TheAISContext()->SelectedShape();
1408 di<<" Select a face."<<"\n";
1409 // Boucle d'attente waitpick.
1410 Standard_Integer argccc = 5;
1411 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1412 const char **argvvv = (const char **) bufff;
1413 while (ViewerMainLoop( argccc, argvvv) ) { }
1416 TopoDS_Shape ShapeB;
1417 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1418 ShapeB = TheAISContext()->SelectedShape();
1422 // Shape A et B est une face
1423 if (ShapeA.ShapeType()==TopAbs_FACE && ShapeB.ShapeType()==TopAbs_FACE ) {
1425 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1426 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1428 BRepExtrema_ExtFF myDeltaFaceFace (FaceA ,FaceB );
1429 // On verifie que les deux faces sont bien parelles.
1430 if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1432 // On saisit la distance et on l'arrondit!
1433 theDist=Round (sqrt (myDeltaFaceFace.SquareDistance(1))*10. )/10.;
1434 // Fermeture du contexte local.
1435 TheAISContext()->CloseLocalContext(myCurrentIndex);
1436 // Construction du texte.
1437 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("offset=")+TCollection_ExtendedString(theDist ) );
1439 // on construit l'AIS_OffsetDimension
1440 Handle(AIS_OffsetDimension) myOffsetDim=new AIS_OffsetDimension (FaceA,FaceB,theDist,TheMessage_Str );
1441 TheAISContext()->Display(myOffsetDim );
1442 GetMapOfAIS().Bind (myOffsetDim ,argv[1]);
1449 di<<" voffsetdim error: the selection of a face was expected."<<"\n";return 1;
1459 //==============================================================================
1460 //function : VParallel
1461 //purpose : Display the parallel relation
1462 //Draw arg : vparallel Name
1463 //==============================================================================
1464 #include <AIS_ParallelRelation.hxx>
1465 #include <TCollection_ExtendedString.hxx>
1466 #include <BRepExtrema_ExtFF.hxx>
1467 #include <BRepExtrema_ExtCC.hxx>
1468 #include <GC_MakePlane.hxx>
1469 #include <BRepAdaptor_Curve.hxx>
1470 #include <TopExp_Explorer.hxx>
1473 static int VParallelBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1476 Standard_Integer myCurrentIndex;
1479 if (argc!=2) {di<<" vparallel error"<<"\n";return 1;}
1481 // Fermeture des contextes locaux
1482 TheAISContext()->CloseAllContexts();
1484 // Ouverture d'un contexte local et recuperation de son index.
1485 TheAISContext()->OpenLocalContext();
1486 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1488 // On active les modes de selections Edges.
1489 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1490 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1491 di<<" Select an edge or a face "<<"\n";
1493 // Boucle d'attente waitpick.
1494 Standard_Integer argcc = 5;
1495 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1496 const char **argvv = (const char **) buff;
1497 while (ViewerMainLoop( argcc, argvv) ) { }
1500 TopoDS_Shape ShapeA;
1501 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1502 ShapeA = TheAISContext()->SelectedShape();
1505 // SahpeA est un edge.
1506 // ===================
1507 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1509 // desactivation du mode face
1510 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1511 di<<" Select a second edge"<<"\n";
1512 // Boucle d'attente waitpick.
1513 Standard_Integer argccc = 5;
1514 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1515 const char **argvvv = (const char **) bufff;
1516 while (ViewerMainLoop( argccc, argvvv) ) { }
1519 TopoDS_Shape ShapeB;
1520 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1521 ShapeB = TheAISContext()->SelectedShape();
1524 // recuperation des edges.
1525 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1526 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1527 BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB );
1528 // on verifie qu'ils ne sont pas paralleles.
1529 if (!myDeltaEdge.IsParallel() ) {di<<"vparallel error: non parallel edges."<<"\n";return 1; }
1532 // On recupere les vertexes extremites des edge A et B.
1533 BRepAdaptor_Curve theCurveA(EdgeA);
1534 BRepAdaptor_Curve theCurveB(EdgeB);
1535 // On recupere 3 points A,B,C des curves.
1536 gp_Pnt A=theCurveA.Value(0.1);
1537 gp_Pnt B=theCurveA.Value(0.9);
1538 gp_Pnt C=theCurveB.Value(0.5);
1540 // Construction du Geom_Plane
1541 GC_MakePlane MkPlane(A,B,C);
1542 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1543 // Fermeture du contexte local.
1544 TheAISContext()->CloseLocalContext(myCurrentIndex);
1545 // Construction de l'AIS_ParallelRelation
1546 Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(EdgeA ,EdgeB ,theGeomPlane );
1547 TheAISContext()->Display(myParaRelation );
1548 GetMapOfAIS().Bind (myParaRelation ,argv[1]);
1553 // Shape A est une face
1554 // ====================
1557 // desactivation du mode edge
1558 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1559 di<<" Select a second edge"<<"\n";
1560 // Boucle d'attente waitpick.
1561 Standard_Integer argccc = 5;
1562 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1563 const char **argvvv = (const char **) bufff;
1564 while (ViewerMainLoop( argccc, argvvv) ) { }
1567 TopoDS_Shape ShapeB;
1568 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1569 ShapeB = TheAISContext()->SelectedShape();
1572 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1573 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1575 BRepExtrema_ExtFF myDeltaFaceFace (FaceA ,FaceB );
1576 // On verifie que les deux faces sont bien parelles.
1577 if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1579 // recuperation des edges des faces.
1580 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
1581 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
1583 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
1584 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
1586 // On recupere les vertexes extremites des edge A et B.
1587 BRepAdaptor_Curve theCurveA(EdgeA);
1588 BRepAdaptor_Curve theCurveB(EdgeB);
1589 // On recupere 3 points A,B,C des curves.
1590 gp_Pnt A=theCurveA.Value(0.1);
1591 gp_Pnt B=theCurveA.Value(0.9);
1592 gp_Pnt C=theCurveB.Value(0.5);
1594 // Construction du Geom_Plane
1595 GC_MakePlane MkPlane(A,B,C);
1596 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1597 // Fermeture du contexte local.
1598 TheAISContext()->CloseLocalContext(myCurrentIndex);
1599 // Construction de l'AIS_ParallelRelation
1600 Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(FaceA ,FaceB ,theGeomPlane );
1601 TheAISContext()->Display(myParaRelation );
1602 GetMapOfAIS().Bind (myParaRelation ,argv[1]);
1616 //==============================================================================
1617 //function : VPerpendicularRelation
1618 //purpose : Display the Perpendicular Relation
1619 //Draw arg : vperpendicular Name
1620 //==============================================================================
1621 #include <AIS_PerpendicularRelation.hxx>
1622 #include <TCollection_ExtendedString.hxx>
1623 #include <GC_MakePlane.hxx>
1624 #include <BRepAdaptor_Curve.hxx>
1625 #include <TopExp_Explorer.hxx>
1629 static int VPerpendicularBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1632 Standard_Integer myCurrentIndex;
1635 if (argc!=2) {di<<" vortho error"<<"\n";return 1;}
1637 // Fermeture des contextes locaux
1638 TheAISContext()->CloseAllContexts();
1640 // Ouverture d'un contexte local et recuperation de son index.
1641 TheAISContext()->OpenLocalContext();
1642 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1644 // On active les modes de selections Edges.
1645 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1646 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1647 di<<" Select an edge or a face "<<"\n";
1649 // Boucle d'attente waitpick.
1650 Standard_Integer argcc = 5;
1651 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1652 const char **argvv = (const char **) buff;
1653 while (ViewerMainLoop( argcc, argvv) ) { }
1656 TopoDS_Shape ShapeA;
1657 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1658 ShapeA = TheAISContext()->SelectedShape();
1661 // ShapeA est un edge.
1662 // ===================
1663 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1665 // desactivation du mode face
1666 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1667 di<<" Select a second edge"<<"\n";
1668 // Boucle d'attente waitpick.
1669 Standard_Integer argccc = 5;
1670 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1671 const char **argvvv = (const char **) bufff;
1672 while (ViewerMainLoop( argccc, argvvv) ) { }
1675 TopoDS_Shape ShapeB;
1676 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1677 ShapeB = TheAISContext()->SelectedShape();
1680 // recuperation des edges.
1681 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1682 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1684 // On recupere les curves
1685 BRepAdaptor_Curve theCurveA(EdgeA);
1686 BRepAdaptor_Curve theCurveB(EdgeB);
1687 // on verifie si les edges sont orthogonaux.
1688 //gp_Lin theLineA=theCurveA.Line();
1689 //gp_Lin theLineB=theCurveB.Line();
1690 //if (abs(theLineA.Angle(theLineB) ) != M_PI/2 ) {cout<<"vperpendicular error: Edges are not othogonals."<<endl;return 1;}
1692 // On recupere 3 points A,B,C des curves.
1693 gp_Pnt A=theCurveA.Value(0.1);
1694 gp_Pnt B=theCurveA.Value(0.9);
1695 gp_Pnt C=theCurveB.Value(0.5);
1696 // Construction du Geom_Plane
1697 GC_MakePlane MkPlane(A,B,C);
1698 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1699 // Fermeture du contexte local.
1700 TheAISContext()->CloseLocalContext(myCurrentIndex);
1701 // Construction de l'AIS_ParallelRelation
1702 Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation (EdgeA ,EdgeB ,theGeomPlane );
1703 TheAISContext()->Display(myOrthoRelation );
1704 GetMapOfAIS().Bind (myOrthoRelation ,argv[1]);
1709 // Shape A est une face
1710 // ====================
1713 // desactivation du mode edge
1714 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1715 di<<" Select a second edge"<<"\n";
1716 // Boucle d'attente waitpick.
1717 Standard_Integer argccc = 5;
1718 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1719 const char **argvvv = (const char **) bufff;
1720 while (ViewerMainLoop( argccc, argvvv) ) { }
1723 TopoDS_Shape ShapeB;
1724 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1725 ShapeB = TheAISContext()->SelectedShape();
1728 // pas de verification d'orthogonalite.
1729 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1730 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1732 // recuperation des edges des faces.
1733 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
1734 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
1736 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
1737 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
1739 // On recupere les vertexes extremites des edge A et B.
1740 BRepAdaptor_Curve theCurveA(EdgeA);
1741 BRepAdaptor_Curve theCurveB(EdgeB);
1742 // On recupere 3 points A,B,C des curves.
1743 gp_Pnt A=theCurveA.Value(0.1);
1744 gp_Pnt B=theCurveA.Value(0.9);
1745 gp_Pnt C=theCurveB.Value(0.5);
1746 // Construction du Geom_Plane
1747 GC_MakePlane MkPlane(A,B,C);
1748 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1749 // Fermeture du contexte local.
1750 TheAISContext()->CloseLocalContext(myCurrentIndex);
1751 // Construction de l'AIS_PerpendicularRelation
1752 Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation(FaceA ,FaceB );
1753 TheAISContext()->Display(myOrthoRelation );
1754 GetMapOfAIS().Bind (myOrthoRelation ,argv[1]);
1766 //==============================================================================
1767 //function : VTangentRelation
1768 //purpose : Display the tangent Relation
1769 //Draw arg : vtangent Name
1770 //==============================================================================
1771 #include <AIS_TangentRelation.hxx>
1774 static int VTangentBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1777 Standard_Integer myCurrentIndex;
1780 if (argc!=2) {di<<" vtangent error"<<"\n";return 1;}
1782 // Fermeture des contextes locaux
1783 TheAISContext()->CloseAllContexts();
1785 // Ouverture d'un contexte local et recuperation de son index.
1786 TheAISContext()->OpenLocalContext();
1787 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1789 // On active les modes de selections Edges.
1790 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1791 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1792 di<<" Select two coplanar edges(First the circular edge then the tangent edge) or two faces "<<"\n";
1794 // Boucle d'attente waitpick.
1795 Standard_Integer argcc = 5;
1796 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1797 const char **argvv = (const char **) buff;
1798 while (ViewerMainLoop( argcc, argvv) ) { }
1801 TopoDS_Shape ShapeA;
1802 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1803 ShapeA = TheAISContext()->SelectedShape();
1806 // ShapeA est un edge.
1807 // ===================
1808 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1810 // desactivation du mode face
1811 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1812 di<<" Select a second edge"<<"\n";
1813 // Boucle d'attente waitpick.
1814 Standard_Integer argccc = 5;
1815 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1816 const char **argvvv = (const char **) bufff;
1817 while (ViewerMainLoop( argccc, argvvv) ) { }
1820 TopoDS_Shape ShapeB;
1821 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1822 ShapeB = TheAISContext()->SelectedShape();
1825 // recuperation des edges.
1826 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1827 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1829 // On recupere les curves
1830 BRepAdaptor_Curve theCurveA(EdgeA);
1831 BRepAdaptor_Curve theCurveB(EdgeB);
1833 // On recupere 3 points A,B,C des curves.
1834 gp_Pnt A=theCurveA.Value(0.1);
1835 gp_Pnt B=theCurveA.Value(0.9);
1836 gp_Pnt C=theCurveB.Value(0.5);
1838 // Construction du Geom_Plane
1839 GC_MakePlane MkPlane(A,B,C);
1840 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1841 // Fermeture du contexte local.
1842 TheAISContext()->CloseLocalContext(myCurrentIndex);
1843 // Construction de l'AIS_TangentRelation
1844 Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation (EdgeA ,EdgeB ,theGeomPlane );
1845 TheAISContext()->Display(myTanRelation );
1846 GetMapOfAIS().Bind (myTanRelation ,argv[1]);
1851 // Shape A est une face
1852 // ====================
1855 // desactivation du mode edge
1856 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1857 di<<" Select a second edge"<<"\n";
1858 // Boucle d'attente waitpick.
1859 Standard_Integer argccc = 5;
1860 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1861 const char **argvvv = (const char **) bufff;
1862 while (ViewerMainLoop( argccc, argvvv) ) { }
1865 TopoDS_Shape ShapeB;
1866 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1867 ShapeB = TheAISContext()->SelectedShape();
1870 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1871 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1873 // recuperation des edges des faces.
1874 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
1875 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
1877 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
1878 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
1880 // On recupere les vertexes extremites des edge A et B.
1881 BRepAdaptor_Curve theCurveA(EdgeA);
1882 BRepAdaptor_Curve theCurveB(EdgeB);
1883 // On recupere 3 points A,B,C des curves.
1884 gp_Pnt A=theCurveA.Value(0.1);
1885 gp_Pnt B=theCurveA.Value(0.9);
1886 gp_Pnt C=theCurveB.Value(0.5);
1888 // Construction du Geom_Plane
1889 GC_MakePlane MkPlane(A,B,C);
1890 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1891 // Fermeture du contexte local.
1892 TheAISContext()->CloseLocalContext(myCurrentIndex);
1893 // Construction de l'AIS_PerpendicularRelation
1894 Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation(FaceA ,FaceB,theGeomPlane );
1895 TheAISContext()->Display(myTanRelation );
1896 GetMapOfAIS().Bind (myTanRelation ,argv[1]);
1907 //==============================================================================
1908 //function : VSymetricalRelation
1909 //purpose : Display the Symetrical Relation
1910 //Draw arg : vsymetric Name
1911 //==============================================================================
1912 #include <AIS_SymmetricRelation.hxx>
1915 static int VSymmetricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1918 Standard_Integer myCurrentIndex;
1921 if (argc!=2) {di<<" vSymmetric error"<<"\n";return 1;}
1923 // Fermeture des contextes locaux
1924 TheAISContext()->CloseAllContexts();
1926 // Ouverture d'un contexte local et recuperation de son index.
1927 TheAISContext()->OpenLocalContext();
1928 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1930 // On active les modes de selections
1931 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1932 di<<" Select an edge:the axis of symetry "<<"\n";
1934 // Boucle d'attente waitpick.
1935 Standard_Integer argcc = 5;
1936 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1937 const char **argvv = (const char **) buff;
1938 while (ViewerMainLoop( argcc, argvv) ) { }
1941 TopoDS_Shape ShapeA;
1942 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1943 ShapeA = TheAISContext()->SelectedShape();
1945 // recuperation des edges.
1946 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1948 // On active les modes de selections
1949 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1950 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1951 di<<" Select two edges or two vertices. "<<"\n";
1953 // Boucle d'attente waitpick.
1954 Standard_Integer argcc2 = 5;
1955 // const char *buff2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1956 const char **argvv2 = (const char **) buff;
1957 while (ViewerMainLoop( argcc2, argvv2) ) { }
1960 TopoDS_Shape ShapeB;
1961 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1962 ShapeB = TheAISContext()->SelectedShape();
1969 // ShapeB est un edge.
1970 // ===================
1971 if (ShapeB.ShapeType()==TopAbs_EDGE ) {
1973 // desactivation du mode vertex
1974 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) );
1975 di<<" Select a second edge"<<"\n";
1976 // Boucle d'attente waitpick.
1977 Standard_Integer argccc = 5;
1978 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1979 const char **argvvv = (const char **) bufff;
1980 while (ViewerMainLoop( argccc, argvvv) ) { }
1983 TopoDS_Shape ShapeC;
1984 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1985 ShapeC = TheAISContext()->SelectedShape();
1988 // recuperation des edges.
1989 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1990 TopoDS_Edge EdgeC=TopoDS::Edge(ShapeC);
1991 // on verifie que les edges sont paralleles
1992 BRepExtrema_ExtCC myDeltaEdgeAB (EdgeA ,EdgeB );
1993 BRepExtrema_ExtCC myDeltaEdgeAC (EdgeA ,EdgeC );
1994 // on verifie qu'ils sont paralleles.
1995 if (!myDeltaEdgeAB.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; }
1996 if (!myDeltaEdgeAC.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; }
1997 // on recupere les vertexs
1998 TopoDS_Vertex Va,Vb,Vc,Vd;
1999 TopExp::Vertices(EdgeB,Va,Vb );
2000 TopExp::Vertices(EdgeC,Vc,Vd );
2001 gp_Pnt A=BRep_Tool::Pnt(Va);
2002 gp_Pnt B=BRep_Tool::Pnt(Vc);
2003 gp_Pnt C = Get3DPointAtMousePosition();
2005 // gp_Pnt C=BRep_Tool::Pnt(Vc);
2006 // Construction du Geom_Plane
2007 GC_MakePlane MkPlane(A,B,C);
2008 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2009 // Fermeture du contexte local.
2010 TheAISContext()->CloseLocalContext(myCurrentIndex);
2011 // Construction de l'AIS_SymmetricRelation
2012 Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,EdgeB ,EdgeC, theGeomPlane );
2013 TheAISContext()->Display(mySymRelation );
2014 GetMapOfAIS().Bind (mySymRelation ,argv[1]);
2019 // Shape B est un vertex
2020 // =====================
2023 // desactivation du mode edge
2024 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
2025 di<<" Select a second edge"<<"\n";
2026 // Boucle d'attente waitpick.
2027 Standard_Integer argccc = 5;
2028 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2029 const char **argvvv = (const char **) bufff;
2030 while (ViewerMainLoop( argccc, argvvv) ) { }
2033 TopoDS_Shape ShapeC;
2034 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2035 ShapeC = TheAISContext()->SelectedShape();
2038 // recuperation des Vertex
2039 TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB);
2040 TopoDS_Vertex VertexC=TopoDS::Vertex(ShapeC);
2041 // transfo en gp_Pnt
2042 gp_Pnt B=BRep_Tool::Pnt(VertexB);
2043 gp_Pnt C=BRep_Tool::Pnt(VertexC);
2045 // on recupere les vertexes de l'axe de sym
2046 TopoDS_Vertex Va,Vb;
2047 TopExp::Vertices(EdgeA,Va,Vb );
2048 gp_Pnt A=BRep_Tool::Pnt(Va);
2049 // Construction du Geom_Plane
2050 GC_MakePlane MkPlane(A,B,C);
2051 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2052 // Fermeture du contexte local.
2053 TheAISContext()->CloseLocalContext(myCurrentIndex);
2054 // Construction de l'AIS_SymmetricRelation
2055 Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,VertexB ,VertexC, theGeomPlane );
2056 TheAISContext()->Display(mySymRelation );
2057 GetMapOfAIS().Bind (mySymRelation ,argv[1]);
2067 //=======================================================================
2068 //function : VMoveDim
2070 //=======================================================================
2071 static int VMoveDim(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2073 if(argc>2) return 1;
2075 const Handle(V3d_View) aview = ViewerTest::CurrentView();
2076 Handle(AIS_InteractiveObject) pickedobj;
2078 pickedobj = TheAISContext()->FirstCurrentObject();
2079 if(pickedobj.IsNull() || pickedobj->Type()!=AIS_KOI_Relation)
2080 pickedobj = ViewerTest::PickObject(AIS_KOI_Relation);
2083 // reperage dans le viewer...
2084 if(!strcasecmp(argv[1],".")){
2085 pickedobj = ViewerTest::PickObject(AIS_KOI_Relation);
2088 else if(GetMapOfAIS().IsBound2(argv[1]))
2089 pickedobj = Handle(AIS_InteractiveObject)::DownCast
2090 (GetMapOfAIS().Find2(argv[1]));
2093 if(pickedobj.IsNull()){
2094 di<<"Bad Type Object"<<"\n";
2097 if(pickedobj->Type() != AIS_KOI_Relation)
2099 Standard_Integer argccc = 5;
2101 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2102 const char **argvvv = (const char **) bufff;
2104 Handle(AIS_Relation) R = *((Handle(AIS_Relation)*)&pickedobj);
2105 Handle(Geom_Plane) ThePl;
2106 // Standard_Real x,y,z,xv,yv,zv;
2107 Standard_Real x,y,xv,yv,zv;
2108 static Standard_Real last_xv(0),last_yv(0),last_zv(0);
2109 Standard_Integer xpix,ypix;
2110 // Standard_Boolean SameAsLast(Standard_False);
2111 Select3D_Projector prj(aview);
2114 while (ViewerMainLoop( argccc, argvvv) ) {
2115 //....... la ligne de tir
2116 ViewerTest::GetMousePosition(xpix,ypix);
2117 aview->Convert(xpix,ypix,x,y); // espace reel 2D de la vue...
2118 gp_Lin L = prj.Shoot(x,y);
2122 // ....... le plan de la vue...
2123 aview->Proj(xv,yv,zv);
2124 static Standard_Boolean haschanged(Standard_False);
2125 if(Abs(last_xv-xv)>Precision::Confusion() ||
2126 Abs(last_yv-yv)>Precision::Confusion() ||
2127 Abs(last_zv-zv)>Precision::Confusion() ){
2131 Standard_Real xat,yat,zat;
2132 aview->At(xat,yat,zat);
2133 ThePl = new Geom_Plane(gp_Pnt(xat,yat,zat),gp_Dir(xv,yv,zv));
2134 haschanged = Standard_True;
2135 di <<"changement de plan"<<"\n";
2139 // Standard_Integer xpix,ypix;
2140 // Standard_Real x,y;
2144 ComputeNewPlaneForDim(R,NewPlane,GoodPoint);
2145 haschanged = Standard_False;
2148 if(ComputeIntersection(L,ThePl->Pln(),GoodPoint)){
2149 R->SetPosition(GoodPoint);
2151 TheAISContext()->Redisplay(R);
2157 //=======================================================================
2158 //function : RelationsCommands
2160 //=======================================================================
2163 void ViewerTest::RelationCommands(Draw_Interpretor& theCommands)
2165 const char *group = "AISRelations";
2168 theCommands.Add("vangledim",
2169 "vangledim Name:Selection in the viewer only ",
2170 __FILE__,VAngleDimBuilder,group);
2172 theCommands.Add("vdiameterdim",
2173 "vdiameterdim Name : Selection in the viewer only ",
2174 __FILE__,VDiameterDimBuilder,group);
2176 theCommands.Add("vconcentric",
2177 "vconcentric Name : Selection in the viewer only ",
2178 __FILE__,VConcentricBuilder,group);
2180 theCommands.Add("vequaldist",
2181 "vequaldist Name Selection in the viewer only ",
2182 __FILE__,VEqualDistRelation ,group);
2184 theCommands.Add("vequalrad",
2185 "vequalrad Name Selection in the viewer only ",
2186 __FILE__,VEqualRadiusRelation ,group);
2188 theCommands.Add("vfix",
2189 "vfix Name Selection in the viewer only ",
2190 __FILE__,VFixRelation ,group);
2192 theCommands.Add("videntity",
2193 "videntity Name Selection in the viewer only ",
2194 __FILE__,VIdenticRelation ,group);
2196 theCommands.Add("vdistdim",
2197 "vdistdim Name Selection in the viewer only ",
2198 __FILE__,VLenghtDimension ,group);
2200 theCommands.Add("vradiusdim",
2201 "vradiusdim Name Selection in the viewer only ",
2202 __FILE__,VRadiusDimBuilder ,group);
2204 theCommands.Add("voffsetdim",
2205 "voffsetdim Name Selection in the viewer only ",
2206 __FILE__,VOffsetDimBuilder ,group);
2208 theCommands.Add("vparallel",
2209 "vparallel Name Selection in the viewer only ",
2210 __FILE__,VParallelBuilder ,group);
2212 theCommands.Add("vortho",
2213 "vortho Name Selection in the viewer only ",
2214 __FILE__,VPerpendicularBuilder ,group);
2216 theCommands.Add("vtangent",
2217 "vtangent Name Selection in the viewer only ",
2218 __FILE__,VTangentBuilder ,group);
2221 theCommands.Add("vsymetric",
2222 "vsymetric Name Selection in the viewer only ",
2223 __FILE__,VSymmetricBuilder ,group);
2225 theCommands.Add("vmovedim",
2226 "vmovedim [name] : move Mouse in the viewer; click MB1 to stop motion...",
2227 __FILE__,VMoveDim,group);