1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
22 // Modified by Robert Coublanc [nov 16-17-18 1998]
23 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
24 // ViewerTest_ObjectCommands.cxx
25 // ViewerTest_RelationCommands.cxx
26 // -add Functions and commands for interactive selection of shapes and objects
27 // in AIS Viewers. (PickShape(s), PickObject(s),
29 #include <Standard_Stream.hxx>
31 #include <ViewerTest.hxx>
32 #include <TopLoc_Location.hxx>
33 #include <TopTools_HArray1OfShape.hxx>
34 #include <TColStd_HArray1OfTransient.hxx>
35 #include <OSD_Directory.hxx>
36 #include <OSD_File.hxx>
37 #include <OSD_Path.hxx>
38 #include <OSD_Timer.hxx>
39 #include <Geom_Axis2Placement.hxx>
40 #include <Geom_Axis1Placement.hxx>
41 #include <gp_Trsf.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <StdSelect_ShapeTypeFilter.hxx>
46 #include <AIS_Drawer.hxx>
47 #include <AIS_InteractiveObject.hxx>
48 #include <AIS_Trihedron.hxx>
49 #include <AIS_Axis.hxx>
50 #include <AIS_Relation.hxx>
51 #include <AIS_TypeFilter.hxx>
52 #include <AIS_SignatureFilter.hxx>
53 #include <AIS_ListOfInteractive.hxx>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
55 #include <Aspect_InteriorStyle.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_TextureRoot.hxx>
58 #include <Graphic3d_AspectLine3d.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Prs3d_ShadingAspect.hxx>
61 #include <Prs3d_IsoAspect.hxx>
71 #include <Draw_Interpretor.hxx>
72 #include <TCollection_AsciiString.hxx>
73 #include <Draw_PluginMacro.hxx>
74 #include <ViewerTest.hxx>
76 // avoid warnings on 'extern "C"' functions returning C++ classes
78 #define _CRT_SECURE_NO_DEPRECATE
79 #pragma warning(4:4190)
80 #pragma warning (disable:4996)
83 #include <NIS_InteractiveContext.hxx>
84 #include <NIS_Triangulated.hxx>
85 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
87 #include <Quantity_Color.hxx>
88 #include <Quantity_NameOfColor.hxx>
90 #include <Graphic3d_NameOfMaterial.hxx>
92 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
96 //=======================================================================
97 //function : GetColorFromName
98 //purpose : get the Quantity_NameOfColor from a string
99 //=======================================================================
101 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
103 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
105 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
106 if (strcasecmp (theName, aColorName) == 0)
108 return Quantity_NameOfColor (anIter);
112 return DEFAULT_COLOR;
115 //=======================================================================
116 //function : GetMaterialFromName
117 //purpose : get the Graphic3d_NameOfMaterial from a string
118 //=======================================================================
120 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
122 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
124 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
125 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
126 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
127 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
128 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
129 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
130 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
131 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
132 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
133 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
134 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
135 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
136 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
137 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
138 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
139 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
140 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
141 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
142 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
147 //=======================================================================
148 //function : GetTypeNames
150 //=======================================================================
151 static const char** GetTypeNames()
153 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
154 "Shape","ConnectedShape","MultiConn.Shape",
155 "ConnectedInter.","MultiConn.",
156 "Constraint","Dimension"};
157 static const char** ThePointer = names;
161 //=======================================================================
162 //function : GetTypeAndSignfromString
164 //=======================================================================
165 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
167 const char ** thefullnames = GetTypeNames();
168 Standard_Integer index(-1);
170 for(Standard_Integer i=0;i<=13 && index==-1;i++)
171 if(!strcasecmp(name,thefullnames[i]))
175 TheType = AIS_KOI_None;
181 TheType = AIS_KOI_Datum;
185 TheType = AIS_KOI_Shape;
189 TheType = AIS_KOI_Object;
193 TheType = AIS_KOI_Relation;
202 #include <Draw_Interpretor.hxx>
204 #include <Draw_Appli.hxx>
208 #include <TCollection_AsciiString.hxx>
209 #include <V3d_Viewer.hxx>
210 #include <V3d_View.hxx>
213 #include <AIS_InteractiveContext.hxx>
214 #include <AIS_Shape.hxx>
215 #include <AIS_TexturedShape.hxx>
216 #include <AIS_DisplayMode.hxx>
217 #include <TColStd_MapOfInteger.hxx>
218 #include <AIS_MapOfInteractive.hxx>
219 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
220 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
221 #include <ViewerTest_EventManager.hxx>
223 #include <TopoDS_Solid.hxx>
224 #include <BRepTools.hxx>
225 #include <BRep_Builder.hxx>
226 #include <TopAbs_ShapeEnum.hxx>
228 #include <TopoDS.hxx>
229 #include <BRep_Tool.hxx>
232 #include <Draw_Window.hxx>
233 #include <AIS_ListIteratorOfListOfInteractive.hxx>
234 #include <AIS_ListOfInteractive.hxx>
235 #include <AIS_DisplayMode.hxx>
236 #include <TopTools_ListOfShape.hxx>
237 #include <BRepOffsetAPI_MakeThickSolid.hxx>
238 #include <BRepOffset.hxx>
241 //==============================================================================
242 //function : GetTypeNameFromShape
243 //purpose : get the shape type as a string from a shape
244 //==============================================================================
246 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
247 { const char *ret = "????";
249 if ( aShape.IsNull() ) ret = "Null Shape";
251 switch ( aShape.ShapeType() ) {
252 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
253 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
254 case TopAbs_SOLID : ret = "SOLID" ; break;
255 case TopAbs_SHELL : ret = "SHELL" ; break;
256 case TopAbs_FACE : ret = "FACE" ; break;
257 case TopAbs_WIRE : ret = "WIRE" ; break;
258 case TopAbs_EDGE : ret = "EDGE" ; break;
259 case TopAbs_VERTEX : ret = "VERTEX" ; break;
260 case TopAbs_SHAPE : ret = "SHAPE" ; break;
264 //==============================================================================
265 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
266 //==============================================================================
267 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
268 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
273 //==============================================================================
274 //function : VDisplayAISObject
275 //purpose : register interactive object in the map of AIS objects;
276 // if other object with such name already registered, it will be kept
277 // or replaced depending on value of <theReplaceIfExists>,
278 // if "true" - the old object will be cleared from AIS context;
279 // returns Standard_True if <theAISObj> registered in map;
280 //==============================================================================
281 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
282 const Handle(AIS_InteractiveObject)& theAISObj,
283 Standard_Boolean theReplaceIfExists = Standard_True)
285 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
286 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
287 if (aContextAIS.IsNull())
289 std::cout << "AIS context is not available.\n";
290 return Standard_False;
293 if (aMap.IsBound2 (theName))
295 if (!theReplaceIfExists)
297 std::cout << "Other interactive object has been already "
298 << "registered with name: " << theName << ".\n"
299 << "Please use another name.\n";
300 return Standard_False;
303 // stop displaying object
304 Handle(AIS_InteractiveObject) anOldObj =
305 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
307 if (!anOldObj.IsNull())
308 aContextAIS->Clear (anOldObj, Standard_True);
310 // remove name and old object from map
311 aMap.UnBind2 (theName);
314 if (theAISObj.IsNull())
316 // object with specified name already unbound
317 return Standard_True;
320 // unbind AIS object if was bound with another name
321 aMap.UnBind1 (theAISObj);
323 // can be registered without rebinding
324 aMap.Bind (theAISObj, theName);
325 aContextAIS->Display (theAISObj, Standard_True);
326 return Standard_True;
329 static TColStd_MapOfInteger theactivatedmodes(8);
330 static TColStd_ListOfTransient theEventMgrs;
332 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
333 const Handle(AIS_InteractiveContext)& Ctx)
335 theEventMgrs.Clear();
336 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
339 static Handle(V3d_View)& a3DView()
341 static Handle(V3d_View) Viou;
346 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
347 static Handle(AIS_InteractiveContext) aContext;
351 const Handle(V3d_View)& ViewerTest::CurrentView()
355 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
360 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
362 static Handle(NIS_InteractiveContext) aContext;
363 if (aContext.IsNull()) {
364 aContext = new NIS_InteractiveContext;
365 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
370 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
372 return TheAISContext();
375 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
377 TheAISContext() = aCtx;
378 ViewerTest::ResetEventManager();
381 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
383 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
386 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
388 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
392 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
393 theEventMgrs.Prepend(EM);
396 void ViewerTest::UnsetEventManager()
398 theEventMgrs.RemoveFirst();
402 void ViewerTest::ResetEventManager()
404 const Handle(NIS_View) aView =
405 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
406 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
409 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
411 Handle(ViewerTest_EventManager) EM;
412 if(theEventMgrs.IsEmpty()) return EM;
413 Handle(Standard_Transient) Tr = theEventMgrs.First();
414 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
419 //=======================================================================
420 //function : Get Context and active viou..
422 //=======================================================================
423 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
424 Handle(V3d_View)& Viou)
426 Ctx = ViewerTest::GetAISContext();
429 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
430 Vwr->InitActiveViews();
431 if(Vwr->MoreActiveViews())
432 Viou = Vwr->ActiveView();
437 //==============================================================================
438 //function : GetShapeFromName
439 //purpose : Compute an Shape from a draw variable or a file name
440 //==============================================================================
442 static TopoDS_Shape GetShapeFromName(const char* name)
444 TopoDS_Shape S = DBRep::Get(name);
447 BRep_Builder aBuilder;
448 BRepTools::Read( S, name, aBuilder);
453 //==============================================================================
454 //function : GetShapeFromName
455 //purpose : Compute an Shape from a draw variable or a file name
456 //==============================================================================
459 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
461 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
465 //==============================================================================
466 //function : GetAISShapeFromName
467 //purpose : Compute an AIS_Shape from a draw variable or a file name
468 //==============================================================================
469 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
471 Handle(AIS_Shape) retsh;
473 if(GetMapOfAIS().IsBound2(name)){
474 const Handle(AIS_InteractiveObject) IO =
475 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
477 if(IO->Type()==AIS_KOI_Shape)
478 if(IO->Signature()==0){
479 retsh = *((Handle(AIS_Shape)*)&IO);
482 cout << "an Object which is not an AIS_Shape "
483 "already has this name!!!"<<endl;
489 TopoDS_Shape S = GetShapeFromName(name);
491 retsh = new AIS_Shape(S);
497 //==============================================================================
499 //purpose : Remove all the object from the viewer
500 //==============================================================================
501 void ViewerTest::Clear()
503 if ( !a3DView().IsNull() ) {
504 if (TheAISContext()->HasOpenedContext())
505 TheAISContext()->CloseLocalContext();
506 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
507 while ( it.More() ) {
508 cout << "Remove " << it.Key2() << endl;
509 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
510 const Handle(AIS_InteractiveObject) anObj =
511 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
512 TheAISContext()->Remove(anObj,Standard_False);
513 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
514 const Handle(NIS_InteractiveObject) anObj =
515 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
516 TheNISContext()->Remove(anObj);
520 TheAISContext()->UpdateCurrentViewer();
521 // TheNISContext()->UpdateViews();
522 GetMapOfAIS().Clear();
526 //==============================================================================
527 //function : StandardModesActivation
528 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
530 //==============================================================================
531 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
533 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
535 if (TheAISContext()->HasOpenedContext())
536 aContext->CloseLocalContext();
539 if(!aContext->HasOpenedContext()) {
540 // To unhilight the preselected object
541 aContext->UnhilightCurrents(Standard_False);
542 // Open a local Context in order to be able to select subshape from
543 // the selected shape if any or for all if there is no selection
544 if (!aContext->FirstCurrentObject().IsNull()){
545 aContext->OpenLocalContext(Standard_False);
547 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
548 aContext->Load( aContext->Current(),-1,Standard_True);
552 aContext->OpenLocalContext();
555 const char *cmode="???";
558 case 0: cmode = "Shape"; break;
559 case 1: cmode = "Vertex"; break;
560 case 2: cmode = "Edge"; break;
561 case 3: cmode = "Wire"; break;
562 case 4: cmode = "Face"; break;
563 case 5: cmode = "Shell"; break;
564 case 6: cmode = "Solid"; break;
565 case 7: cmode = "Compsolid"; break;
566 case 8: cmode = "Compound"; break;
569 if(theactivatedmodes.Contains(mode))
571 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
572 theactivatedmodes.Remove(mode);
573 cout<<"Mode "<< cmode <<" OFF"<<endl;
577 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
578 theactivatedmodes.Add(mode);
579 cout<<"Mode "<< cmode << " ON" << endl;
584 //==============================================================================
585 //function : CopyIsoAspect
586 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
587 //==============================================================================
588 static Handle(Prs3d_IsoAspect) CopyIsoAspect
589 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
590 const Standard_Integer theNbIsos)
592 Quantity_Color aColor;
593 Aspect_TypeOfLine aType;
594 Standard_Real aWidth;
596 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
598 Handle(Prs3d_IsoAspect) aResult =
599 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
604 //==============================================================================
606 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
607 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
608 //==============================================================================
609 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
611 if (TheAISContext().IsNull()) {
612 di << argv[0] << " Call 'vinit' before!\n";
617 di << "Current number of isos : " <<
618 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
619 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
620 di << "IsoOnPlane mode is " <<
621 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
626 Standard_Integer aLastInd = argc - 1;
627 Standard_Boolean isChanged = Standard_False;
628 Standard_Integer aNbUIsos;
629 Standard_Integer aNbVIsos;
632 Standard_Boolean isIsoOnPlane = Standard_False;
634 if (strcmp(argv[aLastInd], "1") == 0) {
635 isIsoOnPlane = Standard_True;
636 isChanged = Standard_True;
637 } else if (strcmp(argv[aLastInd], "0") == 0) {
638 isIsoOnPlane = Standard_False;
639 isChanged = Standard_True;
643 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
644 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
647 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
648 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
650 TheAISContext()->IsoOnPlane(isIsoOnPlane);
653 // If there are no shapes provided set the default numbers.
654 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
655 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
662 for (i = 1; i <= aLastInd; i++) {
663 TCollection_AsciiString name(argv[i]);
664 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
667 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
668 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
669 const Handle(AIS_InteractiveObject) aShape =
670 Handle(AIS_InteractiveObject)::DownCast (anObj);
671 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
672 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
673 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
676 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
677 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
678 TheAISContext()->SetLocalAttributes
679 (aShape, CurDrawer, Standard_False);
680 TheAISContext()->Redisplay(aShape);
682 di << "Number of isos for " << argv[i] << " : "
683 << aUIso->Number() << " " << aVIso->Number() << "\n";
686 di << argv[i] << ": Not an AIS interactive object!\n";
689 di << argv[i] << ": Use 'vdisplay' before\n";
694 TheAISContext()->UpdateCurrentViewer();
700 //==============================================================================
701 //function : VDispAreas,VDispSensitive,...
702 //purpose : Redraw the view
704 //==============================================================================
705 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
708 Handle(AIS_InteractiveContext) Ctx;
709 Handle(V3d_View) Viou;
710 GetCtxAndView(Ctx,Viou);
711 Ctx->DisplayActiveAreas(Viou);
714 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
716 Handle(AIS_InteractiveContext) Ctx;
717 Handle(V3d_View) Viou;
718 GetCtxAndView(Ctx,Viou);
719 Ctx->ClearActiveAreas(Viou);
723 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
725 Handle(AIS_InteractiveContext) Ctx;
726 Handle(V3d_View) Viou;
727 GetCtxAndView(Ctx,Viou);
728 Ctx->DisplayActiveSensitive(Viou);
732 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
734 Handle(AIS_InteractiveContext) Ctx;
735 Handle(V3d_View) Viou;
736 GetCtxAndView(Ctx,Viou);
737 Ctx->ClearActiveSensitive(Viou);
741 //==============================================================================
743 //purpose : To list the displayed object with their attributes
745 //==============================================================================
746 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
747 { if ( !a3DView().IsNull() ) {
748 di << "List of object in the viewer :" << "\n";
750 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
752 while ( it.More() ) {
753 di << "\t" << it.Key2().ToCString() << "\n";
761 //==============================================================================
762 //function : VSelPrecision
763 //purpose : To set the selection precision mode and tolerance value
764 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
765 // value (integer number of pixel for window mode, double value of
766 // sensitivity for view mode). Without arguments the function just
767 // prints the current precision mode and the corresponding tolerance.
768 //==============================================================================
769 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
773 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
777 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
778 if( aContext.IsNull() )
783 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
784 if( aMode == StdSelect_SM_WINDOW )
786 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
787 di << "Precision mode : 0 (window)\n";
788 di << "Pixel tolerance : " << aPixelTolerance << "\n";
790 else if( aMode == StdSelect_SM_VIEW )
792 Standard_Real aSensitivity = aContext->Sensitivity();
793 di << "Precision mode : 1 (view)\n";
794 di << "Sensitivity : " << aSensitivity << "\n";
799 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
800 aContext->SetSensitivityMode( aMode );
803 if( aMode == StdSelect_SM_WINDOW )
805 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
806 aContext->SetPixelTolerance( aPixelTolerance );
808 else if( aMode == StdSelect_SM_VIEW )
810 Standard_Real aSensitivity = Draw::Atof( argv[2] );
811 aContext->SetSensitivity( aSensitivity );
818 //==============================================================================
820 //purpose : To dump the active view snapshot to image file
821 //Draw arg : Picture file name with extension corresponding to desired format
822 //==============================================================================
823 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
827 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
831 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
834 TCollection_AsciiString aBuffTypeStr (argv[2]);
835 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
837 aBufferType = Graphic3d_BT_RGB;
839 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
841 aBufferType = Graphic3d_BT_RGBA;
843 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
845 aBufferType = Graphic3d_BT_Depth;
849 Standard_Integer aWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
850 Standard_Integer aHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
852 Handle(AIS_InteractiveContext) IC;
853 Handle(V3d_View) view;
854 GetCtxAndView (IC, view);
857 di << "Cannot find an active viewer/view\n";
861 if (aWidth <= 0 || aHeight <= 0)
863 if (!view->Dump (argv[1], aBufferType))
865 di << "Dumping failed!\n";
871 Image_AlienPixMap aPixMap;
872 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
874 di << "Dumping failed!\n";
878 if (aPixMap.SizeX() != Standard_Size(aWidth)
879 || aPixMap.SizeY() != Standard_Size(aHeight))
881 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
882 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
884 if (!aPixMap.Save (argv[1]))
886 di << "Saving image failed!\n";
893 //==============================================================================
894 //function : Displays,Erase...
897 //==============================================================================
898 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
899 const Standard_Integer Mode,
900 const Standard_Integer TypeOfOperation,
901 const Standard_Boolean Upd)
903 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
905 switch(TypeOfOperation){
907 Ctx->Display(IO,Mode,Upd);
910 Ctx->Erase(IO,Mode,Upd);
915 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
917 Ctx->SetDisplayMode(IO,Mode,Upd);
922 Ctx->SetDisplayMode(0,Upd);
924 Ctx->UnsetDisplayMode(IO,Upd);
931 //=======================================================================
934 //=======================================================================
935 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
938 TCollection_AsciiString name;
941 // display others presentations
942 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
943 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
944 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
945 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
947 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
949 //unset displaymode.. comportement particulier...
950 if(TypeOfOperation==4){
952 if(Ctx->NbCurrents()==0 ||
953 Ctx->NbSelected()==0){
954 Handle(AIS_InteractiveObject) IO;
955 VwrTst_DispErase(IO,-1,4,Standard_False);
957 else if(!Ctx->HasOpenedContext()){
958 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
959 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
962 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
963 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
964 Ctx->UpdateCurrentViewer();
967 Handle(AIS_InteractiveObject) IO;
969 if(GetMapOfAIS().IsBound2(name)){
970 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
972 VwrTst_DispErase(IO,-1,4,Standard_True);
977 Standard_Integer Dmode = Draw::Atoi(argv[1]);
978 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
979 Handle(AIS_InteractiveObject) IO;
980 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
982 if(!Ctx->HasOpenedContext()){
983 // set/unset display mode sur le Contexte...
984 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
985 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
987 Ctx->UpdateCurrentViewer();
990 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
991 Ctx->Display(Ctx->Interactive(),Dmode);
995 Handle(AIS_InteractiveObject) IO;
997 if(GetMapOfAIS().IsBound2(name))
998 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1000 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1006 //=======================================================================
1009 //=======================================================================
1010 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1012 if(argc==1) return 1;
1013 Standard_Integer On = Draw::Atoi(argv[1]);
1014 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1018 if(!Ctx->HasOpenedContext()){
1019 di<<"sub intensite ";
1022 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1023 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1025 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1027 di <<"passage dans off"<<"\n";
1028 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1033 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1035 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1037 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1040 Ctx->UpdateCurrentViewer();
1043 Handle(AIS_InteractiveObject) IO;
1044 TCollection_AsciiString name = argv[2];
1045 if(GetMapOfAIS().IsBound2(name)){
1046 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1049 Ctx->SubIntensityOn(IO);
1051 Ctx->SubIntensityOff(IO);
1059 //==============================================================================
1060 //function : VColor2
1062 //purpose : change the color of a selected or named or displayed shape
1063 //Draw arg : vcolor2 [name] color
1064 //==============================================================================
1065 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1068 Standard_Boolean ThereIsCurrent;
1069 Standard_Boolean ThereIsArgument;
1070 Standard_Boolean IsBound = Standard_False ;
1072 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1074 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1075 ThereIsArgument = (argc != 2);
1078 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1079 ThereIsArgument = (argc == 2);
1082 if ( !a3DView().IsNull() ) {
1083 TCollection_AsciiString name;
1084 if (ThereIsArgument) {
1086 IsBound= GetMapOfAIS().IsBound2(name);
1088 if (TheAISContext()->HasOpenedContext())
1089 TheAISContext()->CloseLocalContext();
1091 // On set le Booleen There is current
1092 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1093 else ThereIsCurrent =Standard_False;
1095 //=======================================================================
1096 // Il y a un argument
1097 //=======================================================================
1098 if ( ThereIsArgument && IsBound ) {
1099 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1100 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1101 Handle(AIS_InteractiveObject) ashape =
1102 Handle(AIS_InteractiveObject)::DownCast (anObj);
1105 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1107 di << "HaveToSet 0\n";
1111 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1113 TheAISContext()->UnsetColor(ashape);
1114 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1115 Handle(NIS_Triangulated) ashape =
1116 Handle(NIS_Triangulated)::DownCast (anObj);
1117 if (!ashape.IsNull())
1118 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1123 //=======================================================================
1124 // Il n'y a pas d'arguments
1125 // Mais un ou plusieurs objets on des current representation
1126 //=======================================================================
1127 if (ThereIsCurrent && !ThereIsArgument) {
1128 for (TheAISContext() -> InitCurrent() ;
1129 TheAISContext() -> MoreCurrent() ;
1130 TheAISContext() ->NextCurrent() )
1132 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1133 if (ashape.IsNull())
1137 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1139 di << "HaveToSet 0\n";
1142 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1144 TheAISContext()->UnsetColor(ashape,Standard_False);
1147 TheAISContext()->UpdateCurrentViewer();
1150 //=======================================================================
1151 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1152 // on impose a tous les objets du viewer la couleur passee
1153 //=======================================================================
1154 else if (!ThereIsCurrent && !ThereIsArgument){
1155 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1156 while ( it.More() ) {
1157 const Handle(AIS_InteractiveObject) ashape =
1158 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1159 if (!ashape.IsNull())
1161 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1163 TheAISContext()->UnsetColor(ashape,Standard_False);
1166 TheAISContext()->UpdateCurrentViewer();
1172 //==============================================================================
1173 //function : VTransparency
1175 //purpose : change the transparency of a selected or named or displayed shape
1176 //Draw arg : vtransparency [name] TransparencyCoeficient
1177 //==============================================================================
1179 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1182 Standard_Boolean ThereIsCurrent;
1183 Standard_Boolean ThereIsArgument;
1184 Standard_Boolean IsBound = Standard_False ;
1186 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1188 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1189 ThereIsArgument = (argc != 2);
1192 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1193 ThereIsArgument = (argc == 2);
1196 if ( !a3DView().IsNull() ) {
1197 TCollection_AsciiString name;
1198 if (ThereIsArgument) {
1200 IsBound= GetMapOfAIS().IsBound2(name);
1202 if (TheAISContext()->HasOpenedContext())
1203 TheAISContext()->CloseLocalContext();
1205 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1206 else ThereIsCurrent = Standard_False;
1208 //=======================================================================
1209 // Il y a des arguments: un nom et une couleur
1210 //=======================================================================
1211 if ( ThereIsArgument && IsBound ) {
1212 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1213 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1214 const Handle(AIS_InteractiveObject) ashape =
1215 Handle(AIS_InteractiveObject)::DownCast(anObj);
1217 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
1219 TheAISContext()->UnsetTransparency(ashape);
1220 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1221 const Handle(NIS_InteractiveObject) ashape =
1222 Handle(NIS_InteractiveObject)::DownCast(anObj);
1224 ashape->SetTransparency(Draw::Atof(argv[2]) );
1226 ashape->UnsetTransparency();
1229 //=======================================================================
1230 // Il n'y a pas d'arguments
1231 // Mais un ou plusieurs objets on des current representation
1232 //=======================================================================
1233 if (ThereIsCurrent && !ThereIsArgument) {
1234 for (TheAISContext() -> InitCurrent() ;
1235 TheAISContext() -> MoreCurrent() ;
1236 TheAISContext() ->NextCurrent() )
1238 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1240 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1242 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1245 TheAISContext()->UpdateCurrentViewer();
1247 //=======================================================================
1248 // Il n'y a pas d'arguments ET aucun objet courrant
1249 //=======================================================================
1250 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1251 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1253 while ( it.More() ) {
1254 Handle(AIS_InteractiveObject) ashape =
1255 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1256 if (!ashape.IsNull())
1258 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1260 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1263 TheAISContext()->UpdateCurrentViewer();
1270 //==============================================================================
1271 //function : VMaterial
1273 //purpose : change the Material of a selected or named or displayed shape
1274 //Draw arg : vmaterial [Name] Material
1275 //==============================================================================
1276 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1279 Standard_Boolean ThereIsCurrent;
1280 Standard_Boolean ThereIsName;
1281 Standard_Boolean IsBound = Standard_False ;
1283 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1285 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1286 ThereIsName = (argc != 2);
1289 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1290 ThereIsName = (argc == 2);
1293 if ( !a3DView().IsNull() ) {
1294 TCollection_AsciiString name;
1297 IsBound= GetMapOfAIS().IsBound2(name);
1299 if (TheAISContext()->HasOpenedContext())
1300 TheAISContext()->CloseLocalContext();
1301 if (TheAISContext() -> NbCurrents() > 0 )
1302 ThereIsCurrent =Standard_True;
1304 ThereIsCurrent =Standard_False;
1306 //=======================================================================
1307 // Ther is a name of shape and a material name
1308 //=======================================================================
1309 if ( ThereIsName && IsBound ) {
1310 Handle(AIS_InteractiveObject) ashape =
1311 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1312 if (!ashape.IsNull())
1314 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1316 TheAISContext()->UnsetMaterial(ashape);
1318 //=======================================================================
1319 // Il n'y a pas de nom de shape
1320 // Mais un ou plusieurs objets on des current representation
1321 //=======================================================================
1322 if (ThereIsCurrent && !ThereIsName) {
1323 for (TheAISContext() -> InitCurrent() ;
1324 TheAISContext() -> MoreCurrent() ;
1325 TheAISContext() ->NextCurrent() )
1327 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1329 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1331 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1333 TheAISContext()->UpdateCurrentViewer();
1336 //=======================================================================
1337 // Il n'y a pas de noms de shape ET aucun objet courrant
1338 // On impose a tous les objets du viewer le material passe en argument
1339 //=======================================================================
1340 else if (!ThereIsCurrent && !ThereIsName){
1341 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1343 while ( it.More() ) {
1344 Handle(AIS_InteractiveObject) ashape =
1345 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1346 if (!ashape.IsNull())
1348 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1350 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1353 TheAISContext()->UpdateCurrentViewer();
1361 //==============================================================================
1364 //purpose : change the width of the edges of a selected or named or displayed shape
1365 //Draw arg : vwidth [Name] WidthValue(1->10)
1366 //==============================================================================
1367 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1370 Standard_Boolean ThereIsCurrent;
1371 Standard_Boolean ThereIsArgument;
1372 Standard_Boolean IsBound = Standard_False ;
1374 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1376 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1377 ThereIsArgument = (argc != 2);
1380 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1381 ThereIsArgument = (argc == 2);
1383 if ( !a3DView().IsNull() ) {
1384 TCollection_AsciiString name;
1385 if (ThereIsArgument) {
1387 IsBound= GetMapOfAIS().IsBound2(name);
1389 if (TheAISContext()->HasOpenedContext())
1390 TheAISContext()->CloseLocalContext();
1392 if (TheAISContext() -> NbCurrents() > 0 )
1393 ThereIsCurrent =Standard_True;
1395 ThereIsCurrent =Standard_False;
1397 if ( ThereIsArgument && IsBound ) {
1398 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1399 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1400 const Handle(AIS_InteractiveObject) ashape =
1401 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1403 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
1405 TheAISContext()->UnsetWidth (ashape);
1406 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1407 const Handle(NIS_Triangulated) ashape =
1408 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1409 if (HaveToSet && !ashape.IsNull())
1410 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
1414 //=======================================================================
1415 // Il n'y a pas d'arguments
1416 // Mais un ou plusieurs objets on des current representation
1417 //=======================================================================
1418 if (ThereIsCurrent && !ThereIsArgument) {
1419 for (TheAISContext() -> InitCurrent() ;
1420 TheAISContext() -> MoreCurrent() ;
1421 TheAISContext() ->NextCurrent() )
1423 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1425 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1427 TheAISContext()->UnsetWidth(ashape,Standard_False);
1429 TheAISContext()->UpdateCurrentViewer();
1431 //=======================================================================
1432 // Il n'y a pas d'arguments ET aucun objet courrant
1433 //=======================================================================
1434 else if (!ThereIsCurrent && !ThereIsArgument){
1435 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1437 while ( it.More() ) {
1438 Handle(AIS_InteractiveObject) ashape =
1439 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1440 if (!ashape.IsNull())
1442 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1444 TheAISContext()->UnsetWidth(ashape,Standard_False);
1447 TheAISContext()->UpdateCurrentViewer();
1453 //==============================================================================
1454 //function : VInteriorStyle
1455 //purpose : sets interior style of the a selected or named or displayed shape
1456 //Draw arg : vsetinteriorstyle [shape] style
1457 //==============================================================================
1458 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1459 const Standard_Integer theStyle,
1460 Draw_Interpretor& di)
1462 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1463 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1464 " (Aspect_IS_HIDDENLINE)]\n";
1467 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1468 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1469 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1470 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1471 aFillAspect->SetInteriorStyle (aStyle);
1472 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1475 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1477 if (argc < 2 || argc > 3) {
1478 di << argv[0] << " requires 2 or 3 arguments\n";
1479 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1480 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1481 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1485 Standard_Boolean ThereIsCurrent;
1486 Standard_Boolean ThereIsArgument;
1487 Standard_Boolean IsBound = Standard_False ;
1489 ThereIsArgument = (argc > 2);
1490 if ( !a3DView().IsNull() ) {
1491 TCollection_AsciiString name;
1492 if (ThereIsArgument) {
1494 IsBound= GetMapOfAIS().IsBound2(name);
1496 if (TheAISContext()->HasOpenedContext())
1497 TheAISContext()->CloseLocalContext();
1499 if (TheAISContext() -> NbCurrents() > 0 )
1500 ThereIsCurrent =Standard_True;
1502 ThereIsCurrent =Standard_False;
1504 if ( ThereIsArgument && IsBound ) {
1505 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1506 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1507 const Handle(AIS_InteractiveObject) ashape =
1508 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1509 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
1512 //=======================================================================
1513 // No arguments specified
1514 // But there are one or more selected objects
1515 //=======================================================================
1516 if (ThereIsCurrent && !ThereIsArgument) {
1517 for (TheAISContext() -> InitCurrent() ;
1518 TheAISContext() -> MoreCurrent() ;
1519 TheAISContext() ->NextCurrent() )
1521 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1522 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1525 //=======================================================================
1526 // No arguments specified and there are no selected objects
1527 //=======================================================================
1528 else if (!ThereIsCurrent && !ThereIsArgument){
1529 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1531 while ( it.More() ) {
1532 Handle(AIS_InteractiveObject) ashape =
1533 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1534 if (!ashape.IsNull())
1535 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1539 TheAISContext()->UpdateCurrentViewer();
1544 //==============================================================================
1545 //function : VDonly2
1547 //purpose : Display only a selected or named object
1548 // if there is no selected or named object s, nothing is donne
1549 //Draw arg : vdonly2 [name1] ... [name n]
1550 //==============================================================================
1551 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1554 if ( a3DView().IsNull() )
1557 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1558 Standard_Boolean ThereIsArgument= argc>1;
1560 if (TheAISContext()->HasOpenedContext())
1561 TheAISContext()->CloseLocalContext();
1563 //===============================================================
1564 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1566 //===============================================================
1567 if (!ThereIsArgument && ThereIsCurrent) {
1570 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1573 for(TheAISContext()->InitCurrent();
1574 TheAISContext()->MoreCurrent();
1575 TheAISContext()->NextCurrent()){
1576 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1577 TheAISContext()->Erase(aShape,Standard_False);}
1579 TheAISContext() ->UpdateCurrentViewer();
1580 //===============================================================
1581 // Il y a des arguments
1582 //===============================================================
1583 if (ThereIsArgument) {
1584 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1586 while ( it.More() ) {
1587 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1588 const Handle(AIS_InteractiveObject) aShape =
1589 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1590 TheAISContext()->Erase(aShape,Standard_False);
1591 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1592 const Handle(NIS_InteractiveObject) aShape =
1593 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1594 TheNISContext()->Erase(aShape);
1599 // On display les objets passes par parametre
1600 for (int i=1; i<argc ; i++) {
1601 TCollection_AsciiString name=argv[i];
1602 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1604 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1605 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1606 const Handle(AIS_InteractiveObject) aShape =
1607 Handle(AIS_InteractiveObject)::DownCast (anObj);
1608 TheAISContext()->Display(aShape, Standard_False);
1609 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1610 Handle(NIS_InteractiveObject) aShape =
1611 Handle(NIS_InteractiveObject)::DownCast (anObj);
1612 TheNISContext()->Display(aShape);
1616 TheAISContext() ->UpdateCurrentViewer();
1617 // TheNISContext() ->UpdateViews();
1622 //==============================================================================
1623 //function : VErase2
1625 //purpose : Erase some selected or named objects
1626 // if there is no selected or named objects, the whole viewer is erased
1627 //Draw arg : verase2 [name1] ... [name n]
1628 //==============================================================================
1629 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1632 if ( a3DView().IsNull() )
1635 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1636 Standard_Boolean ThereIsArgument= argc>1;
1637 if(TheAISContext()->HasOpenedContext())
1638 TheAISContext()->CloseLocalContext();
1640 //===============================================================
1641 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1643 //===============================================================
1644 if (!ThereIsArgument && ThereIsCurrent) {
1645 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1647 while ( it.More() ) {
1648 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1649 const Handle(AIS_InteractiveObject) aShape =
1650 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1651 if (TheAISContext()->IsCurrent(aShape))
1652 TheAISContext()->Erase(aShape,Standard_False);
1657 TheAISContext() ->UpdateCurrentViewer();
1660 //===============================================================
1661 // Il n'y a pas d'arguments et aucuns objets selectionnes
1663 // On erase tout le viewer
1664 //===============================================================
1666 if (!ThereIsArgument && !ThereIsCurrent) {
1667 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1668 while ( it.More() ) {
1669 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1670 const Handle(AIS_InteractiveObject) aShape =
1671 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1672 TheAISContext()->Erase(aShape,Standard_False);
1673 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1674 const Handle(NIS_InteractiveObject) aShape =
1675 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1676 TheNISContext()->Erase(aShape);
1680 TheAISContext() ->UpdateCurrentViewer();
1681 // TheNISContext()->UpdateViews();
1684 //===============================================================
1685 // Il y a des arguments
1686 //===============================================================
1687 if (ThereIsArgument) {
1688 for (int i=1; i<argc ; i++) {
1689 TCollection_AsciiString name=argv[i];
1690 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1692 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1693 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1694 const Handle(AIS_InteractiveObject) aShape =
1695 Handle(AIS_InteractiveObject)::DownCast (anObj);
1696 TheAISContext()->Erase(aShape,Standard_False);
1697 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1698 const Handle(NIS_InteractiveObject) aShape =
1699 Handle(NIS_InteractiveObject)::DownCast (anObj);
1700 TheNISContext()->Erase(aShape);
1704 TheAISContext() ->UpdateCurrentViewer();
1705 // TheNISContext() ->UpdateViews();
1710 //==============================================================================
1711 //function : VEraseAll
1713 //purpose : Erase all the objects displayed in the viewer
1714 //Draw arg : veraseall
1715 //==============================================================================
1716 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1719 // Verification des arguments
1720 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1721 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1722 TheAISContext()->CloseAllContexts(Standard_False);
1723 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1725 while ( it.More() ) {
1726 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1727 const Handle(AIS_InteractiveObject) aShape =
1728 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1729 TheAISContext()->Erase(aShape,Standard_False);
1730 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1731 const Handle(NIS_InteractiveObject) aShape =
1732 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1733 TheNISContext()->Erase(aShape);
1737 TheAISContext() ->UpdateCurrentViewer();
1738 // TheNISContext() ->UpdateViews();
1743 //==============================================================================
1744 //function : VDisplayAll
1746 //purpose : Display all the objects of the Map
1747 //Draw arg : vdisplayall
1748 //==============================================================================
1749 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1752 if (! a3DView().IsNull() ) {
1753 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1754 if (TheAISContext()->HasOpenedContext())
1755 TheAISContext()->CloseLocalContext();
1756 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1758 while ( it.More() ) {
1759 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1760 const Handle(AIS_InteractiveObject) aShape =
1761 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1762 TheAISContext()->Erase(aShape,Standard_False);
1763 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1764 const Handle(NIS_InteractiveObject) aShape =
1765 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1766 TheNISContext()->Erase(aShape);
1771 while ( it.More() ) {
1772 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1773 const Handle(AIS_InteractiveObject) aShape =
1774 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1775 TheAISContext()->Display(aShape, Standard_False);
1776 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1777 Handle(NIS_InteractiveObject) aShape =
1778 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1779 TheNISContext()->Display(aShape);
1783 TheAISContext() ->UpdateCurrentViewer();
1784 // TheNISContext() ->UpdateViews();
1789 //#######################################################################################################
1793 //#######################################################################################################
1795 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1797 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1798 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1799 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1800 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1801 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1803 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1804 if(myAISContext.IsNull())
1806 di << "use 'vinit' command before " << argv[0] << "\n";
1810 Handle(AIS_InteractiveObject) TheAisIO;
1811 Handle(AIS_TexturedShape) myShape;
1812 Standard_Integer myPreviousMode = 0;
1814 if (argc<2 || !argv[1])
1816 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1820 TCollection_AsciiString name = argv[1];
1821 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1823 if (GetMapOfAIS().IsBound2(name))
1824 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1825 (GetMapOfAIS().Find2(name));
1826 if (TheAisIO.IsNull())
1828 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1832 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1834 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1835 myPreviousMode = myShape->DisplayMode() ;
1839 myAISContext->Clear(TheAisIO,Standard_False);
1840 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1841 GetMapOfAIS().UnBind1(TheAisIO);
1842 GetMapOfAIS().UnBind2(name);
1843 GetMapOfAIS().Bind(myShape, name);
1847 case 1: // vtexture : we only map a texture on the shape
1850 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1853 if (argc>2 && argv[2])
1855 if(strcasecmp(argv[2],"?")==0)
1857 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1858 di<<"\n Files in current directory : \n"<<"\n";
1859 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1860 di.Eval(Cmnd.ToCString());
1862 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1865 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1866 di.Eval(Cmnd.ToCString());
1871 myShape->SetTextureFileName(argv[2]);
1875 di <<"Texture mapping disabled \n \
1876 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1878 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1879 if (myPreviousMode == 3 )
1880 myAISContext->RecomputePrsOnly(myShape);
1881 myAISContext->Display(myShape, Standard_True);
1886 case 2: // vtexscale : we change the scaling factor of the texture
1890 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1894 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1895 ( argv[2] ? Draw::Atof(argv[2]) : 1.0 ),
1896 ( argv[2] ? Draw::Atof(argv[argc-1]) : 1.0 ) );
1899 case 3: // vtexorigin : we change the origin of the texture on the shape
1902 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1905 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1906 ( argv[2] ? Draw::Atof(argv[2]) : 0.0 ),
1907 ( argv[2] ? Draw::Atof(argv[argc-1]) : 0.0 ));
1910 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1913 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1916 if (argc>2 && argv[2])
1918 di <<"Texture repeat enabled"<<"\n";
1919 myShape->SetTextureRepeat(Standard_True, Draw::Atof(argv[2]), Draw::Atof(argv[argc-1]) );
1923 di <<"Texture repeat disabled"<<"\n";
1924 myShape->SetTextureRepeat(Standard_False);
1928 case 5: // vtexdefault : default texture mapping
1929 // ScaleU = ScaleV = 100.0
1930 // URepeat = VRepeat = 1.0
1931 // Uorigin = VOrigin = 0.0
1935 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1938 myShape->SetTextureRepeat(Standard_False);
1939 myShape->SetTextureOrigin(Standard_False);
1940 myShape->SetTextureScale (Standard_False);
1944 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1945 myAISContext->RecomputePrsOnly(myShape);
1948 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1949 myAISContext->Display(myShape, Standard_True);
1950 myAISContext->Update(myShape,Standard_True);
1955 //==============================================================================
1956 //function : VDisplay2
1958 //purpose : Display an object from its name
1959 //Draw arg : vdisplay name1 [name2] ... [name n]
1960 //==============================================================================
1961 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1964 // Verification des arguments
1965 if ( a3DView().IsNull() ) {
1967 ViewerTest::ViewerInit();
1968 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1973 di<<argv[0]<<" Syntaxe error"<<"\n";
1978 TCollection_AsciiString name;
1979 if (TheAISContext()->HasOpenedContext())
1980 TheAISContext()->CloseLocalContext();
1982 for ( int i = 1; i < argc; i++ ) {
1984 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1985 Standard_Boolean IsDatum = Standard_False;
1986 Handle(Standard_Transient) anObj;
1988 anObj = GetMapOfAIS().Find2(name);
1989 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1990 Handle(AIS_InteractiveObject) aShape =
1991 Handle(AIS_InteractiveObject)::DownCast(anObj);
1992 if (aShape->Type()==AIS_KOI_Datum) {
1993 IsDatum = Standard_True;
1994 TheAISContext()->Display(aShape, Standard_False);
1997 di << "Display " << name.ToCString() << "\n";
1998 // Get the Shape from a name
1999 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
2001 // Update the Shape in the AIS_Shape
2002 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
2003 if(!TheRealSh.IsNull())
2004 TheRealSh->Set(NewShape);
2005 TheAISContext()->Redisplay(aShape, Standard_False);
2006 TheAISContext()->Display(aShape, Standard_False);
2009 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
2010 Handle(NIS_InteractiveObject) aShape =
2011 Handle(NIS_InteractiveObject)::DownCast(anObj);
2012 TheNISContext()->Display(aShape);
2015 else { // Create the AIS_Shape from a name
2016 const Handle(AIS_InteractiveObject) aShape =
2017 GetAISShapeFromName((const char *)name.ToCString());
2018 if ( !aShape.IsNull() ) {
2019 GetMapOfAIS().Bind(aShape, name);
2020 TheAISContext()->Display(aShape, Standard_False);
2024 // Upadate the screen and redraw the view
2025 TheAISContext()->UpdateCurrentViewer();
2026 // TheNISContext()->UpdateViews();
2030 //==============================================================================
2032 //purpose : Test the annimation of an object along a
2033 // predifined trajectory
2034 //Draw arg : vmove ShapeName
2035 //==============================================================================
2038 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2043 if (TheAISContext()->HasOpenedContext())
2044 TheAISContext()->CloseLocalContext();
2046 Standard_Real Step=2*M_PI/180;
2047 Standard_Real Angle=0;
2048 // R est le rayon de l'hellicoide
2050 // D est la distance parcourue en translation en 1 tour
2053 Handle(AIS_InteractiveObject) aIO;
2055 if (GetMapOfAIS().IsBound2(argv[1]))
2056 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2059 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
2062 TheAISContext()->Deactivate(aIO);
2064 // boucle generant le mouvement
2066 di<<" Transformations"<<"\n";
2067 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2070 gp_Ax3 newBase(gp_Pnt(R*cos(Angle), R*sin(Angle), D*Angle/(2*M_PI) ), gp_Vec(0,0,1), gp_Vec(1,0,0) );
2072 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
2073 TheAISContext()->SetLocation(aIO,myTransfo);
2075 TheAISContext() ->UpdateCurrentViewer();
2080 di<<" Locations"<<"\n";
2081 gp_Trsf myAngleTrsf;
2082 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2083 TopLoc_Location myDeltaAngle (myAngleTrsf);
2085 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
2086 TopLoc_Location myDeltaDist (myDistTrsf);
2087 TopLoc_Location myTrueLoc;
2089 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2092 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
2093 TheAISContext()->SetLocation(aIO,myTrueLoc );
2094 TheAISContext() ->UpdateCurrentViewer();
2099 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
2101 //TopLoc_Location Tempo=aIO->Location();
2102 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
2103 //ShapeBis.Located(Tempo);
2106 // On reset la location (origine) contenue dans l'AISInteractiveObject
2107 TheAISContext() ->ResetLocation(aIO);
2109 // On force aShape a devenir l'AIS IO propre a ShapeBis
2111 // Pour cela on force aShape(AIS IO) a devenir une AISShape
2112 // ->Set() est une methode de AIS_Shape
2113 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
2115 // On donne a ShapeBis le nom de l'AIS IO
2116 //Rep::Set(argv[1],ShapeBis);
2119 TheAISContext()->Redisplay(aIO,Standard_False);
2121 // On reactive la selection des primitives sensibles
2122 TheAISContext()->Activate(aIO,0);
2124 TheAISContext() ->UpdateCurrentViewer();
2125 a3DView() -> Redraw();
2128 di<<" Temps ecoule "<<"\n";
2136 //==============================================================================
2138 //purpose : Test the annimation of an object along a
2139 // predifined trajectory
2140 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2141 //==============================================================================
2143 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2146 if (TheAISContext()->HasOpenedContext())
2147 TheAISContext()->CloseLocalContext();
2149 Standard_Real Step=4*M_PI/180;
2150 Standard_Real Angle=0;
2152 Handle(AIS_InteractiveObject) aIO;
2153 if (GetMapOfAIS().IsBound2(argv[1]))
2154 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2158 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2162 if (Draw::Atoi(argv[3])==1 ) {
2163 di<<" Primitives sensibles OFF"<<"\n";
2164 TheAISContext()->Deactivate(aIO);
2167 di<<" Primitives sensibles ON"<<"\n";
2169 // Movement par transformation
2170 if(Draw::Atoi(argv[2]) ==1) {
2171 di<<" Calcul par Transformation"<<"\n";
2172 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2176 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2177 TheAISContext()->SetLocation(aShape,myTransfo);
2178 TheAISContext() ->UpdateCurrentViewer();
2183 di<<" Calcul par Locations"<<"\n";
2184 gp_Trsf myAngleTrsf;
2185 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2186 TopLoc_Location myDeltaAngle (myAngleTrsf);
2187 TopLoc_Location myTrueLoc;
2189 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2192 myTrueLoc=myTrueLoc*myDeltaAngle;
2193 TheAISContext()->SetLocation(aShape,myTrueLoc );
2194 TheAISContext() ->UpdateCurrentViewer();
2197 if (Draw::Atoi(argv[3])==1 ){
2198 // On reactive la selection des primitives sensibles
2199 TheAISContext()->Activate(aIO,0);
2201 a3DView() -> Redraw();
2203 di<<" Temps ecoule "<<"\n";
2209 //==================================================================================
2210 // Function : VAnimation
2211 //==================================================================================
2212 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2214 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2218 Standard_Real thread = 4;
2219 Standard_Real angleA=0;
2220 Standard_Real angleB;
2222 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2225 TopoDS_Shape CrankArm;
2226 TopoDS_Shape CylinderHead;
2227 TopoDS_Shape Propeller;
2228 TopoDS_Shape EngineBlock;
2230 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2231 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2232 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2233 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2234 BRepTools::Read(CrankArm,argv[1],B);
2235 BRepTools::Read(CylinderHead,argv[2],B);
2236 BRepTools::Read(Propeller,argv[3],B);
2237 BRepTools::Read(EngineBlock,argv[4],B);
2239 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2245 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2246 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2247 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2248 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2250 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2251 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2252 GetMapOfAIS().Bind(myAisCrankArm,"c");
2253 GetMapOfAIS().Bind(myAisPropeller,"d");
2255 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2256 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2257 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2259 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2260 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2261 TheAISContext()->Display(myAisCrankArm,Standard_False );
2262 TheAISContext()->Display(myAisPropeller,Standard_False);
2264 TheAISContext()->Deactivate(myAisCylinderHead);
2265 TheAISContext()->Deactivate(myAisEngineBlock );
2266 TheAISContext()->Deactivate(myAisCrankArm );
2267 TheAISContext()->Deactivate(myAisPropeller );
2269 // Boucle de mouvement
2270 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2272 angleA = thread*myAngle*M_PI/180;
2273 X = Sin(angleA)*3/8;
2274 angleB = atan(X / Sqrt(-X * X + 1));
2275 Standard_Real decal(25*0.6);
2278 //Build a transformation on the display
2279 gp_Trsf aPropellerTrsf;
2280 aPropellerTrsf.SetRotation(Ax1,angleA);
2281 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2283 gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)),-3*decal*Sin(angleA),0),gp_Vec(0,0,1),gp_Vec(1,0,0));
2284 gp_Trsf aCrankArmTrsf;
2285 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2286 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2288 TheAISContext()->UpdateCurrentViewer();
2291 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2292 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2294 myAisCrankArm ->ResetLocation();
2295 myAisPropeller->ResetLocation();
2297 myAisCrankArm -> Set(myNewCrankArm );
2298 myAisPropeller -> Set(myNewPropeller);
2300 TheAISContext()->Activate(myAisCylinderHead,0);
2301 TheAISContext()->Activate(myAisEngineBlock,0 );
2302 TheAISContext()->Activate(myAisCrankArm ,0 );
2303 TheAISContext()->Activate(myAisPropeller ,0 );
2309 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2310 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2312 TheAISContext()->UpdateCurrentViewer();
2313 a3DView()->Redraw();
2322 //==============================================================================
2323 //function : VShading
2324 //purpose : Sharpen or roughten the quality of the shading
2325 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2326 //==============================================================================
2327 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2329 Standard_Real myDevCoef;
2330 Handle(AIS_InteractiveObject) TheAisIO;
2333 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2335 if (TheAISContext()->HasOpenedContext())
2336 TheAISContext()->CloseLocalContext();
2341 myDevCoef =Draw::Atof(argv[2]);
2344 TCollection_AsciiString name=argv[1];
2345 if (GetMapOfAIS().IsBound2(name ))
2346 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2347 if (TheAisIO.IsNull())
2348 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2351 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2353 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2355 TheAISContext()->Redisplay(TheAisIO);
2358 //==============================================================================
2359 //function : HaveMode
2360 //use : VActivatedModes
2361 //==============================================================================
2362 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2364 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2366 TColStd_ListOfInteger List;
2367 TheAISContext()->ActivatedModes (TheAisIO,List);
2368 TColStd_ListIteratorOfListOfInteger it;
2369 Standard_Boolean Found=Standard_False;
2370 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2371 if (it.Value()==mode ) Found=Standard_True;
2378 //==============================================================================
2379 //function : VActivatedMode
2381 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2382 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2383 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2384 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2385 // qu'un nom et qu'un mode.
2386 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2387 //==============================================================================
2388 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2390 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2393 Standard_Boolean ThereIsName = Standard_False ;
2395 if(!a3DView().IsNull()){
2397 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2398 // verification des arguments
2400 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2401 ThereIsName = (argc == 3);
2405 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2407 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2408 di<<" Fermeture du Context local"<<"\n";
2409 if (TheAISContext()->HasOpenedContext())
2410 TheAISContext()->CloseLocalContext();
2414 // IL n'y a aps de nom de shape passe en argument
2415 if (HaveToSet && !ThereIsName){
2416 Standard_Integer aMode=Draw::Atoi(argv [1]);
2418 const char *cmode="???";
2420 case 0: cmode = "Shape"; break;
2421 case 1: cmode = "Vertex"; break;
2422 case 2: cmode = "Edge"; break;
2423 case 3: cmode = "Wire"; break;
2424 case 4: cmode = "Face"; break;
2425 case 5: cmode = "Shell"; break;
2426 case 6: cmode = "Solid"; break;
2427 case 7: cmode = "Compound"; break;
2430 if( !TheAISContext()->HasOpenedContext() ) {
2431 // il n'y a pas de Context local d'ouvert
2432 // on en ouvre un et on charge toutes les shapes displayees
2433 // on load tous les objets displayees et on Activate les objets de la liste
2434 AIS_ListOfInteractive ListOfIO;
2435 // on sauve dans une AISListOfInteractive tous les objets currents
2436 if (TheAISContext()->NbCurrents()>0 ){
2437 TheAISContext()->UnhilightCurrents(Standard_False);
2439 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2440 ListOfIO.Append(TheAISContext()->Current() );
2444 TheAISContext()->OpenLocalContext(Standard_False);
2445 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2448 Handle(AIS_InteractiveObject) aIO =
2449 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2451 TheAISContext()->Load(aIO,0,Standard_False);
2454 // traitement des objets qui etaient currents dans le Contexte global
2455 if (!ListOfIO.IsEmpty() ) {
2456 // il y avait des objets currents
2457 AIS_ListIteratorOfListOfInteractive iter;
2458 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2459 Handle(AIS_InteractiveObject) aIO=iter.Value();
2460 TheAISContext()->Activate(aIO,aMode);
2461 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2465 // On applique le mode a tous les objets displayes
2466 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2467 it2 (GetMapOfAIS());
2469 Handle(AIS_InteractiveObject) aIO =
2470 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2471 if (!aIO.IsNull()) {
2472 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2473 TheAISContext()->Activate(aIO,aMode);
2482 // un Context local est deja ouvert
2483 // Traitement des objets du Context local
2484 if (TheAISContext()->NbSelected()>0 ){
2485 TheAISContext()->UnhilightSelected(Standard_False);
2486 // il y a des objets selected,on les parcourt
2487 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2488 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2491 if (HaveMode(aIO,aMode) ) {
2492 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2493 TheAISContext()->Deactivate(aIO,aMode);
2496 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2497 TheAISContext()->Activate(aIO,aMode);
2503 // il n'y a pas d'objets selected
2504 // tous les objets diplayes sont traites
2505 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2508 Handle(AIS_InteractiveObject) aIO =
2509 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2510 if (!aIO.IsNull()) {
2511 if (HaveMode(aIO,aMode) ) {
2512 di<<" Mode: "<<cmode<<" OFF pour "
2513 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2514 TheAISContext()->Deactivate(aIO,aMode);
2517 di<<" Mode: "<<cmode<<" ON pour"
2518 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2519 TheAISContext()->Activate(aIO,aMode);
2527 else if (HaveToSet && ThereIsName){
2528 Standard_Integer aMode=Draw::Atoi(argv [2]);
2529 Handle(AIS_InteractiveObject) aIO =
2530 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2532 if (!aIO.IsNull()) {
2533 const char *cmode="???";
2536 case 0: cmode = "Shape"; break;
2537 case 1: cmode = "Vertex"; break;
2538 case 2: cmode = "Edge"; break;
2539 case 3: cmode = "Wire"; break;
2540 case 4: cmode = "Face"; break;
2541 case 5: cmode = "Shell"; break;
2542 case 6: cmode = "Solid"; break;
2543 case 7: cmode = "Compound"; break;
2546 if( !TheAISContext()->HasOpenedContext() ) {
2547 TheAISContext()->OpenLocalContext(Standard_False);
2548 // On charge tous les objets de la map
2549 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2551 Handle(AIS_InteractiveObject) aShape=
2552 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2553 if (!aShape.IsNull())
2554 TheAISContext()->Load(aShape,0,Standard_False);
2557 TheAISContext()->Activate(aIO,aMode);
2558 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2562 // un Context local est deja ouvert
2563 if (HaveMode(aIO,aMode) ) {
2564 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2565 TheAISContext()->Deactivate(aIO,aMode);
2568 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2569 TheAISContext()->Activate(aIO,aMode);
2581 //==============================================================================
2582 // function : WhoAmI
2584 //==============================================================================
2585 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2588 if (theShape->Type()==AIS_KOI_Datum) {
2589 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2590 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2591 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2592 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2593 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2594 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2595 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2598 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2599 // AIS_Dimentions et AIS_Relations
2600 else if (theShape->Type()==AIS_KOI_Relation) {
2601 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2603 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2604 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2605 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2606 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2607 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2608 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2609 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2610 // AIS no repertorie.
2611 else {di<<" Type Unknown.";}
2617 //==============================================================================
2620 //Draw arg : vstate [nameA] ... [nameN]
2621 //==============================================================================
2622 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2624 TheAISContext()->CloseAllContexts();
2625 const Standard_Boolean ThereIsArguments=(argc>=2);
2626 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2628 // ==================
2629 // Il y a un argument
2630 // ==================
2631 if (ThereIsArguments) {
2632 for (int cpt=1;cpt<argc;cpt++) {
2633 // Verification que lq piece est bien bindee.
2634 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2635 const Handle(AIS_InteractiveObject) theShape=
2636 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2638 if (!theShape.IsNull()) {
2639 di<<argv[cpt];WhoAmI(theShape, di);
2640 if (TheAISContext()->IsDisplayed(theShape) ) {
2641 di<<" Displayed"<<"\n";
2644 di<<" Not Displayed"<<"\n";
2649 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2653 else if (ThereIsCurrent ) {
2654 for (TheAISContext() -> InitCurrent() ;
2655 TheAISContext() -> MoreCurrent() ;
2656 TheAISContext() ->NextCurrent() )
2658 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2659 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2660 if (TheAISContext()->IsDisplayed(theShape) ) {
2661 di<<" Displayed"<<"\n";
2664 di<<" Not Displayed"<<"\n";
2670 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2672 while ( it.More() ) {
2673 Handle(AIS_InteractiveObject) theShape =
2674 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2675 if (!theShape.IsNull()) {
2676 di<<it.Key2().ToCString();
2677 WhoAmI(theShape, di);
2678 if (TheAISContext()->IsDisplayed(theShape) ) {
2679 di<<" Displayed"<<"\n";
2682 di<<" Not Displayed"<<"\n";
2693 //=======================================================================
2694 //function : PickObjects
2696 //=======================================================================
2697 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2698 const AIS_KindOfInteractive TheType,
2699 const Standard_Integer TheSignature,
2700 const Standard_Integer MaxPick)
2702 Handle(AIS_InteractiveObject) IO;
2703 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2705 // step 1: prepare the data
2707 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2708 TheAISContext()->AddFilter(F1);
2711 // step 2 : wait for the selection...
2712 // Standard_Boolean IsGood (Standard_False);
2713 // Standard_Integer NbPick(0);
2714 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2715 Standard_Integer NbPickFail(0);
2716 Standard_Integer argccc = 5;
2717 const char *bufff[] = { "A", "B", "C","D", "E" };
2718 const char **argvvv = (const char **) bufff;
2721 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2722 while(ViewerMainLoop(argccc,argvvv)){}
2723 Standard_Integer NbStored = TheAISContext()->NbSelected();
2724 if((unsigned int ) NbStored != NbPickGood)
2725 NbPickGood= NbStored;
2728 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2731 // step3 get result.
2733 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2735 Standard_Integer i(0);
2736 for(TheAISContext()->InitSelected();
2737 TheAISContext()->MoreSelected();
2738 TheAISContext()->NextSelected()){
2740 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2741 arr->SetValue(i,IO2);
2746 TheAISContext()->CloseLocalContext(curindex);
2748 return Standard_True;
2752 //=======================================================================
2753 //function : PickObject
2755 //=======================================================================
2756 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2757 const Standard_Integer TheSignature,
2758 const Standard_Integer MaxPick)
2760 Handle(AIS_InteractiveObject) IO;
2761 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2763 // step 1: prepare the data
2766 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2767 TheAISContext()->AddFilter(F1);
2770 // step 2 : wait for the selection...
2771 Standard_Boolean IsGood (Standard_False);
2772 Standard_Integer NbPick(0);
2773 Standard_Integer argccc = 5;
2774 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2775 const char **argvvv = (const char **) bufff;
2778 while(!IsGood && NbPick<= MaxPick){
2779 while(ViewerMainLoop(argccc,argvvv)){}
2780 IsGood = (TheAISContext()->NbSelected()>0) ;
2782 cout<<"Nb Pick :"<<NbPick<<endl;
2786 // step3 get result.
2788 TheAISContext()->InitSelected();
2789 IO = TheAISContext()->SelectedInteractive();
2793 TheAISContext()->CloseLocalContext(curindex);
2797 //=======================================================================
2798 //function : PickShape
2799 //purpose : First Activate the rightmode + Put Filters to be able to
2800 // pick objets that are of type <TheType>...
2801 //=======================================================================
2803 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2804 const Standard_Integer MaxPick)
2807 // step 1: prepare the data
2809 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2810 TopoDS_Shape result;
2812 if(TheType==TopAbs_SHAPE){
2813 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2814 TheAISContext()->AddFilter(F1);
2817 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2818 TheAISContext()->AddFilter(TF);
2819 TheAISContext()->ActivateStandardMode(TheType);
2824 // step 2 : wait for the selection...
2825 Standard_Boolean NoShape (Standard_True);
2826 Standard_Integer NbPick(0);
2827 Standard_Integer argccc = 5;
2828 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2829 const char **argvvv = (const char **) bufff;
2832 while(NoShape && NbPick<= MaxPick){
2833 while(ViewerMainLoop(argccc,argvvv)){}
2834 NoShape = (TheAISContext()->NbSelected()==0) ;
2836 cout<<"Nb Pick :"<<NbPick<<endl;
2839 // step3 get result.
2843 TheAISContext()->InitSelected();
2844 if(TheAISContext()->HasSelectedShape())
2845 result = TheAISContext()->SelectedShape();
2847 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2848 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2853 TheAISContext()->CloseLocalContext(curindex);
2859 //=======================================================================
2860 //function : PickShapes
2862 //=======================================================================
2863 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2864 Handle(TopTools_HArray1OfShape)& thearr,
2865 const Standard_Integer MaxPick)
2868 Standard_Integer Taille = thearr->Length();
2870 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2872 // step 1: prepare the data
2873 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2874 if(TheType==TopAbs_SHAPE){
2875 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2876 TheAISContext()->AddFilter(F1);
2879 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2880 TheAISContext()->AddFilter(TF);
2881 TheAISContext()->ActivateStandardMode(TheType);
2885 // step 2 : wait for the selection...
2887 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2888 Standard_Integer NbPickFail(0);
2889 Standard_Integer argccc = 5;
2890 const char *bufff[] = { "A", "B", "C","D", "E" };
2891 const char **argvvv = (const char **) bufff;
2894 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2895 while(ViewerMainLoop(argccc,argvvv)){}
2896 Standard_Integer NbStored = TheAISContext()->NbSelected();
2897 if((unsigned int ) NbStored != NbPickGood)
2898 NbPickGood= NbStored;
2901 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2904 // step3 get result.
2906 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2908 Standard_Integer i(0);
2909 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2911 if(TheAISContext()->HasSelectedShape())
2912 thearr->SetValue(i,TheAISContext()->SelectedShape());
2914 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2915 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2919 TheAISContext()->CloseLocalContext(curindex);
2920 return Standard_True;
2924 //=======================================================================
2925 //function : VPickShape
2927 //=======================================================================
2928 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2930 TopoDS_Shape PickSh;
2931 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2934 theType = TopAbs_SHAPE;
2936 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2937 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2938 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2939 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2940 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2941 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2942 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2945 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2946 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2948 TCollection_AsciiString name;
2951 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2953 PickSh = ViewerTest::PickShape(theType);
2962 if(!PickSh.IsNull()){
2963 nbOfSub[Standard_Integer(theType)]++;
2965 name += nameType[Standard_Integer(theType)];
2966 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2971 // si on avait une petite methode pour voir si la shape
2972 // est deja dans la Double map, ca eviterait de creer....
2973 DBRep::Set(name.ToCString(),PickSh);
2975 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2976 GetMapOfAIS().Bind(newsh, name);
2977 TheAISContext()->Display(newsh);
2978 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2981 // Plusieurs objets a picker, vite vite vite....
2984 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2985 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2986 if(ViewerTest::PickShapes(theType,arr)){
2987 for(Standard_Integer i=1;i<=NbToPick;i++){
2988 PickSh = arr->Value(i);
2989 if(!PickSh.IsNull()){
2991 nbOfSub[Standard_Integer(theType)]++;
2994 name += nameType[Standard_Integer(theType)];
2995 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3003 DBRep::Set(name.ToCString(),PickSh);
3004 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3005 GetMapOfAIS().Bind(newsh, name);
3006 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3007 TheAISContext()->Display(newsh);
3017 //=======================================================================
3018 //function : VPickObject
3019 //purpose : filters can be set (type of Object to pick....
3021 //=======================================================================
3024 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
3026 // preparation de la nomination automatique
3027 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
3028 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
3030 /* TCollection_AsciiString name;
3032 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3034 PickSh = ViewerTest::PickObject(theType);
3043 if(!PickSh.IsNull()){
3044 nbOfSub[Standard_Integer(theType)]++;
3046 name += nameType[Standard_Integer(theType)];
3047 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3052 // si on avait une petite methode pour voir si la shape
3053 // est deja dans la Double map, ca eviterait de creer....
3054 DBRep::Set(name.ToCString(),PickSh);
3056 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3057 GetMapOfAIS().Bind(newsh, name);
3058 TheAISContext()->Display(newsh);
3059 cout<<"Nom de la shape pickee : "<<name<<endl;
3062 // Plusieurs objets a picker, vite vite vite....
3065 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3066 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3067 if(ViewerTest::PickShapes(theType,arr)){
3068 for(Standard_Integer i=1;i<=NbToPick;i++){
3069 PickSh = arr->Value(i);
3070 if(!PickSh.IsNull()){
3072 nbOfSub[Standard_Integer(theType)]++;
3075 name += nameType[Standard_Integer(theType)];
3076 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3084 DBRep::Set(name.ToCString(),PickSh);
3085 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3086 GetMapOfAIS().Bind(newsh, name);
3087 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
3088 TheAISContext()->Display(newsh);
3098 //=======================================================================
3099 //function : list of known objects
3101 //=======================================================================
3102 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3104 // 1234567890 12345678901234567 123456789
3105 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3106 TCollection_AsciiString BlankLine(64,'_');
3107 Standard_Integer i ;
3109 di<<"/n"<<BlankLine.ToCString()<<"\n";
3112 Colum[i].Center(20,' ');
3114 di<<"|"<<Colum[i].ToCString();
3117 di<<BlankLine.ToCString()<<"\n";
3119 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3120 const char ** names = GetTypeNames();
3122 TCollection_AsciiString curstring;
3123 TCollection_AsciiString curcolum[3];
3126 // les objets de type Datum..
3127 curcolum[1]+="Datum";
3129 curcolum[0].Clear();
3130 curcolum[0] += names[i];
3132 curcolum[2].Clear();
3133 curcolum[2]+=TCollection_AsciiString(i+1);
3135 for(Standard_Integer j =0;j<=2;j++){
3136 curcolum[j].Center(20,' ');
3137 di<<"|"<<curcolum[j].ToCString();
3141 di<<BlankLine.ToCString()<<"\n";
3143 // les objets de type shape
3144 curcolum[1].Clear();
3145 curcolum[1]+="Shape";
3146 curcolum[1].Center(20,' ');
3149 curcolum[0].Clear();
3150 curcolum[0] += names[7+i];
3151 curcolum[2].Clear();
3152 curcolum[2]+=TCollection_AsciiString(i);
3154 for(Standard_Integer j =0;j<=2;j++){
3155 curcolum[j].Center(20,' ');
3156 di<<"|"<<curcolum[j].ToCString();
3160 di<<BlankLine.ToCString()<<"\n";
3161 // les IO de type objet...
3162 curcolum[1].Clear();
3163 curcolum[1]+="Object";
3164 curcolum[1].Center(20,' ');
3166 curcolum[0].Clear();
3167 curcolum[0] += names[10+i];
3168 curcolum[2].Clear();
3169 curcolum[2]+=TCollection_AsciiString(i);
3171 for(Standard_Integer j =0;j<=2;j++){
3172 curcolum[j].Center(20,' ');
3173 di<<"|"<<curcolum[j].ToCString();
3177 di<<BlankLine.ToCString()<<"\n";
3178 // les contraintes et dimensions.
3179 // pour l'instant on separe juste contraintes et dimensions...
3180 // plus tard, on detaillera toutes les sortes...
3181 curcolum[1].Clear();
3182 curcolum[1]+="Relation";
3183 curcolum[1].Center(20,' ');
3185 curcolum[0].Clear();
3186 curcolum[0] += names[12+i];
3187 curcolum[2].Clear();
3188 curcolum[2]+=TCollection_AsciiString(i);
3190 for(Standard_Integer j =0;j<=2;j++){
3191 curcolum[j].Center(20,' ');
3192 di<<"|"<<curcolum[j].ToCString();
3196 di<<BlankLine.ToCString()<<"\n";
3203 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3205 if(argc!=2) return 1;
3207 AIS_KindOfInteractive TheType;
3208 Standard_Integer TheSign(-1);
3209 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3212 AIS_ListOfInteractive LIO;
3214 // en attendant l'amelioration ais pour les dimensions...
3216 Standard_Integer dimension_status(-1);
3217 if(TheType==AIS_KOI_Relation){
3218 dimension_status = TheSign ==1 ? 1 : 0;
3222 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3223 Handle(AIS_InteractiveObject) curio;
3224 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3227 if(dimension_status == -1)
3228 TheAISContext()->Erase(curio,Standard_False);
3230 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3231 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3232 (dimension_status==1 && KOD != AIS_KOD_NONE))
3233 TheAISContext()->Erase(curio,Standard_False);
3236 TheAISContext()->UpdateCurrentViewer();
3239 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3241 if(argc!=2) return 1;
3243 AIS_KindOfInteractive TheType;
3244 Standard_Integer TheSign(-1);
3245 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3247 // en attendant l'amelioration ais pour les dimensions...
3249 Standard_Integer dimension_status(-1);
3250 if(TheType==AIS_KOI_Relation){
3251 dimension_status = TheSign ==1 ? 1 : 0;
3255 AIS_ListOfInteractive LIO;
3256 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3257 Handle(AIS_InteractiveObject) curio;
3258 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3260 if(dimension_status == -1)
3261 TheAISContext()->Display(curio,Standard_False);
3263 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3264 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3265 (dimension_status==1 && KOD != AIS_KOD_NONE))
3266 TheAISContext()->Display(curio,Standard_False);
3271 TheAISContext()->UpdateCurrentViewer();
3275 //==============================================================================
3276 //function : VSetTransMode
3278 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3279 //==============================================================================
3281 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3282 // Verification des arguments
3283 if ( a3DView().IsNull() ) {
3284 ViewerTest::ViewerInit();
3285 di << "La commande vinit n'a pas ete appele avant" << "\n";
3288 if ( argc < 3 || argc > 8 ) {
3289 di << argv[0] << " Invalid number of arguments" << "\n";
3293 TCollection_AsciiString shapeName;
3294 shapeName = argv[1];
3295 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
3296 Standard_Integer persFlag2 = 0;
3297 Standard_Integer persFlag3 = 0;
3298 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3299 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3300 persFlag2 = Draw::Atoi(argv[3]);
3302 if ( argc == 5 || argc == 8 ) {
3303 persFlag3 = Draw::Atoi(argv[4]);
3306 origin.SetX( Draw::Atof(argv[argc - 3]) );
3307 origin.SetY( Draw::Atof(argv[argc - 2]) );
3308 origin.SetZ( Draw::Atof(argv[argc - 1]) );
3311 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3312 Handle(Standard_Transient) anObj;
3314 anObj = GetMapOfAIS().Find2(shapeName);
3315 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3316 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3317 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3318 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3319 di << argv[0] << " All persistence modifiers were removed" << "\n";
3322 di << argv[0] << " Wrong object type" << "\n";
3325 } else { // Create the AIS_Shape from a name
3326 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3327 if ( !aShape.IsNull() ) {
3328 GetMapOfAIS().Bind( aShape, shapeName );
3329 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3330 TheAISContext()->Display( aShape, Standard_False );
3332 di << argv[0] << " Object not found" << "\n";
3337 // Upadate the screen and redraw the view
3338 TheAISContext()->UpdateCurrentViewer();
3342 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3345 BRep_Builder builder;
3347 BRepTools::Read(shape, s, builder);
3348 DBRep::Set(a[1], shape);
3349 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3350 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3354 //============================================================================
3355 #include <HLRAlgo_Projector.hxx>
3356 #include <Prs3d_Projector.hxx>
3358 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3361 /*Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3362 /////////////////////
3363 TopoDS_Shape aShape = DBRep::Get(a[1]);
3364 aContext2D->EraseAll(Standard_True);
3365 //Standard_Integer aPolyAlgo = 0;
3366 Standard_Boolean IsPoly = Standard_False;
3367 gp_Ax2 anAx2 = gp::XOY();
3369 //if(n > 2) aPolyAlgo = Draw::Atoi(a[2]);
3371 //IsPoly = aPolyAlgo > 0;
3373 TopoDS_Shape aResult = aShape;
3378 Standard_Real x = Draw::Atof(a[2]);
3379 Standard_Real y = Draw::Atof(a[3]);
3380 Standard_Real z = Draw::Atof(a[4]);
3382 Standard_Real dx = Draw::Atof(a[5]);
3383 Standard_Real dy = Draw::Atof(a[6]);
3384 Standard_Real dz = Draw::Atof(a[7]);
3386 Standard_Real dx1 = Draw::Atof(a[8]);
3387 Standard_Real dy1 = Draw::Atof(a[9]);
3388 Standard_Real dz1 = Draw::Atof(a[10]);
3390 gp_Pnt anOrigin (x, y, z);
3391 gp_Dir aNormal (dx, dy, dz);
3392 gp_Dir aDX (dx1, dy1, dz1);
3393 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3397 HLRAlgo_Projector aProjector(anAx2);
3399 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3401 //aProjector = aProjector_t.Projector();
3403 Handle(AIS2D_ProjShape) myDisplayableShape =
3404 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3406 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3407 Standard_False, Standard_True, Standard_False);
3409 myDisplayableShape->Add( aResult );
3412 aContext2D->Display( myDisplayableShape,Standard_True );
3413 aContext2D->UpdateCurrentViewer();*/
3418 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3421 /*Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3422 /////////////////////
3423 TopoDS_Shape aShape = DBRep::Get(a[1]);
3424 aContext2D->EraseAll(Standard_True);
3425 //Standard_Integer aPolyAlgo = 0;
3426 Standard_Boolean IsPoly = Standard_True;
3427 gp_Ax2 anAx2 = gp::XOY();
3429 //if(n > 2) aPolyAlgo = Draw::Atoi(a[2]);
3431 //IsPoly = aPolyAlgo > 0;
3433 TopoDS_Shape aResult = aShape;
3438 Standard_Real x = Draw::Atof(a[2]);
3439 Standard_Real y = Draw::Atof(a[3]);
3440 Standard_Real z = Draw::Atof(a[4]);
3442 Standard_Real dx = Draw::Atof(a[5]);
3443 Standard_Real dy = Draw::Atof(a[6]);
3444 Standard_Real dz = Draw::Atof(a[7]);
3446 Standard_Real dx1 = Draw::Atof(a[8]);
3447 Standard_Real dy1 = Draw::Atof(a[9]);
3448 Standard_Real dz1 = Draw::Atof(a[10]);
3450 gp_Pnt anOrigin (x, y, z);
3451 gp_Dir aNormal (dx, dy, dz);
3452 gp_Dir aDX (dx1, dy1, dz1);
3453 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3457 HLRAlgo_Projector aProjector(anAx2);
3459 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3461 //aProjector = aProjector_t.Projector();
3463 Handle(AIS2D_ProjShape) myDisplayableShape =
3464 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3466 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3467 Standard_False, Standard_True, Standard_False);
3469 myDisplayableShape->Add( aResult );
3472 aContext2D->Display( myDisplayableShape,Standard_True );
3473 aContext2D->UpdateCurrentViewer();*/
3478 //==============================================================================
3479 //function : ViewerTest::Commands
3480 //purpose : Add all the viewer command in the Draw_Interpretor
3481 //==============================================================================
3483 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3485 ViewerTest::ViewerCommands(theCommands);
3486 ViewerTest::RelationCommands(theCommands);
3487 ViewerTest::ObjectCommands(theCommands);
3488 ViewerTest::FilletCommands(theCommands);
3489 ViewerTest::VoxelCommands(theCommands);
3490 ViewerTest::OpenGlCommands(theCommands);
3492 const char *group = "AIS_Display";
3495 theCommands.Add("visos",
3496 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3497 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3498 __FILE__, visos, group);
3500 theCommands.Add("vdisplay",
3501 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3502 __FILE__,VDisplay2,group);
3504 theCommands.Add("verase",
3505 "verase : verase2 [name1] ... [name n] ",
3506 __FILE__,VErase2,group);
3508 theCommands.Add("vdonly",
3509 "vdonly : vdonly2 [name1] ... [name n]",
3510 __FILE__,VDonly2,group);
3512 theCommands.Add("vdisplayall",
3513 "vdisplayall : vdisplayall",
3514 __FILE__,VDisplayAll,group);
3516 theCommands.Add("veraseall",
3517 "veraseall : veraseall ",
3518 __FILE__,VEraseAll,group);
3520 theCommands.Add("verasetype",
3521 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3522 __FILE__,VEraseType,group);
3524 theCommands.Add("vdisplaytype",
3525 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3526 __FILE__,VDisplayType,group);
3528 theCommands.Add("vdisplaymode",
3529 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3530 __FILE__,VDispMode,group);
3532 theCommands.Add("verasemode",
3533 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3534 __FILE__,VDispMode,group);
3536 theCommands.Add("vsetdispmode",
3537 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3538 __FILE__,VDispMode,group);
3540 theCommands.Add("vunsetdispmode",
3541 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3542 __FILE__,VDispMode,group);
3544 theCommands.Add("vdir",
3546 __FILE__,VDebug,group);
3548 theCommands.Add("vdump",
3549 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n\t\t: Dump contents of viewer window to PNG, BMP, JPEG or GIF file",
3550 __FILE__,VDump,group);
3552 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3553 __FILE__,VSubInt,group);
3555 theCommands.Add("vsetcolor",
3556 "vsetcolor : vsetcolor [name of shape] ColorName",
3557 __FILE__,VColor2,group);
3559 theCommands.Add("vunsetcolor",
3560 "vunsetcolor : vunsetcolor [name of shape] ",
3561 __FILE__,VColor2,group);
3563 theCommands.Add("vsettransparency",
3564 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3565 __FILE__,VTransparency,group);
3567 theCommands.Add("vunsettransparency",
3568 "vunsettransparency : vtransparency [name of shape]",
3569 __FILE__,VTransparency,group);
3571 theCommands.Add("vsetmaterial",
3572 "vmaterial : vmaterial [name of shape] MaterialName",
3573 __FILE__,VMaterial,group);
3575 theCommands.Add("vunsetmaterial",
3576 "vmaterial : vmaterial [name of shape]",
3577 __FILE__,VMaterial,group);
3579 theCommands.Add("vsetwidth",
3580 "vsetwidth : vwidth [name of shape] width(0->10)",
3581 __FILE__,VWidth,group);
3583 theCommands.Add("vunsetwidth",
3584 "vunsetwidth : vwidth [name of shape]",
3585 __FILE__,VWidth,group);
3587 theCommands.Add("vsetinteriorstyle",
3588 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3589 __FILE__,VInteriorStyle,group);
3591 theCommands.Add("vardis",
3592 "vardis : display activeareas",
3593 __FILE__,VDispAreas,group);
3595 theCommands.Add("varera",
3596 "varera : erase activeareas",
3597 __FILE__,VClearAreas,group);
3599 theCommands.Add("vsensdis",
3600 "vardisp : display active entities",
3601 __FILE__,VDispSensi,group);
3602 theCommands.Add("vsensera",
3603 "vardisp : erase active entities",
3604 __FILE__,VClearSensi,group);
3606 theCommands.Add("vselprecision",
3607 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3608 __FILE__,VSelPrecision,group);
3610 theCommands.Add("vperf",
3611 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3612 __FILE__,VPerf,group);
3614 theCommands.Add("vanimation",
3615 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3616 __FILE__,VAnimation,group);
3618 theCommands.Add("vsetshading",
3619 "vsetshading : vsetshading name Quality(default=0.0008) ",
3620 __FILE__,VShading,group);
3622 theCommands.Add("vunsetshading",
3623 "vunsetshading :vunsetshading name ",
3624 __FILE__,VShading,group);
3626 theCommands.Add("vtexture",
3627 "'vtexture NameOfShape TextureFile' \n \
3628 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3629 or 'vtexture NameOfShape ?' to list available textures\n \
3630 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3631 __FILE__,VTexture,group);
3633 theCommands.Add("vtexscale",
3634 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3635 or 'vtexscale NameOfShape ScaleUV' \n \
3636 or 'vtexscale NameOfShape' to disable scaling\n ",
3637 __FILE__,VTexture,group);
3639 theCommands.Add("vtexorigin",
3640 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3641 or 'vtexorigin NameOfShape UVOrigin' \n \
3642 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3643 __FILE__,VTexture,group);
3645 theCommands.Add("vtexrepeat",
3646 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3647 or 'vtexrepeat NameOfShape UVRepeat \n \
3648 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3651 theCommands.Add("vtexdefault",
3652 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3655 theCommands.Add("vsetam",
3656 "vsetActivatedModes: vsetam mode(1->7) ",
3657 __FILE__,VActivatedMode,group);
3659 theCommands.Add("vunsetam",
3660 "vunsetActivatedModes: vunsetam ",
3661 __FILE__,VActivatedMode,group);
3663 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3664 __FILE__,VState,group);
3666 theCommands.Add("vpickshapes",
3667 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3668 __FILE__,VPickShape,group);
3670 theCommands.Add("vtypes",
3671 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3674 theCommands.Add("vsettransmode",
3675 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3676 __FILE__,VSetTransMode,group);
3678 theCommands.Add("vr", "vr : reading of the shape",
3679 __FILE__,vr, group);
3681 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3682 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3686 //=====================================================================
3687 //========================= for testing Draft and Rib =================
3688 //=====================================================================
3689 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3690 #include <DBRep.hxx>
3691 #include <TopoDS_Face.hxx>
3692 #include <gp_Pln.hxx>
3693 #include <AIS_KindOfSurface.hxx>
3694 #include <BRepOffsetAPI_DraftAngle.hxx>
3695 #include <Precision.hxx>
3696 #include <BRepAlgo.hxx>
3697 #include <OSD_Environment.hxx>
3698 #include <DrawTrSurf.hxx>
3699 //#include <DbgTools.hxx>
3700 //#include <FeatAlgo_MakeLinearForm.hxx>
3705 //=======================================================================
3706 //function : IsValid
3708 //=======================================================================
3709 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3710 const TopoDS_Shape& theResult,
3711 const Standard_Boolean closedSolid,
3712 const Standard_Boolean GeomCtrl)
3714 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3715 TCollection_AsciiString checkValid = check.Value();
3716 Standard_Boolean ToCheck = Standard_True;
3717 if (!checkValid.IsEmpty()) {
3719 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3721 if ( checkValid=="true" || checkValid=="TRUE" ) {
3722 ToCheck= Standard_False;
3726 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3729 Standard_Boolean IsValid = Standard_True;
3731 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3736 //===============================================================================
3737 // TDraft : test draft, uses AIS Viewer
3738 // Solid Face Plane Angle Reverse
3739 //===============================================================================
3740 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3742 if (argc < 5) return 1;
3743 // argv[1] - TopoDS_Shape Solid
3744 // argv[2] - TopoDS_Shape Face
3745 // argv[3] - TopoDS_Shape Plane
3746 // argv[4] - Standard_Real Angle
3747 // argv[5] - Standard_Integer Reverse
3749 // Sprintf(prefix, argv[1]);
3750 Standard_Real anAngle = 0;
3751 Standard_Boolean Rev = Standard_False;
3752 Standard_Integer rev = 0;
3753 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3754 TopoDS_Shape face = GetShapeFromName(argv[2]);
3755 TopoDS_Face Face = TopoDS::Face(face);
3756 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3757 if (Plane.IsNull ()) {
3758 di << "TEST : Plane is NULL" << "\n";
3761 anAngle = Draw::Atof(argv[4]);
3762 anAngle = 2*M_PI * anAngle / 360.0;
3764 Handle( Geom_Surface )aSurf;
3765 AIS_KindOfSurface aSurfType;
3766 Standard_Real Offset;
3768 if(argc > 4) { // == 5
3769 rev = Draw::Atoi(argv[5]);
3770 Rev = (rev)? Standard_True : Standard_False;
3773 TopoDS_Face face2 = TopoDS::Face(Plane);
3774 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3776 di << "TEST : Can't find plane" << "\n";
3780 aDir = aPln.Axis().Direction();
3783 if (Plane.Orientation() == TopAbs_REVERSED)
3785 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3787 BRepOffsetAPI_DraftAngle Draft (Solid);
3789 if(Abs(anAngle)< Precision::Angular()) {
3790 di << "TEST : NULL angle" << "\n";
3793 if(Rev) anAngle = - anAngle;
3794 Draft.Add (Face, aDir, anAngle, aPln);
3796 if (!Draft.IsDone()) {
3797 di << "TEST : Draft Not DONE " << "\n";
3800 TopTools_ListOfShape Larg;
3802 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3803 di << "TEST : DesignAlgo returns Not valid" << "\n";
3807 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3808 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3810 if ( !ais.IsNull() ) {
3811 ais->SetColor(DEFAULT_COLOR);
3812 ais->SetMaterial(DEFAULT_MATERIAL);
3813 // Display the AIS_Shape without redraw
3814 Ctx->Display(ais, Standard_False);
3816 const char *Name = "draft1";
3817 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3819 Handle(AIS_InteractiveObject) an_object =
3820 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3821 if (!an_object.IsNull()) {
3822 Ctx->Remove(an_object,
3824 GetMapOfAIS().UnBind2(Name) ;
3827 GetMapOfAIS().Bind(ais, Name);
3828 // DBRep::Set("draft", ais->Shape());
3830 Ctx->Display(ais, Standard_True);
3836 //============================================================================
3838 //============================================================================
3839 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3842 DrawTrSurf::BasicCommands(theCommands);
3843 const char* group = "Check Features Operations commands";
3845 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3847 &TDraft,group); //Draft_Modification
3850 //==============================================================================
3851 // ViewerTest::Factory
3852 //==============================================================================
3853 void ViewerTest::Factory(Draw_Interpretor& theDI)
3855 // definition of Viewer Command
3856 ViewerTest::Commands(theDI);
3857 ViewerTest::AviCommands(theDI);
3860 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3864 // Declare entry point PLUGINFACTORY