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