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