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