0025298: New option of BRepOffsetAPI_MakeOffset algorithm: processing of sharp corner...
[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>
900f7229 32#include <TColStd_HSequenceOfAsciiString.hxx>
7fd59977 33#include <OSD_Timer.hxx>
34#include <Geom_Axis2Placement.hxx>
35#include <Geom_Axis1Placement.hxx>
36#include <gp_Trsf.hxx>
37#include <TopExp_Explorer.hxx>
38#include <BRepAdaptor_Curve.hxx>
39#include <StdSelect_ShapeTypeFilter.hxx>
40#include <AIS.hxx>
99c56d44 41#include <AIS_Drawer.hxx>
ad3217cd 42#include <AIS_ColoredShape.hxx>
7fd59977 43#include <AIS_InteractiveObject.hxx>
44#include <AIS_Trihedron.hxx>
45#include <AIS_Axis.hxx>
46#include <AIS_Relation.hxx>
47#include <AIS_TypeFilter.hxx>
48#include <AIS_SignatureFilter.hxx>
cb78155f 49#include <AIS_LocalContext.hxx>
7fd59977 50#include <AIS_ListOfInteractive.hxx>
51#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 52#include <Aspect_InteriorStyle.hxx>
34db9c00 53#include <Aspect_Window.hxx>
99c56d44 54#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 55#include <Graphic3d_AspectLine3d.hxx>
392ac980 56#include <Graphic3d_TextureRoot.hxx>
692613e5 57#include <Image_AlienPixMap.hxx>
99c56d44 58#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 59#include <Prs3d_IsoAspect.hxx>
cb78155f 60#include <TopTools_MapOfShape.hxx>
4e18052b 61#include <ViewerTest_AutoUpdater.hxx>
7fd59977 62
7fd59977 63#include <stdio.h>
7fd59977 64
65#include <Draw_Interpretor.hxx>
66#include <TCollection_AsciiString.hxx>
67#include <Draw_PluginMacro.hxx>
7fd59977 68
69// avoid warnings on 'extern "C"' functions returning C++ classes
70#ifdef WNT
71#define _CRT_SECURE_NO_DEPRECATE
72#pragma warning(4:4190)
73#pragma warning (disable:4996)
74#endif
75
76#include <NIS_InteractiveContext.hxx>
77#include <NIS_Triangulated.hxx>
78extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
79
7fd59977 80#include <Quantity_Color.hxx>
81#include <Quantity_NameOfColor.hxx>
82
83#include <Graphic3d_NameOfMaterial.hxx>
84
85#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
86#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
87
792c785c 88//=======================================================================
89//function : GetColorFromName
90//purpose : get the Quantity_NameOfColor from a string
91//=======================================================================
7fd59977 92
792c785c 93Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
94{
95 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
96 {
97 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
98 if (strcasecmp (theName, aColorName) == 0)
7fd59977 99 {
792c785c 100 return Quantity_NameOfColor (anIter);
7fd59977 101 }
792c785c 102 }
7fd59977 103
792c785c 104 return DEFAULT_COLOR;
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())
244 aContextAIS->Clear (anOldObj, Standard_True);
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;
1513 aChangeSet->Color = ViewerTest::GetColorFromName (aNames.Last().ToCString());
1514 aNames.Remove (aNames.Length());
1515 }
1516 else if (aCmdName == "vunsetcolor")
1517 {
1518 aChangeSet->ToSetColor = -1;
1519 }
1520 else if (aCmdName == "vsettransparency")
1521 {
1522 if (aNames.IsEmpty()
1523 || !aNames.Last().IsRealValue())
1524 {
1525 std::cout << "Error: not enough arguments!\n";
1526 return 1;
1527 }
1528 aChangeSet->ToSetTransparency = 1;
1529 aChangeSet->Transparency = aNames.Last().RealValue();
1530 aNames.Remove (aNames.Length());
1531 }
1532 else if (aCmdName == "vunsettransparency")
1533 {
1534 aChangeSet->ToSetTransparency = -1;
1535 }
1536 else if (aCmdName == "vsetmaterial")
1537 {
1538 if (aNames.IsEmpty())
1539 {
1540 std::cout << "Error: not enough arguments!\n";
1541 return 1;
1542 }
1543 aChangeSet->ToSetMaterial = 1;
1544 aChangeSet->MatName = aNames.Last();
1545 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1546 aNames.Remove (aNames.Length());
1547 }
1548 else if (aCmdName == "vunsetmaterial")
1549 {
1550 aChangeSet->ToSetMaterial = -1;
1551 }
1552 else if (anArgIter >= theArgNb)
1553 {
1554 std::cout << "Error: not enough arguments!\n";
1555 return 1;
7fd59977 1556 }
1557
ad3217cd 1558 if (!aChangeSet->IsEmpty())
1559 {
1560 anArgIter = theArgNb;
1561 }
1562 for (; anArgIter < theArgNb; ++anArgIter)
1563 {
1564 TCollection_AsciiString anArg = theArgVec[anArgIter];
1565 anArg.LowerCase();
1566 if (anArg == "-setwidth"
1567 || anArg == "-setlinewidth")
1568 {
1569 if (++anArgIter >= theArgNb)
1570 {
1571 std::cout << "Error: wrong syntax at " << anArg << "\n";
1572 return 1;
1573 }
1574 aChangeSet->ToSetLineWidth = 1;
1575 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1576 }
ad3217cd 1577 else if (anArg == "-unsetwidth"
1578 || anArg == "-unsetlinewidth")
1579 {
1580 aChangeSet->ToSetLineWidth = -1;
1581 aChangeSet->LineWidth = 1.0;
1582 }
1583 else if (anArg == "-settransp"
0ae61cf3 1584 || anArg == "-settransparency")
ad3217cd 1585 {
1586 if (++anArgIter >= theArgNb)
1587 {
1588 std::cout << "Error: wrong syntax at " << anArg << "\n";
1589 return 1;
1590 }
1591 aChangeSet->ToSetTransparency = 1;
1592 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1593 if (aChangeSet->Transparency >= 0.0
1594 && aChangeSet->Transparency <= Precision::Confusion())
1595 {
1596 aChangeSet->ToSetTransparency = -1;
1597 aChangeSet->Transparency = 0.0;
eafb234b 1598 }
7fd59977 1599 }
ad3217cd 1600 else if (anArg == "-setalpha")
1601 {
1602 if (++anArgIter >= theArgNb)
7fd59977 1603 {
ad3217cd 1604 std::cout << "Error: wrong syntax at " << anArg << "\n";
1605 return 1;
1606 }
1607 aChangeSet->ToSetTransparency = 1;
1608 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1609 if (aChangeSet->Transparency < 0.0
1610 || aChangeSet->Transparency > 1.0)
1611 {
1612 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1613 return 1;
1614 }
1615 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1616 if (aChangeSet->Transparency >= 0.0
1617 && aChangeSet->Transparency <= Precision::Confusion())
1618 {
1619 aChangeSet->ToSetTransparency = -1;
1620 aChangeSet->Transparency = 0.0;
7fd59977 1621 }
7fd59977 1622 }
ad3217cd 1623 else if (anArg == "-unsettransp"
0ae61cf3 1624 || anArg == "-unsettransparency"
ad3217cd 1625 || anArg == "-unsetalpha"
1626 || anArg == "-opaque")
1627 {
1628 aChangeSet->ToSetTransparency = -1;
1629 aChangeSet->Transparency = 0.0;
1630 }
1631 else if (anArg == "-setcolor")
1632 {
1633 if (++anArgIter >= theArgNb)
1634 {
1635 std::cout << "Error: wrong syntax at " << anArg << "\n";
1636 return 1;
7fd59977 1637 }
ad3217cd 1638 aChangeSet->ToSetColor = 1;
1639 aChangeSet->Color = ViewerTest::GetColorFromName (theArgVec[anArgIter]);
7fd59977 1640 }
ad3217cd 1641 else if (anArg == "-unsetcolor")
1642 {
1643 aChangeSet->ToSetColor = -1;
1644 aChangeSet->Color = DEFAULT_COLOR;
1645 }
1646 else if (anArg == "-setmat"
1647 || anArg == "-setmaterial")
1648 {
1649 if (++anArgIter >= theArgNb)
1650 {
1651 std::cout << "Error: wrong syntax at " << anArg << "\n";
1652 return 1;
1653 }
1654 aChangeSet->ToSetMaterial = 1;
1655 aChangeSet->MatName = theArgVec[anArgIter];
1656 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1657 }
1658 else if (anArg == "-unsetmat"
1659 || anArg == "-unsetmaterial")
1660 {
1661 aChangeSet->ToSetMaterial = -1;
1662 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1663 }
1664 else if (anArg == "-subshape"
1665 || anArg == "-subshapes")
1666 {
1667 if (aNames.IsEmpty())
1668 {
1669 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1670 return 1;
1671 }
7fd59977 1672
ad3217cd 1673 aChanges.Append (ViewerTest_AspectsChangeSet());
1674 aChangeSet = &aChanges.ChangeLast();
7fd59977 1675
ad3217cd 1676 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1677 {
1678 Standard_CString aSubShapeName = theArgVec[anArgIter];
1679 if (*aSubShapeName == '-')
1680 {
1681 --anArgIter;
1682 break;
1683 }
7fd59977 1684
ad3217cd 1685 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1686 if (aSubShape.IsNull())
1687 {
1688 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1689 return 1;
1690 }
1691 aChangeSet->SubShapes.Append (aSubShape);
1692 }
7fd59977 1693
ad3217cd 1694 if (aChangeSet->SubShapes.IsEmpty())
1695 {
1696 std::cerr << "Error: empty list is specified after -subshapes!\n";
1697 return 1;
1698 }
1699 }
1700 else if (anArg == "-unset")
1701 {
1702 aChangeSet->ToSetLineWidth = -1;
1703 aChangeSet->LineWidth = 1.0;
1704 aChangeSet->ToSetTransparency = -1;
1705 aChangeSet->Transparency = 0.0;
1706 aChangeSet->ToSetColor = -1;
1707 aChangeSet->Color = DEFAULT_COLOR;
1708 aChangeSet->ToSetMaterial = -1;
1709 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
7fd59977 1710 }
7fd59977 1711 else
ad3217cd 1712 {
1713 std::cout << "Error: wrong syntax at " << anArg << "\n";
1714 return 1;
1715 }
7fd59977 1716 }
99c56d44 1717
ad3217cd 1718 Standard_Boolean isFirst = Standard_True;
1719 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1720 aChangesIter.More(); aChangesIter.Next())
1721 {
1722 if (!aChangesIter.Value().Validate (!isFirst))
1723 {
1724 return 1;
1725 }
1726 isFirst = Standard_False;
99c56d44 1727 }
99c56d44 1728
ad3217cd 1729 if (aCtx->HasOpenedContext())
1730 {
1731 aCtx->CloseLocalContext();
99c56d44 1732 }
ad3217cd 1733 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
1734 {
1735 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
1736 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
1737 Handle(AIS_ColoredShape) aColoredPrs;
1738 Standard_Boolean toDisplay = Standard_False;
1739 if (aChanges.Length() > 1)
1740 {
1741 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
1742 if (aShapePrs.IsNull())
1743 {
1744 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
1745 return 1;
1746 }
1747 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
1748 if (aColoredPrs.IsNull())
1749 {
1750 aColoredPrs = new AIS_ColoredShape (aShapePrs);
1751 aCtx->Remove (aShapePrs, Standard_False);
1752 GetMapOfAIS().UnBind2 (aName);
1753 GetMapOfAIS().Bind (aColoredPrs, aName);
1754 toDisplay = Standard_True;
1755 aShapePrs = aColoredPrs;
1756 aPrs = aColoredPrs;
1757 }
1758 }
99c56d44 1759
ad3217cd 1760 if (!aPrs.IsNull())
1761 {
1762 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1763 aChangeSet = &aChangesIter.ChangeValue();
1764 if (aChangeSet->ToSetMaterial == 1)
1765 {
1766 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
1767 }
1768 else if (aChangeSet->ToSetMaterial == -1)
1769 {
1770 aCtx->UnsetMaterial (aPrs, Standard_False);
1771 }
1772 if (aChangeSet->ToSetColor == 1)
1773 {
1774 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
1775 }
1776 else if (aChangeSet->ToSetColor == -1)
1777 {
1778 aCtx->UnsetColor (aPrs, Standard_False);
1779 }
1780 if (aChangeSet->ToSetTransparency == 1)
1781 {
1782 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
1783 }
1784 else if (aChangeSet->ToSetTransparency == -1)
1785 {
1786 aCtx->UnsetTransparency (aPrs, Standard_False);
1787 }
1788 if (aChangeSet->ToSetLineWidth == 1)
1789 {
1790 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
1791 }
1792 else if (aChangeSet->ToSetLineWidth == -1)
1793 {
1794 aCtx->UnsetWidth (aPrs, Standard_False);
1795 }
99c56d44 1796
ad3217cd 1797 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
1798 {
1799 aChangeSet = &aChangesIter.ChangeValue();
1800 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
1801 aSubShapeIter.More(); aSubShapeIter.Next())
1802 {
1803 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
1804 if (aChangeSet->ToSetColor == 1)
1805 {
1806 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
1807 }
1808 if (aChangeSet->ToSetLineWidth == 1)
1809 {
1810 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
1811 }
1812 if (aChangeSet->ToSetColor == -1
1813 || aChangeSet->ToSetLineWidth == -1)
1814 {
1815 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
1816 }
1817 }
1818 }
1819 if (toDisplay)
1820 {
1821 aCtx->Display (aPrs, Standard_False);
1822 }
1823 else if (!aColoredPrs.IsNull())
1824 {
1825 aColoredPrs->Redisplay();
1826 }
99c56d44 1827 }
99c56d44 1828 else
ad3217cd 1829 {
1830 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
1831 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
1832 if (!aNisObj.IsNull())
1833 {
1834 if (aChangeSet->ToSetTransparency != 0)
1835 {
1836 aNisObj->SetTransparency (aChangeSet->Transparency);
1837 }
1838 }
1839 if (!aNisTri.IsNull())
1840 {
1841 if (aChangeSet->ToSetColor != 0)
1842 {
1843 aNisTri->SetColor (aChangeSet->Color);
1844 }
1845 if (aChangeSet->ToSetLineWidth != 0)
1846 {
1847 aNisTri->SetLineWidth (aChangeSet->LineWidth);
1848 }
99c56d44 1849 }
1850 }
ad3217cd 1851 }
99c56d44 1852 return 0;
1853}
1854
7fd59977 1855//==============================================================================
1856//function : VDonly2
1857//author : ege
1858//purpose : Display only a selected or named object
519d35d8 1859// if there is no selected or named object s, nothing is done
7fd59977 1860//==============================================================================
519d35d8 1861static int VDonly2 (Draw_Interpretor& ,
1862 Standard_Integer theArgNb,
1863 const char** theArgVec)
7fd59977 1864{
519d35d8 1865 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1866 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 1867 if (aCtx.IsNull())
1868 {
1869 std::cerr << "Error: no active view!\n";
7fd59977 1870 return 1;
519d35d8 1871 }
7fd59977 1872
519d35d8 1873 if (aCtx->HasOpenedContext())
1874 {
1875 aCtx->CloseLocalContext();
1876 }
7fd59977 1877
519d35d8 1878 Standard_Integer anArgIter = 1;
1879 for (; anArgIter < theArgNb; ++anArgIter)
1880 {
4e18052b 1881 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 1882 {
1883 break;
1884 }
1885 }
7fd59977 1886
519d35d8 1887 NCollection_Map<Handle(Standard_Transient)> aDispSet;
1888 if (anArgIter >= theArgNb)
1889 {
1890 // display only selected objects
1891 if (aCtx->NbCurrents() < 1)
1892 {
1893 return 0;
7fd59977 1894 }
1895
519d35d8 1896 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1897 {
1898 aDispSet.Add (aCtx->Current());
1899 }
1900 }
1901 else
1902 {
1903 // display only specified objects
1904 for (; anArgIter < theArgNb; ++anArgIter)
1905 {
1906 TCollection_AsciiString aName = theArgVec[anArgIter];
1907 if (GetMapOfAIS().IsBound2 (aName))
1908 {
1909 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1910 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1911 {
1912 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1913 aCtx->Display (aShape, Standard_False);
1914 }
1915 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1916 {
1917 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
1918 TheNISContext()->Display (aShape);
7fd59977 1919 }
519d35d8 1920 aDispSet.Add (anObj);
7fd59977 1921 }
1922 }
7fd59977 1923 }
519d35d8 1924
1925 // weed out other objects
1926 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1927 {
1928 if (aDispSet.Contains (anIter.Key1()))
1929 {
1930 continue;
1931 }
1932
1933 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1934 {
1935 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1936 aCtx->Erase (aShape, Standard_False);
1937 }
1938 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1939 {
1940 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1941 TheNISContext()->Erase (aShape);
1942 }
1943 }
7fd59977 1944 return 0;
1945}
1946
1947//==============================================================================
eef7fc64 1948//function : VRemove
1949//purpose : Removes selected or named objects.
1950// If there is no selected or named objects,
1951// all objects in the viewer can be removed with argument -all.
1952// If -context is in arguments, the object is not deleted from the map of
1953// objects (deleted only from the current context).
1954//==============================================================================
1955int VRemove (Draw_Interpretor& theDI,
519d35d8 1956 Standard_Integer theArgNb,
1957 const char** theArgVec)
eef7fc64 1958{
4e18052b 1959 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1960 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1961 if (aCtx.IsNull())
eef7fc64 1962 {
4e18052b 1963 std::cout << "Error: no active view!\n";
eef7fc64 1964 return 1;
1965 }
1966
4e18052b 1967 aCtx->CloseAllContexts (Standard_False);
eef7fc64 1968
4e18052b 1969 Standard_Boolean isContextOnly = Standard_False;
1970 Standard_Boolean toRemoveAll = Standard_False;
1971 Standard_Boolean toPrintInfo = Standard_True;
519d35d8 1972
1973 Standard_Integer anArgIter = 1;
1974 for (; anArgIter < theArgNb; ++anArgIter)
1975 {
1976 TCollection_AsciiString anArg = theArgVec[anArgIter];
1977 anArg.LowerCase();
1978 if (anArg == "-context")
1979 {
1980 isContextOnly = Standard_True;
1981 }
1982 else if (anArg == "-all")
1983 {
1984 toRemoveAll = Standard_True;
1985 }
b7cd4ba7 1986 else if (anArg == "-noinfo")
1987 {
1988 toPrintInfo = Standard_False;
1989 }
4e18052b 1990 else if (!anUpdateTool.parseRedrawMode (anArg))
519d35d8 1991 {
1992 break;
1993 }
1994 }
1995 if (toRemoveAll
1996 && anArgIter < theArgNb)
1997 {
1998 std::cout << "Error: wrong syntax!\n";
1999 return 1;
2000 }
2001
eef7fc64 2002 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2003 if (toRemoveAll)
eef7fc64 2004 {
2005 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2006 anIter.More(); anIter.Next())
2007 {
2008 anIONameList.Append (anIter.Key2());
2009 }
2010 }
519d35d8 2011 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2012 {
519d35d8 2013 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2014 {
519d35d8 2015 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2016 if (!GetMapOfAIS().IsBound2 (aName))
2017 {
2018 theDI << aName.ToCString() << " was not bound to some object.\n";
2019 continue;
2020 }
2021
2022 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2023
2024 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2025 if (!anIO.IsNull())
2026 {
4e18052b 2027 if (anIO->GetContext() != aCtx)
eef7fc64 2028 {
2029 theDI << aName.ToCString() << " was not displayed in current context.\n";
2030 theDI << "Please activate view with this object displayed and try again.\n";
2031 continue;
2032 }
2033
2034 anIONameList.Append (aName);
2035 continue;
2036 }
2037
2038 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2039 if (!aNisIO.IsNull())
2040 {
2041 anIONameList.Append (aName);
2042 }
2043 }
2044 }
4e18052b 2045 else if (aCtx->NbCurrents() > 0
eef7fc64 2046 || TheNISContext()->GetSelected().Extent() > 0)
2047 {
2048 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2049 anIter.More(); anIter.Next())
2050 {
2051 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2052 if (!anIO.IsNull())
2053 {
4e18052b 2054 if (!aCtx->IsCurrent (anIO))
eef7fc64 2055 {
2056 continue;
2057 }
2058
2059 anIONameList.Append (anIter.Key2());
2060 continue;
2061 }
2062
2063 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2064 if (!aNisIO.IsNull())
2065 {
2066 if (!TheNISContext()->IsSelected (aNisIO))
2067 {
2068 continue;
2069 }
2070
2071 anIONameList.Append (anIter.Key2());
2072 }
2073 }
2074 }
2075
2076 // Unbind all removed objects from the map of displayed IO.
2077 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2078 anIter.More(); anIter.Next())
2079 {
519d35d8 2080 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
519d35d8 2081 if (!anIO.IsNull())
2082 {
4e18052b 2083 aCtx->Remove (anIO, Standard_False);
b7cd4ba7 2084 if (toPrintInfo)
2085 {
2086 theDI << anIter.Value().ToCString() << " was removed\n";
2087 }
519d35d8 2088 }
2089 else
2090 {
2091 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2092 if (!aNisIO.IsNull())
eef7fc64 2093 {
519d35d8 2094 TheNISContext()->Remove (aNisIO);
b7cd4ba7 2095 if (toPrintInfo)
2096 {
2097 theDI << anIter.Value().ToCString() << " was removed\n";
2098 }
eef7fc64 2099 }
519d35d8 2100 }
519d35d8 2101 if (!isContextOnly)
2102 {
2103 GetMapOfAIS().UnBind2 (anIter.Value());
2104 }
2105 }
eef7fc64 2106 return 0;
2107}
2108
2109//==============================================================================
b514beda 2110//function : VErase
2111//purpose : Erase some selected or named objects
7fd59977 2112// if there is no selected or named objects, the whole viewer is erased
7fd59977 2113//==============================================================================
b514beda 2114int VErase (Draw_Interpretor& theDI,
2115 Standard_Integer theArgNb,
2116 const char** theArgVec)
7fd59977 2117{
4e18052b 2118 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2119 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2120 if (aCtx.IsNull())
b514beda 2121 {
519d35d8 2122 std::cout << "Error: no active view!\n";
7fd59977 2123 return 1;
b514beda 2124 }
4e18052b 2125 aCtx->CloseAllContexts (Standard_False);
519d35d8 2126
519d35d8 2127 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2128
2129 Standard_Integer anArgIter = 1;
2130 for (; anArgIter < theArgNb; ++anArgIter)
2131 {
4e18052b 2132 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2133 {
2134 break;
2135 }
2136 }
2137
2138 if (anArgIter < theArgNb)
b514beda 2139 {
519d35d8 2140 if (toEraseAll)
b514beda 2141 {
519d35d8 2142 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
b514beda 2143 return 1;
7fd59977 2144 }
2145
b514beda 2146 // has a list of names
519d35d8 2147 for (; anArgIter < theArgNb; ++anArgIter)
b514beda 2148 {
2149 TCollection_AsciiString aName = theArgVec[anArgIter];
2150 if (!GetMapOfAIS().IsBound2 (aName))
2151 {
2152 continue;
2153 }
7fd59977 2154
b514beda 2155 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2156 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2157 theDI << aName.ToCString() << " ";
2158 if (!anIO.IsNull())
2159 {
4e18052b 2160 aCtx->Erase (anIO, Standard_False);
b514beda 2161 }
2162 else
2163 {
2164 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2165 if (!aNisIO.IsNull())
2166 {
2167 TheNISContext()->Erase (aNisIO);
2168 }
7fd59977 2169 }
7fd59977 2170 }
7fd59977 2171 }
519d35d8 2172 else if (!toEraseAll
4e18052b 2173 && aCtx->NbCurrents() > 0)
b514beda 2174 {
2175 // remove all currently selected objects
2176 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2177 anIter.More(); anIter.Next())
2178 {
2179 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2180 if (!anIO.IsNull()
4e18052b 2181 && aCtx->IsCurrent (anIO))
b514beda 2182 {
2183 theDI << anIter.Key2().ToCString() << " ";
4e18052b 2184 aCtx->Erase (anIO, Standard_False);
7fd59977 2185 }
2186 }
b514beda 2187 }
519d35d8 2188 else
b514beda 2189 {
519d35d8 2190 // erase entire viewer
2191 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2192 anIter.More(); anIter.Next())
b514beda 2193 {
519d35d8 2194 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2195 if (!anIO.IsNull())
2196 {
4e18052b 2197 aCtx->Erase (anIO, Standard_False);
519d35d8 2198 }
2199 else
b514beda 2200 {
519d35d8 2201 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2202 if (!aNisIO.IsNull())
2203 {
2204 TheNISContext()->Erase (aNisIO);
2205 }
b514beda 2206 }
7fd59977 2207 }
7fd59977 2208 }
7fd59977 2209 return 0;
2210}
2211
7fd59977 2212//==============================================================================
2213//function : VDisplayAll
2214//author : ege
2215//purpose : Display all the objects of the Map
7fd59977 2216//==============================================================================
519d35d8 2217static int VDisplayAll (Draw_Interpretor& ,
2218 Standard_Integer theArgNb,
2219 const char** theArgVec)
7fd59977 2220
2221{
4e18052b 2222 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2223 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2224 if (aCtx.IsNull())
519d35d8 2225 {
2226 std::cout << "Error: no active view!\n";
2227 return 1;
2228 }
2229
519d35d8 2230 Standard_Integer anArgIter = 1;
2231 for (; anArgIter < theArgNb; ++anArgIter)
2232 {
4e18052b 2233 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2234 {
2235 break;
7fd59977 2236 }
519d35d8 2237 }
2238 if (anArgIter < theArgNb)
2239 {
2240 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2241 return 1;
2242 }
2243
4e18052b 2244 if (aCtx->HasOpenedContext())
519d35d8 2245 {
4e18052b 2246 aCtx->CloseLocalContext();
519d35d8 2247 }
2248
2249 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2250 anIter.More(); anIter.Next())
2251 {
2252 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2253 {
2254 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
4e18052b 2255 aCtx->Erase (aShape, Standard_False);
519d35d8 2256 }
2257 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2258 {
2259 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2260 TheNISContext()->Erase (aShape);
2261 }
2262 }
2263
2264 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2265 anIter.More(); anIter.Next())
2266 {
2267 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2268 {
2269 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
4e18052b 2270 aCtx->Display (aShape, Standard_False);
519d35d8 2271 }
2272 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2273 {
2274 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2275 TheNISContext()->Display (aShape);
7fd59977 2276 }
7fd59977 2277 }
2278 return 0;
2279}
2280
c2a388f8 2281//! Auxiliary method to find presentation
2282inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2283 const Handle(AIS_InteractiveObject)& theIO,
2284 const Standard_Integer theMode)
2285{
2286 if (theIO.IsNull())
2287 {
2288 return Handle(PrsMgr_Presentation)();
2289 }
2290
2291 if (theMode != -1)
2292 {
2293 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2294 {
2295 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2296 }
2297 }
2298 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2299 {
2300 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2301 }
2302 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2303 {
2304 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2305 }
2306 return Handle(PrsMgr_Presentation)();
2307}
2308
2309enum ViewerTest_BndAction
2310{
2311 BndAction_Hide,
2312 BndAction_Show,
2313 BndAction_Print
2314};
2315
2316//! Auxiliary method to print bounding box of presentation
2317inline void bndPresentation (Draw_Interpretor& theDI,
2318 const Handle(PrsMgr_Presentation)& thePrs,
2319 const TCollection_AsciiString& theName,
2320 const ViewerTest_BndAction theAction)
2321{
2322 switch (theAction)
2323 {
2324 case BndAction_Hide:
2325 {
2326 thePrs->Presentation()->GraphicUnHighlight();
2327 break;
2328 }
2329 case BndAction_Show:
2330 {
2331 thePrs->Presentation()->BoundBox();
2332 break;
2333 }
2334 case BndAction_Print:
2335 {
2336 Graphic3d_Vec3d aMin, aMax;
2337 thePrs->Presentation()->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2338 aMax.x(), aMax.y(), aMax.z());
2339 theDI << theName << "\n"
2340 << aMin.x() << " " << aMin.y() << " " << aMin.z() << " "
2341 << aMax.x() << " " << aMax.y() << " " << aMax.z() << "\n";
2342 break;
2343 }
2344 }
2345}
2346
2347//==============================================================================
2348//function : VBounding
2349//purpose :
2350//==============================================================================
2351int VBounding (Draw_Interpretor& theDI,
2352 Standard_Integer theArgNb,
2353 const char** theArgVec)
2354{
2355 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2356 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2357 if (aCtx.IsNull())
2358 {
2359 std::cout << "Error: no active view!\n";
2360 return 1;
2361 }
2362
4e18052b 2363 ViewerTest_BndAction anAction = BndAction_Show;
2364 Standard_Integer aMode = -1;
c2a388f8 2365
2366 Standard_Integer anArgIter = 1;
2367 for (; anArgIter < theArgNb; ++anArgIter)
2368 {
2369 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2370 anArg.LowerCase();
2371 if (anArg == "-print")
2372 {
2373 anAction = BndAction_Print;
2374 }
2375 else if (anArg == "-show")
2376 {
2377 anAction = BndAction_Show;
2378 }
2379 else if (anArg == "-hide")
2380 {
2381 anAction = BndAction_Hide;
2382 }
2383 else if (anArg == "-mode")
2384 {
2385 if (++anArgIter >= theArgNb)
2386 {
2387 std::cout << "Error: wrong syntax at " << anArg << "\n";
2388 return 1;
2389 }
2390 aMode = Draw::Atoi (theArgVec[anArgIter]);
2391 }
4e18052b 2392 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 2393 {
2394 break;
2395 }
2396 }
2397
2398 if (anArgIter < theArgNb)
2399 {
2400 // has a list of names
2401 for (; anArgIter < theArgNb; ++anArgIter)
2402 {
2403 TCollection_AsciiString aName = theArgVec[anArgIter];
2404 if (!GetMapOfAIS().IsBound2 (aName))
2405 {
2406 std::cout << "Error: presentation " << aName << " does not exist\n";
2407 return 1;
2408 }
2409
2410 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2411 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2412 if (aPrs.IsNull())
2413 {
2414 std::cout << "Error: presentation " << aName << " does not exist\n";
2415 return 1;
2416 }
2417 bndPresentation (theDI, aPrs, aName, anAction);
2418 }
2419 }
4e18052b 2420 else if (aCtx->NbCurrents() > 0)
c2a388f8 2421 {
2422 // remove all currently selected objects
2423 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2424 {
2425 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2426 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2427 if (!aPrs.IsNull())
2428 {
2429 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2430 }
2431 }
2432 }
2433 else
2434 {
2435 // all objects
2436 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2437 anIter.More(); anIter.Next())
2438 {
2439 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2440 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2441 if (!aPrs.IsNull())
2442 {
2443 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2444 }
2445 }
2446 }
c2a388f8 2447 return 0;
2448}
2449
d399d3c3 2450//==============================================================================
2451//function : VTexture
2452//purpose :
2453//==============================================================================
2454Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 2455{
d399d3c3 2456 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 2457
900f7229 2458 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 2459 if (aCommandName == "vtexture")
2460 {
2461 if (theArgsNb < 2)
7fd59977 2462 {
d399d3c3 2463 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2464 std::cout << "Type help for more information.\n";
31160f80 2465 return 1;
7fd59977 2466 }
2467
d399d3c3 2468 // look for options of vtexture command
2469 TCollection_AsciiString aParseKey;
2470 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2471 {
2472 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 2473
d399d3c3 2474 anArg.UpperCase();
2475 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2476 {
2477 aParseKey = anArg;
2478 aParseKey.Remove (1);
2479 aParseKey.UpperCase();
900f7229 2480 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 2481 continue;
2482 }
2483
2484 if (aParseKey.IsEmpty())
2485 {
2486 continue;
2487 }
2488
900f7229 2489 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 2490 }
2491 }
2492 else if (aCommandName == "vtexscale"
2493 || aCommandName == "vtexorigin"
2494 || aCommandName == "vtexrepeat")
2495 {
2496 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2497 // equal to -scale, -origin, -repeat options of vtexture command
2498 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 2499 {
d399d3c3 2500 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2501 std::cout << "Type help for more information.\n";
31160f80 2502 return 1;
7fd59977 2503 }
2504
900f7229 2505 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 2506 if (theArgsNb == 2)
2507 {
900f7229 2508 anArgs->Append ("OFF");
d399d3c3 2509 }
2510 else if (theArgsNb == 4)
2511 {
900f7229 2512 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2513 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 2514 }
7fd59977 2515
d399d3c3 2516 TCollection_AsciiString anArgKey;
2517 if (aCommandName == "vtexscale")
2518 {
2519 anArgKey = "SCALE";
2520 }
2521 else if (aCommandName == "vtexorigin")
2522 {
2523 anArgKey = "ORIGIN";
2524 }
2525 else
2526 {
2527 anArgKey = "REPEAT";
2528 }
2529
2530 aMapOfArgs.Bind (anArgKey, anArgs);
2531 }
2532 else if (aCommandName == "vtexdefault")
7fd59977 2533 {
d399d3c3 2534 // scan for parameters of vtexdefault command
2535 // equal to -default option of vtexture command
900f7229 2536 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 2537 }
2538
d399d3c3 2539 // Check arguments for validity
900f7229 2540 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 2541 for (; aMapIt.More(); aMapIt.Next())
2542 {
2543 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 2544 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 2545
2546 // -scale, -origin, -repeat: one argument "off", or two real values
2547 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 2548 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2549 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 2550 {
d399d3c3 2551 continue;
7fd59977 2552 }
d399d3c3 2553
2554 // -modulate: single argument "on" / "off"
900f7229 2555 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 2556 {
2557 continue;
2558 }
2559
2560 // -default: no arguments
900f7229 2561 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 2562 {
2563 continue;
2564 }
2565
2566 TCollection_AsciiString aLowerKey;
2567 aLowerKey = "-";
2568 aLowerKey += aKey;
2569 aLowerKey.LowerCase();
2570 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2571 std::cout << "Type help for more information.\n";
2572 return 1;
2573 }
2574
2575 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2576 if (anAISContext.IsNull())
2577 {
2578 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2579 return 1;
2580 }
2581
2582 Standard_Integer aPreviousMode = 0;
2583
2584 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2585
2586 TCollection_AsciiString aShapeName (theArgv[1]);
2587 Handle(AIS_InteractiveObject) anIO;
2588
2589 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2590 if (aMapOfIO.IsBound2 (aShapeName))
2591 {
2592 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2593 }
2594
2595 if (anIO.IsNull())
2596 {
2597 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2598 return 1;
2599 }
2600
2601 Handle(AIS_TexturedShape) aTexturedIO;
2602 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2603 {
2604 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2605 aPreviousMode = aTexturedIO->DisplayMode();
2606 }
7fd59977 2607 else
d399d3c3 2608 {
2609 anAISContext->Clear (anIO, Standard_False);
2610 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2611 GetMapOfAIS().UnBind1 (anIO);
2612 GetMapOfAIS().UnBind2 (aShapeName);
2613 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2614 }
2615
2616 // -------------------------------------------
2617 // Turn texturing on/off - only for vtexture
2618 // -------------------------------------------
2619
2620 if (aCommandName == "vtexture")
2621 {
2622 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2623
2624 if (aTextureArg.IsEmpty())
7fd59977 2625 {
d399d3c3 2626 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2627 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2628
2629 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2630 if (aPreviousMode == 3)
2631 {
2632 anAISContext->RecomputePrsOnly (aTexturedIO);
2633 }
2634
2635 anAISContext->Display (aTexturedIO, Standard_True);
2636 return 0;
7fd59977 2637 }
d399d3c3 2638 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 2639 {
d399d3c3 2640 if (aTextureArg == "?")
2641 {
2642 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 2643
d399d3c3 2644 theDi << "\n Files in current directory : \n" << "\n";
2645 theDi.Eval ("glob -nocomplain *");
7fd59977 2646
d399d3c3 2647 TCollection_AsciiString aCmnd ("glob -nocomplain ");
2648 aCmnd += aTextureFolder;
2649 aCmnd += "/* ";
7fd59977 2650
d399d3c3 2651 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2652 theDi.Eval (aCmnd.ToCString());
2653 return 0;
2654 }
2655 else
2656 {
2657 aTexturedIO->SetTextureFileName (aTextureArg);
2658 }
2659 }
2660 }
7fd59977 2661
d399d3c3 2662 // ------------------------------------
2663 // Process other options and commands
2664 // ------------------------------------
7fd59977 2665
900f7229 2666 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 2667 if (aMapOfArgs.Find ("DEFAULT", aValues))
2668 {
2669 aTexturedIO->SetTextureRepeat (Standard_False);
2670 aTexturedIO->SetTextureOrigin (Standard_False);
2671 aTexturedIO->SetTextureScale (Standard_False);
2672 aTexturedIO->EnableTextureModulate();
2673 }
2674 else
2675 {
2676 if (aMapOfArgs.Find ("SCALE", aValues))
2677 {
900f7229 2678 if (aValues->Value(1) != "OFF")
d399d3c3 2679 {
900f7229 2680 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 2681 }
7fd59977 2682 else
d399d3c3 2683 {
2684 aTexturedIO->SetTextureScale (Standard_False);
2685 }
2686 }
7fd59977 2687
d399d3c3 2688 if (aMapOfArgs.Find ("ORIGIN", aValues))
2689 {
900f7229 2690 if (aValues->Value(1) != "OFF")
d399d3c3 2691 {
900f7229 2692 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 2693 }
2694 else
2695 {
2696 aTexturedIO->SetTextureOrigin (Standard_False);
2697 }
2698 }
7fd59977 2699
d399d3c3 2700 if (aMapOfArgs.Find ("REPEAT", aValues))
2701 {
900f7229 2702 if (aValues->Value(1) != "OFF")
d399d3c3 2703 {
900f7229 2704 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 2705 }
2706 else
2707 {
2708 aTexturedIO->SetTextureRepeat (Standard_False);
2709 }
7fd59977 2710 }
2711
d399d3c3 2712 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 2713 {
900f7229 2714 if (aValues->Value(1) == "ON")
d399d3c3 2715 {
2716 aTexturedIO->EnableTextureModulate();
2717 }
2718 else
2719 {
2720 aTexturedIO->DisableTextureModulate();
2721 }
7fd59977 2722 }
d399d3c3 2723 }
2724
2725 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
2726 {
2727 anAISContext->RecomputePrsOnly (aTexturedIO);
2728 }
2729 else
2730 {
2731 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
2732 anAISContext->Display (aTexturedIO, Standard_True);
2733 anAISContext->Update (aTexturedIO,Standard_True);
2734 }
2735
31160f80 2736 return 0;
7fd59977 2737}
2738
2739//==============================================================================
2740//function : VDisplay2
2741//author : ege
2742//purpose : Display an object from its name
7fd59977 2743//==============================================================================
519d35d8 2744static int VDisplay2 (Draw_Interpretor& theDI,
2745 Standard_Integer theArgNb,
2746 const char** theArgVec)
7fd59977 2747{
4e18052b 2748 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
519d35d8 2749 if (theArgNb < 2)
2750 {
2751 std::cout << theArgVec[0] << "Error: wrong syntax!\n";
2752 return 1;
2753 }
4e18052b 2754 else if (aCtx.IsNull())
519d35d8 2755 {
7fd59977 2756 ViewerTest::ViewerInit();
519d35d8 2757 std::cout << "Command vinit should be called before!\n";
2758 // return 1;
4e18052b 2759 aCtx = ViewerTest::GetAISContext();
7fd59977 2760 }
2761
4e18052b 2762 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2763 if (aCtx->HasOpenedContext())
2764 {
2765 aCtx->CloseLocalContext();
7fd59977 2766 }
2767
4e18052b 2768 Standard_Integer isMutable = -1;
519d35d8 2769 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2770 {
b7cd4ba7 2771 const TCollection_AsciiString aName = theArgVec[anArgIter];
2772 TCollection_AsciiString aNameCase = aName;
2773 aNameCase.LowerCase();
4e18052b 2774 if (anUpdateTool.parseRedrawMode (aName))
519d35d8 2775 {
2776 continue;
2777 }
b7cd4ba7 2778 else if (aNameCase == "-mutable")
2779 {
2780 isMutable = 1;
2781 continue;
2782 }
519d35d8 2783 else if (!GetMapOfAIS().IsBound2 (aName))
2784 {
2785 // create the AIS_Shape from a name
2786 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2787 if (!aShape.IsNull())
2788 {
b7cd4ba7 2789 if (isMutable != -1)
2790 {
2791 aShape->SetMutable (isMutable == 1);
2792 }
519d35d8 2793 GetMapOfAIS().Bind (aShape, aName);
2794 aCtx->Display (aShape, Standard_False);
2795 }
2796 continue;
2797 }
7fd59977 2798
519d35d8 2799 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2800 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2801 {
2802 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
b7cd4ba7 2803 if (isMutable != -1)
2804 {
2805 aShape->SetMutable (isMutable == 1);
2806 }
2807
519d35d8 2808 if (aShape->Type() == AIS_KOI_Datum)
2809 {
2810 aCtx->Display (aShape, Standard_False);
2811 }
2812 else
2813 {
2814 theDI << "Display " << aName.ToCString() << "\n";
2815 // get the Shape from a name
2816 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
7fd59977 2817
519d35d8 2818 // update the Shape in the AIS_Shape
2819 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2820 if (!aShapePrs.IsNull())
2821 {
2822 aShapePrs->Set (aNewShape);
7fd59977 2823 }
519d35d8 2824 aCtx->Redisplay (aShape, Standard_False);
2825 aCtx->Display (aShape, Standard_False);
7fd59977 2826 }
2827 }
519d35d8 2828 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
2829 {
2830 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2831 TheNISContext()->Display (aShape);
7fd59977 2832 }
2833 }
7fd59977 2834 return 0;
2835}
2836
f3889691 2837//===============================================================================================
2838//function : VUpdate
2839//purpose :
2840//===============================================================================================
2841static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2842{
2843 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2844 if (aContextAIS.IsNull())
2845 {
2846 std::cout << theArgVec[0] << "AIS context is not available.\n";
2847 return 1;
2848 }
2849
2850 if (theArgsNb < 2)
2851 {
2852 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2853 return 1;
2854 }
2855
2856 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2857
2858 AIS_ListOfInteractive aListOfIO;
2859
2860 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2861 {
2862 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2863
2864 Handle(AIS_InteractiveObject) anAISObj;
2865 if (anAISMap.IsBound2 (aName))
2866 {
2867 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2868 }
2869
2870 if (anAISObj.IsNull())
2871 {
2872 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2873 return 1;
2874 }
2875
2876 aListOfIO.Append (anAISObj);
2877 }
2878
2879 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2880 for (; anIOIt.More(); anIOIt.Next())
2881 {
2882 aContextAIS->Update (anIOIt.Value(), Standard_False);
2883 }
2884
2885 aContextAIS->UpdateCurrentViewer();
2886
2887 return 0;
2888}
2889
7fd59977 2890//==============================================================================
7fd59977 2891//function : VPerf
2892//purpose : Test the annimation of an object along a
2893// predifined trajectory
2894//Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2895//==============================================================================
2896
2897static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2898
2899 OSD_Timer myTimer;
2900 if (TheAISContext()->HasOpenedContext())
2901 TheAISContext()->CloseLocalContext();
2902
c6541a0c 2903 Standard_Real Step=4*M_PI/180;
7fd59977 2904 Standard_Real Angle=0;
2905
2906 Handle(AIS_InteractiveObject) aIO;
2907 if (GetMapOfAIS().IsBound2(argv[1]))
2908 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2909 if (aIO.IsNull())
2910 return 1;
2911
2912 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2913
2914 myTimer.Start();
2915
91322f44 2916 if (Draw::Atoi(argv[3])==1 ) {
7fd59977 2917 di<<" Primitives sensibles OFF"<<"\n";
2918 TheAISContext()->Deactivate(aIO);
2919 }
2920 else {
2921 di<<" Primitives sensibles ON"<<"\n";
2922 }
2923 // Movement par transformation
91322f44 2924 if(Draw::Atoi(argv[2]) ==1) {
7fd59977 2925 di<<" Calcul par Transformation"<<"\n";
c6541a0c 2926 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 2927
2928 Angle=Step*myAngle;
2929 gp_Trsf myTransfo;
2930 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2931 TheAISContext()->SetLocation(aShape,myTransfo);
2932 TheAISContext() ->UpdateCurrentViewer();
2933
2934 }
2935 }
2936 else {
2937 di<<" Calcul par Locations"<<"\n";
2938 gp_Trsf myAngleTrsf;
2939 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2940 TopLoc_Location myDeltaAngle (myAngleTrsf);
2941 TopLoc_Location myTrueLoc;
2942
c6541a0c 2943 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 2944
2945 Angle=Step*myAngle;
2946 myTrueLoc=myTrueLoc*myDeltaAngle;
2947 TheAISContext()->SetLocation(aShape,myTrueLoc );
2948 TheAISContext() ->UpdateCurrentViewer();
2949 }
2950 }
91322f44 2951 if (Draw::Atoi(argv[3])==1 ){
7fd59977 2952 // On reactive la selection des primitives sensibles
2953 TheAISContext()->Activate(aIO,0);
2954 }
2955 a3DView() -> Redraw();
2956 myTimer.Stop();
2957 di<<" Temps ecoule "<<"\n";
2958 myTimer.Show();
2959 return 0;
2960}
2961
2962
2963//==================================================================================
2964// Function : VAnimation
2965//==================================================================================
2966static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
31160f80 2967 if (argc != 5) {
7fd59977 2968 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2969 return 1;
2970 }
2971
2972 Standard_Real thread = 4;
2973 Standard_Real angleA=0;
2974 Standard_Real angleB;
2975 Standard_Real X;
2976 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2977
2978 BRep_Builder B;
2979 TopoDS_Shape CrankArm;
2980 TopoDS_Shape CylinderHead;
2981 TopoDS_Shape Propeller;
2982 TopoDS_Shape EngineBlock;
2983
2984 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2985 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2986 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2987 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2988 BRepTools::Read(CrankArm,argv[1],B);
2989 BRepTools::Read(CylinderHead,argv[2],B);
2990 BRepTools::Read(Propeller,argv[3],B);
2991 BRepTools::Read(EngineBlock,argv[4],B);
2992
2993 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2994
2995
2996 OSD_Timer myTimer;
2997 myTimer.Start();
2998
2999 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3000 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3001 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3002 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3003
3004 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3005 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3006 GetMapOfAIS().Bind(myAisCrankArm,"c");
3007 GetMapOfAIS().Bind(myAisPropeller,"d");
3008
b7cd4ba7 3009 myAisCylinderHead->SetMutable (Standard_True);
3010 myAisEngineBlock ->SetMutable (Standard_True);
3011 myAisCrankArm ->SetMutable (Standard_True);
3012 myAisPropeller ->SetMutable (Standard_True);
7fd59977 3013
b7cd4ba7 3014 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3015 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3016 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3017
3018 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3019 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3020 TheAISContext()->Display (myAisCrankArm, Standard_False);
3021 TheAISContext()->Display (myAisPropeller, Standard_False);
7fd59977 3022
3023 TheAISContext()->Deactivate(myAisCylinderHead);
3024 TheAISContext()->Deactivate(myAisEngineBlock );
3025 TheAISContext()->Deactivate(myAisCrankArm );
3026 TheAISContext()->Deactivate(myAisPropeller );
3027
3028 // Boucle de mouvement
c6541a0c 3029 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
7fd59977 3030
c6541a0c 3031 angleA = thread*myAngle*M_PI/180;
7fd59977 3032 X = Sin(angleA)*3/8;
3033 angleB = atan(X / Sqrt(-X * X + 1));
3034 Standard_Real decal(25*0.6);
3035
3036
3037 //Build a transformation on the display
3038 gp_Trsf aPropellerTrsf;
3039 aPropellerTrsf.SetRotation(Ax1,angleA);
3040 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3041
3042 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));
3043 gp_Trsf aCrankArmTrsf;
3044 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3045 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3046
3047 TheAISContext()->UpdateCurrentViewer();
3048 }
3049
0717ddc1 3050 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3051 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
7fd59977 3052
0717ddc1 3053 myAisCrankArm ->ResetTransformation();
3054 myAisPropeller->ResetTransformation();
7fd59977 3055
3056 myAisCrankArm -> Set(myNewCrankArm );
3057 myAisPropeller -> Set(myNewPropeller);
3058
3059 TheAISContext()->Activate(myAisCylinderHead,0);
3060 TheAISContext()->Activate(myAisEngineBlock,0 );
3061 TheAISContext()->Activate(myAisCrankArm ,0 );
3062 TheAISContext()->Activate(myAisPropeller ,0 );
3063
3064 myTimer.Stop();
3065 myTimer.Show();
3066 myTimer.Start();
3067
3068 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3069 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3070
3071 TheAISContext()->UpdateCurrentViewer();
3072 a3DView()->Redraw();
3073
3074 myTimer.Stop();
3075 myTimer.Show();
3076
3077 return 0;
3078
3079}
3080
3081//==============================================================================
3082//function : VShading
3083//purpose : Sharpen or roughten the quality of the shading
3084//Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3085//==============================================================================
5cbef0fe
S
3086static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3087{
7fd59977 3088 Standard_Real myDevCoef;
3089 Handle(AIS_InteractiveObject) TheAisIO;
3090
3091 // Verifications
5cbef0fe
S
3092 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3093
7fd59977 3094 if (TheAISContext()->HasOpenedContext())
3095 TheAISContext()->CloseLocalContext();
3096
3097 if (argc < 3) {
3098 myDevCoef = 0.0008;
3099 } else {
91322f44 3100 myDevCoef =Draw::Atof(argv[2]);
7fd59977 3101 }
3102
7fd59977 3103 TCollection_AsciiString name=argv[1];
3104 if (GetMapOfAIS().IsBound2(name ))
5cbef0fe 3105 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
7fd59977 3106 if (TheAisIO.IsNull())
3107 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3108
5cbef0fe 3109 if (HaveToSet)
7fd59977 3110 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5cbef0fe 3111 else
7fd59977 3112 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3113
7fd59977 3114 TheAISContext()->Redisplay(TheAisIO);
3115 return 0;
3116}
3117//==============================================================================
3118//function : HaveMode
3119//use : VActivatedModes
3120//==============================================================================
3121#include <TColStd_ListIteratorOfListOfInteger.hxx>
3122
3123Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3124{
3125 TColStd_ListOfInteger List;
3126 TheAISContext()->ActivatedModes (TheAisIO,List);
3127 TColStd_ListIteratorOfListOfInteger it;
3128 Standard_Boolean Found=Standard_False;
3129 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3130 if (it.Value()==mode ) Found=Standard_True;
3131 }
3132 return Found;
3133}
3134
3135
3136
3137//==============================================================================
3138//function : VActivatedMode
3139//author : ege
3140//purpose : permet d'attribuer a chacune des shapes un mode d'activation
3141// (edges,vertex...)qui lui est propre et le mode de selection standard.
3142// La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3143// Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3144// qu'un nom et qu'un mode.
3145//Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3146//==============================================================================
3147#include <AIS_ListIteratorOfListOfInteractive.hxx>
3148
3149static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3150
3151{
7fd59977 3152 Standard_Boolean ThereIsName = Standard_False ;
3153
3154 if(!a3DView().IsNull()){
3155
5cbef0fe 3156 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
7fd59977 3157 // verification des arguments
3158 if (HaveToSet) {
3159 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
5cbef0fe 3160 ThereIsName = (argc == 3);
7fd59977 3161 }
3162 else {
3163 // vunsetam
3164 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3165 else {
5cbef0fe
S
3166 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3167 di<<" Fermeture du Context local"<<"\n";
7fd59977 3168 if (TheAISContext()->HasOpenedContext())
3169 TheAISContext()->CloseLocalContext();
3170 }
7fd59977 3171 }
3172
7fd59977 3173 // IL n'y a aps de nom de shape passe en argument
3174 if (HaveToSet && !ThereIsName){
91322f44 3175 Standard_Integer aMode=Draw::Atoi(argv [1]);
7fd59977 3176
3177 const char *cmode="???";
7fd59977 3178 switch (aMode) {
3179 case 0: cmode = "Shape"; break;
3180 case 1: cmode = "Vertex"; break;
3181 case 2: cmode = "Edge"; break;
3182 case 3: cmode = "Wire"; break;
3183 case 4: cmode = "Face"; break;
3184 case 5: cmode = "Shell"; break;
3185 case 6: cmode = "Solid"; break;
3186 case 7: cmode = "Compound"; break;
3187 }
3188
3189 if( !TheAISContext()->HasOpenedContext() ) {
5cbef0fe
S
3190 // il n'y a pas de Context local d'ouvert
3191 // on en ouvre un et on charge toutes les shapes displayees
3192 // on load tous les objets displayees et on Activate les objets de la liste
3193 AIS_ListOfInteractive ListOfIO;
3194 // on sauve dans une AISListOfInteractive tous les objets currents
3195 if (TheAISContext()->NbCurrents()>0 ){
3196 TheAISContext()->UnhilightCurrents(Standard_False);
3197
3198 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3199 ListOfIO.Append(TheAISContext()->Current() );
7fd59977 3200 }
3201 }
3202
3203 TheAISContext()->OpenLocalContext(Standard_False);
3204 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3205 it (GetMapOfAIS());
3206 while(it.More()){
3207 Handle(AIS_InteractiveObject) aIO =
3208 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3209 if (!aIO.IsNull())
3210 TheAISContext()->Load(aIO,0,Standard_False);
3211 it.Next();
3212 }
3213 // traitement des objets qui etaient currents dans le Contexte global
3214 if (!ListOfIO.IsEmpty() ) {
3215 // il y avait des objets currents
3216 AIS_ListIteratorOfListOfInteractive iter;
3217 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3218 Handle(AIS_InteractiveObject) aIO=iter.Value();
3219 TheAISContext()->Activate(aIO,aMode);
3220 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3221 }
3222 }
3223 else {
3224 // On applique le mode a tous les objets displayes
3225 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3226 it2 (GetMapOfAIS());
3227 while(it2.More()){
3228 Handle(AIS_InteractiveObject) aIO =
3229 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3230 if (!aIO.IsNull()) {
3231 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3232 TheAISContext()->Activate(aIO,aMode);
3233 }
3234 it2.Next();
3235 }
3236 }
3237
3238 }
3239
3240 else {
3241 // un Context local est deja ouvert
3242 // Traitement des objets du Context local
3243 if (TheAISContext()->NbSelected()>0 ){
3244 TheAISContext()->UnhilightSelected(Standard_False);
3245 // il y a des objets selected,on les parcourt
3246 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3247 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3248
3249
3250 if (HaveMode(aIO,aMode) ) {
3251 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3252 TheAISContext()->Deactivate(aIO,aMode);
3253 }
3254 else{
3255 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3256 TheAISContext()->Activate(aIO,aMode);
3257 }
3258
3259 }
3260 }
3261 else{
3262 // il n'y a pas d'objets selected
3263 // tous les objets diplayes sont traites
3264 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3265 it (GetMapOfAIS());
3266 while(it.More()){
3267 Handle(AIS_InteractiveObject) aIO =
3268 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3269 if (!aIO.IsNull()) {
3270 if (HaveMode(aIO,aMode) ) {
3271 di<<" Mode: "<<cmode<<" OFF pour "
3272 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3273 TheAISContext()->Deactivate(aIO,aMode);
3274 }
3275 else{
3276 di<<" Mode: "<<cmode<<" ON pour"
3277 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3278 TheAISContext()->Activate(aIO,aMode);
3279 }
3280 }
3281 it.Next();
3282 }
3283 }
3284 }
3285 }
3286 else if (HaveToSet && ThereIsName){
91322f44 3287 Standard_Integer aMode=Draw::Atoi(argv [2]);
7fd59977 3288 Handle(AIS_InteractiveObject) aIO =
3289 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3290
3291 if (!aIO.IsNull()) {
3292 const char *cmode="???";
3293
3294 switch (aMode) {
3295 case 0: cmode = "Shape"; break;
3296 case 1: cmode = "Vertex"; break;
3297 case 2: cmode = "Edge"; break;
3298 case 3: cmode = "Wire"; break;
3299 case 4: cmode = "Face"; break;
3300 case 5: cmode = "Shell"; break;
3301 case 6: cmode = "Solid"; break;
3302 case 7: cmode = "Compound"; break;
3303 }
3304
3305 if( !TheAISContext()->HasOpenedContext() ) {
3306 TheAISContext()->OpenLocalContext(Standard_False);
3307 // On charge tous les objets de la map
3308 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3309 while(it.More()){
3310 Handle(AIS_InteractiveObject) aShape=
3311 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3312 if (!aShape.IsNull())
3313 TheAISContext()->Load(aShape,0,Standard_False);
3314 it.Next();
3315 }
3316 TheAISContext()->Activate(aIO,aMode);
3317 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3318 }
3319
3320 else {
3321 // un Context local est deja ouvert
3322 if (HaveMode(aIO,aMode) ) {
3323 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3324 TheAISContext()->Deactivate(aIO,aMode);
3325 }
3326 else{
3327 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3328 TheAISContext()->Activate(aIO,aMode);
3329 }
3330 }
3331 }
3332 }
3333 }
3334 return 0;
7fd59977 3335}
3336
cb78155f 3337//! Auxiliary method to print Interactive Object information
3338static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3339 const Handle(Standard_Transient)& theObject,
3340 Draw_Interpretor& theDI)
3341{
3342 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3343 if (anObj.IsNull())
3344 {
3345 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3346 return;
3347 }
7fd59977 3348
cb78155f 3349 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3350 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3351 << (theDetected.Contains (anObj) ? " Detected" : " ")
3352 << " Type: ";
3353 if (anObj->Type() == AIS_KOI_Datum)
3354 {
3355 // AIS_Datum
3356 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3357 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3358 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3359 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3360 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3361 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3362 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
7fd59977 3363 }
3364 // AIS_Shape
cb78155f 3365 else if (anObj->Type() == AIS_KOI_Shape
3366 && anObj->Signature() == 0)
3367 {
3368 theDI << " AIS_Shape";
7fd59977 3369 }
cb78155f 3370 else if (anObj->Type() == AIS_KOI_Relation)
3371 {
3372 // AIS_Dimention and AIS_Relation
3373 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3374 switch (aRelation->KindOfDimension())
3375 {
3376 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
3377 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3378 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
3379 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
3380 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
3381 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
3382 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
3383 default: theDI << " UNKNOWN dimension"; break;
3384 }
3385 }
3386 else
3387 {
3388 theDI << " UserPrs";
3389 }
3390 theDI << " (" << theObject->DynamicType()->Name() << ")";
7fd59977 3391}
3392
cb78155f 3393//! Print information about locally selected sub-shapes
3394static void localCtxInfo (Draw_Interpretor& theDI)
3395{
3396 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3397 if (!aCtx->HasOpenedContext())
3398 {
3399 return;
3400 }
7fd59977 3401
cb78155f 3402 TCollection_AsciiString aPrevName;
3403 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3404 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3405 {
3406 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
3407 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3408 if (aSubShape.IsNull()
3409 || aShapeIO.IsNull()
3410 || !GetMapOfAIS().IsBound1 (aShapeIO))
3411 {
3412 continue;
3413 }
3414
3415 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3416 TopTools_MapOfShape aFilter;
3417 Standard_Integer aNumber = 0;
3418 const TopoDS_Shape aShape = aShapeIO->Shape();
3419 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
3420 anIter.More(); anIter.Next())
3421 {
3422 if (!aFilter.Add (anIter.Current()))
3423 {
3424 continue; // filter duplicates
3425 }
3426
3427 ++aNumber;
3428 if (!anIter.Current().IsSame (aSubShape))
3429 {
3430 continue;
3431 }
3432
3433 Standard_CString aShapeName = NULL;
3434 switch (aSubShape.ShapeType())
3435 {
3436 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
3437 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
3438 case TopAbs_SOLID: aShapeName = " Solid"; break;
3439 case TopAbs_SHELL: aShapeName = " Shell"; break;
3440 case TopAbs_FACE: aShapeName = " Face"; break;
3441 case TopAbs_WIRE: aShapeName = " Wire"; break;
3442 case TopAbs_EDGE: aShapeName = " Edge"; break;
3443 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
3444 default:
3445 case TopAbs_SHAPE: aShapeName = " Shape"; break;
3446 }
3447
3448 if (aParentName != aPrevName)
3449 {
3450 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
3451 aPrevName = aParentName;
3452 }
3453 theDI << " " << aShapeName << " #" << aNumber << "\n";
3454 break;
3455 }
3456 }
3457}
7fd59977 3458
3459//==============================================================================
3460//function : VState
3461//purpose :
3462//Draw arg : vstate [nameA] ... [nameN]
3463//==============================================================================
cb78155f 3464static Standard_Integer VState (Draw_Interpretor& theDI,
3465 Standard_Integer theArgNb,
3466 Standard_CString* theArgVec)
7fd59977 3467{
cb78155f 3468 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3469 if (aCtx.IsNull())
3470 {
3471 std::cerr << "Error: No opened viewer!\n";
3472 return 1;
7fd59977 3473 }
cb78155f 3474
3475 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
3476 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
3477 {
3478 aDetected.Add (aCtx->DetectedCurrentObject());
3479 }
3480
3481 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
3482 if (theArgNb >= 2
3483 && !toShowAll)
3484 {
3485 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7fd59977 3486 {
cb78155f 3487 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
3488 if (!GetMapOfAIS().IsBound2 (anObjName))
3489 {
3490 theDI << anObjName << " doesn't exist!\n";
3491 continue;
7fd59977 3492 }
3493
cb78155f 3494 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
3495 TCollection_AsciiString aName = anObjName;
3496 aName.LeftJustify (20, ' ');
3497 theDI << " " << aName << " ";
3498 objInfo (aDetected, anObjTrans, theDI);
3499 theDI << "\n";
7fd59977 3500 }
cb78155f 3501 return 0;
7fd59977 3502 }
cb78155f 3503
3504 if (aCtx->NbCurrents() > 0