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 // Ñheck that the radius is >= 0
91322f44 2033 if (Draw::Atof(argv[4]) <= 0 )
329843e2
A
2034 {
2035 std::cout << "vcircle error: the radius must be >=0.\n";
2036 return 1; // TCL_ERROR
7fd59977 2037 }
7fd59977 2038
329843e2
A
2039 // Recover the normal to the plane
2040 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2041 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
7fd59977 2042
329843e2
A
2043 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2044 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2045 Handle(Geom_CartesianPoint) myCartPointB =
2046 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
7fd59977 2047
2048 gp_Pln mygpPlane = myGeomPlane->Pln();
2049 gp_Ax1 thegpAxe = mygpPlane.Axis();
2050 gp_Dir theDir = thegpAxe.Direction();
329843e2 2051 gp_Pnt theCenter = myCartPointB->Pnt();
91322f44 2052 Standard_Real TheR = Draw::Atof(argv[4]);
329843e2
A
2053 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2054 Handle (Geom_Circle) theGeomCircle;
2055 try
2056 {
2057 theGeomCircle = Cir.Value();
2058 }
2059 catch (StdFail_NotDone)
2060 {
2061 std::cout << "vcircle error: can't create circle\n";
2062 return -1; // TCL_ERROR
2063 }
2064
2065 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2066
2067 }
2068
2069 // Error
329843e2
A
2070 else
2071 {
2072 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2073 return 1; // TCL_ERROR
7fd59977 2074 }
2075
2076 }
329843e2 2077 // No arguments: selection in the viewer
7fd59977 2078 // =========================================
329843e2
A
2079 else
2080 {
2081 // Get the name of the circle
2082 TCollection_AsciiString aName(argv[1]);
7fd59977 2083
2084 TheAISContext()->OpenLocalContext();
329843e2 2085 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 2086
329843e2 2087 // Activate selection mode for vertices and faces
7fd59977 2088 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2089 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
ceae62f0 2090 std::cout << " Select a vertex or a face\n";
7fd59977 2091
329843e2 2092 // Wait for picking
7fd59977 2093 Standard_Integer argcc = 5;
2094 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2095 const char **argvv = (const char **) buff;
2096 while (ViewerMainLoop( argcc, argvv) ) { }
329843e2 2097 // end of the loop
7fd59977 2098
2099 TopoDS_Shape ShapeA;
329843e2
A
2100 for(TheAISContext()->InitSelected();
2101 TheAISContext()->MoreSelected();
2102 TheAISContext()->NextSelected() )
2103 {
7fd59977 2104 ShapeA = TheAISContext()->SelectedShape();
2105 }
2106
329843e2
A
2107 // ShapeA is a Vertex
2108 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2109 {
7fd59977 2110 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
ceae62f0 2111 std::cout << " Select a different vertex\n";
7fd59977 2112
2113 TopoDS_Shape ShapeB;
329843e2
A
2114 do
2115 {
2116 // Wait for picking
7fd59977 2117 Standard_Integer argccc = 5;
2118 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2119 const char **argvvv = (const char **) bufff;
2120 while (ViewerMainLoop( argccc, argvvv) ) { }
329843e2 2121 // end of the loop
7fd59977 2122
329843e2
A
2123 for(TheAISContext()->InitSelected();
2124 TheAISContext()->MoreSelected();
2125 TheAISContext()->NextSelected() )
2126 {
7fd59977 2127 ShapeB = TheAISContext()->SelectedShape();
2128 }
7fd59977 2129 } while(ShapeB.IsSame(ShapeA) );
2130
329843e2 2131 // Selection of ShapeC
ceae62f0 2132 std::cout << " Select the last vertex\n";
7fd59977 2133 TopoDS_Shape ShapeC;
329843e2
A
2134 do
2135 {
2136 // Wait for picking
7fd59977 2137 Standard_Integer argcccc = 5;
2138 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2139 const char **argvvvv = (const char **) buffff;
2140 while (ViewerMainLoop( argcccc, argvvvv) ) { }
329843e2 2141 // end of the loop
7fd59977 2142
329843e2
A
2143 for(TheAISContext()->InitSelected();
2144 TheAISContext()->MoreSelected();
2145 TheAISContext()->NextSelected() )
2146 {
7fd59977 2147 ShapeC = TheAISContext()->SelectedShape();
2148 }
7fd59977 2149 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
329843e2
A
2150
2151 // Get isFilled
2152 Standard_Boolean isFilled;
2153 std::cout << "Enter filled status (0 or 1)\n";
2154 cin >> isFilled;
7fd59977 2155
329843e2 2156 // Close the local context
7fd59977 2157 TheAISContext()->CloseLocalContext(myCurrentIndex);
2158
329843e2
A
2159 // Construction of the circle
2160 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2161 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2162 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2163
2164 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2165 Handle (Geom_Circle) theGeomCircle;
2166 try
2167 {
2168 theGeomCircle = Cir.Value();
2169 }
2170 catch (StdFail_NotDone)
2171 {
2172 std::cout << "vcircle error: can't create circle\n";
2173 return -1; // TCL_ERROR
2174 }
7fd59977 2175
329843e2 2176 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2177
2178 }
329843e2 2179 // Shape is a face
ceae62f0 2180 else
329843e2 2181 {
ceae62f0 2182 std::cout << " Select a vertex (in your face)\n";
7fd59977 2183 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2184
2185 TopoDS_Shape ShapeB;
329843e2 2186 // Wait for picking
7fd59977 2187 Standard_Integer argccc = 5;
2188 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2189 const char **argvvv = (const char **) bufff;
2190 while (ViewerMainLoop( argccc, argvvv) ) { }
329843e2 2191 // end of the loop
7fd59977 2192
329843e2
A
2193 for(TheAISContext()->InitSelected();
2194 TheAISContext()->MoreSelected();
2195 TheAISContext()->NextSelected() )
2196 {
7fd59977 2197 ShapeB = TheAISContext()->SelectedShape();
2198 }
2199
329843e2
A
2200 // Recover the radius
2201 Standard_Real theRad;
2202 do
2203 {
2204 std::cout << " Enter the value of the radius:\n";
2205 cin >> theRad;
2206 } while (theRad <= 0);
2207
2208 // Get filled status
2209 Standard_Boolean isFilled;
2210 std::cout << "Enter filled status (0 or 1)\n";
2211 cin >> isFilled;
7fd59977 2212
329843e2 2213 // Close the local context
7fd59977 2214 TheAISContext()->CloseLocalContext(myCurrentIndex);
329843e2 2215 // Construction of the circle
7fd59977 2216
329843e2
A
2217 // Recover the normal to the plane. tag
2218 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2219 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2220 gp_Pln myPlane = mySurface.Plane();
2221 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
7fd59977 2222 gp_Pln mygpPlane = theGeomPlane->Pln();
2223 gp_Ax1 thegpAxe = mygpPlane.Axis();
2224 gp_Dir theDir = thegpAxe.Direction();
2225
329843e2
A
2226 // Recover the center
2227 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
7fd59977 2228
329843e2
A
2229 // Ñonstruct the circle
2230 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2231 Handle (Geom_Circle) theGeomCircle;
2232 try
2233 {
2234 theGeomCircle = Cir.Value();
2235 }
2236 catch (StdFail_NotDone)
2237 {
2238 std::cout << "vcircle error: can't create circle\n";
2239 return -1; // TCL_ERROR
2240 }
7fd59977 2241
329843e2
A
2242 DisplayCircle(theGeomCircle, aName, isFilled);
2243
7fd59977 2244 }
2245
7fd59977 2246 }
2247
2248 return 0;
2249}
2250
ceae62f0 2251
7fd59977 2252//===============================================================================================
2253//function : VDrawText
2254//author : psn
2255//purpose : Create a text.
2256//Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2257//===============================================================================================
2258#include <Graphic3d_Group.hxx>
2259#include <Graphic3d_Structure.hxx>
7fd59977 2260#include <Graphic3d_AspectText3d.hxx>
161c4476 2261#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 2262#include <Graphic3d_StructureManager.hxx>
2263#include <Graphic3d_VerticalTextAlignment.hxx>
2264#include <Graphic3d_HorizontalTextAlignment.hxx>
2265
aff395a3 2266#include <Font_NameOfFont.hxx>
2267
7fd59977 2268#include <Visual3d_ViewManager.hxx>
2269#include <ViewerTest_Tool.ixx>
2270
2271#include <Standard_DefineHandle.hxx>
2272
7fd59977 2273#include <Prs3d_Root.hxx>
2274#include <Prs3d_Text.hxx>
2275#include <Prs3d_TextAspect.hxx>
7fd59977 2276#include <Prs3d_ShadingAspect.hxx>
2277#include <PrsMgr_PresentationManager3d.hxx>
2278
2279#include <TCollection_ExtendedString.hxx>
2280#include <TCollection_AsciiString.hxx>
2281
2282#include <gp_Pnt.hxx>
2283#include <Quantity_NameOfColor.hxx>
161c4476 2284#include <Quantity_Color.hxx>
7fd59977 2285
2286
2287DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2288
13a22457
S
2289class MyTextClass:public AIS_InteractiveObject
2290{
7fd59977 2291public:
2292 // CASCADE RTTI
2293 DEFINE_STANDARD_RTTI(MyTextClass );
2294
2295 MyTextClass(){};
2296
161c4476 2297 MyTextClass
7fd59977 2298 (
2299 const TCollection_ExtendedString& , const gp_Pnt& ,
161c4476
K
2300 Quantity_Color color,
2301 Standard_Integer aHJust,
7fd59977 2302 Standard_Integer aVJust ,
161c4476
K
2303 Standard_Real Angle ,
2304 Standard_Boolean Zoom ,
2305 Standard_Real Height,
eeaaaefb 2306 Font_FontAspect FontAspect,
7fd59977 2307 Standard_CString Font
2308 );
2309
2310private:
2311
2312 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2313 const Handle(Prs3d_Presentation)& aPresentation,
2314 const Standard_Integer aMode);
2315
35e08fe8 2316 void ComputeSelection ( const Handle(SelectMgr_Selection)& /*aSelection*/,
2317 const Standard_Integer /*aMode*/){} ;
7fd59977 2318
2319protected:
2320 TCollection_ExtendedString aText;
2321 gp_Pnt aPosition;
2322 Standard_Real Red;
2323 Standard_Real Green;
2324 Standard_Real Blue;
2325 Standard_Real aAngle;
161c4476 2326 Standard_Real aHeight;
7fd59977 2327 Standard_Boolean aZoomable;
2328 Quantity_Color aColor;
eb4320f2 2329 TCollection_AsciiString aFont;
eeaaaefb 2330 Font_FontAspect aFontAspect;
7fd59977 2331 Graphic3d_HorizontalTextAlignment aHJustification;
2332 Graphic3d_VerticalTextAlignment aVJustification;
2333};
2334
2335
2336
2337IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
161c4476 2338IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
7fd59977 2339
2340
161c4476
K
2341MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2342 Quantity_Color color = Quantity_NOC_YELLOW,
2343 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
7fd59977 2344 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2345 Standard_Real angle = 0.0 ,
2346 Standard_Boolean zoomable = Standard_True,
2347 Standard_Real height = 12.,
eeaaaefb 2348 Font_FontAspect fontAspect = Font_FA_Regular,
7fd59977 2349 Standard_CString font = "Courier")
2350{
2351 aText = text;
161c4476 2352 aPosition = position;
7fd59977 2353 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2354 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2355 aAngle = angle;
161c4476
K
2356 aZoomable = zoomable;
2357 aHeight = height;
7fd59977 2358 aColor = color;
2359 aFontAspect = fontAspect;
2360 aFont = font;
2361};
2362
2363
2364
2365//////////////////////////////////////////////////////////////////////////////
35e08fe8 2366void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
7fd59977 2367 const Handle(Prs3d_Presentation)& aPresentation,
35e08fe8 2368 const Standard_Integer /*aMode*/)
7fd59977 2369{
2370
2371 aPresentation->Clear();
2372
2373 Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
2374
eb4320f2 2375 asp->SetFont(aFont.ToCString());
7fd59977 2376 asp->SetColor(aColor);
2377 asp->SetHeight(aHeight); // I am changing the myHeight value
2378
2379 asp->SetHorizontalJustification(aHJustification);
161c4476 2380 asp->SetVerticalJustification(aVJustification);
7fd59977 2381 asp->Aspect()->SetTextZoomable(aZoomable);
2382 asp->Aspect()->SetTextAngle(aAngle);
2383 asp->Aspect()->SetTextFontAspect(aFontAspect);
2384 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
161c4476 2385
7fd59977 2386 /* This comment code is worked
2387 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2388 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2389 Graphic3d_Vertex vertices_text;
2390 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2391 TheGroup->SetPrimitivesAspect(aspect);
7fd59977 2392 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
7fd59977 2393 */
2394};
2395
2396static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2397{
13a22457
S
2398 // Check arguments
2399 if (argc < 14)
7fd59977 2400 {
13a22457
S
2401 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2402 di<<"Usage: type help "<<argv[0]<<"\n";
2403 return 1; //TCL_ERROR
7fd59977 2404 }
13a22457
S
2405
2406 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2407
2408 // Create 3D view if it doesn't exist
2409 if ( aContext.IsNull() )
161c4476 2410 {
13a22457
S
2411 ViewerTest::ViewerInit();
2412 aContext = ViewerTest::GetAISContext();
2413 if( aContext.IsNull() )
2414 {
2415 di << "Error: Cannot create a 3D view\n";
2416 return 1; //TCL_ERROR
2417 }
7fd59977 2418 }
2419
13a22457 2420 // Text position
91322f44 2421 const Standard_Real X = Draw::Atof(argv[2]);
2422 const Standard_Real Y = Draw::Atof(argv[3]);
2423 const Standard_Real Z = Draw::Atof(argv[4]);
13a22457 2424 const gp_Pnt pnt(X,Y,Z);
7fd59977 2425
13a22457 2426 // Text color
91322f44 2427 const Quantity_Parameter R = Draw::Atof(argv[5])/255.;
2428 const Quantity_Parameter G = Draw::Atof(argv[6])/255.;
2429 const Quantity_Parameter B = Draw::Atof(argv[7])/255.;
13a22457 2430 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
7fd59977 2431
13a22457 2432 // Text alignment
91322f44 2433 const int hor_align = Draw::Atoi(argv[8]);
2434 const int ver_align = Draw::Atoi(argv[9]);
7fd59977 2435
13a22457 2436 // Text angle
91322f44 2437 const Standard_Real angle = Draw::Atof(argv[10]);
7fd59977 2438
13a22457 2439 // Text zooming
91322f44 2440 const Standard_Boolean zoom = Draw::Atoi(argv[11]);
13a22457
S
2441
2442 // Text height
91322f44 2443 const Standard_Real height = Draw::Atof(argv[12]);
13a22457
S
2444
2445 // Text aspect
91322f44 2446 const Font_FontAspect aspect = Font_FontAspect(Draw::Atoi(argv[13]));
13a22457
S
2447
2448 // Text font
2449 TCollection_AsciiString font;
2450 if(argc < 15)
2451 font.AssignCat("Courier");
2452 else
2453 font.AssignCat(argv[14]);
2454
2455 // Text is multibyte
91322f44 2456 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (Draw::Atoi(argv[15]) != 0);
13a22457
S
2457
2458 // Read text string
2459 TCollection_ExtendedString name;
2460 if (isMultibyte)
161c4476 2461 {
13a22457 2462 const char *str = argv[1];
f3f08423 2463 while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
2464 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
13a22457
S
2465 {
2466 unsigned short c1 = *str++;
2467 unsigned short c2 = *str++;
f3f08423 2468 if (!c2) break;
13a22457
S
2469 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2470 }
7fd59977 2471 }
13a22457
S
2472 else
2473 {
2474 name += argv[1];
2475 }
2476
2477 if (name.Length())
2478 {
2479 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2480 aContext->Display(myT,Standard_True);
2481 }
2482
161c4476 2483 return 0;
7fd59977 2484}
2485
2486#include <math.h>
2487#include <gp_Pnt.hxx>
2488#include <Graphic3d_ArrayOfPoints.hxx>
2489#include <Graphic3d_ArrayOfPrimitives.hxx>
7fd59977 2490#include <Graphic3d_ArrayOfTriangles.hxx>
2491#include <Poly_Array1OfTriangle.hxx>
2492#include <Poly_Triangle.hxx>
2493#include <Poly_Triangulation.hxx>
2494#include <TColgp_Array1OfPnt.hxx>
2495#include <TShort_Array1OfShortReal.hxx>
2496#include <TShort_HArray1OfShortReal.hxx>
2497
2498#include <AIS_Triangulation.hxx>
7fd59977 2499#include <StdPrs_ToolShadedShape.hxx>
2500#include <Poly_Connect.hxx>
2501#include <TColgp_Array1OfDir.hxx>
2502#include <Graphic3d_GraphicDriver.hxx>
2503
7fd59977 2504#include <TColStd_Array1OfInteger.hxx>
2505#include <TColStd_HArray1OfInteger.hxx>
2506#include <Prs3d_ShadingAspect.hxx>
2507#include <Graphic3d_MaterialAspect.hxx>
2508#include <Graphic3d_AspectFillArea3d.hxx>
2509
2510#include <BRepPrimAPI_MakeCylinder.hxx>
2511#include <TopoDS_Shape.hxx>
2512#include <TopExp_Explorer.hxx>
2513#include <TopAbs.hxx>
2514#include <StdSelect_ShapeTypeFilter.hxx>
2515
2516
2517//===============================================================================================
2518//function : CalculationOfSphere
2519//author : psn
2520//purpose : Create a Sphere
2521//===============================================================================================
2522
161c4476 2523Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
7fd59977 2524 int res ,
2525 double Radius ){
2526 double mRadius = Radius;
2527 double mCenter[3] = {X,Y,Z};
2528 int mThetaResolution;
2529 int mPhiResolution;
2530 double mStartTheta = 0;//StartTheta;
2531 double mEndTheta = 360;//EndTheta;
2532 double mStartPhi = 0;//StartPhi;
2533 double mEndPhi = 180;//EndPhi;
2534 res = res < 4 ? 4 : res;
2535
2536 mThetaResolution = res;
2537 mPhiResolution = res;
2538
2539 int i, j;
2540 int jStart, jEnd, numOffset;
2541 int numPts, numPolys;
2542 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2543 double startTheta, endTheta, startPhi, endPhi;
2544 int base, numPoles=0, thetaResolution, phiResolution;
2545
2546 int pts[3];
2547 int piece = -1;
2548 int numPieces = 1;
2549 if ( numPieces > mThetaResolution ) {
2550 numPieces = mThetaResolution;
2551 }
2552
2553 int localThetaResolution = mThetaResolution;
2554 double localStartTheta = mStartTheta;
2555 double localEndTheta = mEndTheta;
2556
2557 while ( localEndTheta < localStartTheta ) {
2558 localEndTheta += 360.0;
2559 }
2560
2561 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2562
2563 // Change the ivars based on pieces.
2564 int start, end;
2565 start = piece * localThetaResolution / numPieces;
2566 end = (piece+1) * localThetaResolution / numPieces;
2567 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2568 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2569 localThetaResolution = end - start;
2570
2571 numPts = mPhiResolution * localThetaResolution + 2;
2572 numPolys = mPhiResolution * 2 * localThetaResolution;
2573
2574 // Create north pole if needed
2575 int number_point = 0;
2576 int number_pointArray = 0;
2577
2578 if ( mStartPhi <= 0.0 ) {
2579 number_pointArray++;
2580 numPoles++;
2581 }
2582 if ( mEndPhi >= 180.0 ) {
2583 number_pointArray++;
2584 numPoles++;
2585 }
161c4476 2586
7fd59977 2587 // Check data, determine increments, and convert to radians
2588 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
c6541a0c 2589 startTheta *= M_PI / 180.0;
7fd59977 2590 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
c6541a0c 2591 endTheta *= M_PI / 180.0;
7fd59977 2592
2593
2594 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
c6541a0c 2595 startPhi *= M_PI / 180.0;
7fd59977 2596 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
c6541a0c 2597 endPhi *= M_PI / 180.0;
7fd59977 2598
2599 phiResolution = mPhiResolution - numPoles;
2600 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2601 thetaResolution = localThetaResolution;
2602 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2603 ++localThetaResolution;
2604 }
2605 deltaTheta = (endTheta - startTheta) / thetaResolution;
2606
2607 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2608 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2609
2610 // Create intermediate points
2611 for ( i = 0; i < localThetaResolution; i++ ) {
2612 for ( j = jStart; j < jEnd; j++ ) {
2613 number_pointArray++;
2614 }
2615 }
2616
2617 //Generate mesh connectivity
2618 base = phiResolution * localThetaResolution;
2619
2620 int number_triangle = 0 ;
2621 if ( mStartPhi <= 0.0 ) { // around north pole
2622 number_triangle += localThetaResolution;
2623 }
161c4476 2624
7fd59977 2625 if ( mEndPhi >= 180.0 ) { // around south pole
2626 number_triangle += localThetaResolution;
2627 }
2628
2629 // bands in-between poles
2630 for ( i=0; i < localThetaResolution; i++){
2631 for ( j=0; j < (phiResolution-1); j++){
2632 number_triangle +=2;
2633 }
2634 }
2635
2636 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2637 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2638 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2639
2640 if ( mStartPhi <= 0.0 ){
2641 x[0] = mCenter[0];
2642 x[1] = mCenter[1];
2643 x[2] = mCenter[2] + mRadius;
2644 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2645 }
2646
2647 // Create south pole if needed
2648 if ( mEndPhi >= 180.0 ){
2649 x[0] = mCenter[0];
2650 x[1] = mCenter[1];
2651 x[2] = mCenter[2] - mRadius;
2652 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2653 }
2654
2655 number_point = 3;
2656 for ( i=0; i < localThetaResolution; i++){
c6541a0c 2657 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
7fd59977 2658 for ( j = jStart; j < jEnd; j++){
2659 phi = startPhi + j*deltaPhi;
2660 radius = mRadius * sin((double)phi);
2661 n[0] = radius * cos((double)theta);
2662 n[1] = radius * sin((double)theta);
2663 n[2] = mRadius * cos((double)phi);
2664 x[0] = n[0] + mCenter[0];
2665 x[1] = n[1] + mCenter[1];
2666 x[2] = n[2] + mCenter[2];
2667 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2668 number_point++;
2669 }
2670 }
2671
2672 numPoles = 3;
2673 number_triangle = 1;
2674 if ( mStartPhi <= 0.0 ){// around north pole
2675 for (i=0; i < localThetaResolution; i++){
2676 pts[0] = phiResolution*i + numPoles;
2677 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2678 pts[2] = 1;
2679 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2680 number_triangle++;
2681 }
2682 }
161c4476 2683
7fd59977 2684 if ( mEndPhi >= 180.0 ){ // around south pole
2685 numOffset = phiResolution - 1 + numPoles;
2686 for (i=0; i < localThetaResolution; i++){
2687 pts[0] = phiResolution*i + numOffset;
2688 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2689 pts[1] = numPoles - 1;
2690 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2691 number_triangle++;
2692 }
2693 }
2694
2695 // bands in-between poles
161c4476 2696
7fd59977 2697 for (i=0; i < localThetaResolution; i++){
2698 for (j=0; j < (phiResolution-1); j++){
2699 pts[0] = phiResolution*i + j + numPoles;
2700 pts[1] = pts[0] + 1;
2701 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2702 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2703 number_triangle++;
2704 pts[1] = pts[2];
2705 pts[2] = pts[1] - 1;
2706 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2707 number_triangle++;
2708 }
2709 }
2710
2711 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2712
2713 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2714
2715 Standard_Integer index[3];
2716 Standard_Real Tol = Precision::Confusion();
2717
2718 gp_Dir Nor;
2719 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2720 gp_XYZ eqPlan(0, 0, 0);
2721 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2722 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2723 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2724 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2725 gp_XYZ vv = v1^v2;
2726 Standard_Real mod = vv.Modulus();
2727 if(mod < Tol) continue;
2728 eqPlan += vv/mod;
2729 }
2730
2731 Standard_Real modmax = eqPlan.Modulus();
2732
161c4476 2733 if(modmax > Tol)
7fd59977 2734 Nor = gp_Dir(eqPlan);
161c4476 2735 else
7fd59977 2736 Nor = gp_Dir(0., 0., 1.);
2737
2738 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2739 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2740 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2741 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2742 }
2743
2744 delete pc;
2745 polyTriangulation->SetNormals(Normals);
2746
2747 return polyTriangulation;
2748}
2749
2750//===============================================================================================
2751//function : VDrawSphere
2752//author : psn
2753//purpose : Create an AIS shape.
7fd59977 2754//===============================================================================================
35e08fe8 2755static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
161c4476
K
2756{
2757 // check for errors
2758 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2759 if (aContextAIS.IsNull())
2760 {
2761 std::cout << "Call vinit before!\n";
2762 return 1;
2763 }
2764 else if (argc < 3)
2765 {
2766 std::cout << "Use: " << argv[0]
58655684 2767 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
161c4476
K
2768 return 1;
2769 }
7fd59977 2770
161c4476
K
2771 // read the arguments
2772 TCollection_AsciiString aShapeName (argv[1]);
91322f44 2773 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2774 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2775 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2776 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2777 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2778 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) : Standard_False;
7fd59977 2779
161c4476 2780 // remove AIS object with given name from map
208e6839 2781 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
161c4476
K
2782
2783 std::cout << "Compute Triangulation...\n";
2784 Handle(AIS_Triangulation) aShape
2785 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2786 aResolution,
2787 aRadius));
2788 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2789 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2790
161c4476
K
2791 // stupid initialization of Green color in RGBA space as integer
2792 // probably wrong for big-endian CPUs
2793 Standard_Integer aRed = 0;
2794 Standard_Integer aGreen = 255;
2795 Standard_Integer aBlue = 0;
2796 Standard_Integer anAlpha = 0; // not used
2797 Standard_Integer aColorInt = aRed;
2798 aColorInt += aGreen << 8;
2799 aColorInt += aBlue << 16;
2800 aColorInt += anAlpha << 24;
2801
2802 // setup colors array per vertex
2803 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2804 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2805 {
2806 aColorArray->SetValue (aNodeId, aColorInt);
7fd59977 2807 }
161c4476
K
2808 aShape->SetColors (aColorArray);
2809
2810 // show statistics
2811 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2812 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2813 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2814 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2815 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2816 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2817 aTotalSize >>= 20; //MB
2818 aNormalsSize >>= 20;
2819 aColorsSize >>= 20;
2820 aTrianglesSize >>= 20;
2821 aPolyConnectSize >>= 20;
2822 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2823 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2824 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2825 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2826 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2827 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
7fd59977 2828
2829 // Setting material properties, very important for desirable visual result!
161c4476
K
2830 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2831 aMat.SetAmbient (0.2);
2832 aMat.SetSpecular (0.5);
2833 Handle(Graphic3d_AspectFillArea3d) anAspect
2834 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2835 Quantity_NOC_RED,
2836 Quantity_NOC_YELLOW,
2837 Aspect_TOL_SOLID,
2838 1.0,
2839 aMat,
2840 aMat);
7fd59977 2841 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
161c4476
K
2842 if (toShowEdges)
2843 {
2844 anAspect->SetEdgeOn();
2845 }
7fd59977 2846 else
161c4476
K
2847 {
2848 anAspect->SetEdgeOff();
2849 }
2850 aShAsp->SetAspect (anAspect);
2851 aShape->Attributes()->SetShadingAspect (aShAsp);
7fd59977 2852
208e6839 2853 VDisplayAISObject (aShapeName, aShape);
7fd59977 2854 return 0;
2855}
2856
3fc57801 2857//=============================================================================
2858//function : VComputeHLR
2859//purpose :
2860//=============================================================================
2861
2862static int VComputeHLR (Draw_Interpretor& di,
2863 Standard_Integer argc,
2864 const char** argv)
2865{
2866 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2867
2868 if (aContextAIS.IsNull ())
2869 {
2870 di << "Please call vinit before\n";
2871 return 1;
2872 }
2873
2874 if ( argc != 3 && argc != 12 )
2875 {
2876 di << "Usage: " << argv[0] << " ShapeName HlrName "
2877 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
2878 << " ShapeName - name of the initial shape\n"
2879 << " HlrName - result hlr object from initial shape\n"
2880 << " eye, dir are eye position and look direction\n"
2881 << " up is the look up direction vector\n"
2882 << " Use vtop to see projected hlr shape\n";
2883 return 1;
2884 }
2885
2886 // shape and new object name
2887 TCollection_AsciiString aShapeName (argv[1]);
2888 TCollection_AsciiString aHlrName (argv[2]);
2889
2890 TopoDS_Shape aSh = DBRep::Get (argv[1]);
2891 if (aSh.IsNull())
2892 {
2893 BRep_Builder aBrepBuilder;
2894 BRepTools::Read (aSh, argv[1], aBrepBuilder);
2895 if (aSh.IsNull ())
2896 {
2897 di << "No shape with name " << argv[1] << " found\n";
2898 return 1;
2899 }
2900 }
2901
2902 if (GetMapOfAIS ().IsBound2 (aHlrName))
2903 {
2904 di << "Presentable object with name " << argv[2] << " already exists\n";
2905 return 1;
2906 }
2907
2908 // close local context
2909 if (aContextAIS->HasOpenedContext ())
2910 aContextAIS->CloseLocalContext ();
2911
2912 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
2913 HLRBRep_PolyHLRToShape aHLRToShape;
2914
2915 gp_Pnt anEye;
2916 gp_Dir aDir;
2917 gp_Ax2 aProjAx;
2918 if (argc == 9)
2919 {
2920 gp_Dir anUp;
2921
91322f44 2922 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
2923 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
2924 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3fc57801 2925 aProjAx.SetLocation (anEye);
2926 aProjAx.SetDirection (aDir);
2927 aProjAx.SetYDirection (anUp);
2928 }
2929 else
2930 {
2931 gp_Dir aRight;
2932
2933 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2934 Handle(V3d_View) aView = ViewerTest::CurrentView();
2935 Standard_Integer aWidth, aHeight;
2936 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
2937 Standard_Real aRightX, aRightY, aRightZ;
2938 aView->Window()->Size (aWidth, aHeight);
2939
2940 aView->ConvertWithProj (aWidth, aHeight/2,
2941 aRightX, aRightY, aRightZ,
2942 aDirX, aDirY, aDirZ);
2943
2944 aView->ConvertWithProj (aWidth/2, aHeight/2,
2945 aCentX, aCentY, aCentZ,
2946 aDirX, aDirY, aDirZ);
2947
2948 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
2949 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
2950 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
2951 aProjAx.SetLocation (anEye);
2952 aProjAx.SetDirection (aDir);
2953 aProjAx.SetXDirection (aRight);
2954 }
2955
2956 HLRAlgo_Projector aProjector (aProjAx);
2957 aPolyAlgo->Projector (aProjector);
2958 aPolyAlgo->Load (aSh);
2959 aPolyAlgo->Update ();
2960
2961 aHLRToShape.Update (aPolyAlgo);
2962
2963 // make hlr shape from input shape
2964 TopoDS_Compound aHlrShape;
2965 BRep_Builder aBuilder;
2966 aBuilder.MakeCompound (aHlrShape);
2967
2968 TopoDS_Shape aCompound = aHLRToShape.VCompound();
2969 if (!aCompound.IsNull ())
2970 {
2971 aBuilder.Add (aHlrShape, aCompound);
2972 }
2973
2974 // extract visible outlines
2975 aCompound = aHLRToShape.OutLineVCompound();
2976 if (!aCompound.IsNull ())
2977 {
2978 aBuilder.Add (aHlrShape, aCompound);
2979 }
2980
2981 // create an AIS shape and display it
2982 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
2983 GetMapOfAIS().Bind (anObject, aHlrName);
2984 aContextAIS->Display (anObject);
2985
2986 aContextAIS->UpdateCurrentViewer ();
2987
2988 return 0;
2989}
2990
9558a876
A
2991// This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
2992// manipulating and displaying such an array with AIS context
2993DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
2994class MyPArrayObject : public AIS_InteractiveObject
2995{
2996
2997public:
2998
eb4320f2 2999 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
a577aaab 3000 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
9558a876 3001 {
eb4320f2 3002 myArrayDescription = theArrayDescription;
a577aaab 3003 myMarkerAspect = theMarkerAspect;
9558a876
A
3004 }
3005
3006 DEFINE_STANDARD_RTTI(MyPArrayObject);
3007
3008private:
3009
3010 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3011 const Handle(Prs3d_Presentation)& aPresentation,
3012 const Standard_Integer aMode);
3013
a577aaab 3014 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3015 const Standard_Integer /*theMode*/);
9558a876 3016
eb4320f2 3017 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3018 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3019 Standard_Integer &theArgIndex,
3020 Standard_Integer theArgCount,
3021 Standard_Integer theMaxArgs);
3022
9558a876
A
3023protected:
3024
eb4320f2 3025 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
a577aaab 3026 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
9558a876
A
3027
3028};
3029
3030IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3031IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3032
35e08fe8 3033void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
9558a876 3034 const Handle(Prs3d_Presentation)& aPresentation,
35e08fe8 3035 const Standard_Integer /*aMode*/)
9558a876 3036{
9558a876 3037
eb4320f2 3038 // Parsing array description
9558a876
A
3039 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3040 Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
3041 hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
3042
eb4320f2 3043 Standard_Integer anArgIndex = 0;
3044 Standard_Integer anArgsCount = myArrayDescription->Length();
3045 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3046
9558a876 3047 TCollection_AsciiString aCommand;
eb4320f2 3048 while (anArgIndex < anArgsCount)
9558a876 3049 {
eb4320f2 3050 aCommand = myArrayDescription->Value (anArgIndex);
9558a876 3051 aCommand.LowerCase();
9558a876
A
3052
3053 // vertex command
eb4320f2 3054 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3055 {
3056 // vertex has a normal or normal with color or texel
eb4320f2 3057 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3058 hasNormals = Standard_True;
3059
3060 // vertex has a color
eb4320f2 3061 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3062 hasVColors = Standard_True;
3063
3064 // vertex has a texel
eb4320f2 3065 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
9558a876
A
3066 hasTexels = Standard_True;
3067
3068 aVertexNum++;
3069 }
3070 // bound command
eb4320f2 3071 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876
A
3072 {
3073 // bound has color
eb4320f2 3074 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3075 hasBColors = Standard_True;
3076
3077 aBoundNum++;
3078 }
3079 // edge command
eb4320f2 3080 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876
A
3081 {
3082 // edge has a hide flag
eb4320f2 3083 if (CheckInputCommand ("h", myArrayDescription, anArgIndex, 0, anArgsCount))
9558a876
A
3084 hasInfos = Standard_True;
3085
3086 aEdgeNum++;
3087 }
3088 // unknown command
3089 else
eb4320f2 3090 anArgIndex++;
9558a876
A
3091 }
3092
9558a876
A
3093 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3094 if (anArrayType == "points")
a577aaab 3095 {
9558a876 3096 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
a577aaab 3097 }
9558a876
A
3098 else if (anArrayType == "segments")
3099 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3100 else if (anArrayType == "polylines")
3101 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3102 hasVColors, hasBColors, hasInfos);
3103 else if (anArrayType == "triangles")
3104 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3105 hasVColors, hasTexels, hasInfos);
3106 else if (anArrayType == "trianglefans")
3107 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3108 hasNormals, hasVColors,
3109 hasBColors, hasTexels);
3110 else if (anArrayType == "trianglestrips")
3111 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3112 hasNormals, hasVColors,
3113 hasBColors, hasTexels);
3114 else if (anArrayType == "quads")
3115 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3116 hasNormals, hasVColors,
3117 hasTexels, hasInfos);
3118 else if (anArrayType == "quadstrips")
3119 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3120 hasNormals, hasVColors,
3121 hasBColors, hasTexels);
3122 else if (anArrayType == "polygons")
3123 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3124 hasNormals, hasVColors, hasBColors,
3125 hasTexels, hasInfos);
9558a876 3126
eb4320f2 3127 anArgIndex = 1;
3128 while (anArgIndex < anArgsCount)
9558a876 3129 {
eb4320f2 3130 aCommand = myArrayDescription->Value (anArgIndex);
9558a876
A
3131 aCommand.LowerCase();
3132 if (!aCommand.IsAscii())
3133 break;
3134
3135 // vertex command
eb4320f2 3136 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3137 {
eb4320f2 3138 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3139 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3140 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876
A
3141
3142 // vertex has a normal or normal with color or texel
eb4320f2 3143 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3144 anArray->SetVertexNormal (anArray->VertexNumber (),
eb4320f2 3145 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3146 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3147 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876 3148
eb4320f2 3149 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3150 anArray->SetVertexColor (anArray->VertexNumber (),
eb4320f2 3151 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3152 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3153 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876 3154
eb4320f2 3155 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
9558a876 3156 anArray->SetVertexTexel (anArray->VertexNumber (),
eb4320f2 3157 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3158 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876
A
3159 }
3160 // bounds command
eb4320f2 3161 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))