0022776: XCAFPrs_AISObject does not support transparency
[occt.git] / src / ViewerTest / ViewerTest.cxx
CommitLineData
7fd59977 1// File: ViewerTest.cxx
2// Created: Wed Jul 23 14:14:01 1997
3// Author: Henri JEANNIN
7fd59977 4// Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
5//
6// Modified by Robert Coublanc [nov 16-17-18 1998]
7// -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
8// ViewerTest_ObjectCommands.cxx
9// ViewerTest_RelationCommands.cxx
10// -add Functions and commands for interactive selection of shapes and objects
11// in AIS Viewers. (PickShape(s), PickObject(s),
12
13#include <Standard_Stream.hxx>
14
15#include <ViewerTest.hxx>
16#include <TopLoc_Location.hxx>
17#include <TopTools_HArray1OfShape.hxx>
18#include <TColStd_HArray1OfTransient.hxx>
19#include <OSD_Directory.hxx>
20#include <OSD_File.hxx>
21#include <OSD_Path.hxx>
22#include <OSD_Timer.hxx>
23#include <Geom_Axis2Placement.hxx>
24#include <Geom_Axis1Placement.hxx>
25#include <gp_Trsf.hxx>
26#include <TopExp_Explorer.hxx>
27#include <BRepAdaptor_Curve.hxx>
28#include <StdSelect_ShapeTypeFilter.hxx>
29#include <AIS.hxx>
30#include <AIS_InteractiveObject.hxx>
31#include <AIS_Trihedron.hxx>
32#include <AIS_Axis.hxx>
33#include <AIS_Relation.hxx>
34#include <AIS_TypeFilter.hxx>
35#include <AIS_SignatureFilter.hxx>
36#include <AIS_ListOfInteractive.hxx>
37#include <AIS_ListIteratorOfListOfInteractive.hxx>
38#include <Image_PixMap.hxx>
39
40#ifdef HAVE_CONFIG_H
41# include <config.h>
42#endif
43#include <stdio.h>
44#ifdef HAVE_STRINGS_H
45# include <strings.h>
46#endif
47
48#include <Draw_Interpretor.hxx>
49#include <TCollection_AsciiString.hxx>
50#include <Draw_PluginMacro.hxx>
51#include <ViewerTest.hxx>
52#include <Viewer2dTest.hxx>
53
54// avoid warnings on 'extern "C"' functions returning C++ classes
55#ifdef WNT
56#define _CRT_SECURE_NO_DEPRECATE
57#pragma warning(4:4190)
58#pragma warning (disable:4996)
59#endif
60
61#include <NIS_InteractiveContext.hxx>
62#include <NIS_Triangulated.hxx>
63extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
64
65//=======================================================================
66//function : GetColorFromName
67//purpose : get the Quantity_NameOfColor from a string
68//=======================================================================
69
70#include <Quantity_NameOfColor.hxx>
71#include <Quantity_Color.hxx>
72#include <Quantity_NameOfColor.hxx>
73
74#include <Graphic3d_NameOfMaterial.hxx>
75
76#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
77#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
78
79static Quantity_NameOfColor GetColorFromName( const char *name )
80{
81 Quantity_NameOfColor ret = DEFAULT_COLOR;
82
83 Standard_Boolean Found = Standard_False;
84 Standard_CString colstring;
85 for(Standard_Integer i=0;i<=514 && !Found;i++)
86 {
87 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
88 if (!strcasecmp(name,colstring)) {
89 ret = (Quantity_NameOfColor)i;
90 Found = Standard_True;
91 }
92 }
93
94 return ret;
95}
96
97//=======================================================================
98//function : GetMaterialFromName
99//purpose : get the Graphic3d_NameOfMaterial from a string
100//=======================================================================
101
102static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
103{
104 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
105
106 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
107 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
108 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
109 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
110 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
111 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
112 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
113 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
114 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
115 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
116 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
117 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
118 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
119 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
120 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
121 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
122 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
123 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
124 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
125 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
126
127 return mat;
128}
129
130//=======================================================================
131//function : GetTypeNames
132//purpose :
133//=======================================================================
134static const char** GetTypeNames()
135{
136 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
137 "Shape","ConnectedShape","MultiConn.Shape",
138 "ConnectedInter.","MultiConn.",
139 "Constraint","Dimension"};
140 static const char** ThePointer = names;
141 return ThePointer;
142}
143
144//=======================================================================
145//function : GetTypeAndSignfromString
146//purpose :
147//=======================================================================
148void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
149{
150 const char ** thefullnames = GetTypeNames();
151 Standard_Integer index(-1);
152
153 for(Standard_Integer i=0;i<=13 && index==-1;i++)
154 if(!strcasecmp(name,thefullnames[i]))
155 index = i;
156
157 if(index ==-1){
158 TheType = AIS_KOI_None;
159 TheSign = -1;
160 return;
161 }
162
163 if(index<=6){
164 TheType = AIS_KOI_Datum;
165 TheSign = index+1;
166 }
167 else if (index <=9){
168 TheType = AIS_KOI_Shape;
169 TheSign = index-7;
170 }
171 else if(index<=11){
172 TheType = AIS_KOI_Object;
173 TheSign = index-10;
174 }
175 else{
176 TheType = AIS_KOI_Relation;
177 TheSign = index-12;
178 }
179
180}
181
182
183
184#include <string.h>
185#include <Draw_Interpretor.hxx>
186#include <Draw.hxx>
187#include <Draw_Appli.hxx>
188#include <DBRep.hxx>
189
190
191#include <TCollection_AsciiString.hxx>
192#include <V3d_Viewer.hxx>
193#include <V3d_View.hxx>
194#include <V3d.hxx>
195
196#include <AIS_InteractiveContext.hxx>
197#include <AIS_Shape.hxx>
198#include <AIS_TexturedShape.hxx>
199#include <AIS_DisplayMode.hxx>
200#include <TColStd_MapOfInteger.hxx>
201#include <AIS_MapOfInteractive.hxx>
202#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
203#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
204#include <ViewerTest_EventManager.hxx>
205
206#include <TopoDS_Solid.hxx>
207#include <BRepTools.hxx>
208#include <BRep_Builder.hxx>
209#include <TopAbs_ShapeEnum.hxx>
210
211#include <TopoDS.hxx>
212#include <BRep_Tool.hxx>
213
214
215#include <Draw_Window.hxx>
216#include <AIS_ListIteratorOfListOfInteractive.hxx>
217#include <AIS_ListOfInteractive.hxx>
218#include <AIS_DisplayMode.hxx>
219#include <TopTools_ListOfShape.hxx>
220#include <BRepOffsetAPI_MakeThickSolid.hxx>
221#include <BRepOffset.hxx>
222
223
224//==============================================================================
225//function : GetTypeNameFromShape
226//purpose : get the shape type as a string from a shape
227//==============================================================================
228
229static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
230{ const char *ret = "????";
231
232 if ( aShape.IsNull() ) ret = "Null Shape";
233
234 switch ( aShape.ShapeType() ) {
235 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
236 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
237 case TopAbs_SOLID : ret = "SOLID" ; break;
238 case TopAbs_SHELL : ret = "SHELL" ; break;
239 case TopAbs_FACE : ret = "FACE" ; break;
240 case TopAbs_WIRE : ret = "WIRE" ; break;
241 case TopAbs_EDGE : ret = "EDGE" ; break;
242 case TopAbs_VERTEX : ret = "VERTEX" ; break;
243 case TopAbs_SHAPE : ret = "SHAPE" ; break;
244 }
245 return ret;
246}
247//==============================================================================
248// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
249//==============================================================================
250Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
251 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
252 return TheMap;
253}
254
9558a876
A
255
256//==============================================================================
257//function : VDisplayAISObject
258//purpose : register interactive object in the map of AIS objects;
259// if other object with such name already registered, it will be kept
260// or replaced depending on value of <theReplaceIfExists>,
261// if "true" - the old object will be cleared from AIS context;
262// returns Standard_True if <theAISObj> registered in map;
263//==============================================================================
264Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
265 const Handle(AIS_InteractiveObject)& theAISObj,
266 Standard_Boolean theReplaceIfExists = Standard_True)
267{
268 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
269 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
270 if (aContextAIS.IsNull())
271 {
272 std::cout << "AIS context is not available.\n";
273 return Standard_False;
274 }
275
276 if (aMap.IsBound2 (theName))
277 {
278 if (!theReplaceIfExists)
279 {
280 std::cout << "Other interactive object has been already "
281 << "registered with name: " << theName << ".\n"
282 << "Please use another name.\n";
283 return Standard_False;
284 }
285
286 // stop displaying object
287 Handle(AIS_InteractiveObject) anOldObj =
288 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
289
290 if (!anOldObj.IsNull())
291 aContextAIS->Clear (anOldObj, Standard_True);
292
293 // remove name and old object from map
294 aMap.UnBind2 (theName);
295 }
296
297 // unbind AIS object if was bound with another name
298 aMap.UnBind1 (theAISObj);
299
300 // can be registered without rebinding
301 aMap.Bind (theAISObj, theName);
302 aContextAIS->Display (theAISObj, Standard_True);
303 return Standard_True;
304}
305
7fd59977 306static TColStd_MapOfInteger theactivatedmodes(8);
307static TColStd_ListOfTransient theEventMgrs;
308
309static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
310 const Handle(AIS_InteractiveContext)& Ctx)
311{
312 theEventMgrs.Clear();
313 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
314}
315
316static Handle(V3d_View)& a3DView(){
317 static Handle(V3d_View) Viou;
318 return Viou;
319}
320
321Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
322 static Handle(AIS_InteractiveContext) aContext;
323 return aContext;
324}
325
326Handle(V3d_View) ViewerTest::CurrentView()
327{
328 return a3DView();
329}
330void ViewerTest::CurrentView(const Handle(V3d_View)& V)
331{
332 a3DView() = V;
333}
334
335Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
336{
337 static Handle(NIS_InteractiveContext) aContext;
338 if (aContext.IsNull()) {
339 aContext = new NIS_InteractiveContext;
340 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
341 }
342 return aContext;
343}
344
345Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
346{
347 return TheAISContext();
348}
349
350void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
351{
352 TheAISContext() = aCtx;
353 ViewerTest::ResetEventManager();
354}
355
356Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
357{
4952a30a 358 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 359}
360
361Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
362{
4952a30a 363 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 364}
365
366
367void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
368 theEventMgrs.Prepend(EM);
369}
370
371void ViewerTest::UnsetEventManager()
372{
373 theEventMgrs.RemoveFirst();
374}
375
376
377void ViewerTest::ResetEventManager()
378{
379 const Handle(NIS_View) aView =
380 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
381 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
382}
383
384Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
385{
386 Handle(ViewerTest_EventManager) EM;
387 if(theEventMgrs.IsEmpty()) return EM;
388 Handle(Standard_Transient) Tr = theEventMgrs.First();
389 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
390 return EM;
391}
392
393
394//=======================================================================
395//function : Get Context and active viou..
396//purpose :
397//=======================================================================
398void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
399 Handle(V3d_View)& Viou)
400{
401 Ctx = ViewerTest::GetAISContext();
402 if (!Ctx.IsNull())
403 {
404 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
405 Vwr->InitActiveViews();
406 if(Vwr->MoreActiveViews())
407 Viou = Vwr->ActiveView();
408 }
409}
410
411
412//==============================================================================
413//function : GetShapeFromName
414//purpose : Compute an Shape from a draw variable or a file name
415//==============================================================================
416
417static TopoDS_Shape GetShapeFromName(const char* name)
418{
419 TopoDS_Shape S = DBRep::Get(name);
420
421 if ( S.IsNull() ) {
422 BRep_Builder aBuilder;
423 BRepTools::Read( S, name, aBuilder);
424 }
425
426 return S;
427}
428//==============================================================================
429//function : GetShapeFromName
430//purpose : Compute an Shape from a draw variable or a file name
431//==============================================================================
432// Unused :
433#ifdef DEB
434static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
435{
436 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
437 return TheShape;
438}
439#endif
440//==============================================================================
441//function : GetAISShapeFromName
442//purpose : Compute an AIS_Shape from a draw variable or a file name
443//==============================================================================
444Handle(AIS_Shape) GetAISShapeFromName(const char* name)
445{
446 Handle(AIS_Shape) retsh;
447
448 if(GetMapOfAIS().IsBound2(name)){
449 const Handle(AIS_InteractiveObject) IO =
450 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
451 if (!IO.IsNull()) {
452 if(IO->Type()==AIS_KOI_Shape)
453 if(IO->Signature()==0){
454 retsh = *((Handle(AIS_Shape)*)&IO);
455 }
456 else
457 cout << "an Object which is not an AIS_Shape "
458 "already has this name!!!"<<endl;
459 }
460 return retsh;
461 }
462
463
464 TopoDS_Shape S = GetShapeFromName(name);
465 if ( !S.IsNull() ) {
466 retsh = new AIS_Shape(S);
467 }
468 return retsh;
469}
470
471
472//==============================================================================
473//function : Clear
474//purpose : Remove all the object from the viewer
475//==============================================================================
476void ViewerTest::Clear()
477{
478 if ( !a3DView().IsNull() ) {
479 if (TheAISContext()->HasOpenedContext())
480 TheAISContext()->CloseLocalContext();
481 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
482 while ( it.More() ) {
483 cout << "Remove " << it.Key2() << endl;
484 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
485 const Handle(AIS_InteractiveObject) anObj =
486 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
487 TheAISContext()->Remove(anObj,Standard_False);
488 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
489 const Handle(NIS_InteractiveObject) anObj =
490 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
ffe2bea7 491 TheNISContext()->Remove(anObj);
7fd59977 492 }
493 it.Next();
494 }
495 TheAISContext()->UpdateCurrentViewer();
ffe2bea7 496// TheNISContext()->UpdateViews();
7fd59977 497 GetMapOfAIS().Clear();
498 }
499}
500
501//==============================================================================
502//function : StandardModesActivation
503//purpose : Activate a selection mode, vertex, edge, wire ..., in a local
504// Context
505//==============================================================================
506void ViewerTest::StandardModeActivation(const Standard_Integer mode )
507{
508 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
509 if(mode==0) {
510 if (TheAISContext()->HasOpenedContext())
511 aContext->CloseLocalContext();
512 } else {
513
514 if(!aContext->HasOpenedContext()) {
515 // To unhilight the preselected object
516 aContext->UnhilightCurrents(Standard_False);
517 // Open a local Context in order to be able to select subshape from
518 // the selected shape if any or for all if there is no selection
519 if (!aContext->FirstCurrentObject().IsNull()){
520 aContext->OpenLocalContext(Standard_False);
521
522 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
523 aContext->Load( aContext->Current(),-1,Standard_True);
524 }
525 }
526 else
527 aContext->OpenLocalContext();
528 }
529
530 const char *cmode="???";
531
532 switch (mode) {
533 case 0: cmode = "Shape"; break;
534 case 1: cmode = "Vertex"; break;
535 case 2: cmode = "Edge"; break;
536 case 3: cmode = "Wire"; break;
537 case 4: cmode = "Face"; break;
538 case 5: cmode = "Shell"; break;
539 case 6: cmode = "Solid"; break;
540 case 7: cmode = "Compound"; break;
541 }
542
543 if(theactivatedmodes.Contains(mode))
544 { // Desactivate
545 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
546 theactivatedmodes.Remove(mode);
547 cout<<"Mode "<< cmode <<" OFF"<<endl;
548 }
549 else
550 { // Activate
551 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
552 theactivatedmodes.Add(mode);
553 cout<<"Mode "<< cmode << " ON" << endl;
554 }
555 }
556}
557
558//==============================================================================
559//function : SelectFromContext
560//purpose : pick / select an object from the last MoveTo() on a
561// ButtonPress event
562//==============================================================================
563
564Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
565 const char** argv,
566 Standard_Boolean shift,
567 Standard_Boolean pick )
568{
569 Handle(AIS_InteractiveObject) ret;
570 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
571 if ( shift ) {
572 EM->ShiftSelect();
573 }
574 else {
575 EM->Select();
576 }
577 const Handle(AIS_InteractiveContext) aContext = EM->Context();
578
579 if ( !aContext->HasOpenedContext() ) {
580 aContext->InitCurrent();
581 while ( aContext->MoreCurrent() ) {
582 Handle(AIS_InteractiveObject) aisPickedShape =
583 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
584
585//JR/Hp
586 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
587// const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
588 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
589 "????";
590 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
591 if(!TheRealSh.IsNull()){
592 cout << "Current is " << name
593 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
594 << ")" << endl;
595 }
596 ret = aisPickedShape;
597 if(!TheRealSh.IsNull()){
598 if ( pick && argc > 4 ) {
599 DBRep::Set(argv[4], TheRealSh->Shape());
600 }
601 }
602 aContext->NextCurrent();
603 }
604 }
605 else {
606 // A LocalContext is opened, the use xxxxSelected()
607 // to select an object and its SubShape
608 aContext->InitSelected();
609 while ( aContext->MoreSelected() ) {
610 if ( !aContext->HasSelectedShape() ) {
611 }
612 else {
613 TopoDS_Shape PickedShape = aContext->SelectedShape();
614 if ( pick && argc > 5 ) {
615 DBRep::Set(argv[5], PickedShape);
616 }
617 }
618
619 if ( aContext->Interactive().IsNull() ) {
620 cout << "??? (No InteractiveObject selected)" << endl;
621 }
622 else {
623 Handle(AIS_InteractiveObject) aisPicked =
624 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
625 ret = aisPicked;
626 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
627
628 // Get back its name
629//JR/Hp
630 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
631// const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
632 GetMapOfAIS().Find1(aisPicked).ToCString() :
633 "????";
634
635 if(!aisPickedShape.IsNull()){
636 if ( pick && argc > 4 ) {
637 // Create a draw variable to store the wohole shape
638 // for vpick command
639 DBRep::Set(argv[4], aisPickedShape->Shape());
640 }
641
642 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
643 << ")" << endl ;
644 }
645 }
646 // Goto the next selected object
647 aContext->NextSelected();
648 }
649 }
650 return ret;
651}
652
653//==============================================================================
654//function : DetectedFromContext
655//purpose : hilight dynamicaly an object from the last MoveTo() on a
656// MouseMove event
657//==============================================================================
658Handle(AIS_InteractiveObject) DetectedFromContext(
659 Handle(AIS_InteractiveContext) aContext )
660{
661 Handle(AIS_InteractiveObject) ret;
662 if ( aContext->HasDetected() ) {
663 if ( !aContext->HasDetectedShape() ) {
664 //No SubShape selected
665 }
666 else {
667 // Get the detected SubShape
668 TopoDS_Shape PickedShape = aContext->DetectedShape();
669 }
670 if ( !aContext->DetectedInteractive().IsNull() ) {
671 Handle(AIS_InteractiveObject) aisPickedShape =
672 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
673 ret = aisPickedShape;
674#ifdef DEB
675 const char *name =
676#endif
677 ( GetMapOfAIS().IsBound1(aisPickedShape) )?
678 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
679 (char *) "????";
680 }
681 }
682 return ret;
683}
684
685
686//==============================================================================
687//function : VDispAreas,VDispSensitive,...
688//purpose : Redraw the view
689//Draw arg : No args
690//==============================================================================
691static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
692{
693
694 Handle(AIS_InteractiveContext) Ctx;
695 Handle(V3d_View) Viou;
696 GetCtxAndView(Ctx,Viou);
697 Ctx->DisplayActiveAreas(Viou);
698 return 0;
699}
700static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
701{
702 Handle(AIS_InteractiveContext) Ctx;
703 Handle(V3d_View) Viou;
704 GetCtxAndView(Ctx,Viou);
705 Ctx->ClearActiveAreas(Viou);
706 return 0;
707
708}
709static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
710{
711 Handle(AIS_InteractiveContext) Ctx;
712 Handle(V3d_View) Viou;
713 GetCtxAndView(Ctx,Viou);
714 Ctx->DisplayActiveSensitive(Viou);
715 return 0;
716
717}
718static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
719{
720 Handle(AIS_InteractiveContext) Ctx;
721 Handle(V3d_View) Viou;
722 GetCtxAndView(Ctx,Viou);
723 Ctx->ClearActiveSensitive(Viou);
724 return 0;
725}
726
727//==============================================================================
728//function : VDebug
729//purpose : To list the displayed object with their attributes
730//Draw arg : No args
731//==============================================================================
732static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
733{ if ( !a3DView().IsNull() ) {
734 di << "List of object in the viewer :" << "\n";
735
736 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
737
738 while ( it.More() ) {
739 di << "\t" << it.Key2().ToCString() << "\n";
740 it.Next();
741 }
742 }
743
744 return 0;
745}
746
747//==============================================================================
748//function : VDump
749//purpose : To dump the active view snapshot to image file
750//Draw arg : Picture file name with extension corresponding to desired format
751//==============================================================================
752static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
753{
754 if (argc < 2)
755 {
756 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
757 return 1;
758 }
759
760 Image_TypeOfImage aBufferType = Image_TOI_RGB;
761
762 if (argc > 2)
763 {
764 TCollection_AsciiString aBuffTypeStr (argv[2]);
765 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
766 {
767 aBufferType = Image_TOI_RGB;
768 }
769 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
770 {
771 aBufferType = Image_TOI_RGBA;
772 }
773 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
774 {
775 aBufferType = Image_TOI_FLOAT;
776 }
777 }
778
779 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
780 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
781
782 Handle(AIS_InteractiveContext) IC;
783 Handle(V3d_View) view;
784 GetCtxAndView (IC, view);
785 if (!view.IsNull())
786 {
787 if (aWidth > 0 && aHeight > 0)
788 {
789 return view->ToPixMap (aWidth, aHeight, aBufferType)->Dump (argv[1]) ? 0 : 1;
790 }
791 else
792 {
793 return view->Dump (argv[1], aBufferType) ? 0 : 1;
794 }
795 }
796 else
797 {
798 di << "Cannot find an active viewer/view" << "\n";
799 return 1;
800 }
801}
802
803
804//==============================================================================
805//function : Displays,Erase...
806//purpose :
807//Draw arg :
808//==============================================================================
809static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
810 const Standard_Integer Mode,
811 const Standard_Integer TypeOfOperation,
812 const Standard_Boolean Upd)
813{
814 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
815
816 switch(TypeOfOperation){
817 case 1:
818 Ctx->Display(IO,Mode,Upd);
819 break;
820 case 2:{
821 Ctx->Erase(IO,Mode,Upd);
822 break;
823 }
824 case 3:{
825 if(IO.IsNull())
826 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
827 else
828 Ctx->SetDisplayMode(IO,Mode,Upd);
829 break;
830 }
831 case 4:{
832 if(IO.IsNull())
833 Ctx->SetDisplayMode(0,Upd);
834 else
835 Ctx->UnsetDisplayMode(IO,Upd);
836 break;
837 }
838 }
839 return 0;
840}
841
842//=======================================================================
843//function :
844//purpose :
845//=======================================================================
846static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
847{
848
849 TCollection_AsciiString name;
850 if(argc>3)
851 return 1;
852 // display others presentations
853 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
854 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
855 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
856 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
857
858 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
859
860 //unset displaymode.. comportement particulier...
861 if(TypeOfOperation==4){
862 if(argc==1){
863 if(Ctx->NbCurrents()==0 ||
864 Ctx->NbSelected()==0){
865 Handle(AIS_InteractiveObject) IO;
866 VwrTst_DispErase(IO,-1,4,Standard_False);
867 }
868 else if(!Ctx->HasOpenedContext()){
869 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
870 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
871 }
872 else{
873 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
874 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
875 Ctx->UpdateCurrentViewer();
876 }
877 else{
878 Handle(AIS_InteractiveObject) IO;
879 name = argv[1];
880 if(GetMapOfAIS().IsBound2(name)){
881 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
882 if (!IO.IsNull())
883 VwrTst_DispErase(IO,-1,4,Standard_True);
884 }
885 }
886 }
887 else if(argc==2){
888 Standard_Integer Dmode = atoi(argv[1]);
889 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
890 Handle(AIS_InteractiveObject) IO;
891 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
892 }
893 if(!Ctx->HasOpenedContext()){
894 // set/unset display mode sur le Contexte...
895 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
896 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
897 }
898 Ctx->UpdateCurrentViewer();
899 }
900 else{
901 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
902 Ctx->Display(Ctx->Interactive(),Dmode);
903 }
904 }
905 else{
906 Handle(AIS_InteractiveObject) IO;
907 name = argv[1];
908 if(GetMapOfAIS().IsBound2(name))
909 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
910 if (!IO.IsNull())
911 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
912 }
913 return 0;
914}
915
916
917//=======================================================================
918//function :
919//purpose :
920//=======================================================================
921static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
922{
923 if(argc==1) return 1;
924 Standard_Integer On = atoi(argv[1]);
925 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
926
927 if(argc==2){
928
929 if(!Ctx->HasOpenedContext()){
930 di<<"sub intensite ";
931 if(On==1) di<<"On";
932 else di<<"Off";
933 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
934 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
935 if(On==1){
936 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
937 else{
938 di <<"passage dans off"<<"\n";
939 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
940 }
941 }
942 }
943 else{
944 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
945 if(On==1){
946 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
947 else{
948 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
949 }
950 }
951 Ctx->UpdateCurrentViewer();
952 }
953 else {
954 Handle(AIS_InteractiveObject) IO;
955 TCollection_AsciiString name = argv[2];
956 if(GetMapOfAIS().IsBound2(name)){
957 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
958 if (!IO.IsNull())
959 if(On==1)
960 Ctx->SubIntensityOn(IO);
961 else
962 Ctx->SubIntensityOff(IO);
963
964 }
965 else return 1;
966 }
967 return 0;
968
969}
970//==============================================================================
971//function : VColor2
972//Author : ege
973//purpose : change the color of a selected or named or displayed shape
974//Draw arg : vcolor2 [name] color
975//==============================================================================
976static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
977{
978
979 Standard_Boolean ThereIsCurrent;
980 Standard_Boolean ThereIsArgument;
981 Standard_Boolean IsBound = Standard_False ;
7fd59977 982
5cbef0fe 983 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
7fd59977 984 if (HaveToSet) {
5cbef0fe
S
985 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
986 ThereIsArgument = (argc != 2);
7fd59977 987 }
988 else {
5cbef0fe
S
989 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
990 ThereIsArgument = (argc == 2);
7fd59977 991 }
992
993 if ( !a3DView().IsNull() ) {
994 TCollection_AsciiString name;
995 if (ThereIsArgument) {
996 name = argv[1];
997 IsBound= GetMapOfAIS().IsBound2(name);
998 }
999 if (TheAISContext()->HasOpenedContext())
1000 TheAISContext()->CloseLocalContext();
1001
1002 // On set le Booleen There is current
1003 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1004 else ThereIsCurrent =Standard_False;
1005
1006 //=======================================================================
1007 // Il y a un argument
1008 //=======================================================================
1009 if ( ThereIsArgument && IsBound ) {
1010 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1011 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1012 Handle(AIS_InteractiveObject) ashape =
1013 Handle(AIS_InteractiveObject)::DownCast (anObj);
1014#ifdef DEB
7fd59977 1015 if (HaveToSet)
1016 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1017 else
5cbef0fe 1018 di << "HaveToSet 0\n";
7fd59977 1019#endif
1020
5cbef0fe 1021 if(HaveToSet)
7fd59977 1022 TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) );
7fd59977 1023 else
1024 TheAISContext()->UnsetColor(ashape);
1025 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1026 Handle(NIS_Triangulated) ashape =
1027 Handle(NIS_Triangulated)::DownCast (anObj);
5cbef0fe 1028 if (!ashape.IsNull())
7fd59977 1029 ashape->SetColor (GetColorFromName(argv[2]));
1030 }
1031 }
1032
1033
1034 //=======================================================================
1035 // Il n'y a pas d'arguments
1036 // Mais un ou plusieurs objets on des current representation
1037 //=======================================================================
1038 if (ThereIsCurrent && !ThereIsArgument) {
1039 for (TheAISContext() -> InitCurrent() ;
1040 TheAISContext() -> MoreCurrent() ;
1041 TheAISContext() ->NextCurrent() )
1042 {
5cbef0fe 1043 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
7fd59977 1044 if (ashape.IsNull())
1045 continue;
1046#ifdef DEB
5cbef0fe
S
1047 if (HaveToSet)
1048 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1049 else
1050 di << "HaveToSet 0\n";
7fd59977 1051#endif
5cbef0fe
S
1052 if(HaveToSet)
1053 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1054 else
1055 TheAISContext()->UnsetColor(ashape,Standard_False);
7fd59977 1056 }
1057
1058 TheAISContext()->UpdateCurrentViewer();
1059 }
1060
1061 //=======================================================================
1062 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1063 // on impose a tous les objets du viewer la couleur passee
1064 //=======================================================================
1065 else if (!ThereIsCurrent && !ThereIsArgument){
1066 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1067 while ( it.More() ) {
5cbef0fe 1068 const Handle(AIS_InteractiveObject) ashape =
7fd59977 1069 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1070 if (!ashape.IsNull())
1071 if(HaveToSet)
5cbef0fe 1072 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
7fd59977 1073 else
1074 TheAISContext()->UnsetColor(ashape,Standard_False);
5cbef0fe 1075 it.Next();
7fd59977 1076 }
1077 TheAISContext()->UpdateCurrentViewer();
1078 }
1079 }
1080 return 0;
1081}
1082
1083//==============================================================================
1084//function : VTransparency
1085//Author : ege
1086//purpose : change the transparency of a selected or named or displayed shape
1087//Draw arg : vtransparency [name] TransparencyCoeficient
1088//==============================================================================
1089
7fd59977 1090static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1091 const char** argv)
1092{
1093 Standard_Boolean ThereIsCurrent;
1094 Standard_Boolean ThereIsArgument;
1095 Standard_Boolean IsBound = Standard_False ;
7fd59977 1096
5cbef0fe 1097 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
7fd59977 1098 if (HaveToSet) {
1099 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
5cbef0fe 1100 ThereIsArgument = (argc != 2);
7fd59977 1101 }
1102 else{
1103 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
5cbef0fe 1104 ThereIsArgument = (argc == 2);
7fd59977 1105 }
1106
1107 if ( !a3DView().IsNull() ) {
1108 TCollection_AsciiString name;
1109 if (ThereIsArgument) {
1110 name = argv[1];
1111 IsBound= GetMapOfAIS().IsBound2(name);
1112 }
1113 if (TheAISContext()->HasOpenedContext())
1114 TheAISContext()->CloseLocalContext();
1115
1116 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1117 else ThereIsCurrent = Standard_False;
1118
1119 //=======================================================================
1120 // Il y a des arguments: un nom et une couleur
1121 //=======================================================================
1122 if ( ThereIsArgument && IsBound ) {
1123 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1124 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1125 const Handle(AIS_InteractiveObject) ashape =
1126 Handle(AIS_InteractiveObject)::DownCast(anObj);
1127 if(HaveToSet)
1128 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1129 else
1130 TheAISContext()->UnsetTransparency(ashape);
5cbef0fe 1131 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
7fd59977 1132 const Handle(NIS_InteractiveObject) ashape =
1133 Handle(NIS_InteractiveObject)::DownCast(anObj);
1134 if(HaveToSet)
1135 ashape->SetTransparency(atof(argv[2]) );
1136 else
1137 ashape->UnsetTransparency();
1138 }
1139 }
1140 //=======================================================================
1141 // Il n'y a pas d'arguments
1142 // Mais un ou plusieurs objets on des current representation
1143 //=======================================================================
1144 if (ThereIsCurrent && !ThereIsArgument) {
1145 for (TheAISContext() -> InitCurrent() ;
1146 TheAISContext() -> MoreCurrent() ;
1147 TheAISContext() ->NextCurrent() )
1148 {
5cbef0fe
S
1149 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1150 if(HaveToSet)
1151 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1152 else
1153 TheAISContext()->UnsetTransparency(ashape,Standard_False);
7fd59977 1154 }
1155
1156 TheAISContext()->UpdateCurrentViewer();
1157 }
1158 //=======================================================================
1159 // Il n'y a pas d'arguments ET aucun objet courrant
1160 //=======================================================================
1161 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1162 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1163 it(GetMapOfAIS());
1164 while ( it.More() ) {
5cbef0fe 1165 Handle(AIS_InteractiveObject) ashape =
7fd59977 1166 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1167 if (!ashape.IsNull())
1168 if(HaveToSet)
5cbef0fe 1169 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
7fd59977 1170 else
1171 TheAISContext()->UnsetTransparency(ashape,Standard_False);
5cbef0fe 1172 it.Next();
7fd59977 1173 }
1174 TheAISContext()->UpdateCurrentViewer();
1175 }
1176 }
1177 return 0;
1178}
1179
1180
1181//==============================================================================
1182//function : VMaterial
1183//Author : ege
1184//purpose : change the Material of a selected or named or displayed shape
1185//Draw arg : vmaterial [Name] Material
1186//==============================================================================
1187static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1188{
1189
1190 Standard_Boolean ThereIsCurrent;
1191 Standard_Boolean ThereIsName;
1192 Standard_Boolean IsBound = Standard_False ;
1193
5cbef0fe 1194 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
7fd59977 1195 if (HaveToSet) {
1196 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
5cbef0fe 1197 ThereIsName = (argc != 2);
7fd59977 1198 }
1199 else {
1200 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
5cbef0fe 1201 ThereIsName = (argc == 2);
7fd59977 1202 }
1203
1204 if ( !a3DView().IsNull() ) {
1205 TCollection_AsciiString name;
1206 if (ThereIsName) {
1207 name = argv[1];
1208 IsBound= GetMapOfAIS().IsBound2(name);
1209 }
1210 if (TheAISContext()->HasOpenedContext())
1211 TheAISContext()->CloseLocalContext();
1212 if (TheAISContext() -> NbCurrents() > 0 )
1213 ThereIsCurrent =Standard_True;
1214 else
1215 ThereIsCurrent =Standard_False;
1216
1217 //=======================================================================
1218 // Ther is a name of shape and a material name
1219 //=======================================================================
1220 if ( ThereIsName && IsBound ) {
1221 Handle(AIS_InteractiveObject) ashape =
1222 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1223 if (!ashape.IsNull())
1224 if (HaveToSet)
5cbef0fe 1225 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
7fd59977 1226 else
1227 TheAISContext()->UnsetMaterial(ashape);
1228 }
1229 //=======================================================================
1230 // Il n'y a pas de nom de shape
1231 // Mais un ou plusieurs objets on des current representation
1232 //=======================================================================
1233 if (ThereIsCurrent && !ThereIsName) {
1234 for (TheAISContext() -> InitCurrent() ;
1235 TheAISContext() -> MoreCurrent() ;
1236 TheAISContext() ->NextCurrent() )
1237 {
5cbef0fe
S
1238 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1239 if (HaveToSet)
1240 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1241 else
1242 TheAISContext()->UnsetMaterial(ashape,Standard_False);
7fd59977 1243 }
1244 TheAISContext()->UpdateCurrentViewer();
1245 }
1246
1247 //=======================================================================
1248 // Il n'y a pas de noms de shape ET aucun objet courrant
1249 // On impose a tous les objets du viewer le material passe en argument
1250 //=======================================================================
1251 else if (!ThereIsCurrent && !ThereIsName){
1252 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1253 it(GetMapOfAIS());
1254 while ( it.More() ) {
5cbef0fe 1255 Handle(AIS_InteractiveObject) ashape =
7fd59977 1256 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
5cbef0fe 1257 if (!ashape.IsNull())
7fd59977 1258 if (HaveToSet)
5cbef0fe 1259 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
7fd59977 1260 else
1261 TheAISContext()->UnsetMaterial(ashape,Standard_False);
5cbef0fe 1262 it.Next();
7fd59977 1263 }
1264 TheAISContext()->UpdateCurrentViewer();
1265 }
1266 }
1267 return 0;
1268}
1269
1270
1271
1272//==============================================================================
1273//function : VWidth
1274//Author : ege
1275//purpose : change the width of the edges of a selected or named or displayed shape
1276//Draw arg : vwidth [Name] WidthValue(1->10)
1277//==============================================================================
1278static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1279{
1280
1281 Standard_Boolean ThereIsCurrent;
1282 Standard_Boolean ThereIsArgument;
1283 Standard_Boolean IsBound = Standard_False ;
1284
5cbef0fe 1285 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
7fd59977 1286 if (HaveToSet) {
1287 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
5cbef0fe 1288 ThereIsArgument = (argc != 2);
7fd59977 1289 }
1290 else {
1291 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
5cbef0fe 1292 ThereIsArgument = (argc == 2);
7fd59977 1293 }
1294 if ( !a3DView().IsNull() ) {
1295 TCollection_AsciiString name;
1296 if (ThereIsArgument) {
1297 name = argv[1];
1298 IsBound= GetMapOfAIS().IsBound2(name);
1299 }
1300 if (TheAISContext()->HasOpenedContext())
1301 TheAISContext()->CloseLocalContext();
1302
1303 if (TheAISContext() -> NbCurrents() > 0 )
1304 ThereIsCurrent =Standard_True;
1305 else
1306 ThereIsCurrent =Standard_False;
1307
1308 if ( ThereIsArgument && IsBound ) {
1309 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1310 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1311 const Handle(AIS_InteractiveObject) ashape =
1312 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1313 if (HaveToSet)
1314 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1315 else
1316 TheAISContext()->UnsetWidth (ashape);
1317 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1318 const Handle(NIS_Triangulated) ashape =
1319 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1320 if (HaveToSet && !ashape.IsNull())
1321 ashape->SetLineWidth ( atof (argv[2]) );
1322 }
1323 }
1324
1325 //=======================================================================
1326 // Il n'y a pas d'arguments
1327 // Mais un ou plusieurs objets on des current representation
1328 //=======================================================================
1329 if (ThereIsCurrent && !ThereIsArgument) {
1330 for (TheAISContext() -> InitCurrent() ;
1331 TheAISContext() -> MoreCurrent() ;
1332 TheAISContext() ->NextCurrent() )
1333 {
5cbef0fe
S
1334 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1335 if (HaveToSet)
1336 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1337 else
1338 TheAISContext()->UnsetWidth(ashape,Standard_False);
7fd59977 1339 }
1340 TheAISContext()->UpdateCurrentViewer();
1341 }
1342 //=======================================================================
1343 // Il n'y a pas d'arguments ET aucun objet courrant
1344 //=======================================================================
1345 else if (!ThereIsCurrent && !ThereIsArgument){
1346 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1347 it(GetMapOfAIS());
1348 while ( it.More() ) {
1349 Handle(AIS_InteractiveObject) ashape =
1350 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1351 if (!ashape.IsNull())
1352 if (HaveToSet)
5cbef0fe 1353 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
7fd59977 1354 else
5cbef0fe 1355 TheAISContext()->UnsetWidth(ashape,Standard_False);
7fd59977 1356 it.Next();
1357 }
1358 TheAISContext()->UpdateCurrentViewer();
1359 }
1360 }
1361 return 0;
1362}
1363//==============================================================================
1364//function : VDonly2
1365//author : ege
1366//purpose : Display only a selected or named object
1367// if there is no selected or named object s, nothing is donne
1368//Draw arg : vdonly2 [name1] ... [name n]
1369//==============================================================================
1370static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1371
1372{
1373 if ( a3DView().IsNull() )
1374 return 1;
1375
1376 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1377 Standard_Boolean ThereIsArgument= argc>1;
1378
1379 if (TheAISContext()->HasOpenedContext())
1380 TheAISContext()->CloseLocalContext();
1381
1382 //===============================================================
1383 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1384 // dans le viewer
1385 //===============================================================
1386 if (!ThereIsArgument && ThereIsCurrent) {
1387
1388#ifdef DEB
1389 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1390 it (GetMapOfAIS());
1391#endif
1392 for(TheAISContext()->InitCurrent();
1393 TheAISContext()->MoreCurrent();
1394 TheAISContext()->NextCurrent()){
1395 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1396 TheAISContext()->Erase(aShape,Standard_False);}
1397 }
1398 TheAISContext() ->UpdateCurrentViewer();
1399 //===============================================================
1400 // Il y a des arguments
1401 //===============================================================
1402 if (ThereIsArgument) {
1403 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1404 it (GetMapOfAIS());
1405 while ( it.More() ) {
1406 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1407 const Handle(AIS_InteractiveObject) aShape =
1408 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1409 TheAISContext()->Erase(aShape,Standard_False);
1410 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1411 const Handle(NIS_InteractiveObject) aShape =
1412 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
ffe2bea7 1413 TheNISContext()->Erase(aShape);
7fd59977 1414 }
1415 it.Next();
1416 }
1417
1418 // On display les objets passes par parametre
1419 for (int i=1; i<argc ; i++) {
1420 TCollection_AsciiString name=argv[i];
1421 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1422 if (IsBound) {
1423 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1424 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1425 const Handle(AIS_InteractiveObject) aShape =
1426 Handle(AIS_InteractiveObject)::DownCast (anObj);
1427 TheAISContext()->Display(aShape, Standard_False);
1428 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
ffe2bea7 1429 Handle(NIS_InteractiveObject) aShape =
7fd59977 1430 Handle(NIS_InteractiveObject)::DownCast (anObj);
ffe2bea7 1431 TheNISContext()->Display(aShape);
7fd59977 1432 }
1433 }
1434 }
1435 TheAISContext() ->UpdateCurrentViewer();
ffe2bea7 1436// TheNISContext() ->UpdateViews();
7fd59977 1437 }
1438 return 0;
1439}
1440
1441//==============================================================================
1442//function : VErase2
1443//author : ege
1444//purpose : Erase some selected or named objects
1445// if there is no selected or named objects, the whole viewer is erased
1446//Draw arg : verase2 [name1] ... [name n]
1447//==============================================================================
1448static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1449
1450{
1451 if ( a3DView().IsNull() )
1452 return 1;
1453
1454 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1455 Standard_Boolean ThereIsArgument= argc>1;
1456 if(TheAISContext()->HasOpenedContext())
1457 TheAISContext()->CloseLocalContext();
1458
1459 //===============================================================
1460 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1461 // dans le viewer
1462 //===============================================================
1463 if (!ThereIsArgument && ThereIsCurrent) {
1464 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1465 it (GetMapOfAIS());
1466 while ( it.More() ) {
1467 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1468 const Handle(AIS_InteractiveObject) aShape =
1469 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1470 if (TheAISContext()->IsCurrent(aShape))
1471 TheAISContext()->Erase(aShape,Standard_False);
1472 }
1473 it.Next();
1474 }
1475
1476 TheAISContext() ->UpdateCurrentViewer();
1477 }
1478
1479 //===============================================================
1480 // Il n'y a pas d'arguments et aucuns objets selectionnes
1481 // dans le viewer:
1482 // On erase tout le viewer
1483 //===============================================================
1484
1485 if (!ThereIsArgument && !ThereIsCurrent) {
1486 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1487 while ( it.More() ) {
1488 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1489 const Handle(AIS_InteractiveObject) aShape =
1490 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1491 TheAISContext()->Erase(aShape,Standard_False);
1492 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1493 const Handle(NIS_InteractiveObject) aShape =
1494 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
ffe2bea7 1495 TheNISContext()->Erase(aShape);
7fd59977 1496 }
1497 it.Next();
1498 }
1499 TheAISContext() ->UpdateCurrentViewer();
ffe2bea7 1500// TheNISContext()->UpdateViews();
7fd59977 1501 }
1502
1503 //===============================================================
1504 // Il y a des arguments
1505 //===============================================================
1506 if (ThereIsArgument) {
1507 for (int i=1; i<argc ; i++) {
1508 TCollection_AsciiString name=argv[i];
1509 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1510 if (IsBound) {
1511 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1512 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1513 const Handle(AIS_InteractiveObject) aShape =
1514 Handle(AIS_InteractiveObject)::DownCast (anObj);
1515 TheAISContext()->Erase(aShape,Standard_False);
1516 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1517 const Handle(NIS_InteractiveObject) aShape =
1518 Handle(NIS_InteractiveObject)::DownCast (anObj);
ffe2bea7 1519 TheNISContext()->Erase(aShape);
7fd59977 1520 }
1521 }
1522 }
1523 TheAISContext() ->UpdateCurrentViewer();
ffe2bea7 1524// TheNISContext() ->UpdateViews();
7fd59977 1525 }
1526 return 0;
1527}
1528
1529//==============================================================================
1530//function : VEraseAll
1531//author : ege
1532//purpose : Erase all the objects displayed in the viewer
1533//Draw arg : veraseall
1534//==============================================================================
1535static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1536
1537{
1538 // Verification des arguments
1539 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1540 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1541 TheAISContext()->CloseAllContexts(Standard_False);
1542 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1543 it(GetMapOfAIS());
1544 while ( it.More() ) {
1545 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1546 const Handle(AIS_InteractiveObject) aShape =
1547 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1548 TheAISContext()->Erase(aShape,Standard_False);
1549 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1550 const Handle(NIS_InteractiveObject) aShape =
1551 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
ffe2bea7 1552 TheNISContext()->Erase(aShape);
7fd59977 1553 }
1554 it.Next();
1555 }
1556 TheAISContext() ->UpdateCurrentViewer();
ffe2bea7 1557// TheNISContext() ->UpdateViews();
7fd59977 1558 return 0;
1559}
1560
1561
1562//==============================================================================
1563//function : VDisplayAll
1564//author : ege
1565//purpose : Display all the objects of the Map
1566//Draw arg : vdisplayall
1567//==============================================================================
1568static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1569
1570{
1571 if (! a3DView().IsNull() ) {
1572 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1573 if (TheAISContext()->HasOpenedContext())
1574 TheAISContext()->CloseLocalContext();
1575 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1576 it (GetMapOfAIS());
1577 while ( it.More() ) {
1578 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1579 const Handle(AIS_InteractiveObject) aShape =
1580 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1581 TheAISContext()->Erase(aShape,Standard_False);
1582 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1583 const Handle(NIS_InteractiveObject) aShape =
1584 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
ffe2bea7 1585 TheNISContext()->Erase(aShape);
7fd59977 1586 }
1587 it.Next();
1588 }
1589 it.Reset();
1590 while ( it.More() ) {
1591 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1592 const Handle(AIS_InteractiveObject) aShape =
1593 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1594 TheAISContext()->Display(aShape, Standard_False);
1595 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
ffe2bea7 1596 Handle(NIS_InteractiveObject) aShape =
7fd59977 1597 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
ffe2bea7 1598 TheNISContext()->Display(aShape);
7fd59977 1599 }
1600 it.Next();
1601 }
1602 TheAISContext() ->UpdateCurrentViewer();
ffe2bea7 1603// TheNISContext() ->UpdateViews();
7fd59977 1604 }
1605 return 0;
1606}
1607
1608
1609//#######################################################################################################
1610
1611
1612static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) {
1613
1614 static Standard_Boolean IsDefined=Standard_False ;
1615 static TCollection_AsciiString VarName;
1616 if ( !IsDefined ) {
1617 const char *envir, *casroot ;
1618 envir = getenv("CSF_MDTVTexturesDirectory") ;
1619
1620 Standard_Boolean HasDefinition = Standard_False ;
1621 if ( !envir ) {
1622 casroot = getenv("CASROOT");
1623 if ( casroot ) {
1624 VarName = TCollection_AsciiString (casroot);
1625 VarName += "/src/Textures" ;
1626 HasDefinition = Standard_True ;
1627 }
1628 } else {
1629 VarName = TCollection_AsciiString (envir);
1630 HasDefinition = Standard_True ;
1631 }
1632 if ( HasDefinition ) {
1633 OSD_Path aPath ( VarName );
1634 OSD_Directory aDir(aPath);
1635 if ( aDir.Exists () ) {
1636 TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
1637 OSD_File TextureFile ( aTexture );
1638 if ( !TextureFile.Exists() ) {
1639 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1640 di << " not all files are found in : "<<VarName.ToCString() << "\n";
1641 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1642 }
1643 } else {
1644 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1645 di << " Directory : "<< VarName.ToCString() << " not exist " << "\n";
1646 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1647 }
1648 return VarName ;
1649 } else {
1650 di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n";
1651 di << " one of these variable are mandatory to use this fonctionnality" << "\n";
1652 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
1653 }
1654 IsDefined = Standard_True ;
1655 }
1656 return VarName ;
1657
1658}
1659
1660//#######################################################################################################
1661
1662
1663//#######################################################################################################
1664
1665//## VTexture
1666
1667//#######################################################################################################
1668
1669Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1670{
1671 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1672 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1673 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1674 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1675 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1676
1677 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1678 if(myAISContext.IsNull())
1679 {
1680 di << "use 'vinit' command before " << argv[0] << "\n";
31160f80 1681 return 1;
7fd59977 1682 }
1683
1684 Handle(AIS_InteractiveObject) TheAisIO;
1685 Handle(AIS_TexturedShape) myShape;
1686 Standard_Integer myPreviousMode = 0;
1687
31160f80 1688 if (argc<2 || !argv[1])
7fd59977 1689 {
1690 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
31160f80 1691 return 1;
7fd59977 1692 }
1693
1694 TCollection_AsciiString name = argv[1];
1695 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1696
1697 if (GetMapOfAIS().IsBound2(name))
1698 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1699 (GetMapOfAIS().Find2(name));
1700 if (TheAisIO.IsNull())
1701 {
1702 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
31160f80 1703 return 1;
7fd59977 1704 }
1705
1706 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1707 {
1708 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1709 myPreviousMode = myShape->DisplayMode() ;
1710 }
1711 else
1712 {
31160f80 1713 myAISContext->Clear(TheAisIO,Standard_False);
7fd59977 1714 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1715 GetMapOfAIS().UnBind1(TheAisIO);
1716 GetMapOfAIS().UnBind2(name);
1717 GetMapOfAIS().Bind(myShape, name);
1718 }
1719 switch (command)
1720 {
1721 case 1: // vtexture : we only map a texture on the shape
1722 if(argc<=1)
1723 {
1724 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1725 return 1;
7fd59977 1726 }
31160f80 1727 if (argc>2 && argv[2])
7fd59977 1728 {
1729 if(strcasecmp(argv[2],"?")==0)
1730 {
1731 TCollection_AsciiString monPath = GetEnvir (di) ;
1732
1733 di<<"\n Files in current directory : \n"<<"\n";
1734 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1735 di.Eval(Cmnd.ToCString());
1736
1737 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1738 Cmnd += monPath ;
1739 Cmnd += "/* " ;
1740 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1741 di.Eval(Cmnd.ToCString());
1742
1743 return 0;
1744 }
1745 else
1746 myShape->SetTextureFileName(argv[2]);
1747 }
1748 else
1749 {
1750 di <<"Texture mapping disabled \n \
1751 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1752
1753 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1754 if (myPreviousMode == 3 )
1755 myAISContext->RecomputePrsOnly(myShape);
1756 myAISContext->Display(myShape, Standard_True);
1757 return 0;
1758 }
1759 break;
1760
1761 case 2: // vtexscale : we change the scaling factor of the texture
1762
1763 if(argc<2)
1764 {
1765 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1766 return 1;
7fd59977 1767 }
1768
1769 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1770 ( argv[2] ? atof(argv[2]) : 1.0 ),
1771 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1772 break;
1773
1774 case 3: // vtexorigin : we change the origin of the texture on the shape
1775 if(argc<2)
1776 {
1777 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1778 return 1;
7fd59977 1779 }
1780 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1781 ( argv[2] ? atof(argv[2]) : 0.0 ),
1782 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1783 break;
1784
1785 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1786 if(argc<2)
1787 {
1788 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1789 return 1;
7fd59977 1790 }
31160f80 1791 if (argc>2 && argv[2])
7fd59977 1792 {
1793 di <<"Texture repeat enabled"<<"\n";
1794 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1795 }
1796 else
1797 {
1798 di <<"Texture repeat disabled"<<"\n";
1799 myShape->SetTextureRepeat(Standard_False);
1800 }
1801 break;
1802
1803 case 5: // vtexdefault : default texture mapping
1804 // ScaleU = ScaleV = 100.0
1805 // URepeat = VRepeat = 1.0
1806 // Uorigin = VOrigin = 0.0
1807
1808 if(argc<2)
1809 {
1810 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1811 return 1;
7fd59977 1812 }
1813 myShape->SetTextureRepeat(Standard_False);
1814 myShape->SetTextureOrigin(Standard_False);
1815 myShape->SetTextureScale (Standard_False);
1816 break;
1817 }
1818
1819 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1820 myAISContext->RecomputePrsOnly(myShape);
1821 else
1822 {
1823 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1824 myAISContext->Display(myShape, Standard_True);
1825 myAISContext->Update(myShape,Standard_True);
1826 }
31160f80 1827 return 0;
7fd59977 1828}
1829
1830//==============================================================================
1831//function : VDisplay2
1832//author : ege
1833//purpose : Display an object from its name
1834//Draw arg : vdisplay name1 [name2] ... [name n]
1835//==============================================================================
1836static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1837
1838{
1839 // Verification des arguments
1840 if ( a3DView().IsNull() ) {
1841
1842 ViewerTest::ViewerInit();
1843 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1844 // return 1;
1845 }
1846
1847 if ( argc<2) {
1848 di<<argv[0]<<" Syntaxe error"<<"\n";
1849 return 1;
1850 }
1851
1852
1853 TCollection_AsciiString name;
1854 if (TheAISContext()->HasOpenedContext())
1855 TheAISContext()->CloseLocalContext();
1856
1857 for ( int i = 1; i < argc; i++ ) {
1858 name = argv[i];
1859 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1860 Standard_Boolean IsDatum = Standard_False;
1861 Handle(Standard_Transient) anObj;
1862 if ( IsBound ) {
1863 anObj = GetMapOfAIS().Find2(name);
1864 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1865 Handle(AIS_InteractiveObject) aShape =
1866 Handle(AIS_InteractiveObject)::DownCast(anObj);
1867 if (aShape->Type()==AIS_KOI_Datum) {
1868 IsDatum = Standard_True;
1869 TheAISContext()->Display(aShape, Standard_False);
1870 }
1871 if (!IsDatum) {
1872 di << "Display " << name.ToCString() << "\n";
1873 // Get the Shape from a name
1874 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1875
1876 // Update the Shape in the AIS_Shape
1877 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1878 if(!TheRealSh.IsNull())
1879 TheRealSh->Set(NewShape);
1880 TheAISContext()->Redisplay(aShape, Standard_False);
1881 TheAISContext()->Display(aShape, Standard_False);
1882 }
1883 aShape.Nullify();
1884 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1885 Handle(NIS_InteractiveObject) aShape =
1886 Handle(NIS_InteractiveObject)::DownCast(anObj);
ffe2bea7 1887 TheNISContext()->Display(aShape);
7fd59977 1888 }
1889 }
1890 else { // Create the AIS_Shape from a name
1891 const Handle(AIS_InteractiveObject) aShape =
1892 GetAISShapeFromName((const char *)name.ToCString());
1893 if ( !aShape.IsNull() ) {
1894 GetMapOfAIS().Bind(aShape, name);
1895 TheAISContext()->Display(aShape, Standard_False);
1896 }
1897 }
1898 }
1899 // Upadate the screen and redraw the view
1900 TheAISContext()->UpdateCurrentViewer();
ffe2bea7 1901// TheNISContext()->UpdateViews();
7fd59977 1902 return 0;
1903}
1904
1905//==============================================================================
1906//function : VMoveA
1907//purpose : Test the annimation of an object along a
1908// predifined trajectory
1909//Draw arg : vmove ShapeName
1910//==============================================================================
1911
1912#ifdef DEB
1913static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
1914
1915 OSD_Timer myTimer;
1916 myTimer.Start();
1917
1918 if (TheAISContext()->HasOpenedContext())
1919 TheAISContext()->CloseLocalContext();
1920
c6541a0c 1921 Standard_Real Step=2*M_PI/180;
7fd59977 1922 Standard_Real Angle=0;
1923 // R est le rayon de l'hellicoide
1924 Standard_Real R=50;
1925 // D est la distance parcourue en translation en 1 tour
1926 Standard_Real D=50;
1927
1928 Handle(AIS_InteractiveObject) aIO;
1929
1930 if (GetMapOfAIS().IsBound2(argv[1]))
1931 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
1932
1933 if (aIO.IsNull()) {
1934 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
1935 return 1;
1936 }
1937 TheAISContext()->Deactivate(aIO);
1938
1939 // boucle generant le mouvement
1940 if(argc==3) {
1941 di<<" Transformations"<<"\n";
c6541a0c 1942 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
7fd59977 1943
1944 Angle=Step*myAngle;
c6541a0c 1945 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) );
7fd59977 1946 gp_Trsf myTransfo;
1947 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
1948 TheAISContext()->SetLocation(aIO,myTransfo);
1949
1950 TheAISContext() ->UpdateCurrentViewer();
1951
1952 }
1953 }
1954 else {
1955 di<<" Locations"<<"\n";
1956 gp_Trsf myAngleTrsf;
1957 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
1958 TopLoc_Location myDeltaAngle (myAngleTrsf);
1959 gp_Trsf myDistTrsf;
1960 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
1961 TopLoc_Location myDeltaDist (myDistTrsf);
1962 TopLoc_Location myTrueLoc;
1963
c6541a0c 1964 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
7fd59977 1965
1966 Angle=Step*myAngle;
1967 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
1968 TheAISContext()->SetLocation(aIO,myTrueLoc );
1969 TheAISContext() ->UpdateCurrentViewer();
1970 }
1971 }
1972
1973
1974 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
1975
1976 //TopLoc_Location Tempo=aIO->Location();
1977 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
1978 //ShapeBis.Located(Tempo);
1979
1980
1981 // On reset la location (origine) contenue dans l'AISInteractiveObject
1982 TheAISContext() ->ResetLocation(aIO);
1983
1984 // On force aShape a devenir l'AIS IO propre a ShapeBis
1985
1986 // Pour cela on force aShape(AIS IO) a devenir une AISShape
1987 // ->Set() est une methode de AIS_Shape
1988 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
1989
1990 // On donne a ShapeBis le nom de l'AIS IO
1991 //Rep::Set(argv[1],ShapeBis);
1992
1993
1994 TheAISContext()->Redisplay(aIO,Standard_False);
1995
1996 // On reactive la selection des primitives sensibles
1997 TheAISContext()->Activate(aIO,0);
1998
1999 TheAISContext() ->UpdateCurrentViewer();
2000 a3DView() -> Redraw();
2001
2002 myTimer.Stop();
2003 di<<" Temps ecoule "<<"\n";
2004 myTimer.Show();
2005
2006 return 0;
2007}
2008#endif
2009
2010
2011//==============================================================================
2012//function : VPerf
2013//purpose : Test the annimation of an object along a
2014// predifined trajectory
2015//Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2016//==============================================================================
2017
2018static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2019
2020 OSD_Timer myTimer;
2021 if (TheAISContext()->HasOpenedContext())
2022 TheAISContext()->CloseLocalContext();
2023
c6541a0c 2024 Standard_Real Step=4*M_PI/180;
7fd59977 2025 Standard_Real Angle=0;
2026
2027 Handle(AIS_InteractiveObject) aIO;
2028 if (GetMapOfAIS().IsBound2(argv[1]))
2029 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2030 if (aIO.IsNull())
2031 return 1;
2032
2033 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2034
2035 myTimer.Start();
2036
2037 if (atoi(argv[3])==1 ) {
2038 di<<" Primitives sensibles OFF"<<"\n";
2039 TheAISContext()->Deactivate(aIO);
2040 }
2041 else {
2042 di<<" Primitives sensibles ON"<<"\n";
2043 }
2044 // Movement par transformation
2045 if(atoi(argv[2]) ==1) {
2046 di<<" Calcul par Transformation"<<"\n";
c6541a0c 2047 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 2048
2049 Angle=Step*myAngle;
2050 gp_Trsf myTransfo;
2051 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2052 TheAISContext()->SetLocation(aShape,myTransfo);
2053 TheAISContext() ->UpdateCurrentViewer();
2054
2055 }
2056 }
2057 else {
2058 di<<" Calcul par Locations"<<"\n";
2059 gp_Trsf myAngleTrsf;
2060 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2061 TopLoc_Location myDeltaAngle (myAngleTrsf);
2062 TopLoc_Location myTrueLoc;
2063
c6541a0c 2064 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 2065
2066 Angle=Step*myAngle;
2067 myTrueLoc=myTrueLoc*myDeltaAngle;
2068 TheAISContext()->SetLocation(aShape,myTrueLoc );
2069 TheAISContext() ->UpdateCurrentViewer();
2070 }
2071 }
2072 if (atoi(argv[3])==1 ){
2073 // On reactive la selection des primitives sensibles
2074 TheAISContext()->Activate(aIO,0);
2075 }
2076 a3DView() -> Redraw();
2077 myTimer.Stop();
2078 di<<" Temps ecoule "<<"\n";
2079 myTimer.Show();
2080 return 0;
2081}
2082
2083
2084//==================================================================================
2085// Function : VAnimation
2086//==================================================================================
2087static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
31160f80 2088 if (argc != 5) {
7fd59977 2089 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2090 return 1;
2091 }
2092
2093 Standard_Real thread = 4;
2094 Standard_Real angleA=0;
2095 Standard_Real angleB;
2096 Standard_Real X;
2097 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2098
2099 BRep_Builder B;
2100 TopoDS_Shape CrankArm;
2101 TopoDS_Shape CylinderHead;
2102 TopoDS_Shape Propeller;
2103 TopoDS_Shape EngineBlock;
2104
2105 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2106 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2107 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2108 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2109 BRepTools::Read(CrankArm,argv[1],B);
2110 BRepTools::Read(CylinderHead,argv[2],B);
2111 BRepTools::Read(Propeller,argv[3],B);
2112 BRepTools::Read(EngineBlock,argv[4],B);
2113
2114 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2115
2116
2117 OSD_Timer myTimer;
2118 myTimer.Start();
2119
2120 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2121 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2122 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2123 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2124
2125 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2126 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2127 GetMapOfAIS().Bind(myAisCrankArm,"c");
2128 GetMapOfAIS().Bind(myAisPropeller,"d");
2129
2130 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2131 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2132 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2133
2134 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2135 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2136 TheAISContext()->Display(myAisCrankArm,Standard_False );
2137 TheAISContext()->Display(myAisPropeller,Standard_False);
2138
2139 TheAISContext()->Deactivate(myAisCylinderHead);
2140 TheAISContext()->Deactivate(myAisEngineBlock );
2141 TheAISContext()->Deactivate(myAisCrankArm );
2142 TheAISContext()->Deactivate(myAisPropeller );
2143
2144 // Boucle de mouvement
c6541a0c 2145 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
7fd59977 2146
c6541a0c 2147 angleA = thread*myAngle*M_PI/180;
7fd59977 2148 X = Sin(angleA)*3/8;
2149 angleB = atan(X / Sqrt(-X * X + 1));
2150 Standard_Real decal(25*0.6);
2151
2152
2153 //Build a transformation on the display
2154 gp_Trsf aPropellerTrsf;
2155 aPropellerTrsf.SetRotation(Ax1,angleA);
2156 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2157
2158 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));
2159 gp_Trsf aCrankArmTrsf;
2160 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2161 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2162
2163 TheAISContext()->UpdateCurrentViewer();
2164 }
2165
2166 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2167 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2168
2169 myAisCrankArm ->ResetLocation();
2170 myAisPropeller->ResetLocation();
2171
2172 myAisCrankArm -> Set(myNewCrankArm );
2173 myAisPropeller -> Set(myNewPropeller);
2174
2175 TheAISContext()->Activate(myAisCylinderHead,0);
2176 TheAISContext()->Activate(myAisEngineBlock,0 );
2177 TheAISContext()->Activate(myAisCrankArm ,0 );
2178 TheAISContext()->Activate(myAisPropeller ,0 );
2179
2180 myTimer.Stop();
2181 myTimer.Show();
2182 myTimer.Start();
2183
2184 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2185 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2186
2187 TheAISContext()->UpdateCurrentViewer();
2188 a3DView()->Redraw();
2189
2190 myTimer.Stop();
2191 myTimer.Show();
2192
2193 return 0;
2194
2195}
2196
2197//==============================================================================
2198//function : VShading
2199//purpose : Sharpen or roughten the quality of the shading
2200//Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2201//==============================================================================
5cbef0fe
S
2202static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2203{
7fd59977 2204 Standard_Real myDevCoef;
2205 Handle(AIS_InteractiveObject) TheAisIO;
2206
2207 // Verifications
5cbef0fe
S
2208 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2209
7fd59977 2210 if (TheAISContext()->HasOpenedContext())
2211 TheAISContext()->CloseLocalContext();
2212
2213 if (argc < 3) {
2214 myDevCoef = 0.0008;
2215 } else {
2216 myDevCoef =atof(argv[2]);
2217 }
2218
7fd59977 2219 TCollection_AsciiString name=argv[1];
2220 if (GetMapOfAIS().IsBound2(name ))
5cbef0fe 2221 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
7fd59977 2222 if (TheAisIO.IsNull())
2223 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2224
5cbef0fe 2225 if (HaveToSet)
7fd59977 2226 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5cbef0fe 2227 else
7fd59977 2228 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2229
7fd59977 2230 TheAISContext()->Redisplay(TheAisIO);
2231 return 0;
2232}
2233//==============================================================================
2234//function : HaveMode
2235//use : VActivatedModes
2236//==============================================================================
2237#include <TColStd_ListIteratorOfListOfInteger.hxx>
2238
2239Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2240{
2241 TColStd_ListOfInteger List;
2242 TheAISContext()->ActivatedModes (TheAisIO,List);
2243 TColStd_ListIteratorOfListOfInteger it;
2244 Standard_Boolean Found=Standard_False;
2245 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2246 if (it.Value()==mode ) Found=Standard_True;
2247 }
2248 return Found;
2249}
2250
2251
2252
2253//==============================================================================
2254//function : VActivatedMode
2255//author : ege
2256//purpose : permet d'attribuer a chacune des shapes un mode d'activation
2257// (edges,vertex...)qui lui est propre et le mode de selection standard.
2258// La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2259// Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2260// qu'un nom et qu'un mode.
2261//Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2262//==============================================================================
2263#include <AIS_ListIteratorOfListOfInteractive.hxx>
2264
2265static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2266
2267{
7fd59977 2268 Standard_Boolean ThereIsName = Standard_False ;
2269
2270 if(!a3DView().IsNull()){
2271
5cbef0fe 2272 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
7fd59977 2273 // verification des arguments
2274 if (HaveToSet) {
2275 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
5cbef0fe 2276 ThereIsName = (argc == 3);
7fd59977 2277 }
2278 else {
2279 // vunsetam
2280 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2281 else {
5cbef0fe
S
2282 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2283 di<<" Fermeture du Context local"<<"\n";
7fd59977 2284 if (TheAISContext()->HasOpenedContext())
2285 TheAISContext()->CloseLocalContext();
2286 }
7fd59977 2287 }
2288
7fd59977 2289 // IL n'y a aps de nom de shape passe en argument
2290 if (HaveToSet && !ThereIsName){
2291 Standard_Integer aMode=atoi(argv [1]);
2292
2293 const char *cmode="???";
7fd59977 2294 switch (aMode) {
2295 case 0: cmode = "Shape"; break;
2296 case 1: cmode = "Vertex"; break;
2297 case 2: cmode = "Edge"; break;
2298 case 3: cmode = "Wire"; break;
2299 case 4: cmode = "Face"; break;
2300 case 5: cmode = "Shell"; break;
2301 case 6: cmode = "Solid"; break;
2302 case 7: cmode = "Compound"; break;
2303 }
2304
2305 if( !TheAISContext()->HasOpenedContext() ) {
5cbef0fe
S
2306 // il n'y a pas de Context local d'ouvert
2307 // on en ouvre un et on charge toutes les shapes displayees
2308 // on load tous les objets displayees et on Activate les objets de la liste
2309 AIS_ListOfInteractive ListOfIO;
2310 // on sauve dans une AISListOfInteractive tous les objets currents
2311 if (TheAISContext()->NbCurrents()>0 ){
2312 TheAISContext()->UnhilightCurrents(Standard_False);
2313
2314 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2315 ListOfIO.Append(TheAISContext()->Current() );
7fd59977 2316 }
2317 }
2318
2319 TheAISContext()->OpenLocalContext(Standard_False);
2320 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2321 it (GetMapOfAIS());
2322 while(it.More()){
2323 Handle(AIS_InteractiveObject) aIO =
2324 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2325 if (!aIO.IsNull())
2326 TheAISContext()->Load(aIO,0,Standard_False);
2327 it.Next();
2328 }
2329 // traitement des objets qui etaient currents dans le Contexte global
2330 if (!ListOfIO.IsEmpty() ) {
2331 // il y avait des objets currents
2332 AIS_ListIteratorOfListOfInteractive iter;
2333 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2334 Handle(AIS_InteractiveObject) aIO=iter.Value();
2335 TheAISContext()->Activate(aIO,aMode);
2336 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2337 }
2338 }
2339 else {
2340 // On applique le mode a tous les objets displayes
2341 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2342 it2 (GetMapOfAIS());
2343 while(it2.More()){
2344 Handle(AIS_InteractiveObject) aIO =
2345 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2346 if (!aIO.IsNull()) {
2347 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2348 TheAISContext()->Activate(aIO,aMode);
2349 }
2350 it2.Next();
2351 }
2352 }
2353
2354 }
2355
2356 else {
2357 // un Context local est deja ouvert
2358 // Traitement des objets du Context local
2359 if (TheAISContext()->NbSelected()>0 ){
2360 TheAISContext()->UnhilightSelected(Standard_False);
2361 // il y a des objets selected,on les parcourt
2362 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2363 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2364
2365
2366 if (HaveMode(aIO,aMode) ) {
2367 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2368 TheAISContext()->Deactivate(aIO,aMode);
2369 }
2370 else{
2371 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2372 TheAISContext()->Activate(aIO,aMode);
2373 }
2374
2375 }
2376 }
2377 else{
2378 // il n'y a pas d'objets selected
2379 // tous les objets diplayes sont traites
2380 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2381 it (GetMapOfAIS());
2382 while(it.More()){
2383 Handle(AIS_InteractiveObject) aIO =
2384 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2385 if (!aIO.IsNull()) {
2386 if (HaveMode(aIO,aMode) ) {
2387 di<<" Mode: "<<cmode<<" OFF pour "
2388 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2389 TheAISContext()->Deactivate(aIO,aMode);
2390 }
2391 else{
2392 di<<" Mode: "<<cmode<<" ON pour"
2393 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2394 TheAISContext()->Activate(aIO,aMode);
2395 }
2396 }
2397 it.Next();
2398 }
2399 }
2400 }
2401 }
2402 else if (HaveToSet && ThereIsName){
2403 Standard_Integer aMode=atoi(argv [2]);
2404 Handle(AIS_InteractiveObject) aIO =
2405 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2406
2407 if (!aIO.IsNull()) {
2408 const char *cmode="???";
2409
2410 switch (aMode) {
2411 case 0: cmode = "Shape"; break;
2412 case 1: cmode = "Vertex"; break;
2413 case 2: cmode = "Edge"; break;
2414 case 3: cmode = "Wire"; break;
2415 case 4: cmode = "Face"; break;
2416 case 5: cmode = "Shell"; break;
2417 case 6: cmode = "Solid"; break;
2418 case 7: cmode = "Compound"; break;
2419 }
2420
2421 if( !TheAISContext()->HasOpenedContext() ) {
2422 TheAISContext()->OpenLocalContext(Standard_False);
2423 // On charge tous les objets de la map
2424 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2425 while(it.More()){
2426 Handle(AIS_InteractiveObject) aShape=
2427 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2428 if (!aShape.IsNull())
2429 TheAISContext()->Load(aShape,0,Standard_False);
2430 it.Next();
2431 }
2432 TheAISContext()->Activate(aIO,aMode);
2433 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2434 }
2435
2436 else {
2437 // un Context local est deja ouvert
2438 if (HaveMode(aIO,aMode) ) {
2439 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2440 TheAISContext()->Deactivate(aIO,aMode);
2441 }
2442 else{
2443 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2444 TheAISContext()->Activate(aIO,aMode);
2445 }
2446 }
2447 }
2448 }
2449 }
2450 return 0;
2451
2452}
2453
2454
2455
2456//==============================================================================
2457// function : WhoAmI
2458// user : vState
2459//==============================================================================
2460void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2461
2462 // AIS_Datum
2463 if (theShape->Type()==AIS_KOI_Datum) {
2464 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2465 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2466 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2467 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2468 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2469 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2470 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2471 }
2472 // AIS_Shape
2473 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2474 // AIS_Dimentions et AIS_Relations
2475 else if (theShape->Type()==AIS_KOI_Relation) {
2476 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2477
2478 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2479 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2480 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2481 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2482 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2483 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2484 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2485 // AIS no repertorie.
2486 else {di<<" Type Unknown.";}
2487 }
2488}
2489
2490
2491
2492//==============================================================================
2493//function : VState
2494//purpose :
2495//Draw arg : vstate [nameA] ... [nameN]
2496//==============================================================================
2497static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2498{
7fd59977 2499 TheAISContext()->CloseAllContexts();
5cbef0fe
S
2500 const Standard_Boolean ThereIsArguments=(argc>=2);
2501 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
7fd59977 2502 // Debut...
2503 // ==================
2504 // Il y a un argument
2505 // ==================
5cbef0fe 2506 if (ThereIsArguments) {
7fd59977 2507 for (int cpt=1;cpt<argc;cpt++) {
2508 // Verification que lq piece est bien bindee.
2509 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2510 const Handle(AIS_InteractiveObject) theShape=
2511 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2512 (argv[cpt]));
2513 if (!theShape.IsNull()) {
2514 di<<argv[cpt];WhoAmI(theShape, di);
2515 if (TheAISContext()->IsDisplayed(theShape) ) {
2516 di<<" Displayed"<<"\n";
2517 }
2518 else {
2519 di<<" Not Displayed"<<"\n";
2520 }
2521 }
2522 }
2523 else {
2524 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2525 }
2526 }
2527 }
2528 else if (ThereIsCurrent ) {
2529 for (TheAISContext() -> InitCurrent() ;
2530 TheAISContext() -> MoreCurrent() ;
2531 TheAISContext() ->NextCurrent() )
2532 {
2533 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2534 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2535 if (TheAISContext()->IsDisplayed(theShape) ) {
2536 di<<" Displayed"<<"\n";
2537 }
2538 else {
2539 di<<" Not Displayed"<<"\n";
2540 }
2541
2542 }
2543 }
2544 else {
2545 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2546 it(GetMapOfAIS());
2547 while ( it.More() ) {
2548 Handle(AIS_InteractiveObject) theShape =
2549 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2550 if (!theShape.IsNull()) {
2551 di<<it.Key2().ToCString();
2552 WhoAmI(theShape, di);
2553 if (TheAISContext()->IsDisplayed(theShape) ) {
2554 di<<" Displayed"<<"\n";
2555 }
2556 else {
2557 di<<" Not Displayed"<<"\n";
2558 }
2559 }
2560 it.Next();
2561 }
2562 }
2563
2564 return 0;
2565}
2566
2567
2568//=======================================================================
2569//function : PickObjects
2570//purpose :
2571//=======================================================================
2572Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2573 const AIS_KindOfInteractive TheType,
2574 const Standard_Integer TheSignature,
2575 const Standard_Integer MaxPick)
2576{
2577 Handle(AIS_InteractiveObject) IO;
2578 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2579
2580 // step 1: prepare the data
4952a30a 2581 if(curindex !=0){
7fd59977 2582 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2583 TheAISContext()->AddFilter(F1);
2584 }
2585
2586 // step 2 : wait for the selection...
2587// Standard_Boolean IsGood (Standard_False);
2588// Standard_Integer NbPick(0);
2589 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2590 Standard_Integer NbPickFail(0);
2591 Standard_Integer argccc = 5;
2592 const char *bufff[] = { "A", "B", "C","D", "E" };
2593 const char **argvvv = (const char **) bufff;
2594
2595
2596 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2597 while(ViewerMainLoop(argccc,argvvv)){}
2598 Standard_Integer NbStored = TheAISContext()->NbSelected();
2599 if((unsigned int ) NbStored != NbPickGood)
2600 NbPickGood= NbStored;
2601 else
2602 NbPickFail++;
2603 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2604 }
2605
2606 // step3 get result.
2607
2608 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2609
2610 Standard_Integer i(0);
2611 for(TheAISContext()->InitSelected();
2612 TheAISContext()->MoreSelected();
2613 TheAISContext()->NextSelected()){
2614 i++;
2615 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2616 arr->SetValue(i,IO2);
2617 }
2618
2619
2620 if(curindex>0)
2621 TheAISContext()->CloseLocalContext(curindex);
2622
2623 return Standard_True;
2624}
2625
2626
2627//=======================================================================
2628//function : PickObject
2629//purpose :
2630//=======================================================================
2631Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2632 const Standard_Integer TheSignature,
2633 const Standard_Integer MaxPick)
2634{
2635 Handle(AIS_InteractiveObject) IO;
2636 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2637
2638 // step 1: prepare the data
2639
4952a30a 2640 if(curindex !=0){
7fd59977 2641 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2642 TheAISContext()->AddFilter(F1);
2643 }
2644
2645 // step 2 : wait for the selection...
2646 Standard_Boolean IsGood (Standard_False);
2647 Standard_Integer NbPick(0);
2648 Standard_Integer argccc = 5;
2649 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2650 const char **argvvv = (const char **) bufff;
2651
2652
2653 while(!IsGood && NbPick<= MaxPick){
2654 while(ViewerMainLoop(argccc,argvvv)){}
2655 IsGood = (TheAISContext()->NbSelected()>0) ;
2656 NbPick++;
2657 cout<<"Nb Pick :"<<NbPick<<endl;
2658 }
2659
2660
2661 // step3 get result.
2662 if(IsGood){
2663 TheAISContext()->InitSelected();
2664 IO = TheAISContext()->SelectedInteractive();
2665 }
2666
4952a30a 2667 if(curindex!=0)
7fd59977 2668 TheAISContext()->CloseLocalContext(curindex);
2669 return IO;
2670}
2671
2672//=======================================================================
2673//function : PickShape
2674//purpose : First Activate the rightmode + Put Filters to be able to
2675// pick objets that are of type <TheType>...
2676//=======================================================================
2677
2678TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2679 const Standard_Integer MaxPick)
2680{
2681
2682 // step 1: prepare the data
2683
2684 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2685 TopoDS_Shape result;
2686
2687 if(TheType==TopAbs_SHAPE){
2688 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2689 TheAISContext()->AddFilter(F1);
2690 }
2691 else{
2692 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2693 TheAISContext()->AddFilter(TF);
2694 TheAISContext()->ActivateStandardMode(TheType);
2695
2696 }
2697
2698
2699 // step 2 : wait for the selection...
2700 Standard_Boolean NoShape (Standard_True);
2701 Standard_Integer NbPick(0);
2702 Standard_Integer argccc = 5;
2703 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2704 const char **argvvv = (const char **) bufff;
2705
2706
2707 while(NoShape && NbPick<= MaxPick){
2708 while(ViewerMainLoop(argccc,argvvv)){}
2709 NoShape = (TheAISContext()->NbSelected()==0) ;
2710 NbPick++;
2711 cout<<"Nb Pick :"<<NbPick<<endl;
2712 }
2713
2714 // step3 get result.
2715
2716 if(!NoShape){
2717
2718 TheAISContext()->InitSelected();
2719 if(TheAISContext()->HasSelectedShape())
2720 result = TheAISContext()->SelectedShape();
2721 else{
2722 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2723 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2724 }
2725 }
2726
2727 if(curindex>0)
2728 TheAISContext()->CloseLocalContext(curindex);
2729
2730 return result;
2731}
2732
2733
2734//=======================================================================
2735//function : PickShapes
2736//purpose :
2737//=======================================================================
2738Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2739 Handle(TopTools_HArray1OfShape)& thearr,
2740 const Standard_Integer MaxPick)
2741{
2742
2743 Standard_Integer Taille = thearr->Length();
2744 if(Taille>1)
2745 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2746
2747 // step 1: prepare the data
2748 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2749 if(TheType==TopAbs_SHAPE){
2750 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2751 TheAISContext()->AddFilter(F1);
2752 }
2753 else{
2754 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2755 TheAISContext()->AddFilter(TF);
2756 TheAISContext()->ActivateStandardMode(TheType);
2757
2758 }
2759
2760 // step 2 : wait for the selection...
2761
2762 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2763 Standard_Integer NbPickFail(0);
2764 Standard_Integer argccc = 5;
2765 const char *bufff[] = { "A", "B", "C","D", "E" };
2766 const char **argvvv = (const char **) bufff;
2767
2768
2769 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2770 while(ViewerMainLoop(argccc,argvvv)){}
2771 Standard_Integer NbStored = TheAISContext()->NbSelected();
2772 if((unsigned int ) NbStored != NbPickGood)
2773 NbPickGood= NbStored;
2774 else
2775 NbPickFail++;
2776 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2777 }
2778
2779 // step3 get result.
2780
2781 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2782
2783 Standard_Integer i(0);
2784 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2785 i++;
2786 if(TheAISContext()->HasSelectedShape())
2787 thearr->SetValue(i,TheAISContext()->SelectedShape());
2788 else{
2789 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2790 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2791 }
2792 }
2793
2794 TheAISContext()->CloseLocalContext(curindex);
2795 return Standard_True;
2796}
2797
2798
2799//=======================================================================
2800//function : VPickShape
2801//purpose :
2802//=======================================================================
2803static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2804{
2805 TopoDS_Shape PickSh;
2806 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2807
2808 if(argc==1)
2809 theType = TopAbs_SHAPE;
2810 else{
2811 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2812 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2813 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2814 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2815 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2816 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2817 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2818 }
2819
2820 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2821 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2822
2823 TCollection_AsciiString name;
2824
2825
2826 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2827 if(NbToPick==1){
2828 PickSh = ViewerTest::PickShape(theType);
2829
2830 if(PickSh.IsNull())
2831 return 1;
2832 if(argc>2){
2833 name += argv[2];
2834 }
2835 else{
2836
2837 if(!PickSh.IsNull()){
2838 nbOfSub[Standard_Integer(theType)]++;
2839 name += "Picked_";
2840 name += nameType[Standard_Integer(theType)];
2841 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2842 name +="_";
2843 name+=indxstring;
2844 }
2845 }
2846 // si on avait une petite methode pour voir si la shape
2847 // est deja dans la Double map, ca eviterait de creer....
2848 DBRep::Set(name.ToCString(),PickSh);
2849
2850 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2851 GetMapOfAIS().Bind(newsh, name);
2852 TheAISContext()->Display(newsh);
2853 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2854 }
2855
2856 // Plusieurs objets a picker, vite vite vite....
2857 //
2858 else{
2859 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2860 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2861 if(ViewerTest::PickShapes(theType,arr)){
2862 for(Standard_Integer i=1;i<=NbToPick;i++){
2863 PickSh = arr->Value(i);
2864 if(!PickSh.IsNull()){
2865 if(autonaming){
2866 nbOfSub[Standard_Integer(theType)]++;
2867 name.Clear();
2868 name += "Picked_";
2869 name += nameType[Standard_Integer(theType)];
2870 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2871 name +="_";
2872 name+=indxstring;
2873 }
2874 }
2875 else
2876 name = argv[1+i];
2877
2878 DBRep::Set(name.ToCString(),PickSh);
2879 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2880 GetMapOfAIS().Bind(newsh, name);
2881 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2882 TheAISContext()->Display(newsh);
2883
2884 }
2885 }
2886 }
2887 return 0;
2888
2889}
2890
2891
2892//=======================================================================
2893//function : VPickObject
2894//purpose : filters can be set (type of Object to pick....
2895//
2896//=======================================================================
2897// Unused :
2898#ifdef DEB
2899static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
2900{
2901 // preparation de la nomination automatique
2902 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
2903// static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
2904
2905/* TCollection_AsciiString name;
2906
2907 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2908 if(NbToPick==1){
2909 PickSh = ViewerTest::PickObject(theType);
2910
2911 if(PickSh.IsNull())
2912 return 1;
2913 if(argc>2){
2914 name += argv[2];
2915 }
2916 else{
2917
2918 if(!PickSh.IsNull()){
2919 nbOfSub[Standard_Integer(theType)]++;
2920 name += "Picked_";
2921 name += nameType[Standard_Integer(theType)];
2922 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2923 name +="_";
2924 name+=indxstring;
2925 }
2926 }
2927 // si on avait une petite methode pour voir si la shape
2928 // est deja dans la Double map, ca eviterait de creer....
2929 DBRep::Set(name.ToCString(),PickSh);
2930
2931 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2932 GetMapOfAIS().Bind(newsh, name);
2933 TheAISContext()->Display(newsh);
2934 cout<<"Nom de la shape pickee : "<<name<<endl;
2935 }
2936
2937 // Plusieurs objets a picker, vite vite vite....
2938 //
2939 else{
2940 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2941 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2942 if(ViewerTest::PickShapes(theType,arr)){
2943 for(Standard_Integer i=1;i<=NbToPick;i++){
2944 PickSh = arr->Value(i);
2945 if(!PickSh.IsNull()){
2946 if(autonaming){
2947 nbOfSub[Standard_Integer(theType)]++;
2948 name.Clear();
2949 name += "Picked_";
2950 name += nameType[Standard_Integer(theType)];
2951 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2952 name +="_";
2953 name+=indxstring;
2954 }
2955 }
2956 else
2957 name = argv[1+i];
2958
2959 DBRep::Set(name.ToCString(),PickSh);
2960 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2961 GetMapOfAIS().Bind(newsh, name);
2962 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
2963 TheAISContext()->Display(newsh);
2964
2965 }
2966 }
2967 }
2968 */
2969 return 0;
2970}
2971#endif
2972
2973//=======================================================================
2974//function : list of known objects
2975//purpose :
2976//=======================================================================
2977static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2978{
2979 // 1234567890 12345678901234567 123456789
2980 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2981 TCollection_AsciiString BlankLine(64,'_');
2982 Standard_Integer i ;
2983
2984 di<<"/n"<<BlankLine.ToCString()<<"\n";
2985
2986 for( i =0;i<=2;i++)
2987 Colum[i].Center(20,' ');
2988 for(i=0;i<=2;i++)
2989 di<<"|"<<Colum[i].ToCString();
2990 di<<"|"<<"\n";
2991
2992 di<<BlankLine.ToCString()<<"\n";
2993
2994 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
2995 const char ** names = GetTypeNames();
2996
2997 TCollection_AsciiString curstring;
2998 TCollection_AsciiString curcolum[3];
2999
3000
3001 // les objets de type Datum..
3002 curcolum[1]+="Datum";
3003 for(i =0;i<=6;i++){
3004 curcolum[0].Clear();
3005 curcolum[0] += names[i];
3006
3007 curcolum[2].Clear();
3008 curcolum[2]+=TCollection_AsciiString(i+1);
3009
3010 for(Standard_Integer j =0;j<=2;j++){
3011 curcolum[j].Center(20,' ');
3012 di<<"|"<<curcolum[j].ToCString();
3013 }
3014 di<<"|"<<"\n";
3015 }
3016 di<<BlankLine.ToCString()<<"\n";
3017
3018 // les objets de type shape
3019 curcolum[1].Clear();
3020 curcolum[1]+="Shape";
3021 curcolum[1].Center(20,' ');
3022
3023 for(i=0;i<=2;i++){
3024 curcolum[0].Clear();
3025 curcolum[0] += names[7+i];
3026 curcolum[2].Clear();
3027 curcolum[2]+=TCollection_AsciiString(i);
3028
3029 for(Standard_Integer j =0;j<=2;j++){
3030 curcolum[j].Center(20,' ');
3031 di<<"|"<<curcolum[j].ToCString();
3032 }
3033 di<<"|"<<"\n";
3034 }
3035 di<<BlankLine.ToCString()<<"\n";
3036 // les IO de type objet...
3037 curcolum[1].Clear();
3038 curcolum[1]+="Object";
3039 curcolum[1].Center(20,' ');
3040 for(i=0;i<=1;i++){
3041 curcolum[0].Clear();
3042 curcolum[0] += names[10+i];
3043 curcolum[2].Clear();
3044 curcolum[2]+=TCollection_AsciiString(i);
3045
3046 for(Standard_Integer j =0;j<=2;j++){
3047 curcolum[j].Center(20,' ');
3048 di<<"|"<<curcolum[j].ToCString();
3049 }
3050 di<<"|"<<"\n";
3051 }
3052 di<<BlankLine.ToCString()<<"\n";
3053 // les contraintes et dimensions.
3054 // pour l'instant on separe juste contraintes et dimensions...
3055 // plus tard, on detaillera toutes les sortes...
3056 curcolum[1].Clear();
3057 curcolum[1]+="Relation";
3058 curcolum[1].Center(20,' ');
3059 for(i=0;i<=1;i++){
3060 curcolum[0].Clear();
3061 curcolum[0] += names[12+i];
3062 curcolum[2].Clear();
3063 curcolum[2]+=TCollection_AsciiString(i);
3064
3065 for(Standard_Integer j =0;j<=2;j++){
3066 curcolum[j].Center(20,' ');
3067 di<<"|"<<curcolum[j].ToCString();
3068 }
3069 di<<"|"<<"\n";
3070 }
3071 di<<BlankLine.ToCString()<<"\n";
3072
3073
3074 return 0;
3075}
3076
3077
3078static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3079{
4952a30a 3080 if(argc!=2) return 1;
7fd59977 3081
3082 AIS_KindOfInteractive TheType;
3083 Standard_Integer TheSign(-1);
3084 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3085
3086
3087 AIS_ListOfInteractive LIO;
3088
3089 // en attendant l'amelioration ais pour les dimensions...
3090 //
3091 Standard_Integer dimension_status(-1);
3092 if(TheType==AIS_KOI_Relation){
3093 dimension_status = TheSign ==1 ? 1 : 0;
3094 TheSign=-1;
3095 }
3096
3097 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3098 Handle(AIS_InteractiveObject) curio;
3099 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3100 curio = it.Value();
3101
3102 if(dimension_status == -1)
3103 TheAISContext()->Erase(curio,Standard_False);
3104 else {
3105 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3106 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3107 (dimension_status==1 && KOD != AIS_KOD_NONE))
3108 TheAISContext()->Erase(curio,Standard_False);
3109 }
3110 }
3111 TheAISContext()->UpdateCurrentViewer();
3112 return 0;
3113}
3114static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3115{
3116 if(argc!=2) return 1;
3117
3118 AIS_KindOfInteractive TheType;
3119 Standard_Integer TheSign(-1);
3120 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3121
3122 // en attendant l'amelioration ais pour les dimensions...
3123 //
3124 Standard_Integer dimension_status(-1);
3125 if(TheType==AIS_KOI_Relation){
3126 dimension_status = TheSign ==1 ? 1 : 0;
3127 TheSign=-1;
3128 }
3129
3130 AIS_ListOfInteractive LIO;
3131 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3132 Handle(AIS_InteractiveObject) curio;
3133 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3134 curio = it.Value();
3135 if(dimension_status == -1)
3136 TheAISContext()->Display(curio,Standard_False);
3137 else {
3138 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3139 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3140 (dimension_status==1 && KOD != AIS_KOD_NONE))
3141 TheAISContext()->Display(curio,Standard_False);
3142 }
3143
3144 }
3145
3146 TheAISContext()->UpdateCurrentViewer();
3147 return 0;
3148}
3149
3150//==============================================================================
3151//function : VSetTransMode
3152//purpose :
3153//Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3154//==============================================================================
3155
3156static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3157 // Verification des arguments
3158 if ( a3DView().IsNull() ) {
3159 ViewerTest::ViewerInit();
3160 di << "La commande vinit n'a pas ete appele avant" << "\n";
3161 }
3162
3163 if ( argc < 3 || argc > 8 ) {
3164 di << argv[0] << " Invalid number of arguments" << "\n";
3165 return 1;
3166 }
3167
3168 TCollection_AsciiString shapeName;
3169 shapeName = argv[1];
3170 Standard_Integer persFlag1 = atoi(argv[2]);
3171 Standard_Integer persFlag2 = 0;
3172 Standard_Integer persFlag3 = 0;
3173 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3174 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3175 persFlag2 = atoi(argv[3]);
3176 }
3177 if ( argc == 5 || argc == 8 ) {
3178 persFlag3 = atoi(argv[4]);
3179 }
3180 if ( argc >= 6 ) {
3181 origin.SetX( atof(argv[argc - 3]) );
3182 origin.SetY( atof(argv[argc - 2]) );
3183 origin.SetZ( atof(argv[argc - 1]) );
3184 }
3185
3186 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3187 Standard_Boolean IsDatum = Standard_False;
3188 Handle(Standard_Transient) anObj;
3189 if ( IsBound ) {
3190 anObj = GetMapOfAIS().Find2(shapeName);
3191 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3192 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3193 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3194 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3195 di << argv[0] << " All persistence modifiers were removed" << "\n";
3196 }
3197 } else {
3198 di << argv[0] << " Wrong object type" << "\n";
3199 return 1;
3200 }
3201 } else { // Create the AIS_Shape from a name
3202 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3203 if ( !aShape.IsNull() ) {
3204 GetMapOfAIS().Bind( aShape, shapeName );
3205 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3206 TheAISContext()->Display( aShape, Standard_False );
3207 } else {
3208 di << argv[0] << " Object not found" << "\n";
3209 return 1;
3210 }
3211 }
3212
3213 // Upadate the screen and redraw the view
3214 TheAISContext()->UpdateCurrentViewer();
3215 return 0;
3216}
3217
3218static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3219{
3220 ifstream s(a[1]);
3221 BRep_Builder builder;
3222 TopoDS_Shape shape;
3223 BRepTools::Read(shape, s, builder);
3224 DBRep::Set(a[1], shape);
3225 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3226 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3227 Ctx->Display(ais);
3228 return 0;
3229}
3230//============================================================================
3231#include <AIS2D_InteractiveContext.hxx>
3232#include <HLRAlgo_Projector.hxx>
3233#include <Prs3d_Projector.hxx>
3234#include <AIS2D_ProjShape.hxx>
3235#include <gp_Ax2.hxx>
3236#include <gp.hxx>
3237Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3238{
3239
3240 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3241 /////////////////////
3242 TopoDS_Shape aShape = DBRep::Get(a[1]);
3243 aContext2D->EraseAll(Standard_True);
3244 Standard_Integer aPolyAlgo = 0;
3245 Standard_Boolean IsPoly = Standard_False;
3246 gp_Ax2 anAx2 = gp::XOY();
3247
3248 //if(n > 2) aPolyAlgo = atoi(a[2]);
3249
3250 //IsPoly = aPolyAlgo > 0;
3251
3252 TopoDS_Shape aResult = aShape;
3253
3254
3255 if (n == 11)
3256 {
3257 Standard_Real x = atof(a[2]);
3258 Standard_Real y = atof(a[3]);
3259 Standard_Real z = atof(a[4]);
3260
3261 Standard_Real dx = atof(a[5]);
3262 Standard_Real dy = atof(a[6]);
3263 Standard_Real dz = atof(a[7]);
3264
3265 Standard_Real dx1 = atof(a[8]);
3266 Standard_Real dy1 = atof(a[9]);
3267 Standard_Real dz1 = atof(a[10]);
3268
3269 gp_Pnt anOrigin (x, y, z);
3270 gp_Dir aNormal (dx, dy, dz);
3271 gp_Dir aDX (dx1, dy1, dz1);
3272 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3273 }
3274
3275
3276 HLRAlgo_Projector aProjector(anAx2);
3277
3278 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3279
3280 //aProjector = aProjector_t.Projector();
3281
3282 Handle(AIS2D_ProjShape) myDisplayableShape =
3283 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3284
3285 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3286 Standard_False, Standard_True, Standard_False);
3287
3288 myDisplayableShape->Add( aResult );
3289
3290
3291 aContext2D->Display( myDisplayableShape,Standard_True );
3292 aContext2D->UpdateCurrentViewer();
3293
3294 return 0;
3295}
3296
3297Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3298{
3299
3300 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3301 /////////////////////
3302 TopoDS_Shape aShape = DBRep::Get(a[1]);
3303 aContext2D->EraseAll(Standard_True);
3304 Standard_Integer aPolyAlgo = 0;
3305 Standard_Boolean IsPoly = Standard_True;
3306 gp_Ax2 anAx2 = gp::XOY();
3307
3308 //if(n > 2) aPolyAlgo = atoi(a[2]);
3309
3310 //IsPoly = aPolyAlgo > 0;
3311
3312 TopoDS_Shape aResult = aShape;
3313
3314
3315 if (n == 11)
3316 {
3317 Standard_Real x = atof(a[2]);
3318 Standard_Real y = atof(a[3]);
3319 Standard_Real z = atof(a[4]);
3320
3321 Standard_Real dx = atof(a[5]);
3322 Standard_Real dy = atof(a[6]);
3323 Standard_Real dz = atof(a[7]);
3324
3325 Standard_Real dx1 = atof(a[8]);
3326 Standard_Real dy1 = atof(a[9]);
3327 Standard_Real dz1 = atof(a[10]);
3328
3329 gp_Pnt anOrigin (x, y, z);
3330 gp_Dir aNormal (dx, dy, dz);
3331 gp_Dir aDX (dx1, dy1, dz1);
3332 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3333 }
3334
3335
3336 HLRAlgo_Projector aProjector(anAx2);
3337
3338 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3339
3340 //aProjector = aProjector_t.Projector();
3341
3342 Handle(AIS2D_ProjShape) myDisplayableShape =
3343 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3344
3345 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3346 Standard_False, Standard_True, Standard_False);
3347
3348 myDisplayableShape->Add( aResult );
3349
3350
3351 aContext2D->Display( myDisplayableShape,Standard_True );
3352 aContext2D->UpdateCurrentViewer();
3353
3354 return 0;
3355}
3356
3357//==============================================================================
3358//function : ViewerTest::Commands
3359//purpose : Add all the viewer command in the Draw_Interpretor
3360//==============================================================================
3361
3362void ViewerTest::Commands(Draw_Interpretor& theCommands)
3363{
3364 ViewerTest::ViewerCommands(theCommands);
3365 ViewerTest::RelationCommands(theCommands);
3366 ViewerTest::ObjectCommands(theCommands);
3367 ViewerTest::FilletCommands(theCommands);
3368 ViewerTest::VoxelCommands(theCommands);
3369
3370 const char *group = "AIS_Display";
3371
3372 // display
3373
3374 theCommands.Add("vdisplay",
3375 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3376 __FILE__,VDisplay2,group);
3377
3378 theCommands.Add("verase",
3379 "verase : verase2 [name1] ... [name n] ",
3380 __FILE__,VErase2,group);
3381
3382 theCommands.Add("vdonly",
3383 "vdonly : vdonly2 [name1] ... [name n]",
3384 __FILE__,VDonly2,group);
3385
3386 theCommands.Add("vdisplayall",
3387 "vdisplayall : vdisplayall",
3388 __FILE__,VDisplayAll,group);
3389
3390 theCommands.Add("veraseall",
3391 "veraseall : veraseall ",
3392 __FILE__,VEraseAll,group);
3393
3394 theCommands.Add("verasetype",
3395 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3396 __FILE__,VEraseType,group);
3397
3398 theCommands.Add("vdisplaytype",
3399 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3400 __FILE__,VDisplayType,group);
3401
3402 theCommands.Add("vdisplaymode",
3403 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3404 __FILE__,VDispMode,group);
3405
3406 theCommands.Add("verasemode",
3407 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3408 __FILE__,VDispMode,group);
3409
3410 theCommands.Add("vsetdispmode",
3411 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3412 __FILE__,VDispMode,group);
3413
3414 theCommands.Add("vunsetdispmode",
3415 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3416 __FILE__,VDispMode,group);
3417
3418 theCommands.Add("vdir",
3419 "vdir",
3420 __FILE__,VDebug,group);
3421
3422 theCommands.Add("vdump",
3423 "<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",
3424 __FILE__,VDump,group);
3425
3426 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3427 __FILE__,VSubInt,group);
3428
3429 theCommands.Add("vsetcolor",
3430 "vsetcolor : vsetcolor [name of shape] ColorName",
3431 __FILE__,VColor2,group);
3432
3433 theCommands.Add("vunsetcolor",
3434 "vunsetcolor : vunsetcolor [name of shape] ",
3435 __FILE__,VColor2,group);
3436
3437 theCommands.Add("vsettransparency",
3438 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3439 __FILE__,VTransparency,group);
3440
3441 theCommands.Add("vunsettransparency",
3442 "vunsettransparency : vtransparency [name of shape]",
3443 __FILE__,VTransparency,group);
3444
3445 theCommands.Add("vsetmaterial",
3446 "vmaterial : vmaterial [name of shape] MaterialName",
3447 __FILE__,VMaterial,group);
3448
3449 theCommands.Add("vunsetmaterial",
3450 "vmaterial : vmaterial [name of shape]",
3451 __FILE__,VMaterial,group);
3452
3453 theCommands.Add("vsetwidth",
3454 "vsetwidth : vwidth [name of shape] width(0->10)",
3455 __FILE__,VWidth,group);
3456
3457 theCommands.Add("vunsetwidth",
3458 "vunsetwidth : vwidth [name of shape]",
3459 __FILE__,VWidth,group);
3460
3461 theCommands.Add("vardis",
3462 "vardis : display activeareas",
3463 __FILE__,VDispAreas,group);
3464
3465 theCommands.Add("varera",
3466 "varera : erase activeareas",
3467 __FILE__,VClearAreas,group);
3468
3469 theCommands.Add("vsensdis",
3470 "vardisp : display active entities",
3471 __FILE__,VDispSensi,group);
3472 theCommands.Add("vsensera",
3473 "vardisp : erase active entities",
3474 __FILE__,VClearSensi,group);
3475
3476 theCommands.Add("vperf",
3477 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3478 __FILE__,VPerf,group);
3479
3480 theCommands.Add("vanimation",
3481 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3482 __FILE__,VAnimation,group);
3483
3484 theCommands.Add("vsetshading",
3485 "vsetshading : vsetshading name Quality(default=0.0008) ",
3486 __FILE__,VShading,group);
3487
3488 theCommands.Add("vunsetshading",
3489 "vunsetshading :vunsetshading name ",
3490 __FILE__,VShading,group);
3491
3492 theCommands.Add("vtexture",
3493 "'vtexture NameOfShape TextureFile' \n \
3494 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3495 or 'vtexture NameOfShape ?' to list available textures\n \
3496 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3497 __FILE__,VTexture,group);
3498
3499 theCommands.Add("vtexscale",
3500 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3501 or 'vtexscale NameOfShape ScaleUV' \n \
3502 or 'vtexscale NameOfShape' to disable scaling\n ",
3503 __FILE__,VTexture,group);
3504
3505 theCommands.Add("vtexorigin",
3506 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3507 or 'vtexorigin NameOfShape UVOrigin' \n \
3508 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3509 __FILE__,VTexture,group);
3510
3511 theCommands.Add("vtexrepeat",
3512 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3513 or 'vtexrepeat NameOfShape UVRepeat \n \
3514 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3515 VTexture,group);
3516
3517 theCommands.Add("vtexdefault",
3518 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3519 VTexture,group);
3520
3521 theCommands.Add("vsetam",
3522 "vsetActivatedModes: vsetam mode(1->7) ",
3523 __FILE__,VActivatedMode,group);
3524
3525 theCommands.Add("vunsetam",
3526 "vunsetActivatedModes: vunsetam ",
3527 __FILE__,VActivatedMode,group);
3528
3529 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3530 __FILE__,VState,group);
3531
3532 theCommands.Add("vpickshapes",
3533 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3534 __FILE__,VPickShape,group);
3535
3536 theCommands.Add("vtypes",
3537 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3538 VIOTypes,group);
3539
3540 theCommands.Add("vsettransmode",
3541 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3542 __FILE__,VSetTransMode,group);
3543
3544 theCommands.Add("vr", "vr : reading of the shape",
3545 __FILE__,vr, group);
3546
3547 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3548 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3549
3550}
3551
3552//=====================================================================
3553//========================= for testing Draft and Rib =================
3554//=====================================================================
3555#include <BRepOffsetAPI_MakeThickSolid.hxx>
3556#include <DBRep.hxx>
3557#include <TopoDS_Face.hxx>
3558#include <gp_Pln.hxx>
3559#include <AIS_KindOfSurface.hxx>
3560#include <BRepOffsetAPI_DraftAngle.hxx>
3561#include <Precision.hxx>
3562#include <BRepAlgo.hxx>
3563#include <OSD_Environment.hxx>
3564#include <DrawTrSurf.hxx>
3565//#include <DbgTools.hxx>
3566//#include <FeatAlgo_MakeLinearForm.hxx>
3567
3568
3569
3570
3571//=======================================================================
3572//function : IsValid
3573//purpose :
3574//=======================================================================
3575static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3576 const TopoDS_Shape& theResult,
3577 const Standard_Boolean closedSolid,
3578 const Standard_Boolean GeomCtrl)
3579{
3580 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3581 TCollection_AsciiString checkValid = check.Value();
3582 Standard_Boolean ToCheck = Standard_True;
3583 if (!checkValid.IsEmpty()) {
3584#ifdef DEB
3585 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3586#endif
3587 if ( checkValid=="true" || checkValid=="TRUE" ) {
3588 ToCheck= Standard_False;
3589 }
3590 } else {
3591#ifdef DEB
3592 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3593#endif
3594 }
3595 Standard_Boolean IsValid = Standard_True;
3596 if (ToCheck)
3597 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3598 return IsValid;
3599
3600}
3601
3602//===============================================================================
3603// TDraft : test draft, uses AIS Viewer
3604// Solid Face Plane Angle Reverse
3605//===============================================================================
3606static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3607{
3608 if (argc < 5) return 1;
3609// argv[1] - TopoDS_Shape Solid
3610// argv[2] - TopoDS_Shape Face
3611// argv[3] - TopoDS_Shape Plane
3612// argv[4] - Standard_Real Angle
3613// argv[5] - Standard_Integer Reverse
3614
3615// sprintf(prefix, argv[1]);
3616 Standard_Real anAngle = 0;
3617 Standard_Boolean Rev = Standard_False;
3618 Standard_Integer rev = 0;
3619 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3620 TopoDS_Shape face = GetShapeFromName(argv[2]);
3621 TopoDS_Face Face = TopoDS::Face(face);
3622 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3623 if (Plane.IsNull ()) {
3624 di << "TEST : Plane is NULL" << "\n";
3625 return 1;
3626 }
3627 anAngle = atof(argv[4]);
c6541a0c 3628 anAngle = 2*M_PI * anAngle / 360.0;
7fd59977 3629 gp_Pln aPln;
3630 Handle( Geom_Surface )aSurf;
3631 AIS_KindOfSurface aSurfType;
3632 Standard_Real Offset;
3633 gp_Dir aDir;
3634 if(argc > 4) { // == 5
3635 rev = atoi(argv[5]);
3636 Rev = (rev)? Standard_True : Standard_False;
3637 }
3638
3639 TopoDS_Face face2 = TopoDS::Face(Plane);
3640 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3641 {
3642 di << "TEST : Can't find plane" << "\n";
3643 return 1;
3644 }
3645
3646 aDir = aPln.Axis().Direction();
3647 if (!aPln.Direct())
3648 aDir.Reverse();
3649 if (Plane.Orientation() == TopAbs_REVERSED)
3650 aDir.Reverse();
3651 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3652
3653 BRepOffsetAPI_DraftAngle Draft (Solid);
3654
3655 if(Abs(anAngle)< Precision::Angular()) {
3656 di << "TEST : NULL angle" << "\n";
3657 return 1;}
3658
3659 if(Rev) anAngle = - anAngle;
3660 Draft.Add (Face, aDir, anAngle, aPln);
3661 Draft.Build ();
3662 if (!Draft.IsDone()) {
3663 di << "TEST : Draft Not DONE " << "\n";
3664 return 1;
3665 }
3666 TopTools_ListOfShape Larg;
3667 Larg.Append(Solid);
3668 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3669 di << "TEST : DesignAlgo returns Not valid" << "\n";
3670 return 1;
3671 }
3672
3673 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3674 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3675
3676 if ( !ais.IsNull() ) {
3677 ais->SetColor(DEFAULT_COLOR);
3678 ais->SetMaterial(DEFAULT_MATERIAL);
3679 // Display the AIS_Shape without redraw
3680 Ctx->Display(ais, Standard_False);
3681
3682 const char *Name = "draft1";
3683 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3684 if (IsBound) {
3685 Handle(AIS_InteractiveObject) an_object =
3686 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3687 if (!an_object.IsNull()) {
3688 Ctx->Remove(an_object,
3689 Standard_True) ;
3690 GetMapOfAIS().UnBind2(Name) ;
3691 }
3692 }
3693 GetMapOfAIS().Bind(ais, Name);
3694// DBRep::Set("draft", ais->Shape());
3695 }
3696 Ctx->Display(ais, Standard_True);
3697 return 0;
3698}
3699
3700
3701
3702//============================================================================
3703// MyCommands
3704//============================================================================
3705void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3706{
3707
3708 DrawTrSurf::BasicCommands(theCommands);
3709 const char* group = "Check Features Operations commands";
3710
3711 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3712 __FILE__,
3713 &TDraft,group); //Draft_Modification
3714}
3715
3716//==============================================================================
3717// ViewerTest::Factory
3718//==============================================================================
3719void ViewerTest::Factory(Draw_Interpretor& theDI)
3720{
3721 // definition of Viewer Command
3722 ViewerTest::Commands(theDI);
3723 ViewerTest::AviCommands(theDI);
3724 Viewer2dTest::Commands(theDI);
3725#ifdef DEB
3726 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3727#endif
3728}
3729
3730// Declare entry point PLUGINFACTORY
3731DPLUGIN(ViewerTest)