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