0026203: Foundation Classes - provide method ::Swap() for NCollection_IndexedMap...
[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>
ad3217cd 43#include <AIS_ColoredShape.hxx>
7fd59977 44#include <AIS_InteractiveObject.hxx>
45#include <AIS_Trihedron.hxx>
46#include <AIS_Axis.hxx>
47#include <AIS_Relation.hxx>
48#include <AIS_TypeFilter.hxx>
49#include <AIS_SignatureFilter.hxx>
cb78155f 50#include <AIS_LocalContext.hxx>
7fd59977 51#include <AIS_ListOfInteractive.hxx>
52#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 53#include <Aspect_InteriorStyle.hxx>
34db9c00 54#include <Aspect_Window.hxx>
99c56d44 55#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 56#include <Graphic3d_AspectLine3d.hxx>
a1954302 57#include <Graphic3d_CStructure.hxx>
392ac980 58#include <Graphic3d_TextureRoot.hxx>
692613e5 59#include <Image_AlienPixMap.hxx>
6262338c 60#include <Prs3d_Drawer.hxx>
99c56d44 61#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 62#include <Prs3d_IsoAspect.hxx>
6262338c 63#include <Prs3d_PointAspect.hxx>
8e7c8ccf 64#include <Select3D_SensitiveWire.hxx>
65#include <SelectMgr_EntityOwner.hxx>
66#include <StdSelect_BRepOwner.hxx>
67#include <StdSelect_ViewerSelector3d.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
6262338c 93#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
94#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
95#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
7fd59977 96
792c785c 97//=======================================================================
98//function : GetColorFromName
99//purpose : get the Quantity_NameOfColor from a string
100//=======================================================================
7fd59977 101
792c785c 102Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
103{
8316c618 104 Quantity_NameOfColor aColor = DEFAULT_COLOR;
105 Quantity_Color::ColorFromName (theName, aColor);
106 return aColor;
7fd59977 107}
108
536d98e2 109//=======================================================================
110//function : ParseColor
111//purpose :
112//=======================================================================
113
114Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
115 const char** theArgVec,
116 Quantity_Color& theColor)
117{
118 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
119 if (theArgNb >= 1
120 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
121 {
122 theColor = aColor;
123 return 1;
124 }
125 else if (theArgNb >= 3)
126 {
127 const TCollection_AsciiString anRgbStr[3] =
128 {
129 theArgVec[0],
130 theArgVec[1],
131 theArgVec[2]
132 };
133 if (!anRgbStr[0].IsRealValue()
134 || !anRgbStr[1].IsRealValue()
135 || !anRgbStr[2].IsRealValue())
136 {
137 return 0;
138 }
139
140 Graphic3d_Vec4d anRgb;
141 anRgb.x() = anRgbStr[0].RealValue();
142 anRgb.y() = anRgbStr[1].RealValue();
143 anRgb.z() = anRgbStr[2].RealValue();
144 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
145 || anRgb.y() < 0.0 || anRgb.y() > 1.0
146 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
147 {
148 std::cout << "Error: RGB color values should be within range 0..1!\n";
149 return 0;
150 }
151
152 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
153 return 3;
154 }
155
156 return 0;
157}
158
7fd59977 159//=======================================================================
160//function : GetTypeNames
161//purpose :
162//=======================================================================
163static const char** GetTypeNames()
164{
165 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
166 "Shape","ConnectedShape","MultiConn.Shape",
167 "ConnectedInter.","MultiConn.",
168 "Constraint","Dimension"};
169 static const char** ThePointer = names;
170 return ThePointer;
171}
172
173//=======================================================================
174//function : GetTypeAndSignfromString
175//purpose :
176//=======================================================================
177void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
178{
179 const char ** thefullnames = GetTypeNames();
180 Standard_Integer index(-1);
181
182 for(Standard_Integer i=0;i<=13 && index==-1;i++)
183 if(!strcasecmp(name,thefullnames[i]))
184 index = i;
185
186 if(index ==-1){
187 TheType = AIS_KOI_None;
188 TheSign = -1;
189 return;
190 }
191
192 if(index<=6){
193 TheType = AIS_KOI_Datum;
194 TheSign = index+1;
195 }
196 else if (index <=9){
197 TheType = AIS_KOI_Shape;
198 TheSign = index-7;
199 }
200 else if(index<=11){
201 TheType = AIS_KOI_Object;
202 TheSign = index-10;
203 }
204 else{
205 TheType = AIS_KOI_Relation;
206 TheSign = index-12;
207 }
208
209}
210
211
212
213#include <string.h>
214#include <Draw_Interpretor.hxx>
215#include <Draw.hxx>
216#include <Draw_Appli.hxx>
217#include <DBRep.hxx>
218
219
220#include <TCollection_AsciiString.hxx>
221#include <V3d_Viewer.hxx>
222#include <V3d_View.hxx>
223#include <V3d.hxx>
224
225#include <AIS_InteractiveContext.hxx>
226#include <AIS_Shape.hxx>
227#include <AIS_TexturedShape.hxx>
228#include <AIS_DisplayMode.hxx>
229#include <TColStd_MapOfInteger.hxx>
230#include <AIS_MapOfInteractive.hxx>
231#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
232#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
233#include <ViewerTest_EventManager.hxx>
234
235#include <TopoDS_Solid.hxx>
236#include <BRepTools.hxx>
237#include <BRep_Builder.hxx>
238#include <TopAbs_ShapeEnum.hxx>
239
240#include <TopoDS.hxx>
241#include <BRep_Tool.hxx>
242
243
244#include <Draw_Window.hxx>
245#include <AIS_ListIteratorOfListOfInteractive.hxx>
246#include <AIS_ListOfInteractive.hxx>
247#include <AIS_DisplayMode.hxx>
248#include <TopTools_ListOfShape.hxx>
249#include <BRepOffsetAPI_MakeThickSolid.hxx>
250#include <BRepOffset.hxx>
251
7fd59977 252//==============================================================================
253// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
254//==============================================================================
255Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
256 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
257 return TheMap;
258}
259
29e2c6d2 260//=======================================================================
261//function : Display
262//purpose :
263//=======================================================================
264Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
265 const Handle(AIS_InteractiveObject)& theObject,
266 const Standard_Boolean theToUpdate,
267 const Standard_Boolean theReplaceIfExists)
9558a876
A
268{
269 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29e2c6d2 270 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
271 if (aCtx.IsNull())
9558a876 272 {
29e2c6d2 273 std::cout << "Error: AIS context is not available.\n";
9558a876
A
274 return Standard_False;
275 }
276
277 if (aMap.IsBound2 (theName))
278 {
279 if (!theReplaceIfExists)
280 {
29e2c6d2 281 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
9558a876
A
282 << "Please use another name.\n";
283 return Standard_False;
284 }
285
29e2c6d2 286 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
9558a876 287 if (!anOldObj.IsNull())
29e2c6d2 288 {
289 aCtx->Remove (anOldObj, Standard_True);
290 }
9558a876
A
291 aMap.UnBind2 (theName);
292 }
293
29e2c6d2 294 if (theObject.IsNull())
208e6839 295 {
29e2c6d2 296 // object with specified name has been already unbound
208e6839 297 return Standard_True;
298 }
299
29e2c6d2 300 // unbind AIS object if it was bound with another name
301 aMap.UnBind1 (theObject);
9558a876
A
302
303 // can be registered without rebinding
29e2c6d2 304 aMap.Bind (theObject, theName);
305 aCtx->Display (theObject, theToUpdate);
9558a876
A
306 return Standard_True;
307}
308
29e2c6d2 309//! Alias for ViewerTest::Display(), compatibility with old code.
310Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
311 const Handle(AIS_InteractiveObject)& theObject,
312 Standard_Boolean theReplaceIfExists = Standard_True)
313{
314 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
315}
316
7fd59977 317static TColStd_MapOfInteger theactivatedmodes(8);
318static TColStd_ListOfTransient theEventMgrs;
319
320static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
321 const Handle(AIS_InteractiveContext)& Ctx)
322{
323 theEventMgrs.Clear();
324 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
325}
326
24de79c3 327static Handle(V3d_View)& a3DView()
328{
7fd59977 329 static Handle(V3d_View) Viou;
330 return Viou;
331}
332
24de79c3 333
7fd59977 334Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
335 static Handle(AIS_InteractiveContext) aContext;
336 return aContext;
337}
338
24de79c3 339const Handle(V3d_View)& ViewerTest::CurrentView()
7fd59977 340{
341 return a3DView();
342}
343void ViewerTest::CurrentView(const Handle(V3d_View)& V)
344{
345 a3DView() = V;
346}
347
348Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
349{
350 static Handle(NIS_InteractiveContext) aContext;
351 if (aContext.IsNull()) {
352 aContext = new NIS_InteractiveContext;
353 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
354 }
355 return aContext;
356}
357
24de79c3 358const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
7fd59977 359{
360 return TheAISContext();
361}
362
363void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
364{
365 TheAISContext() = aCtx;
366 ViewerTest::ResetEventManager();
367}
368
369Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
370{
4952a30a 371 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 372}
373
374Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
375{
4952a30a 376 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 377}
378
379
380void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
381 theEventMgrs.Prepend(EM);
382}
383
384void ViewerTest::UnsetEventManager()
385{
386 theEventMgrs.RemoveFirst();
387}
388
389
390void ViewerTest::ResetEventManager()
391{
392 const Handle(NIS_View) aView =
393 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
394 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
395}
396
397Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
398{
399 Handle(ViewerTest_EventManager) EM;
400 if(theEventMgrs.IsEmpty()) return EM;
401 Handle(Standard_Transient) Tr = theEventMgrs.First();
402 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
403 return EM;
404}
405
7fd59977 406//=======================================================================
34db9c00 407//function : Get Context and active view
7fd59977 408//purpose :
409//=======================================================================
34db9c00 410static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
411 Handle(V3d_View)& theView)
7fd59977 412{
34db9c00 413 theCtx = ViewerTest::GetAISContext();
414 theView = ViewerTest::CurrentView();
415 if (theCtx.IsNull()
416 || theView.IsNull())
7fd59977 417 {
34db9c00 418 std::cout << "Error: cannot find an active view!\n";
419 return Standard_False;
7fd59977 420 }
34db9c00 421 return Standard_True;
7fd59977 422}
423
7fd59977 424//==============================================================================
425//function : GetShapeFromName
426//purpose : Compute an Shape from a draw variable or a file name
427//==============================================================================
428
429static TopoDS_Shape GetShapeFromName(const char* name)
430{
431 TopoDS_Shape S = DBRep::Get(name);
432
433 if ( S.IsNull() ) {
434 BRep_Builder aBuilder;
435 BRepTools::Read( S, name, aBuilder);
436 }
437
438 return S;
439}
4e18e72a 440
7fd59977 441//==============================================================================
442//function : GetAISShapeFromName
443//purpose : Compute an AIS_Shape from a draw variable or a file name
444//==============================================================================
445Handle(AIS_Shape) GetAISShapeFromName(const char* name)
446{
447 Handle(AIS_Shape) retsh;
448
449 if(GetMapOfAIS().IsBound2(name)){
450 const Handle(AIS_InteractiveObject) IO =
451 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
452 if (!IO.IsNull()) {
eafb234b 453 if(IO->Type()==AIS_KOI_Shape) {
7fd59977 454 if(IO->Signature()==0){
455 retsh = *((Handle(AIS_Shape)*)&IO);
456 }
457 else
458 cout << "an Object which is not an AIS_Shape "
459 "already has this name!!!"<<endl;
eafb234b 460 }
7fd59977 461 }
462 return retsh;
463 }
464
465
466 TopoDS_Shape S = GetShapeFromName(name);
467 if ( !S.IsNull() ) {
468 retsh = new AIS_Shape(S);
469 }
470 return retsh;
471}
472
473
474//==============================================================================
475//function : Clear
476//purpose : Remove all the object from the viewer
477//==============================================================================
478void ViewerTest::Clear()
479{
480 if ( !a3DView().IsNull() ) {
481 if (TheAISContext()->HasOpenedContext())
482 TheAISContext()->CloseLocalContext();
483 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
484 while ( it.More() ) {
485 cout << "Remove " << it.Key2() << endl;
486 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
487 const Handle(AIS_InteractiveObject) anObj =
488 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
489 TheAISContext()->Remove(anObj,Standard_False);
490 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
491 const Handle(NIS_InteractiveObject) anObj =
492 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
ffe2bea7 493 TheNISContext()->Remove(anObj);
7fd59977 494 }
495 it.Next();
496 }
f751596e 497 TheAISContext()->RebuildSelectionStructs();
7fd59977 498 TheAISContext()->UpdateCurrentViewer();
ffe2bea7 499// TheNISContext()->UpdateViews();
7fd59977 500 GetMapOfAIS().Clear();
501 }
502}
503
504//==============================================================================
505//function : StandardModesActivation
506//purpose : Activate a selection mode, vertex, edge, wire ..., in a local
507// Context
508//==============================================================================
509void ViewerTest::StandardModeActivation(const Standard_Integer mode )
510{
511 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
512 if(mode==0) {
513 if (TheAISContext()->HasOpenedContext())
514 aContext->CloseLocalContext();
515 } else {
516
517 if(!aContext->HasOpenedContext()) {
518 // To unhilight the preselected object
519 aContext->UnhilightCurrents(Standard_False);
520 // Open a local Context in order to be able to select subshape from
521 // the selected shape if any or for all if there is no selection
522 if (!aContext->FirstCurrentObject().IsNull()){
523 aContext->OpenLocalContext(Standard_False);
524
525 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
526 aContext->Load( aContext->Current(),-1,Standard_True);
527 }
528 }
529 else
530 aContext->OpenLocalContext();
531 }
532
533 const char *cmode="???";
534
535 switch (mode) {
536 case 0: cmode = "Shape"; break;
537 case 1: cmode = "Vertex"; break;
538 case 2: cmode = "Edge"; break;
539 case 3: cmode = "Wire"; break;
540 case 4: cmode = "Face"; break;
541 case 5: cmode = "Shell"; break;
542 case 6: cmode = "Solid"; break;
4754e164 543 case 7: cmode = "Compsolid"; break;
544 case 8: cmode = "Compound"; break;
7fd59977 545 }
546
547 if(theactivatedmodes.Contains(mode))
548 { // Desactivate
549 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
550 theactivatedmodes.Remove(mode);
551 cout<<"Mode "<< cmode <<" OFF"<<endl;
552 }
553 else
554 { // Activate
555 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
556 theactivatedmodes.Add(mode);
557 cout<<"Mode "<< cmode << " ON" << endl;
558 }
559 }
560}
561
1c88cbaf 562//==============================================================================
563//function : CopyIsoAspect
564//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
565//==============================================================================
566static Handle(Prs3d_IsoAspect) CopyIsoAspect
567 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
568 const Standard_Integer theNbIsos)
569{
570 Quantity_Color aColor;
571 Aspect_TypeOfLine aType;
572 Standard_Real aWidth;
573
574 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
575
576 Handle(Prs3d_IsoAspect) aResult =
577 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
578
579 return aResult;
580}
581
582//==============================================================================
583//function : visos
584//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
585//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
586//==============================================================================
587static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
588{
589 if (TheAISContext().IsNull()) {
590 di << argv[0] << " Call 'vinit' before!\n";
591 return 1;
592 }
593
594 if (argc <= 1) {
595 di << "Current number of isos : " <<
596 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
597 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
598 di << "IsoOnPlane mode is " <<
599 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
600
601 return 0;
602 }
603
604 Standard_Integer aLastInd = argc - 1;
605 Standard_Boolean isChanged = Standard_False;
1d47d8d0 606 Standard_Integer aNbUIsos = 0;
607 Standard_Integer aNbVIsos = 0;
1c88cbaf 608
609 if (aLastInd >= 3) {
610 Standard_Boolean isIsoOnPlane = Standard_False;
611
612 if (strcmp(argv[aLastInd], "1") == 0) {
613 isIsoOnPlane = Standard_True;
614 isChanged = Standard_True;
615 } else if (strcmp(argv[aLastInd], "0") == 0) {
616 isIsoOnPlane = Standard_False;
617 isChanged = Standard_True;
618 }
619
620 if (isChanged) {
621 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
622 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
623 aLastInd -= 3;
624
625 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
626 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
627
628 TheAISContext()->IsoOnPlane(isIsoOnPlane);
629
630 if (aLastInd == 0) {
631 // If there are no shapes provided set the default numbers.
632 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
633 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
634 }
635 }
636 }
637
638 Standard_Integer i;
639
640 for (i = 1; i <= aLastInd; i++) {
641 TCollection_AsciiString name(argv[i]);
642 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
643
644 if (IsBound) {
645 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
646 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
647 const Handle(AIS_InteractiveObject) aShape =
648 Handle(AIS_InteractiveObject)::DownCast (anObj);
6262338c 649 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
1c88cbaf 650 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
651 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
652
653 if (isChanged) {
654 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
655 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
656 TheAISContext()->SetLocalAttributes
657 (aShape, CurDrawer, Standard_False);
658 TheAISContext()->Redisplay(aShape);
659 } else {
660 di << "Number of isos for " << argv[i] << " : "
661 << aUIso->Number() << " " << aVIso->Number() << "\n";
662 }
663 } else {
664 di << argv[i] << ": Not an AIS interactive object!\n";
665 }
666 } else {
667 di << argv[i] << ": Use 'vdisplay' before\n";
668 }
669 }
670
671 if (isChanged) {
672 TheAISContext()->UpdateCurrentViewer();
673 }
674
675 return 0;
676}
677
34db9c00 678static Standard_Integer VDispSensi (Draw_Interpretor& ,
679 Standard_Integer theArgNb,
680 Standard_CString* )
7fd59977 681{
34db9c00 682 if (theArgNb > 1)
683 {
684 std::cout << "Error: wrong syntax!\n";
685 return 1;
686 }
687
688 Handle(AIS_InteractiveContext) aCtx;
689 Handle(V3d_View) aView;
690 if (!getCtxAndView (aCtx, aView))
691 {
692 return 1;
693 }
694
695 aCtx->DisplayActiveSensitive (aView);
7fd59977 696 return 0;
697
698}
34db9c00 699
700static Standard_Integer VClearSensi (Draw_Interpretor& ,
701 Standard_Integer theArgNb,
702 Standard_CString* )
7fd59977 703{
34db9c00 704 if (theArgNb > 1)
705 {
706 std::cout << "Error: wrong syntax!\n";
707 return 1;
708 }
709
710 Handle(AIS_InteractiveContext) aCtx;
711 Handle(V3d_View) aView;
712 if (!getCtxAndView (aCtx, aView))
713 {
714 return 1;
715 }
716 aCtx->ClearActiveSensitive (aView);
7fd59977 717 return 0;
718}
719
720//==============================================================================
519d35d8 721//function : VDir
7fd59977 722//purpose : To list the displayed object with their attributes
7fd59977 723//==============================================================================
519d35d8 724static int VDir (Draw_Interpretor& theDI,
725 Standard_Integer ,
726 const char** )
727{
728 if (!a3DView().IsNull())
729 {
730 return 0;
7fd59977 731 }
732
519d35d8 733 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
734 anIter.More(); anIter.Next())
735 {
736 theDI << "\t" << anIter.Key2().ToCString() << "\n";
737 }
7fd59977 738 return 0;
739}
740
3c982548 741//==============================================================================
742//function : VSelPrecision
f751596e 743//purpose : To set the selection tolerance value
744//Draw arg : Selection tolerance value (real value determining the width and
745// height of selecting frustum bases). Without arguments the function
746// just prints current tolerance.
3c982548 747//==============================================================================
748static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
749{
f751596e 750 if( argc > 2 )
3c982548 751 {
28ee613b 752 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
3c982548 753 return 1;
754 }
755
756 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
757 if( aContext.IsNull() )
758 return 1;
759
760 if( argc == 1 )
761 {
f751596e 762 Standard_Real aPixelTolerance = aContext->PixelTolerance();
f751596e 763 di << "Pixel tolerance : " << aPixelTolerance << "\n";
3c982548 764 }
f751596e 765 else if (argc == 2)
3c982548 766 {
28ee613b 767 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
768 anArg.LowerCase();
769 if (anArg == "-unset")
770 {
771 aContext->SetPixelTolerance (-1.0);
772 }
773 else
774 {
775 aContext->SetPixelTolerance (anArg.RealValue());
776 }
3c982548 777 }
f751596e 778
3c982548 779 return 0;
780}
781
7fd59977 782//==============================================================================
783//function : VDump
784//purpose : To dump the active view snapshot to image file
7fd59977 785//==============================================================================
34db9c00 786static Standard_Integer VDump (Draw_Interpretor& theDI,
787 Standard_Integer theArgNb,
788 Standard_CString* theArgVec)
7fd59977 789{
34db9c00 790 if (theArgNb < 2)
7fd59977 791 {
34db9c00 792 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
7fd59977 793 return 1;
794 }
795
34db9c00 796 Standard_Integer anArgIter = 1;
797 Standard_CString aFilePath = theArgVec[anArgIter++];
798 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
799 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
800 Standard_Integer aWidth = 0;
801 Standard_Integer aHeight = 0;
802 for (; anArgIter < theArgNb; ++anArgIter)
7fd59977 803 {
34db9c00 804 TCollection_AsciiString anArg (theArgVec[anArgIter]);
805 anArg.LowerCase();
806 if (anArg == "rgba")
7fd59977 807 {
34db9c00 808 aBufferType = Graphic3d_BT_RGBA;
7fd59977 809 }
34db9c00 810 else if (anArg == "rgb")
7fd59977 811 {
34db9c00 812 aBufferType = Graphic3d_BT_RGB;
7fd59977 813 }
34db9c00 814 else if (anArg == "depth")
7fd59977 815 {
692613e5 816 aBufferType = Graphic3d_BT_Depth;
7fd59977 817 }
34db9c00 818 else if (anArg == "l"
819 || anArg == "left")
820 {
821 aStereoOpts = V3d_SDO_LEFT_EYE;
822 }
823 else if (anArg == "r"
824 || anArg == "right")
825 {
826 aStereoOpts = V3d_SDO_RIGHT_EYE;
827 }
828 else if (anArg == "mono")
829 {
830 aStereoOpts = V3d_SDO_MONO;
831 }
832 else if (anArg == "w"
833 || anArg == "width")
834 {
835 if (aWidth != 0)
836 {
837 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
838 return 1;
839 }
840 else if (++anArgIter >= theArgNb)
841 {
842 std::cout << "Error: integer value is expected right after 'width'\n";
843 return 1;
844 }
845 aWidth = Draw::Atoi (theArgVec[anArgIter]);
846 }
847 else if (anArg == "h"
848 || anArg == "height")
849 {
850 if (aHeight != 0)
851 {
852 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
853 return 1;
854 }
855 if (++anArgIter >= theArgNb)
856 {
857 std::cout << "Error: integer value is expected right after 'height'\n";
858 return 1;
859 }
860 aHeight = Draw::Atoi (theArgVec[anArgIter]);
861 }
862 else if (anArg.IsIntegerValue())
863 {
864 // compatibility with old syntax
865 if (aWidth != 0
866 || aHeight != 0)
867 {
868 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
869 return 1;
870 }
871 else if (++anArgIter >= theArgNb)
872 {
873 std::cout << "Error: height value is expected right after width\n";
874 return 1;
875 }
876 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
877 aHeight = Draw::Atoi (theArgVec[anArgIter]);
878 }
879 else
880 {
881 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
882 return 1;
883 }
7fd59977 884 }
34db9c00 885 if ((aWidth <= 0 && aHeight > 0)
886 || (aWidth > 0 && aHeight <= 0))
7fd59977 887 {
34db9c00 888 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
85e096c3 889 return 1;
890 }
891
34db9c00 892 Handle(V3d_View) aView = ViewerTest::CurrentView();
893 if (aView.IsNull())
85e096c3 894 {
34db9c00 895 std::cout << "Error: cannot find an active view!\n";
896 return 1;
7fd59977 897 }
85e096c3 898
34db9c00 899 if (aWidth <= 0 || aHeight <= 0)
b5ac8292 900 {
34db9c00 901 if (aStereoOpts != V3d_SDO_MONO)
b5ac8292 902 {
34db9c00 903 aView->Window()->Size (aWidth, aHeight);
b5ac8292 904 }
34db9c00 905 else
b5ac8292 906 {
34db9c00 907 if (!aView->Dump (aFilePath, aBufferType))
908 {
909 theDI << "Fail: view dump failed!\n";
910 }
911 return 0;
b5ac8292 912 }
913 }
914
692613e5 915 Image_AlienPixMap aPixMap;
34db9c00 916 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
7fd59977 917 {
34db9c00 918 theDI << "Fail: view dump failed!\n";
919 return 0;
7fd59977 920 }
85e096c3 921
692613e5 922 if (aPixMap.SizeX() != Standard_Size(aWidth)
923 || aPixMap.SizeY() != Standard_Size(aHeight))
85e096c3 924 {
34db9c00 925 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
926 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
85e096c3 927 }
34db9c00 928 if (!aPixMap.Save (aFilePath))
85e096c3 929 {
34db9c00 930 theDI << "Fail: image can not be saved!\n";
85e096c3 931 }
932 return 0;
7fd59977 933}
934
935
936//==============================================================================
937//function : Displays,Erase...
938//purpose :
939//Draw arg :
940//==============================================================================
941static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
942 const Standard_Integer Mode,
943 const Standard_Integer TypeOfOperation,
944 const Standard_Boolean Upd)
945{
946 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
947
948 switch(TypeOfOperation){
949 case 1:
950 Ctx->Display(IO,Mode,Upd);
951 break;
952 case 2:{
eb4320f2 953 Ctx->Erase(IO,Upd);
7fd59977 954 break;
955 }
956 case 3:{
957 if(IO.IsNull())
958 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
959 else
960 Ctx->SetDisplayMode(IO,Mode,Upd);
961 break;
962 }
963 case 4:{
964 if(IO.IsNull())
965 Ctx->SetDisplayMode(0,Upd);
966 else
967 Ctx->UnsetDisplayMode(IO,Upd);
968 break;
969 }
970 }
971 return 0;
972}
973
974//=======================================================================
975//function :
976//purpose :
977//=======================================================================
978static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
979{
980
981 TCollection_AsciiString name;
982 if(argc>3)
983 return 1;
984 // display others presentations
985 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
986 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
987 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
988 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
989
990 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
991
992 //unset displaymode.. comportement particulier...
993 if(TypeOfOperation==4){
994 if(argc==1){
995 if(Ctx->NbCurrents()==0 ||
996 Ctx->NbSelected()==0){
997 Handle(AIS_InteractiveObject) IO;
998 VwrTst_DispErase(IO,-1,4,Standard_False);
999 }
1000 else if(!Ctx->HasOpenedContext()){
1001 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1002 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1003 }
1004 else{
1005 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1006 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1007 Ctx->UpdateCurrentViewer();
1008 }
1009 else{
1010 Handle(AIS_InteractiveObject) IO;
1011 name = argv[1];
1012 if(GetMapOfAIS().IsBound2(name)){
1013 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1014 if (!IO.IsNull())
1015 VwrTst_DispErase(IO,-1,4,Standard_True);
1016 }
1017 }
1018 }
1019 else if(argc==2){
91322f44 1020 Standard_Integer Dmode = Draw::Atoi(argv[1]);
7fd59977 1021 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1022 Handle(AIS_InteractiveObject) IO;
1023 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1024 }
1025 if(!Ctx->HasOpenedContext()){
1026 // set/unset display mode sur le Contexte...
1027 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1028 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1029 }
1030 Ctx->UpdateCurrentViewer();
1031 }
1032 else{
1033 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1034 Ctx->Display(Ctx->Interactive(),Dmode);
1035 }
1036 }
1037 else{
1038 Handle(AIS_InteractiveObject) IO;
1039 name = argv[1];
1040 if(GetMapOfAIS().IsBound2(name))
1041 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1042 if (!IO.IsNull())
91322f44 1043 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
7fd59977 1044 }
1045 return 0;
1046}
1047
1048
1049//=======================================================================
1050//function :
1051//purpose :
1052//=======================================================================
1053static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1054{
1055 if(argc==1) return 1;
91322f44 1056 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 1057 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1058
1059 if(argc==2){
1060
1061 if(!Ctx->HasOpenedContext()){
1062 di<<"sub intensite ";
1063 if(On==1) di<<"On";
1064 else di<<"Off";
1065 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1066 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1067 if(On==1){
1068 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1069 else{
1070 di <<"passage dans off"<<"\n";
1071 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1072 }
1073 }
1074 }
1075 else{
1076 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1077 if(On==1){
1078 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1079 else{
1080 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1081 }
1082 }
1083 Ctx->UpdateCurrentViewer();
1084 }
1085 else {
1086 Handle(AIS_InteractiveObject) IO;
1087 TCollection_AsciiString name = argv[2];
1088 if(GetMapOfAIS().IsBound2(name)){
1089 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
eafb234b 1090 if (!IO.IsNull()) {
7fd59977 1091 if(On==1)
1092 Ctx->SubIntensityOn(IO);
1093 else
1094 Ctx->SubIntensityOff(IO);
eafb234b 1095 }
7fd59977 1096 }
1097 else return 1;
1098 }
1099 return 0;
7fd59977 1100}
7fd59977 1101
ad3217cd 1102//! Auxiliary class to iterate presentations from different collections.
1103class ViewTest_PrsIter
1104{
1105public:
7fd59977 1106
ad3217cd 1107 //! Create and initialize iterator object.
1108 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1109 : mySource (IterSource_All)
1110 {
1111 NCollection_Sequence<TCollection_AsciiString> aNames;
1112 if (!theName.IsEmpty())
1113 aNames.Append (theName);
1114 Init (aNames);
7fd59977 1115 }
ad3217cd 1116
1117 //! Create and initialize iterator object.
1118 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1119 : mySource (IterSource_All)
1120 {
1121 Init (theNames);
7fd59977 1122 }
1123
ad3217cd 1124 //! Initialize the iterator.
1125 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1126 {
1127 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1128 mySeq = theNames;
1129 mySelIter.Nullify();
1130 myCurrent.Nullify();
1131 myCurrentTrs.Nullify();
1132 if (!mySeq.IsEmpty())
1133 {
1134 mySource = IterSource_List;
1135 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
7fd59977 1136 }
ad3217cd 1137 else if (aCtx->NbCurrents() > 0)
1138 {
1139 mySource = IterSource_Selected;
1140 mySelIter = aCtx;
1141 mySelIter->InitCurrent();
1142 }
1143 else
1144 {
1145 mySource = IterSource_All;
1146 myMapIter.Initialize (GetMapOfAIS());
1147 }
1148 initCurrent();
1149 }
7fd59977 1150
ad3217cd 1151 const TCollection_AsciiString& CurrentName() const
1152 {
1153 return myCurrentName;
1154 }
7fd59977 1155
ad3217cd 1156 const Handle(AIS_InteractiveObject)& Current() const
1157 {
1158 return myCurrent;
1159 }
7fd59977 1160
ad3217cd 1161 const Handle(Standard_Transient)& CurrentTrs() const
1162 {
1163 return myCurrentTrs;
1164 }
1165
1166 //! @return true if iterator points to valid object within collection
1167 Standard_Boolean More() const
1168 {
1169 switch (mySource)
1170 {
1171 case IterSource_All: return myMapIter.More();
1172 case IterSource_List: return mySeqIter.More();
1173 case IterSource_Selected: return mySelIter->MoreCurrent();
1174 }
1175 return Standard_False;
1176 }
1177
1178 //! Go to the next item.
1179 void Next()
1180 {
1181 myCurrentName.Clear();
1182 myCurrentTrs.Nullify();
1183 myCurrent.Nullify();
1184 switch (mySource)
1185 {
1186 case IterSource_All:
1187 {
1188 myMapIter.Next();
1189 break;
1190 }
1191 case IterSource_List:
1192 {
1193 mySeqIter.Next();
1194 break;
1195 }
1196 case IterSource_Selected:
1197 {
1198 mySelIter->NextCurrent();
1199 break;
7fd59977 1200 }
1201 }
ad3217cd 1202 initCurrent();
1203 }
7fd59977 1204
ad3217cd 1205private:
7fd59977 1206
ad3217cd 1207 void initCurrent()
1208 {
1209 switch (mySource)
1210 {
1211 case IterSource_All:
7fd59977 1212 {
ad3217cd 1213 if (myMapIter.More())
1214 {
1215 myCurrentName = myMapIter.Key2();
1216 myCurrentTrs = myMapIter.Key1();
1217 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
eafb234b 1218 }
ad3217cd 1219 break;
1220 }
1221 case IterSource_List:
1222 {
1223 if (mySeqIter.More())
1224 {
1225 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1226 {
1227 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1228 return;
1229 }
1230 myCurrentName = mySeqIter.Value();
1231 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1232 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1233 }
1234 break;
1235 }
1236 case IterSource_Selected:
1237 {
1238 if (mySelIter->MoreCurrent())
1239 {
1240 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1241 myCurrent = mySelIter->Current();
1242 }
1243 break;
7fd59977 1244 }
7fd59977 1245 }
1246 }
ad3217cd 1247
1248private:
1249
1250 enum IterSource
1251 {
1252 IterSource_All,
1253 IterSource_List,
1254 IterSource_Selected
1255 };
1256
1257private:
1258
1259 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1260 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1261 NCollection_Sequence<TCollection_AsciiString> mySeq;
1262 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1263
1264 TCollection_AsciiString myCurrentName;//!< current item name
1265 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1266 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1267
1268 IterSource mySource; //!< iterated collection
1269
1270};
7fd59977 1271
1272//==============================================================================
ad3217cd 1273//function : VInteriorStyle
1274//purpose : sets interior style of the a selected or named or displayed shape
7fd59977 1275//==============================================================================
ad3217cd 1276static int VSetInteriorStyle (Draw_Interpretor& theDI,
1277 Standard_Integer theArgNb,
1278 const char** theArgVec)
7fd59977 1279{
ad3217cd 1280 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1281 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1282 if (aCtx.IsNull())
1283 {
1284 std::cerr << "Error: no active view!\n";
1285 return 1;
1286 }
7fd59977 1287
4e18052b 1288 Standard_Integer anArgIter = 1;
ad3217cd 1289 for (; anArgIter < theArgNb; ++anArgIter)
1290 {
4e18052b 1291 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
ad3217cd 1292 {
1293 break;
1294 }
7fd59977 1295 }
ad3217cd 1296 TCollection_AsciiString aName;
1297 if (theArgNb - anArgIter == 2)
1298 {
1299 aName = theArgVec[anArgIter++];
1300 }
1301 else if (theArgNb - anArgIter != 1)
1302 {
1303 std::cout << "Error: wrong number of arguments! See usage:\n";
1304 theDI.PrintHelp (theArgVec[0]);
1305 return 1;
1306 }
1307 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1308 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1309 aStyleArg.LowerCase();
1310 if (aStyleArg == "empty")
1311 {
1312 anInterStyle = 0;
1313 }
1314 else if (aStyleArg == "hollow")
1315 {
1316 anInterStyle = 1;
1317 }
1318 else if (aStyleArg == "hatch")
1319 {
1320 anInterStyle = 2;
1321 }
1322 else if (aStyleArg == "solid")
1323 {
1324 anInterStyle = 3;
1325 }
1326 else if (aStyleArg == "hiddenline")
1327 {
1328 anInterStyle = 4;
1329 }
1330 else
1331 {
1332 anInterStyle = aStyleArg.IntegerValue();
1333 }
1334 if (anInterStyle < Aspect_IS_EMPTY
1335 || anInterStyle > Aspect_IS_HIDDENLINE)
1336 {
1337 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1338 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1339 return 1;
7fd59977 1340 }
1341
ad3217cd 1342 if (!aName.IsEmpty()
1343 && !GetMapOfAIS().IsBound2 (aName))
1344 {
1345 std::cout << "Error: object " << aName << " is not displayed!\n";
1346 return 1;
1347 }
1348
1349 if (aCtx->HasOpenedContext())
1350 {
1351 aCtx->CloseLocalContext();
1352 }
1353 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1354 {
1355 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1356 if (!anIO.IsNull())
1357 {
1358 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1359 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1360 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1361 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1362 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
7fd59977 1363 }
ad3217cd 1364 }
ad3217cd 1365 return 0;
1366}
7fd59977 1367
ad3217cd 1368//! Auxiliary structure for VAspects
1369struct ViewerTest_AspectsChangeSet
1370{
5bffb882 1371 Standard_Integer ToSetVisibility;
1372 Standard_Integer Visibility;
1373
ad3217cd 1374 Standard_Integer ToSetColor;
1375 Quantity_Color Color;
1376
1377 Standard_Integer ToSetLineWidth;
1378 Standard_Real LineWidth;
1379
1380 Standard_Integer ToSetTransparency;
1381 Standard_Real Transparency;
1382
1383 Standard_Integer ToSetMaterial;
1384 Graphic3d_NameOfMaterial Material;
1385 TCollection_AsciiString MatName;
1386
1387 NCollection_Sequence<TopoDS_Shape> SubShapes;
1388
6262338c 1389 Standard_Integer ToSetShowFreeBoundary;
1390 Standard_Integer ToSetFreeBoundaryWidth;
1391 Standard_Real FreeBoundaryWidth;
1392 Standard_Integer ToSetFreeBoundaryColor;
1393 Quantity_Color FreeBoundaryColor;
1394
ad3217cd 1395 //! Empty constructor
1396 ViewerTest_AspectsChangeSet()
5bffb882 1397 : ToSetVisibility (0),
1398 Visibility (1),
1399 ToSetColor (0),
ad3217cd 1400 Color (DEFAULT_COLOR),
1401 ToSetLineWidth (0),
1402 LineWidth (1.0),
1403 ToSetTransparency (0),
1404 Transparency (0.0),
1405 ToSetMaterial (0),
6262338c 1406 Material (Graphic3d_NOM_DEFAULT),
1407 ToSetShowFreeBoundary (0),
1408 ToSetFreeBoundaryWidth (0),
1409 FreeBoundaryWidth (1.0),
1410 ToSetFreeBoundaryColor (0),
1411 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR) {}
ad3217cd 1412
1413 //! @return true if no changes have been requested
1414 Standard_Boolean IsEmpty() const
1415 {
6262338c 1416 return ToSetVisibility == 0
1417 && ToSetLineWidth == 0
1418 && ToSetTransparency == 0
1419 && ToSetColor == 0
1420 && ToSetMaterial == 0
1421 && ToSetShowFreeBoundary == 0
1422 && ToSetFreeBoundaryColor == 0
1423 && ToSetFreeBoundaryWidth == 0;
ad3217cd 1424 }
1425
1426 //! @return true if properties are valid
1427 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1428 {
1429 Standard_Boolean isOk = Standard_True;
5bffb882 1430 if (Visibility != 0 && Visibility != 1)
1431 {
1432 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1433 isOk = Standard_False;
1434 }
ad3217cd 1435 if (LineWidth <= 0.0
1436 || LineWidth > 10.0)
1437 {
1438 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1439 isOk = Standard_False;
7fd59977 1440 }
ad3217cd 1441 if (Transparency < 0.0
1442 || Transparency > 1.0)
1443 {
1444 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1445 isOk = Standard_False;
1446 }
1447 if (theIsSubPart
1448 && ToSetTransparency)
1449 {
1450 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1451 isOk = Standard_False;
7fd59977 1452 }
ad3217cd 1453 if (ToSetMaterial == 1
1454 && Material == Graphic3d_NOM_DEFAULT)
1455 {
1456 std::cout << "Error: unknown material " << MatName << ".\n";
1457 isOk = Standard_False;
1458 }
6262338c 1459 if (FreeBoundaryWidth <= 0.0
1460 || FreeBoundaryWidth > 10.0)
1461 {
1462 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1463 isOk = Standard_False;
1464 }
ad3217cd 1465 return isOk;
7fd59977 1466 }
7fd59977 1467
ad3217cd 1468};
7fd59977 1469
1470//==============================================================================
ad3217cd 1471//function : VAspects
1472//purpose :
7fd59977 1473//==============================================================================
ad3217cd 1474static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1475 Standard_Integer theArgNb,
1476 const char** theArgVec)
7fd59977 1477{
ad3217cd 1478 TCollection_AsciiString aCmdName (theArgVec[0]);
1479 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1480 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1481 if (aCtx.IsNull())
1482 {
1483 std::cerr << "Error: no active view!\n";
1484 return 1;
1485 }
7fd59977 1486
4e18052b 1487 Standard_Integer anArgIter = 1;
6262338c 1488 Standard_Boolean isDefaults = Standard_False;
ad3217cd 1489 NCollection_Sequence<TCollection_AsciiString> aNames;
1490 for (; anArgIter < theArgNb; ++anArgIter)
1491 {
1492 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 1493 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 1494 {
1495 continue;
1496 }
1497 else if (!anArg.IsEmpty()
1498 && anArg.Value (1) != '-')
1499 {
1500 aNames.Append (anArg);
1501 }
1502 else
1503 {
6262338c 1504 if (anArg == "-defaults")
1505 {
1506 isDefaults = Standard_True;
1507 ++anArgIter;
1508 }
ad3217cd 1509 break;
1510 }
1511 }
1512
6262338c 1513 if (!aNames.IsEmpty() && isDefaults)
1514 {
1515 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1516 return 1;
1517 }
1518
ad3217cd 1519 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1520 aChanges.Append (ViewerTest_AspectsChangeSet());
1521 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 1522
ad3217cd 1523 // parse syntax of legacy commands
1524 if (aCmdName == "vsetwidth")
1525 {
1526 if (aNames.IsEmpty()
1527 || !aNames.Last().IsRealValue())
1528 {
1529 std::cout << "Error: not enough arguments!\n";
1530 return 1;
1531 }
1532 aChangeSet->ToSetLineWidth = 1;
1533 aChangeSet->LineWidth = aNames.Last().RealValue();
1534 aNames.Remove (aNames.Length());
7fd59977 1535 }
ad3217cd 1536 else if (aCmdName == "vunsetwidth")
1537 {
1538 aChangeSet->ToSetLineWidth = -1;
1539 }
1540 else if (aCmdName == "vsetcolor")
1541 {
1542 if (aNames.IsEmpty())
1543 {
1544 std::cout << "Error: not enough arguments!\n";
1545 return 1;
1546 }
1547 aChangeSet->ToSetColor = 1;
8316c618 1548
1549 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1550 Standard_Boolean isOk = Standard_False;
1551 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1552 {
1553 aChangeSet->Color = aColor;
1554 aNames.Remove (aNames.Length());
1555 isOk = Standard_True;
1556 }
1557 else if (aNames.Length() >= 3)
1558 {
1559 const TCollection_AsciiString anRgbStr[3] =
1560 {
1561 aNames.Value (aNames.Upper() - 2),
1562 aNames.Value (aNames.Upper() - 1),
1563 aNames.Value (aNames.Upper() - 0)
1564 };
1565 isOk = anRgbStr[0].IsRealValue()
1566 && anRgbStr[1].IsRealValue()
1567 && anRgbStr[2].IsRealValue();
1568 if (isOk)
1569 {
1570 Graphic3d_Vec4d anRgb;
1571 anRgb.x() = anRgbStr[0].RealValue();
1572 anRgb.y() = anRgbStr[1].RealValue();
1573 anRgb.z() = anRgbStr[2].RealValue();
1574 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1575 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1576 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1577 {
1578 std::cout << "Error: RGB color values should be within range 0..1!\n";
1579 return 1;
1580 }
1581 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1582 aNames.Remove (aNames.Length());
1583 aNames.Remove (aNames.Length());
1584 aNames.Remove (aNames.Length());
1585 }
1586 }
1587 if (!isOk)
1588 {
1589 std::cout << "Error: not enough arguments!\n";
1590 return 1;
1591 }
ad3217cd 1592 }
1593 else if (aCmdName == "vunsetcolor")
1594 {
1595 aChangeSet->ToSetColor = -1;
1596 }
1597 else if (aCmdName == "vsettransparency")
1598 {
1599 if (aNames.IsEmpty()
1600 || !aNames.Last().IsRealValue())
1601 {
1602 std::cout << "Error: not enough arguments!\n";
1603 return 1;
1604 }
1605 aChangeSet->ToSetTransparency = 1;
1606 aChangeSet->Transparency = aNames.Last().RealValue();
1607 aNames.Remove (aNames.Length());
1608 }
1609 else if (aCmdName == "vunsettransparency")
1610 {
1611 aChangeSet->ToSetTransparency = -1;
1612 }
1613 else if (aCmdName == "vsetmaterial")
1614 {
1615 if (aNames.IsEmpty())
1616 {
1617 std::cout << "Error: not enough arguments!\n";
1618 return 1;
1619 }
1620 aChangeSet->ToSetMaterial = 1;
1621 aChangeSet->MatName = aNames.Last();
1622 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1623 aNames.Remove (aNames.Length());
1624 }
1625 else if (aCmdName == "vunsetmaterial")
1626 {
1627 aChangeSet->ToSetMaterial = -1;
1628 }
1629 else if (anArgIter >= theArgNb)
1630 {
1631 std::cout << "Error: not enough arguments!\n";
1632 return 1;
7fd59977 1633 }
1634
ad3217cd 1635 if (!aChangeSet->IsEmpty())
1636 {
1637 anArgIter = theArgNb;
1638 }
1639 for (; anArgIter < theArgNb; ++anArgIter)
1640 {
1641 TCollection_AsciiString anArg = theArgVec[anArgIter];
1642 anArg.LowerCase();
1643 if (anArg == "-setwidth"
1644 || anArg == "-setlinewidth")
1645 {
1646 if (++anArgIter >= theArgNb)
1647 {
1648 std::cout << "Error: wrong syntax at " << anArg << "\n";
1649 return 1;
1650 }
1651 aChangeSet->ToSetLineWidth = 1;
1652 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1653 }
ad3217cd 1654 else if (anArg == "-unsetwidth"
1655 || anArg == "-unsetlinewidth")
1656 {
1657 aChangeSet->ToSetLineWidth = -1;
1658 aChangeSet->LineWidth = 1.0;
1659 }
1660 else if (anArg == "-settransp"
0ae61cf3 1661 || anArg == "-settransparency")
ad3217cd 1662 {
1663 if (++anArgIter >= theArgNb)
1664 {
1665 std::cout << "Error: wrong syntax at " << anArg << "\n";
1666 return 1;
1667 }
1668 aChangeSet->ToSetTransparency = 1;
1669 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1670 if (aChangeSet->Transparency >= 0.0
1671 && aChangeSet->Transparency <= Precision::Confusion())
1672 {
1673 aChangeSet->ToSetTransparency = -1;
1674 aChangeSet->Transparency = 0.0;
eafb234b 1675 }
7fd59977 1676 }
5bffb882 1677 else if (anArg == "-setvis"
1678 || anArg == "-setvisibility")
1679 {
1680 if (++anArgIter >= theArgNb)
1681 {
1682 std::cout << "Error: wrong syntax at " << anArg << "\n";
1683 return 1;
1684 }
1685
1686 aChangeSet->ToSetVisibility = 1;
1687 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1688 }
ad3217cd 1689 else if (anArg == "-setalpha")
1690 {
1691 if (++anArgIter >= theArgNb)
7fd59977 1692 {
ad3217cd 1693 std::cout << "Error: wrong syntax at " << anArg << "\n";
1694 return 1;
1695 }
1696 aChangeSet->ToSetTransparency = 1;
1697 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1698 if (aChangeSet->Transparency < 0.0
1699 || aChangeSet->Transparency > 1.0)
1700 {
1701 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1702 return 1;
1703 }
1704 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1705 if (aChangeSet->Transparency >= 0.0
1706 && aChangeSet->Transparency <= Precision::Confusion())
1707 {
1708 aChangeSet->ToSetTransparency = -1;
1709 aChangeSet->Transparency = 0.0;
7fd59977 1710 }
7fd59977 1711 }
ad3217cd 1712 else if (anArg == "-unsettransp"
0ae61cf3 1713 || anArg == "-unsettransparency"
ad3217cd 1714 || anArg == "-unsetalpha"
1715 || anArg == "-opaque")
1716 {
1717 aChangeSet->ToSetTransparency = -1;
1718 aChangeSet->Transparency = 0.0;
1719 }
1720 else if (anArg == "-setcolor")
1721 {
8316c618 1722 Standard_Integer aNbComps = 0;
1723 Standard_Integer aCompIter = anArgIter + 1;
1724 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
ad3217cd 1725 {
8316c618 1726 if (theArgVec[aCompIter][0] == '-')
1727 {
1728 break;
1729 }
1730 }
1731 switch (aNbComps)
1732 {
1733 case 1:
1734 {
1735 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1736 Standard_CString aName = theArgVec[anArgIter + 1];
1737 if (!Quantity_Color::ColorFromName (aName, aColor))
1738 {
1739 std::cout << "Error: unknown color name '" << aName << "'\n";
1740 return 1;
1741 }
1742 aChangeSet->Color = aColor;
1743 break;
1744 }
1745 case 3:
1746 {
1747 Graphic3d_Vec3d anRgb;
1748 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1749 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1750 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1751 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1752 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1753 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1754 {
1755 std::cout << "Error: RGB color values should be within range 0..1!\n";
1756 return 1;
1757 }
1758 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1759 break;
1760 }
1761 default:
1762 {
1763 std::cout << "Error: wrong syntax at " << anArg << "\n";
1764 return 1;
1765 }
7fd59977 1766 }
ad3217cd 1767 aChangeSet->ToSetColor = 1;
8316c618 1768 anArgIter += aNbComps;
7fd59977 1769 }
ad3217cd 1770 else if (anArg == "-unsetcolor")
1771 {
1772 aChangeSet->ToSetColor = -1;
1773 aChangeSet->Color = DEFAULT_COLOR;
1774 }
1775 else if (anArg == "-setmat"
1776 || anArg == "-setmaterial")
1777 {
1778 if (++anArgIter >= theArgNb)
1779 {
1780 std::cout << "Error: wrong syntax at " << anArg << "\n";
1781 return 1;
1782 }
1783 aChangeSet->ToSetMaterial = 1;
1784 aChangeSet->MatName = theArgVec[anArgIter];
1785 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1786 }
1787 else if (anArg == "-unsetmat"
1788 || anArg == "-unsetmaterial")
1789 {
1790 aChangeSet->ToSetMaterial = -1;
1791 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1792 }
1793 else if (anArg == "-subshape"
1794 || anArg == "-subshapes")
1795 {
6262338c 1796 if (isDefaults)
1797 {
1798 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1799 return 1;
1800 }
1801
ad3217cd 1802 if (aNames.IsEmpty())
1803 {
1804 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1805 return 1;
1806 }
7fd59977 1807
ad3217cd 1808 aChanges.Append (ViewerTest_AspectsChangeSet());
1809 aChangeSet = &aChanges.ChangeLast();
7fd59977 1810
ad3217cd 1811 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1812 {
1813 Standard_CString aSubShapeName = theArgVec[anArgIter];
1814 if (*aSubShapeName == '-')
1815 {
1816 --anArgIter;
1817 break;
1818 }
7fd59977 1819
ad3217cd 1820 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1821 if (aSubShape.IsNull())
1822 {
1823 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1824 return 1;
1825 }
1826 aChangeSet->SubShapes.Append (aSubShape);
1827 }
7fd59977 1828
ad3217cd 1829 if (aChangeSet->SubShapes.IsEmpty())
1830 {
1831 std::cerr << "Error: empty list is specified after -subshapes!\n";
1832 return 1;
1833 }
1834 }
6262338c 1835 else if (anArg == "-freeboundary"
1836 || anArg == "-fb")
1837 {
1838 if (++anArgIter >= theArgNb)
1839 {
1840 std::cout << "Error: wrong syntax at " << anArg << "\n";
1841 return 1;
1842 }
1843 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1844 aValue.LowerCase();
1845 if (aValue == "on"
1846 || aValue == "1")
1847 {
1848 aChangeSet->ToSetShowFreeBoundary = 1;
1849 }
1850 else if (aValue == "off"
1851 || aValue == "0")
1852 {
1853 aChangeSet->ToSetShowFreeBoundary = -1;
1854 }
1855 else
1856 {
1857 std::cout << "Error: wrong syntax at " << anArg << "\n";
1858 return 1;
1859 }
1860 }
1861 else if (anArg == "-setfreeboundarywidth"
1862 || anArg == "-setfbwidth")
1863 {
1864 if (++anArgIter >= theArgNb)
1865 {
1866 std::cout << "Error: wrong syntax at " << anArg << "\n";
1867 return 1;
1868 }
1869 aChangeSet->ToSetFreeBoundaryWidth = 1;
1870 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
1871 }
1872 else if (anArg == "-unsetfreeboundarywidth"
1873 || anArg == "-unsetfbwidth")
1874 {
1875 aChangeSet->ToSetFreeBoundaryWidth = -1;
1876 aChangeSet->FreeBoundaryWidth = 1.0;
1877 }
1878 else if (anArg == "-setfreeboundarycolor"
1879 || anArg == "-setfbcolor")
1880 {
1881 Standard_Integer aNbComps = 0;
1882 Standard_Integer aCompIter = anArgIter + 1;
1883 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1884 {
1885 if (theArgVec[aCompIter][0] == '-')
1886 {
1887 break;
1888 }
1889 }
1890 switch (aNbComps)
1891 {
1892 case 1:
1893 {
1894 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1895 Standard_CString aName = theArgVec[anArgIter + 1];
1896 if (!Quantity_Color::ColorFromName (aName, aColor))
1897 {
1898 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
1899 return 1;
1900 }
1901 aChangeSet->FreeBoundaryColor = aColor;
1902 break;
1903 }
1904 case 3:
1905 {
1906 Graphic3d_Vec3d anRgb;
1907 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1908 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1909 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1910 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1911 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1912 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1913 {
1914 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
1915 return 1;
1916 }
1917 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1918 break;
1919 }
1920 default:
1921 {
1922 std::cout << "Error: wrong syntax at " << anArg << "\n";
1923 return 1;
1924 }
1925 }
1926 aChangeSet->ToSetFreeBoundaryColor = 1;
1927 anArgIter += aNbComps;
1928 }
1929 else if (anArg == "-unsetfreeboundarycolor"
1930 || anArg == "-unsetfbcolor")
1931 {
1932 aChangeSet->ToSetFreeBoundaryColor = -1;
1933 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1934 }
ad3217cd 1935 else if (anArg == "-unset")
1936 {
5bffb882 1937 aChangeSet->ToSetVisibility = 1;
1938 aChangeSet->Visibility = 1;
ad3217cd 1939 aChangeSet->ToSetLineWidth = -1;
1940 aChangeSet->LineWidth = 1.0;
1941 aChangeSet->ToSetTransparency = -1;
1942 aChangeSet->Transparency = 0.0;
1943 aChangeSet->ToSetColor = -1;
1944 aChangeSet->Color = DEFAULT_COLOR;
1945 aChangeSet->ToSetMaterial = -1;
1946 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
6262338c 1947 aChangeSet->ToSetShowFreeBoundary = -1;
1948 aChangeSet->ToSetFreeBoundaryColor = -1;
1949 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1950 aChangeSet->ToSetFreeBoundaryWidth = -1;
1951 aChangeSet->FreeBoundaryWidth = 1.0;
7fd59977 1952 }
7fd59977 1953 else
ad3217cd 1954 {
1955 std::cout << "Error: wrong syntax at " << anArg << "\n";
1956 return 1;
1957 }
7fd59977 1958 }
99c56d44 1959
ad3217cd 1960 Standard_Boolean isFirst = Standard_True;
1961 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1962 aChangesIter.More(); aChangesIter.Next())
1963 {
1964 if (!aChangesIter.Value().Validate (!isFirst))
1965 {
1966 return 1;
1967 }
1968 isFirst = Standard_False;
99c56d44 1969 }
99c56d44 1970
ad3217cd 1971 if (aCtx->HasOpenedContext())
1972 {
1973 aCtx->CloseLocalContext();
99c56d44 1974 }
6262338c 1975
1976 // special case for -defaults parameter.
1977 // all changed values will be set to DefaultDrawer.
1978 if (isDefaults)
1979 {
1980 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
1981
1982 if (aChangeSet->ToSetLineWidth != 0)
1983 {
1984 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
1985 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
1986 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
1987 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
1988 }
1989 if (aChangeSet->ToSetColor != 0)
1990 {
1991 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
1992 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
1993 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
1994 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
1995 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
1996 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
1997 }
1998 if (aChangeSet->ToSetTransparency != 0)
1999 {
2000 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2001 }
2002 if (aChangeSet->ToSetMaterial != 0)
2003 {
2004 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2005 }
2006 if (aChangeSet->ToSetShowFreeBoundary == 1)
2007 {
2008 aDrawer->SetFreeBoundaryDraw (Standard_True);
2009 }
2010 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2011 {
2012 aDrawer->SetFreeBoundaryDraw (Standard_False);
2013 }
2014 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2015 {
2016 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2017 }
2018 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2019 {
2020 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2021 }
2022
2023 // redisplay all objects in context
2024 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2025 {
2026 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2027 if (!aPrs.IsNull())
2028 {
2029 aCtx->Redisplay (aPrs, Standard_False);
2030 }
2031 }
2032 return 0;
2033 }
2034
ad3217cd 2035 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2036 {
6262338c 2037 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2038 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2039 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 2040 Handle(AIS_ColoredShape) aColoredPrs;
2041 Standard_Boolean toDisplay = Standard_False;
6262338c 2042 Standard_Boolean toRedisplay = Standard_False;
5bffb882 2043 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 2044 {
2045 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2046 if (aShapePrs.IsNull())
2047 {
2048 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2049 return 1;
2050 }
2051 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2052 if (aColoredPrs.IsNull())
2053 {
2054 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2055 aCtx->Remove (aShapePrs, Standard_False);
2056 GetMapOfAIS().UnBind2 (aName);
2057 GetMapOfAIS().Bind (aColoredPrs, aName);
2058 toDisplay = Standard_True;
2059 aShapePrs = aColoredPrs;
2060 aPrs = aColoredPrs;
2061 }
2062 }
99c56d44 2063
ad3217cd 2064 if (!aPrs.IsNull())
2065 {
2066 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2067 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2068 if (aChangeSet->ToSetVisibility == 1)
2069 {
2070 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2071 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2072 }
2073 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2074 {
2075 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2076 }
2077 else if (aChangeSet->ToSetMaterial == -1)
2078 {
2079 aCtx->UnsetMaterial (aPrs, Standard_False);
2080 }
2081 if (aChangeSet->ToSetColor == 1)
2082 {
2083 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2084 }
2085 else if (aChangeSet->ToSetColor == -1)
2086 {
2087 aCtx->UnsetColor (aPrs, Standard_False);
2088 }
2089 if (aChangeSet->ToSetTransparency == 1)
2090 {
2091 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2092 }
2093 else if (aChangeSet->ToSetTransparency == -1)
2094 {
2095 aCtx->UnsetTransparency (aPrs, Standard_False);
2096 }
2097 if (aChangeSet->ToSetLineWidth == 1)
2098 {
2099 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2100 }
2101 else if (aChangeSet->ToSetLineWidth == -1)
2102 {
2103 aCtx->UnsetWidth (aPrs, Standard_False);
2104 }
6262338c 2105 if (!aDrawer.IsNull())
2106 {
2107 if (aChangeSet->ToSetShowFreeBoundary == 1)
2108 {
2109 aDrawer->SetFreeBoundaryDraw (Standard_True);
2110 toRedisplay = Standard_True;
2111 }
2112 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2113 {
2114 aDrawer->SetFreeBoundaryDraw (Standard_False);
2115 toRedisplay = Standard_True;
2116 }
2117 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2118 {
2119 Handle(Prs3d_LineAspect) aBoundaryAspect =
2120 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2121 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2122 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2123 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2124 toRedisplay = Standard_True;
2125 }
2126 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2127 {
2128 Handle(Prs3d_LineAspect) aBoundaryAspect =
2129 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2130 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2131 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2132 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2133 toRedisplay = Standard_True;
2134 }
2135 }
99c56d44 2136
ad3217cd 2137 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2138 {
2139 aChangeSet = &aChangesIter.ChangeValue();
2140 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2141 aSubShapeIter.More(); aSubShapeIter.Next())
2142 {
2143 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2144 if (aChangeSet->ToSetVisibility == 1)
2145 {
2146 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2147 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2148 }
ad3217cd 2149 if (aChangeSet->ToSetColor == 1)
2150 {
2151 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2152 }
2153 if (aChangeSet->ToSetLineWidth == 1)
2154 {
2155 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2156 }
2157 if (aChangeSet->ToSetColor == -1
2158 || aChangeSet->ToSetLineWidth == -1)
2159 {
2160 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2161 }
2162 }
2163 }
2164 if (toDisplay)
2165 {
2166 aCtx->Display (aPrs, Standard_False);
2167 }
6262338c 2168 if (toRedisplay)
2169 {
2170 aCtx->Redisplay (aPrs, Standard_False);
2171 }
ad3217cd 2172 else if (!aColoredPrs.IsNull())
2173 {
36132a2e 2174 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2175 }
99c56d44 2176 }
99c56d44 2177 else
ad3217cd 2178 {
2179 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
2180 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
2181 if (!aNisObj.IsNull())
2182 {
2183 if (aChangeSet->ToSetTransparency != 0)
2184 {
2185 aNisObj->SetTransparency (aChangeSet->Transparency);
2186 }
2187 }
2188 if (!aNisTri.IsNull())
2189 {
2190 if (aChangeSet->ToSetColor != 0)
2191 {
2192 aNisTri->SetColor (aChangeSet->Color);
2193 }
2194 if (aChangeSet->ToSetLineWidth != 0)
2195 {
2196 aNisTri->SetLineWidth (aChangeSet->LineWidth);
2197 }
99c56d44 2198 }
2199 }
ad3217cd 2200 }
99c56d44 2201 return 0;
2202}
2203
7fd59977 2204//==============================================================================
2205//function : VDonly2
2206//author : ege
2207//purpose : Display only a selected or named object
519d35d8 2208// if there is no selected or named object s, nothing is done
7fd59977 2209//==============================================================================
519d35d8 2210static int VDonly2 (Draw_Interpretor& ,
2211 Standard_Integer theArgNb,
2212 const char** theArgVec)
7fd59977 2213{
519d35d8 2214 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2215 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2216 if (aCtx.IsNull())
2217 {
2218 std::cerr << "Error: no active view!\n";
7fd59977 2219 return 1;
519d35d8 2220 }
7fd59977 2221
519d35d8 2222 if (aCtx->HasOpenedContext())
2223 {
2224 aCtx->CloseLocalContext();
2225 }
7fd59977 2226
519d35d8 2227 Standard_Integer anArgIter = 1;
2228 for (; anArgIter < theArgNb; ++anArgIter)
2229 {
4e18052b 2230 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2231 {
2232 break;
2233 }
2234 }
7fd59977 2235
519d35d8 2236 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2237 if (anArgIter >= theArgNb)
2238 {
2239 // display only selected objects
2240 if (aCtx->NbCurrents() < 1)
2241 {
2242 return 0;
7fd59977 2243 }
2244
519d35d8 2245 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2246 {
2247 aDispSet.Add (aCtx->Current());
2248 }
2249 }
2250 else
2251 {
2252 // display only specified objects
2253 for (; anArgIter < theArgNb; ++anArgIter)
2254 {
2255 TCollection_AsciiString aName = theArgVec[anArgIter];
2256 if (GetMapOfAIS().IsBound2 (aName))
2257 {
2258 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2259 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2260 {
2261 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2262 aCtx->Display (aShape, Standard_False);
2263 }
2264 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2265 {
2266 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2267 TheNISContext()->Display (aShape);
7fd59977 2268 }
519d35d8 2269 aDispSet.Add (anObj);
7fd59977 2270 }
2271 }
7fd59977 2272 }
519d35d8 2273
2274 // weed out other objects
2275 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2276 {
2277 if (aDispSet.Contains (anIter.Key1()))
2278 {
2279 continue;
2280 }
2281
2282 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2283 {
2284 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2285 aCtx->Erase (aShape, Standard_False);
2286 }
2287 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2288 {
2289 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2290 TheNISContext()->Erase (aShape);
2291 }
2292 }
7fd59977 2293 return 0;
2294}
2295
eef7fc64 2296//==============================================================================
2297//function : VRemove
2298//purpose : Removes selected or named objects.
2299// If there is no selected or named objects,
2300// all objects in the viewer can be removed with argument -all.
2301// If -context is in arguments, the object is not deleted from the map of
2302// objects (deleted only from the current context).
2303//==============================================================================
2304int VRemove (Draw_Interpretor& theDI,
519d35d8 2305 Standard_Integer theArgNb,
2306 const char** theArgVec)
eef7fc64 2307{
4e18052b 2308 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2309 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2310 if (aCtx.IsNull())
eef7fc64 2311 {
b6d587e3 2312 std::cerr << "Error: no active view!\n";
eef7fc64 2313 return 1;
2314 }
2315
4e18052b 2316 Standard_Boolean isContextOnly = Standard_False;
2317 Standard_Boolean toRemoveAll = Standard_False;
2318 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2319 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2320
2321 Standard_Integer anArgIter = 1;
2322 for (; anArgIter < theArgNb; ++anArgIter)
2323 {
2324 TCollection_AsciiString anArg = theArgVec[anArgIter];
2325 anArg.LowerCase();
2326 if (anArg == "-context")
2327 {
2328 isContextOnly = Standard_True;
2329 }
2330 else if (anArg == "-all")
2331 {
2332 toRemoveAll = Standard_True;
2333 }
b7cd4ba7 2334 else if (anArg == "-noinfo")
2335 {
2336 toPrintInfo = Standard_False;
2337 }
b6d587e3 2338 else if (anArg == "-local")
2339 {
2340 toRemoveLocal = Standard_True;
2341 }
2342 else if (anUpdateTool.parseRedrawMode (anArg))
2343 {
2344 continue;
2345 }
2346 else
519d35d8 2347 {
2348 break;
2349 }
2350 }
2351 if (toRemoveAll
2352 && anArgIter < theArgNb)
2353 {
b6d587e3 2354 std::cerr << "Error: wrong syntax!\n";
2355 return 1;
2356 }
2357
2358 if (toRemoveLocal && !aCtx->HasOpenedContext())
2359 {
2360 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2361 return 1;
2362 }
b6d587e3 2363 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2364 {
2365 aCtx->CloseAllContexts (Standard_False);
2366 }
519d35d8 2367
eef7fc64 2368 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2369 if (toRemoveAll)
eef7fc64 2370 {
2371 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2372 anIter.More(); anIter.Next())
2373 {
2374 anIONameList.Append (anIter.Key2());
2375 }
2376 }
519d35d8 2377 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2378 {
519d35d8 2379 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2380 {
519d35d8 2381 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2382 if (!GetMapOfAIS().IsBound2 (aName))
2383 {
2384 theDI << aName.ToCString() << " was not bound to some object.\n";
2385 continue;
2386 }
2387
2388 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2389
2390 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2391 if (!anIO.IsNull())
2392 {
4e18052b 2393 if (anIO->GetContext() != aCtx)
eef7fc64 2394 {
2395 theDI << aName.ToCString() << " was not displayed in current context.\n";
2396 theDI << "Please activate view with this object displayed and try again.\n";
2397 continue;
2398 }
2399
2400 anIONameList.Append (aName);
2401 continue;
2402 }
2403
2404 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2405 if (!aNisIO.IsNull())
2406 {
2407 anIONameList.Append (aName);
2408 }
2409 }
2410 }
4e18052b 2411 else if (aCtx->NbCurrents() > 0
eef7fc64 2412 || TheNISContext()->GetSelected().Extent() > 0)
2413 {
2414 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2415 anIter.More(); anIter.Next())
2416 {
2417 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2418 if (!anIO.IsNull())
2419 {
4e18052b 2420 if (!aCtx->IsCurrent (anIO))
eef7fc64 2421 {
2422 continue;
2423 }
2424
2425 anIONameList.Append (anIter.Key2());
2426 continue;
2427 }
2428
2429 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2430 if (!aNisIO.IsNull())
2431 {
2432 if (!TheNISContext()->IsSelected (aNisIO))
2433 {
2434 continue;
2435 }
2436
2437 anIONameList.Append (anIter.Key2());
2438 }
2439 }
2440 }
2441
2442 // Unbind all removed objects from the map of displayed IO.
2443 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2444 anIter.More(); anIter.Next())
2445 {
519d35d8 2446 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
519d35d8 2447 if (!anIO.IsNull())
2448 {
4e18052b 2449 aCtx->Remove (anIO, Standard_False);
b7cd4ba7 2450 if (toPrintInfo)
2451 {
2452 theDI << anIter.Value().ToCString() << " was removed\n";
2453 }
519d35d8 2454 }
2455 else
2456 {
2457 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2458 if (!aNisIO.IsNull())
eef7fc64 2459 {
519d35d8 2460 TheNISContext()->Remove (aNisIO);
b7cd4ba7 2461 if (toPrintInfo)
2462 {
2463 theDI << anIter.Value().ToCString() << " was removed\n";
2464 }
eef7fc64 2465 }
519d35d8 2466 }
519d35d8 2467 if (!isContextOnly)
2468 {
2469 GetMapOfAIS().UnBind2 (anIter.Value());
2470 }
2471 }
b6d587e3 2472
2473 // Close local context if it is empty
2474 TColStd_MapOfTransient aLocalIO;
2475 if (aCtx->HasOpenedContext()
2476 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2477 {
2478 aCtx->CloseAllContexts (Standard_False);
2479 }
2480
eef7fc64 2481 return 0;
2482}
2483
7fd59977 2484//==============================================================================
b514beda 2485//function : VErase
2486//purpose : Erase some selected or named objects
7fd59977 2487// if there is no selected or named objects, the whole viewer is erased
7fd59977 2488//==============================================================================
b514beda 2489int VErase (Draw_Interpretor& theDI,
2490 Standard_Integer theArgNb,
2491 const char** theArgVec)
7fd59977 2492{
a1954302 2493 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2494 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2495 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2496 if (aCtx.IsNull())
b514beda 2497 {
b6d587e3 2498 std::cerr << "Error: no active view!\n";
7fd59977 2499 return 1;
b514beda 2500 }
519d35d8 2501
519d35d8 2502 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2503
2504 Standard_Integer anArgIter = 1;
a272ed94 2505 Standard_Boolean toEraseLocal = Standard_False;
2506 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2507 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2508 for (; anArgIter < theArgNb; ++anArgIter)
2509 {
b6d587e3 2510 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2511 anArgCase.LowerCase();
2512 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2513 {
b6d587e3 2514 continue;
2515 }
2516 else if (anArgCase == "-local")
2517 {
2518 toEraseLocal = Standard_True;
2519 }
a272ed94 2520 else if (anArgCase == "-view"
2521 || anArgCase == "-inview")
2522 {
2523 toEraseInView = Standard_True;
2524 }
b6d587e3 2525 else
2526 {
2527 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2528 }
2529 }
2530
b6d587e3 2531 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2532 {
b6d587e3 2533 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2534 return 1;
2535 }
7fd59977 2536
b6d587e3 2537 if (toEraseLocal && !aCtx->HasOpenedContext())
2538 {
2539 std::cerr << "Error: local selection context is not open.\n";
2540 return 1;
2541 }
2542 else if (!toEraseLocal && aCtx->HasOpenedContext())
2543 {
2544 aCtx->CloseAllContexts (Standard_False);
2545 }
2546
2547 if (!aNamesOfEraseIO.IsEmpty())
2548 {
2549 // Erase named objects
2550 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2551 {
b6d587e3 2552 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2553 if (!GetMapOfAIS().IsBound2 (aName))
2554 {
2555 continue;
2556 }
7fd59977 2557
b514beda 2558 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2559 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2560 theDI << aName.ToCString() << " ";
2561 if (!anIO.IsNull())
2562 {
a272ed94 2563 if (toEraseInView)
2564 {
2565 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2566 }
2567 else
2568 {
2569 aCtx->Erase (anIO, Standard_False);
2570 }
b514beda 2571 }
2572 else
2573 {
2574 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2575 if (!aNisIO.IsNull())
2576 {
2577 TheNISContext()->Erase (aNisIO);
2578 }
7fd59977 2579 }
7fd59977 2580 }
7fd59977 2581 }
b6d587e3 2582 else if (!toEraseAll && aCtx->NbCurrents() > 0)
b514beda 2583 {
b6d587e3 2584 // Erase selected objects
b514beda 2585 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2586 anIter.More(); anIter.Next())
2587 {
2588 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2589 if (!anIO.IsNull()
4e18052b 2590 && aCtx->IsCurrent (anIO))
b514beda 2591 {
2592 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2593 if (toEraseInView)
2594 {
2595 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2596 }
2597 else
2598 {
2599 aCtx->Erase (anIO, Standard_False);
2600 }
7fd59977 2601 }
2602 }
b514beda 2603 }
519d35d8 2604 else
b514beda 2605 {
b6d587e3 2606 // Erase all objects
519d35d8 2607 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2608 anIter.More(); anIter.Next())
b514beda 2609 {
519d35d8 2610 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2611 if (!anIO.IsNull())
2612 {
a272ed94 2613 if (toEraseInView)
2614 {
2615 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2616 }
2617 else
2618 {
2619 aCtx->Erase (anIO, Standard_False);
2620 }
519d35d8 2621 }
2622 else
b514beda 2623 {
519d35d8 2624 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2625 if (!aNisIO.IsNull())
2626 {
2627 TheNISContext()->Erase (aNisIO);
2628 }
b514beda 2629 }
7fd59977 2630 }
7fd59977 2631 }
b6d587e3 2632
7fd59977 2633 return 0;
2634}
2635
7fd59977 2636//==============================================================================
2637//function : VDisplayAll
2638//author : ege
2639//purpose : Display all the objects of the Map
7fd59977 2640//==============================================================================
519d35d8 2641static int VDisplayAll (Draw_Interpretor& ,
2642 Standard_Integer theArgNb,
2643 const char** theArgVec)
7fd59977 2644
2645{
4e18052b 2646 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2647 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2648 if (aCtx.IsNull())
519d35d8 2649 {
b6d587e3 2650 std::cerr << "Error: no active view!\n";
519d35d8 2651 return 1;
2652 }
2653
519d35d8 2654 Standard_Integer anArgIter = 1;
b6d587e3 2655 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2656 for (; anArgIter < theArgNb; ++anArgIter)
2657 {
b6d587e3 2658 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2659 anArgCase.LowerCase();
2660 if (anArgCase == "-local")
2661 {
2662 toDisplayLocal = Standard_True;
2663 }
2664 else if (anUpdateTool.parseRedrawMode (anArgCase))
2665 {
2666 continue;
2667 }
2668 else
519d35d8 2669 {
2670 break;
7fd59977 2671 }
519d35d8 2672 }
2673 if (anArgIter < theArgNb)
2674 {
2675 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2676 return 1;
2677 }
2678
b6d587e3 2679 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2680 {
b6d587e3 2681 std::cerr << "Error: local selection context is not open.\n";
2682 return 1;
2683 }
2684 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2685 {
2686 aCtx->CloseLocalContext (Standard_False);
519d35d8 2687 }
2688
2689 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2690 anIter.More(); anIter.Next())
2691 {
2692 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2693 {
2694 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
4e18052b 2695 aCtx->Erase (aShape, Standard_False);
519d35d8 2696 }
2697 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2698 {
2699 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2700 TheNISContext()->Erase (aShape);
2701 }
2702 }
2703
2704 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2705 anIter.More(); anIter.Next())
2706 {
2707 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2708 {
2709 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
4e18052b 2710 aCtx->Display (aShape, Standard_False);
519d35d8 2711 }
2712 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2713 {
2714 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2715 TheNISContext()->Display (aShape);
7fd59977 2716 }
7fd59977 2717 }
2718 return 0;
2719}
2720
c2a388f8 2721//! Auxiliary method to find presentation
2722inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2723 const Handle(AIS_InteractiveObject)& theIO,
2724 const Standard_Integer theMode)
2725{
2726 if (theIO.IsNull())
2727 {
2728 return Handle(PrsMgr_Presentation)();
2729 }
2730
2731 if (theMode != -1)
2732 {
2733 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2734 {
2735 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2736 }
2737 }
2738 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2739 {
2740 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2741 }
2742 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2743 {
2744 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2745 }
2746 return Handle(PrsMgr_Presentation)();
2747}
2748
2749enum ViewerTest_BndAction
2750{
2751 BndAction_Hide,
2752 BndAction_Show,
2753 BndAction_Print
2754};
2755
2756//! Auxiliary method to print bounding box of presentation
2757inline void bndPresentation (Draw_Interpretor& theDI,
2758 const Handle(PrsMgr_Presentation)& thePrs,
2759 const TCollection_AsciiString& theName,
2760 const ViewerTest_BndAction theAction)
2761{
2762 switch (theAction)
2763 {
2764 case BndAction_Hide:
2765 {
2766 thePrs->Presentation()->GraphicUnHighlight();
2767 break;
2768 }
2769 case BndAction_Show:
2770 {
a1954302 2771 Handle(Graphic3d_Structure) aPrs = thePrs->Presentation();
2772 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2773 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2774 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2775 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
c2a388f8 2776 break;
2777 }
2778 case BndAction_Print:
2779 {
ed063270 2780 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2781 gp_Pnt aMin = aBox.CornerMin();
2782 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 2783 theDI << theName << "\n"
ed063270 2784 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2785 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 2786 break;
2787 }
2788 }
2789}
2790
2791//==============================================================================
2792//function : VBounding
2793//purpose :
2794//==============================================================================
2795int VBounding (Draw_Interpretor& theDI,
2796 Standard_Integer theArgNb,
2797 const char** theArgVec)
2798{
2799 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2800 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2801 if (aCtx.IsNull())
2802 {
2803 std::cout << "Error: no active view!\n";
2804 return 1;
2805 }
2806
4e18052b 2807 ViewerTest_BndAction anAction = BndAction_Show;
2808 Standard_Integer aMode = -1;
c2a388f8 2809
2810 Standard_Integer anArgIter = 1;
2811 for (; anArgIter < theArgNb; ++anArgIter)
2812 {
2813 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2814 anArg.LowerCase();
2815 if (anArg == "-print")
2816 {
2817 anAction = BndAction_Print;
2818 }
2819 else if (anArg == "-show")
2820 {
2821 anAction = BndAction_Show;
2822 }
2823 else if (anArg == "-hide")
2824 {
2825 anAction = BndAction_Hide;
2826 }
2827 else if (anArg == "-mode")
2828 {
2829 if (++anArgIter >= theArgNb)
2830 {
2831 std::cout << "Error: wrong syntax at " << anArg << "\n";
2832 return 1;
2833 }
2834 aMode = Draw::Atoi (theArgVec[anArgIter]);
2835 }
4e18052b 2836 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 2837 {
2838 break;
2839 }
2840 }
2841
2842 if (anArgIter < theArgNb)
2843 {
2844 // has a list of names
2845 for (; anArgIter < theArgNb; ++anArgIter)
2846 {
2847 TCollection_AsciiString aName = theArgVec[anArgIter];
2848 if (!GetMapOfAIS().IsBound2 (aName))
2849 {
2850 std::cout << "Error: presentation " << aName << " does not exist\n";
2851 return 1;
2852 }
2853
2854 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2855 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2856 if (aPrs.IsNull())
2857 {
2858 std::cout << "Error: presentation " << aName << " does not exist\n";
2859 return 1;
2860 }
2861 bndPresentation (theDI, aPrs, aName, anAction);
2862 }
2863 }
4e18052b 2864 else if (aCtx->NbCurrents() > 0)
c2a388f8 2865 {
2866 // remove all currently selected objects
2867 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2868 {
2869 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2870 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2871 if (!aPrs.IsNull())
2872 {
2873 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2874 }
2875 }
2876 }
2877 else
2878 {
2879 // all objects
2880 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2881 anIter.More(); anIter.Next())
2882 {
2883 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2884 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2885 if (!aPrs.IsNull())
2886 {
2887 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2888 }
2889 }
2890 }
c2a388f8 2891 return 0;
2892}
2893
d399d3c3 2894//==============================================================================
2895//function : VTexture
2896//purpose :
2897//==============================================================================
2898Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 2899{
d399d3c3 2900 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 2901
900f7229 2902 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 2903 if (aCommandName == "vtexture")
2904 {
2905 if (theArgsNb < 2)
7fd59977 2906 {
d399d3c3 2907 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2908 std::cout << "Type help for more information.\n";
31160f80 2909 return 1;
7fd59977 2910 }
2911
d399d3c3 2912 // look for options of vtexture command
2913 TCollection_AsciiString aParseKey;
2914 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2915 {
2916 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 2917
d399d3c3 2918 anArg.UpperCase();
2919 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2920 {
2921 aParseKey = anArg;
2922 aParseKey.Remove (1);
2923 aParseKey.UpperCase();
900f7229 2924 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 2925 continue;
2926 }
2927
2928 if (aParseKey.IsEmpty())
2929 {
2930 continue;
2931 }
2932
900f7229 2933 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 2934 }
2935 }
2936 else if (aCommandName == "vtexscale"
2937 || aCommandName == "vtexorigin"
2938 || aCommandName == "vtexrepeat")
2939 {
2940 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2941 // equal to -scale, -origin, -repeat options of vtexture command
2942 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 2943 {
d399d3c3 2944 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2945 std::cout << "Type help for more information.\n";
31160f80 2946 return 1;
7fd59977 2947 }
2948
900f7229 2949 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 2950 if (theArgsNb == 2)
2951 {
900f7229 2952 anArgs->Append ("OFF");
d399d3c3 2953 }
2954 else if (theArgsNb == 4)
2955 {
900f7229 2956 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2957 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 2958 }
7fd59977 2959
d399d3c3 2960 TCollection_AsciiString anArgKey;
2961 if (aCommandName == "vtexscale")
2962 {
2963 anArgKey = "SCALE";
2964 }
2965 else if (aCommandName == "vtexorigin")
2966 {
2967 anArgKey = "ORIGIN";
2968 }
2969 else
2970 {
2971 anArgKey = "REPEAT";
2972 }
2973
2974 aMapOfArgs.Bind (anArgKey, anArgs);
2975 }
2976 else if (aCommandName == "vtexdefault")
7fd59977 2977 {
d399d3c3 2978 // scan for parameters of vtexdefault command
2979 // equal to -default option of vtexture command
900f7229 2980 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 2981 }
2982
d399d3c3 2983 // Check arguments for validity
900f7229 2984 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 2985 for (; aMapIt.More(); aMapIt.Next())
2986 {
2987 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 2988 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 2989
2990 // -scale, -origin, -repeat: one argument "off", or two real values
2991 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 2992 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2993 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 2994 {
d399d3c3 2995 continue;
7fd59977 2996 }
d399d3c3 2997
2998 // -modulate: single argument "on" / "off"
900f7229 2999 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 3000 {
3001 continue;
3002 }
3003
3004 // -default: no arguments
900f7229 3005 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 3006 {
3007 continue;
3008 }
3009
3010 TCollection_AsciiString aLowerKey;
3011 aLowerKey = "-";
3012 aLowerKey += aKey;
3013 aLowerKey.LowerCase();
3014 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3015 std::cout << "Type help for more information.\n";
3016 return 1;
3017 }
3018
3019 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3020 if (anAISContext.IsNull())
3021 {
3022 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
3023 return 1;
3024 }
3025
3026 Standard_Integer aPreviousMode = 0;
3027
3028 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
3029
3030 TCollection_AsciiString aShapeName (theArgv[1]);
3031 Handle(AIS_InteractiveObject) anIO;
3032
3033 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3034 if (aMapOfIO.IsBound2 (aShapeName))
3035 {
3036 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3037 }
3038
3039 if (anIO.IsNull())
3040 {
3041 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3042 return 1;
3043 }
3044
3045 Handle(AIS_TexturedShape) aTexturedIO;
3046 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3047 {
3048 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3049 aPreviousMode = aTexturedIO->DisplayMode();
3050 }
7fd59977 3051 else
d399d3c3 3052 {
2195ab96 3053 anAISContext->Remove (anIO, Standard_False);
d399d3c3 3054 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3055 GetMapOfAIS().UnBind1 (anIO);
3056 GetMapOfAIS().UnBind2 (aShapeName);
3057 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3058 }
3059
3060 // -------------------------------------------
3061 // Turn texturing on/off - only for vtexture
3062 // -------------------------------------------
3063
3064 if (aCommandName == "vtexture")
3065 {
3066 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3067
3068 if (aTextureArg.IsEmpty())
7fd59977 3069 {
d399d3c3 3070 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3071 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3072
3073 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3074 if (aPreviousMode == 3)
3075 {
3076 anAISContext->RecomputePrsOnly (aTexturedIO);
3077 }
3078
3079 anAISContext->Display (aTexturedIO, Standard_True);
3080 return 0;
7fd59977 3081 }
d399d3c3 3082 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3083 {
d399d3c3 3084 if (aTextureArg == "?")
3085 {
3086 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3087
d399d3c3 3088 theDi << "\n Files in current directory : \n" << "\n";
3089 theDi.Eval ("glob -nocomplain *");
7fd59977 3090
d399d3c3 3091 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3092 aCmnd += aTextureFolder;
3093 aCmnd += "/* ";
7fd59977 3094
d399d3c3 3095 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3096 theDi.Eval (aCmnd.ToCString());
3097 return 0;
3098 }
3099 else
3100 {
3101 aTexturedIO->SetTextureFileName (aTextureArg);
3102 }
3103 }
3104 }
7fd59977 3105
d399d3c3 3106 // ------------------------------------
3107 // Process other options and commands
3108 // ------------------------------------
7fd59977 3109
900f7229 3110 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3111 if (aMapOfArgs.Find ("DEFAULT", aValues))
3112 {
3113 aTexturedIO->SetTextureRepeat (Standard_False);
3114 aTexturedIO->SetTextureOrigin (Standard_False);
3115 aTexturedIO->SetTextureScale (Standard_False);
3116 aTexturedIO->EnableTextureModulate();
3117 }
3118 else
3119 {
3120 if (aMapOfArgs.Find ("SCALE", aValues))
3121 {
900f7229 3122 if (aValues->Value(1) != "OFF")
d399d3c3 3123 {
900f7229 3124 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3125 }
7fd59977 3126 else
d399d3c3 3127 {
3128 aTexturedIO->SetTextureScale (Standard_False);
3129 }
3130 }
7fd59977 3131
d399d3c3 3132 if (aMapOfArgs.Find ("ORIGIN", aValues))
3133 {
900f7229 3134 if (aValues->Value(1) != "OFF")
d399d3c3 3135 {
900f7229 3136 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3137 }
3138 else
3139 {
3140 aTexturedIO->SetTextureOrigin (Standard_False);
3141 }
3142 }
7fd59977 3143
d399d3c3 3144 if (aMapOfArgs.Find ("REPEAT", aValues))
3145 {
900f7229 3146 if (aValues->Value(1) != "OFF")
d399d3c3 3147 {
900f7229 3148 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3149 }
3150 else
3151 {
3152 aTexturedIO->SetTextureRepeat (Standard_False);
3153 }
7fd59977 3154 }
3155
d399d3c3 3156 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 3157 {
900f7229 3158 if (aValues->Value(1) == "ON")
d399d3c3 3159 {
3160 aTexturedIO->EnableTextureModulate();
3161 }
3162 else
3163 {
3164 aTexturedIO->DisableTextureModulate();
3165 }
7fd59977 3166 }
d399d3c3 3167 }
3168
3169 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3170 {
3171 anAISContext->RecomputePrsOnly (aTexturedIO);
3172 }
3173 else
3174 {
3175 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3176 anAISContext->Display (aTexturedIO, Standard_True);
3177 anAISContext->Update (aTexturedIO,Standard_True);
3178 }
3179
31160f80 3180 return 0;
7fd59977 3181}
3182
af65fb19 3183//! Auxiliary method to parse transformation persistence flags
3184inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3185 Standard_Integer& theFlags)
3186{
3187 if (theFlagString == "pan")
3188 {
3189 theFlags |= Graphic3d_TMF_PanPers;
3190 }
3191 else if (theFlagString == "zoom")
3192 {
3193 theFlags |= Graphic3d_TMF_ZoomPers;
3194 }
3195 else if (theFlagString == "rotate")
3196 {
3197 theFlags |= Graphic3d_TMF_RotatePers;
3198 }
3199 else if (theFlagString == "trihedron")
3200 {
3201 theFlags = Graphic3d_TMF_TriedronPers;
3202 }
3203 else if (theFlagString == "full")
3204 {
3205 theFlags = Graphic3d_TMF_FullPers;
3206 }
3207 else if (theFlagString == "none")
3208 {
3209 theFlags = Graphic3d_TMF_None;
3210 }
3211 else
3212 {
3213 return Standard_False;
3214 }
3215
3216 return Standard_True;
3217}
3218
7fd59977 3219//==============================================================================
3220//function : VDisplay2
3221//author : ege
3222//purpose : Display an object from its name
7fd59977 3223//==============================================================================
519d35d8 3224static int VDisplay2 (Draw_Interpretor& theDI,
3225 Standard_Integer theArgNb,
3226 const char** theArgVec)
7fd59977 3227{
519d35d8 3228 if (theArgNb < 2)
3229 {
b6d587e3 3230 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 3231 return 1;
3232 }
b6d587e3 3233
3234 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3235 if (aCtx.IsNull())
519d35d8 3236 {
7fd59977 3237 ViewerTest::ViewerInit();
4e18052b 3238 aCtx = ViewerTest::GetAISContext();
7fd59977 3239 }
3240
b6d587e3 3241 // Parse input arguments
4e18052b 3242 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 3243 Standard_Integer isMutable = -1;
3244 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3245 Standard_Boolean toDisplayLocal = Standard_False;
3246 Standard_Boolean toReDisplay = Standard_False;
af65fb19 3247 Standard_Integer isSelectable = -1;
3248 Standard_Integer anObjDispMode = -2;
3249 Standard_Integer anObjHighMode = -2;
3250 Standard_Boolean toSetTrsfPers = Standard_False;
3251 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3252 gp_Pnt aTPPosition;
b6d587e3 3253 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 3254 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94 3255 Standard_Integer toDisplayInView = Standard_False;
519d35d8 3256 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3257 {
b7cd4ba7 3258 const TCollection_AsciiString aName = theArgVec[anArgIter];
3259 TCollection_AsciiString aNameCase = aName;
3260 aNameCase.LowerCase();
4e18052b 3261 if (anUpdateTool.parseRedrawMode (aName))
519d35d8 3262 {
3263 continue;
3264 }
b7cd4ba7 3265 else if (aNameCase == "-mutable")
3266 {
3267 isMutable = 1;
b7cd4ba7 3268 }
a1954302 3269 else if (aNameCase == "-neutral")
3270 {
3271 aDispStatus = AIS_DS_Displayed;
3272 }
3273 else if (aNameCase == "-immediate"
3274 || aNameCase == "-top")
3275 {
3276 aZLayer = Graphic3d_ZLayerId_Top;
3277 }
3278 else if (aNameCase == "-topmost")
3279 {
3280 aZLayer = Graphic3d_ZLayerId_Topmost;
3281 }
3282 else if (aNameCase == "-osd"
af65fb19 3283 || aNameCase == "-toposd"
3284 || aNameCase == "-overlay")
a1954302 3285 {
3286 aZLayer = Graphic3d_ZLayerId_TopOSD;
3287 }
af65fb19 3288 else if (aNameCase == "-botosd"
3289 || aNameCase == "-underlay")
3290 {
3291 aZLayer = Graphic3d_ZLayerId_BotOSD;
3292 }
3293 else if (aNameCase == "-select"
3294 || aNameCase == "-selectable")
3295 {
3296 isSelectable = 1;
3297 }
3298 else if (aNameCase == "-noselect"
3299 || aNameCase == "-noselection")
3300 {
3301 isSelectable = 0;
3302 }
3303 else if (aNameCase == "-dispmode"
3304 || aNameCase == "-displaymode")
3305 {
3306 if (++anArgIter >= theArgNb)
3307 {
3308 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3309 return 1;
3310 }
3311
3312 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3313 }
3314 else if (aNameCase == "-highmode"
3315 || aNameCase == "-highlightmode")
3316 {
3317 if (++anArgIter >= theArgNb)
3318 {
3319 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3320 return 1;
3321 }
3322
3323 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3324 }
3325 else if (aNameCase == "-3d")
3326 {
3327 toSetTrsfPers = Standard_True;
3328 aTrsfPersFlags = Graphic3d_TMF_None;
3329 }
3330 else if (aNameCase == "-2d")
3331 {
3332 toSetTrsfPers = Standard_True;
3333 aTrsfPersFlags = Graphic3d_TMF_2d;
3334 }
3335 else if (aNameCase == "-2dtopdown")
3336 {
3337 toSetTrsfPers = Standard_True;
3338 aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
3339 }
3340 else if (aNameCase == "-trsfpers"
3341 || aNameCase == "-pers")
3342 {
3343 if (++anArgIter >= theArgNb)
3344 {
3345 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3346 return 1;
3347 }
3348
3349 toSetTrsfPers = Standard_True;
3350 aTrsfPersFlags = Graphic3d_TMF_None;
3351 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3352 aPersFlags.LowerCase();
3353 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3354 {
3355 if (aParserPos == -1)
3356 {
3357 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3358 {
3359 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3360 return 1;
3361 }
3362 break;
3363 }
3364
3365 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3366 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3367 {
3368 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3369 return 1;
3370 }
3371 aPersFlags = anOtherFlags;
3372 }
3373 }
3374 else if (aNameCase == "-trsfperspos"
3375 || aNameCase == "-perspos")
3376 {
3377 if (anArgIter + 2 >= theArgNb)
3378 {
3379 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3380 return 1;
3381 }
3382
3383 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3384 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3385 TCollection_AsciiString aZ = "0";
3386 if (!aX.IsIntegerValue()
3387 || !aY.IsIntegerValue())
3388 {
3389 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3390 return 1;
3391 }
3392 if (anArgIter + 1 < theArgNb)
3393 {
3394 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3395 if (aTemp.IsIntegerValue())
3396 {
3397 aZ = aTemp;
3398 ++anArgIter;
3399 }
3400 }
3401 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3402 }
a1954302 3403 else if (aNameCase == "-layer")
3404 {
3405 if (++anArgIter >= theArgNb)
3406 {
3407 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3408 return 1;
3409 }
3410
3411 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3412 if (!aValue.IsIntegerValue())
3413 {
3414 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3415 return 1;
3416 }
3417
3418 aZLayer = aValue.IntegerValue();
3419 }
a272ed94 3420 else if (aNameCase == "-view"
3421 || aNameCase == "-inview")
3422 {
3423 toDisplayInView = Standard_True;
3424 }
b6d587e3 3425 else if (aNameCase == "-local")
3426 {
a1954302 3427 aDispStatus = AIS_DS_Temporary;
b6d587e3 3428 toDisplayLocal = Standard_True;
3429 }
a1954302 3430 else if (aNameCase == "-redisplay")
3431 {
3432 toReDisplay = Standard_True;
3433 }
b6d587e3 3434 else
3435 {
3436 aNamesOfDisplayIO.Append (aName);
3437 }
3438 }
3439
3440 if (aNamesOfDisplayIO.IsEmpty())
3441 {
3442 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3443 return 1;
3444 }
3445
3446 // Prepare context for display
3447 if (toDisplayLocal && !aCtx->HasOpenedContext())
3448 {
3449 aCtx->OpenLocalContext (Standard_False);
3450 }
3451 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3452 {
3453 aCtx->CloseAllContexts (Standard_False);
3454 }
3455
3456 // Display interactive objects
3457 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3458 {
3459 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3460
3461 if (!GetMapOfAIS().IsBound2 (aName))
519d35d8 3462 {
3463 // create the AIS_Shape from a name
3464 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3465 if (!aShape.IsNull())
3466 {
b7cd4ba7 3467 if (isMutable != -1)
3468 {
3469 aShape->SetMutable (isMutable == 1);
3470 }
a1954302 3471 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3472 {
3473 aShape->SetZLayer (aZLayer);
3474 }
af65fb19 3475 if (toSetTrsfPers)
3476 {
3477 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3478 }
3479 if (anObjDispMode != -2)
3480 {
3481 aShape->SetDisplayMode (anObjDispMode);
3482 }
3483 if (anObjHighMode != -2)
3484 {
3485 aShape->SetHilightMode (anObjHighMode);
3486 }
b3c433fe 3487 if (!toDisplayLocal)
3488 GetMapOfAIS().Bind (aShape, aName);
a1954302 3489
3490 Standard_Integer aDispMode = aShape->HasDisplayMode()
3491 ? aShape->DisplayMode()
3492 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3493 ? aCtx->DisplayMode()
3494 : 0);
af65fb19 3495 Standard_Integer aSelMode = -1;
3496 if ( isSelectable == 1
3497 || (isSelectable == -1
3498 && aCtx->GetAutoActivateSelection()
3499 && aShape->GetTransformPersistenceMode() == 0))
3500 {
3501 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3502 }
a1954302 3503
3504 aCtx->Display (aShape, aDispMode, aSelMode,
3505 Standard_False, aShape->AcceptShapeDecomposition(),
3506 aDispStatus);
a272ed94 3507 if (toDisplayInView)
3508 {
3509 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3510 {
3511 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3512 }
3513 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3514 }
519d35d8 3515 }
af65fb19 3516 else
3517 {
3518 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3519 }
519d35d8 3520 continue;
3521 }
7fd59977 3522
519d35d8 3523 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
3524 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
3525 {
3526 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
b7cd4ba7 3527 if (isMutable != -1)
3528 {
3529 aShape->SetMutable (isMutable == 1);
3530 }
a1954302 3531 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3532 {
3533 aShape->SetZLayer (aZLayer);
3534 }
af65fb19 3535 if (toSetTrsfPers)
3536 {
3537 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3538 }
3539 if (anObjDispMode != -2)
3540 {
3541 aShape->SetDisplayMode (anObjDispMode);
3542 }
3543 if (anObjHighMode != -2)
3544 {
3545 aShape->SetHilightMode (anObjHighMode);
3546 }
a1954302 3547 Standard_Integer aDispMode = aShape->HasDisplayMode()
3548 ? aShape->DisplayMode()
3549 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3550 ? aCtx->DisplayMode()
3551 : 0);
af65fb19 3552 Standard_Integer aSelMode = -1;
3553 if ( isSelectable == 1
3554 || (isSelectable == -1
3555 && aCtx->GetAutoActivateSelection()
3556 && aShape->GetTransformPersistenceMode() == 0))
3557 {
3558 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3559 }
b7cd4ba7 3560
519d35d8 3561 if (aShape->Type() == AIS_KOI_Datum)
3562 {
3563 aCtx->Display (aShape, Standard_False);
3564 }
3565 else
3566 {
3567 theDI << "Display " << aName.ToCString() << "\n";
7fd59977 3568
519d35d8 3569 // update the Shape in the AIS_Shape
a1954302 3570 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
519d35d8 3571 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3572 if (!aShapePrs.IsNull())
3573 {
a1954302 3574 if (!aShapePrs->Shape().IsEqual (aNewShape))
3575 {
3576 toReDisplay = Standard_True;
3577 }
519d35d8 3578 aShapePrs->Set (aNewShape);
7fd59977 3579 }
a1954302 3580 if (toReDisplay)
3581 {
3582 aCtx->Redisplay (aShape, Standard_False);
3583 }
3584
af65fb19 3585 if (aSelMode == -1)
3586 {
3587 aCtx->Erase (aShape);
3588 }
a1954302 3589 aCtx->Display (aShape, aDispMode, aSelMode,
3590 Standard_False, aShape->AcceptShapeDecomposition(),
3591 aDispStatus);
a272ed94 3592 if (toDisplayInView)
3593 {
3594 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3595 }
7fd59977 3596 }
3597 }
519d35d8 3598 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
3599 {
3600 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
3601 TheNISContext()->Display (aShape);
7fd59977 3602 }
3603 }
b6d587e3 3604
7fd59977 3605 return 0;
3606}
3607
f3889691 3608//===============================================================================================
3609//function : VUpdate
3610//purpose :
3611//===============================================================================================
3612static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3613{
3614 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3615 if (aContextAIS.IsNull())
3616 {
3617 std::cout << theArgVec[0] << "AIS context is not available.\n";
3618 return 1;
3619 }
3620
3621 if (theArgsNb < 2)
3622 {
3623 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3624 return 1;
3625 }
3626
3627 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3628
3629 AIS_ListOfInteractive aListOfIO;
3630
3631 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3632 {
3633 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3634
3635 Handle(AIS_InteractiveObject) anAISObj;
3636 if (anAISMap.IsBound2 (aName))
3637 {
3638 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3639 }
3640
3641 if (anAISObj.IsNull())
3642 {
3643 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3644 return 1;
3645 }
3646
3647 aListOfIO.Append (anAISObj);
3648 }
3649
3650 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3651 for (; anIOIt.More(); anIOIt.Next())
3652 {
3653 aContextAIS->Update (anIOIt.Value(), Standard_False);
3654 }
3655
3656 aContextAIS->UpdateCurrentViewer();
3657
3658 return 0;
3659}
3660
7fd59977 3661//==============================================================================
3662//function : VPerf
3663//purpose : Test the annimation of an object along a
3664// predifined trajectory
3665//Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3666//==============================================================================
3667
3668static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3669
3670 OSD_Timer myTimer;
3671 if (TheAISContext()->HasOpenedContext())
3672 TheAISContext()->CloseLocalContext();
3673
c6541a0c 3674 Standard_Real Step=4*M_PI/180;
7fd59977 3675 Standard_Real Angle=0;
3676
3677 Handle(AIS_InteractiveObject) aIO;
3678 if (GetMapOfAIS().IsBound2(argv[1]))
3679 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3680 if (aIO.IsNull())
3681 return 1;
3682
3683 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3684
3685 myTimer.Start();
3686
91322f44 3687 if (Draw::Atoi(argv[3])==1 ) {
7fd59977 3688 di<<" Primitives sensibles OFF"<<"\n";
3689 TheAISContext()->Deactivate(aIO);
3690 }
3691 else {
3692 di<<" Primitives sensibles ON"<<"\n";
3693 }
3694 // Movement par transformation
91322f44 3695 if(Draw::Atoi(argv[2]) ==1) {
7fd59977 3696 di<<" Calcul par Transformation"<<"\n";
c6541a0c 3697 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 3698
3699 Angle=Step*myAngle;
3700 gp_Trsf myTransfo;
3701 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3702 TheAISContext()->SetLocation(aShape,myTransfo);
3703 TheAISContext() ->UpdateCurrentViewer();
3704
3705 }
3706 }
3707 else {
3708 di<<" Calcul par Locations"<<"\n";
3709 gp_Trsf myAngleTrsf;
3710 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3711 TopLoc_Location myDeltaAngle (myAngleTrsf);
3712 TopLoc_Location myTrueLoc;
3713
c6541a0c 3714 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 3715
3716 Angle=Step*myAngle;
3717 myTrueLoc=myTrueLoc*myDeltaAngle;
3718 TheAISContext()->SetLocation(aShape,myTrueLoc );
3719 TheAISContext() ->UpdateCurrentViewer();
3720 }
3721 }
91322f44 3722 if (Draw::Atoi(argv[3])==1 ){
7fd59977 3723 // On reactive la selection des primitives sensibles
3724 TheAISContext()->Activate(aIO,0);
3725 }
3726 a3DView() -> Redraw();
3727 myTimer.Stop();
3728 di<<" Temps ecoule "<<"\n";
3729 myTimer.Show();
3730 return 0;
3731}
3732
3733
3734//==================================================================================
3735// Function : VAnimation
3736//==================================================================================
3737static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
31160f80 3738 if (argc != 5) {
7fd59977 3739 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3740 return 1;
3741 }
3742
3743 Standard_Real thread = 4;
3744 Standard_Real angleA=0;
3745 Standard_Real angleB;
3746 Standard_Real X;
3747 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3748
3749 BRep_Builder B;
3750 TopoDS_Shape CrankArm;
3751 TopoDS_Shape CylinderHead;
3752 TopoDS_Shape Propeller;
3753 TopoDS_Shape EngineBlock;
3754
3755 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3756 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3757 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3758 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3759 BRepTools::Read(CrankArm,argv[1],B);
3760 BRepTools::Read(CylinderHead,argv[2],B);
3761 BRepTools::Read(Propeller,argv[3],B);
3762 BRepTools::Read(EngineBlock,argv[4],B);
3763
3764 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3765
3766
3767 OSD_Timer myTimer;
3768 myTimer.Start();
3769
3770 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3771 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3772 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3773 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3774
3775 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3776 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3777 GetMapOfAIS().Bind(myAisCrankArm,"c");
3778 GetMapOfAIS().Bind(myAisPropeller,"d");
3779
b7cd4ba7 3780 myAisCylinderHead->SetMutable (Standard_True);
3781 myAisEngineBlock ->SetMutable (Standard_True);
3782 myAisCrankArm ->SetMutable (Standard_True);
3783 myAisPropeller ->SetMutable (Standard_True);
7fd59977 3784
b7cd4ba7 3785 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3786 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3787 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3788
3789 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3790 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3791 TheAISContext()->Display (myAisCrankArm, Standard_False);
3792 TheAISContext()->Display (myAisPropeller, Standard_False);
7fd59977 3793
3794 TheAISContext()->Deactivate(myAisCylinderHead);
3795 TheAISContext()->Deactivate(myAisEngineBlock );
3796 TheAISContext()->Deactivate(myAisCrankArm );
3797 TheAISContext()->Deactivate(myAisPropeller );
3798
3799 // Boucle de mouvement
c6541a0c 3800 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
7fd59977 3801
c6541a0c 3802 angleA = thread*myAngle*M_PI/180;
7fd59977 3803 X = Sin(angleA)*3/8;
3804 angleB = atan(X / Sqrt(-X * X + 1));
3805 Standard_Real decal(25*0.6);
3806
3807
3808 //Build a transformation on the display
3809 gp_Trsf aPropellerTrsf;
3810 aPropellerTrsf.SetRotation(Ax1,angleA);
3811 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3812
3813 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));
3814 gp_Trsf aCrankArmTrsf;
3815 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3816 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3817
3818 TheAISContext()->UpdateCurrentViewer();
3819 }
3820
0717ddc1 3821 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3822 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
7fd59977 3823
0717ddc1 3824 myAisCrankArm ->ResetTransformation();
3825 myAisPropeller->ResetTransformation();
7fd59977 3826
3827 myAisCrankArm -> Set(myNewCrankArm );
3828 myAisPropeller -> Set(myNewPropeller);
3829
3830 TheAISContext()->Activate(myAisCylinderHead,0);
3831 TheAISContext()->Activate(myAisEngineBlock,0 );
3832 TheAISContext()->Activate(myAisCrankArm ,0 );
3833 TheAISContext()->Activate(myAisPropeller ,0 );
3834
3835 myTimer.Stop();
3836 myTimer.Show();
3837 myTimer.Start();
3838
3839 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3840 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3841
3842 TheAISContext()->UpdateCurrentViewer();
3843 a3DView()->Redraw();
3844
3845 myTimer.Stop();
3846 myTimer.Show();
3847
3848 return 0;
3849
3850}
3851
3852//==============================================================================
3853//function : VShading
3854//purpose : Sharpen or roughten the quality of the shading
3855//Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3856//==============================================================================
5cbef0fe
S
3857static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3858{
7fd59977 3859 Standard_Real myDevCoef;
3860 Handle(AIS_InteractiveObject) TheAisIO;
3861
3862 // Verifications
5cbef0fe
S
3863 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3864
7fd59977 3865 if (TheAISContext()->HasOpenedContext())
3866 TheAISContext()->CloseLocalContext();
3867
3868 if (argc < 3) {
3869 myDevCoef = 0.0008;
3870 } else {
91322f44 3871 myDevCoef =Draw::Atof(argv[2]);
7fd59977 3872 }
3873
7fd59977 3874 TCollection_AsciiString name=argv[1];
3875 if (GetMapOfAIS().IsBound2(name ))
5cbef0fe 3876 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
7fd59977 3877 if (TheAisIO.IsNull())
3878 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3879
5cbef0fe 3880 if (HaveToSet)
7fd59977 3881 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5cbef0fe 3882 else
7fd59977 3883 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3884
7fd59977 3885 TheAISContext()->Redisplay(TheAisIO);
3886 return 0;
3887}
3888//==============================================================================
3889//function : HaveMode
3890//use : VActivatedModes
3891//==============================================================================
3892#include <TColStd_ListIteratorOfListOfInteger.hxx>
3893
3894Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3895{
3896 TColStd_ListOfInteger List;
3897 TheAISContext()->ActivatedModes (TheAisIO,List);
3898 TColStd_ListIteratorOfListOfInteger it;
3899 Standard_Boolean Found=Standard_False;
3900 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3901 if (it.Value()==mode ) Found=Standard_True;
3902 }
3903 return Found;
3904}
3905
3906
3907
3908//==============================================================================
3909//function : VActivatedMode
3910//author : ege
3911//purpose : permet d'attribuer a chacune des shapes un mode d'activation
3912// (edges,vertex...)qui lui est propre et le mode de selection standard.
3913// La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3914// Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3915// qu'un nom et qu'un mode.
3916//Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3917//==============================================================================
3918#include <AIS_ListIteratorOfListOfInteractive.hxx>
3919
3920static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3921
3922{
7fd59977 3923 Standard_Boolean ThereIsName = Standard_False ;
3924
3925 if(!a3DView().IsNull()){
3926
5cbef0fe 3927 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
7fd59977 3928 // verification des arguments
3929 if (HaveToSet) {
3930 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
5cbef0fe 3931 ThereIsName = (argc == 3);
7fd59977 3932 }
3933 else {
3934 // vunsetam
3935 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3936 else {
5cbef0fe
S
3937 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3938 di<<" Fermeture du Context local"<<"\n";
7fd59977 3939 if (TheAISContext()->HasOpenedContext())
3940 TheAISContext()->CloseLocalContext();
3941 }
7fd59977 3942 }
3943
7fd59977 3944 // IL n'y a aps de nom de shape passe en argument
3945 if (HaveToSet && !ThereIsName){
91322f44 3946 Standard_Integer aMode=Draw::Atoi(argv [1]);
7fd59977 3947
3948 const char *cmode="???";
7fd59977 3949 switch (aMode) {
3950 case 0: cmode = "Shape"; break;
3951 case 1: cmode = "Vertex"; break;
3952 case 2: cmode = "Edge"; break;
3953 case 3: cmode = "Wire"; break;
3954 case 4: cmode = "Face"; break;
3955 case 5: cmode = "Shell"; break;
3956 case 6: cmode = "Solid"; break;
3957 case 7: cmode = "Compound"; break;
3958 }
3959
3960 if( !TheAISContext()->HasOpenedContext() ) {
5cbef0fe
S
3961 // il n'y a pas de Context local d'ouvert
3962 // on en ouvre un et on charge toutes les shapes displayees
3963 // on load tous les objets displayees et on Activate les objets de la liste
3964 AIS_ListOfInteractive ListOfIO;
3965 // on sauve dans une AISListOfInteractive tous les objets currents
3966 if (TheAISContext()->NbCurrents()>0 ){
3967 TheAISContext()->UnhilightCurrents(Standard_False);
3968
3969 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3970 ListOfIO.Append(TheAISContext()->Current() );
7fd59977 3971 }
3972 }
3973
3974 TheAISContext()->OpenLocalContext(Standard_False);
3975 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3976 it (GetMapOfAIS());
3977 while(it.More()){
3978 Handle(AIS_InteractiveObject) aIO =
3979 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3980 if (!aIO.IsNull())
3981 TheAISContext()->Load(aIO,0,Standard_False);
3982 it.Next();
3983 }
3984 // traitement des objets qui etaient currents dans le Contexte global
3985 if (!ListOfIO.IsEmpty() ) {
3986 // il y avait des objets currents
3987 AIS_ListIteratorOfListOfInteractive iter;
3988 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3989 Handle(AIS_InteractiveObject) aIO=iter.Value();
3990 TheAISContext()->Activate(aIO,aMode);
3991 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3992 }
3993 }
3994 else {
3995 // On applique le mode a tous les objets displayes
3996 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3997 it2 (GetMapOfAIS());
3998 while(it2.More()){
3999 Handle(AIS_InteractiveObject) aIO =
4000 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4001 if (!aIO.IsNull()) {
4002 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4003 TheAISContext()->Activate(aIO,aMode);
4004 }
4005 it2.Next();
4006 }
4007 }
4008
4009 }
4010
4011 else {
4012 // un Context local est deja ouvert
4013 // Traitement des objets du Context local
4014 if (TheAISContext()->NbSelected()>0 ){
4015 TheAISContext()->UnhilightSelected(Standard_False);
4016 // il y a des objets selected,on les parcourt
4017 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4018 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
4019
4020
4021 if (HaveMode(aIO,aMode) ) {
4022 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4023 TheAISContext()->Deactivate(aIO,aMode);
4024 }
4025 else{
4026 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4027 TheAISContext()->Activate(aIO,aMode);
4028 }
4029
4030 }
4031 }
4032 else{
4033 // il n'y a pas d'objets selected
4034 // tous les objets diplayes sont traites
4035 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4036 it (GetMapOfAIS());
4037 while(it.More()){
4038 Handle(AIS_InteractiveObject) aIO =
4039 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4040 if (!aIO.IsNull()) {
4041 if (HaveMode(aIO,aMode) ) {
4042 di<<" Mode: "<<cmode<<" OFF pour "
4043 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4044 TheAISContext()->Deactivate(aIO,aMode);
4045 }
4046 else{
4047 di<<" Mode: "<<cmode<<" ON pour"
4048 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4049 TheAISContext()->Activate(aIO,aMode);
4050 }
4051 }
4052 it.Next();
4053 }
4054 }
4055 }
4056 }
4057 else if (HaveToSet && ThereIsName){
91322f44 4058 Standard_Integer aMode=Draw::Atoi(argv [2]);
7fd59977 4059 Handle(AIS_InteractiveObject) aIO =
4060 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4061
4062 if (!aIO.IsNull()) {
4063 const char *cmode="???";
4064
4065 switch (aMode) {
4066 case 0: cmode = "Shape"; break;
4067 case 1: cmode = "Vertex"; break;
4068 case 2: cmode = "Edge"; break;
4069 case 3: cmode = "Wire"; break;
4070 case 4: cmode = "Face"; break;
4071 case 5: cmode = "Shell"; break;
4072 case 6: cmode = "Solid"; break;
4073 case 7: cmode = "Compound"; break;
4074 }
4075
4076 if( !TheAISContext()->HasOpenedContext() ) {
4077 TheAISContext()->OpenLocalContext(Standard_False);
4078 // On charge tous les objets de la map
4079 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4080 while(it.More()){
4081 Handle(AIS_InteractiveObject) aShape=
4082 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4083 if (!aShape.IsNull())
4084 TheAISContext()->Load(aShape,0,Standard_False);
4085 it.Next();
4086 }
4087 TheAISContext()->Activate(aIO,aMode);
4088 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4089 }
4090
4091 else {
4092 // un Context local est deja ouvert
4093 if (HaveMode(aIO,aMode) ) {
4094 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4095 TheAISContext()->Deactivate(aIO,aMode);
4096 }
4097 else{
4098 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4099 TheAISContext()->Activate(aIO,aMode);
4100 }
4101 }
4102 }
4103 }
4104 }
4105 return 0;
7fd59977 4106}
4107
cb78155f 4108//! Auxiliary method to print Interactive Object information
4109static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4110 const Handle(Standard_Transient)& theObject,
4111 Draw_Interpretor& theDI)
4112{
4113 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4114 if (anObj.IsNull())
4115 {
4116 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4117 return;
4118 }
7fd59977 4119
cb78155f 4120 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4121 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4122 << (theDetected.Contains (anObj) ? " Detected" : " ")
4123 << " Type: ";
4124 if (anObj->Type() == AIS_KOI_Datum)
4125 {
4126 // AIS_Datum
4127 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4128 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4129 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4130 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4131 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4132 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4133 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
7fd59977 4134 }
4135 // AIS_Shape
cb78155f 4136 else if (anObj->Type() == AIS_KOI_Shape
4137 && anObj->Signature() == 0)
4138 {
4139 theDI << " AIS_Shape";
7fd59977 4140 }
cb78155f 4141 else if (anObj->Type() == AIS_KOI_Relation)
4142 {
4143 // AIS_Dimention and AIS_Relation
4144 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4145 switch (aRelation->KindOfDimension())
4146 {
4147 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4148 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4149 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4150 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4151 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4152 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4153 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4154 default: theDI << " UNKNOWN dimension"; break;
4155 }
4156 }
4157 else
4158 {
4159 theDI << " UserPrs";
4160 }
4161 theDI << " (" << theObject->DynamicType()->Name() << ")";
7fd59977 4162}
4163
cb78155f 4164//! Print information about locally selected sub-shapes
4165static void localCtxInfo (Draw_Interpretor& theDI)
4166{
4167 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4168 if (!aCtx->HasOpenedContext())
4169 {
4170 return;
4171 }
7fd59977 4172
cb78155f 4173 TCollection_AsciiString aPrevName;
4174 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
4175 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
4176 {
4177 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
4178 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
4179 if (aSubShape.IsNull()
4180 || aShapeIO.IsNull()
4181 || !GetMapOfAIS().IsBound1 (aShapeIO))
4182 {
4183 continue;
4184 }
4185
4186 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4187 TopTools_MapOfShape aFilter;
4188 Standard_Integer aNumber = 0;
4189 const TopoDS_Shape aShape = aShapeIO->Shape();
4190 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4191 anIter.More(); anIter.Next())
4192 {
4193 if (!aFilter.Add (anIter.Current()))
4194 {
4195 continue; // filter duplicates
4196 }
4197
4198 ++aNumber;
4199 if (!anIter.Current().IsSame (aSubShape))
4200 {
4201 continue;
4202 }
4203
4204 Standard_CString aShapeName = NULL;
4205 switch (aSubShape.ShapeType())
4206 {
4207 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4208 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4209 case TopAbs_SOLID: aShapeName = " Solid"; break;
4210 case TopAbs_SHELL: aShapeName = " Shell"; break;
4211 case TopAbs_FACE: aShapeName = " Face"; break;
4212 case TopAbs_WIRE: aShapeName = " Wire"; break;
4213 case TopAbs_EDGE: aShapeName = " Edge"; break;
4214 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4215 default:
4216 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4217 }
4218
4219 if (aParentName != aPrevName)
4220 {
4221 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4222 aPrevName = aParentName;
4223 }
4224 theDI << " " << aShapeName << " #" << aNumber << "\n";
4225 break;
4226 }
4227 }
4228}
7fd59977 4229
4230//==============================================================================
4231//function : VState
4232//purpose :
7fd59977 4233//==============================================================================
cb78155f 4234static Standard_Integer VState (Draw_Interpretor& theDI,
4235 Standard_Integer theArgNb,
4236 Standard_CString* theArgVec)
7fd59977 4237{
cb78155f 4238 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4239 if (aCtx.IsNull())
4240 {
4241 std::cerr << "Error: No opened viewer!\n";
4242 return 1;
7fd59977 4243 }
cb78155f 4244
51023771 4245 Standard_Boolean toPrintEntities = Standard_False;
4246 Standard_Boolean toCheckSelected = Standard_False;
4247
4248 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4249 {
4250 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4251 anOption.LowerCase();
4252 if (anOption == "-detectedentities"
4253 || anOption == "-entities")
4254 {
4255 toPrintEntities = Standard_True;
4256 }
4257 else if (anOption == "-hasselected")
4258 {
4259 toCheckSelected = Standard_True;
4260 }
4261 }
4262
4263 if (toCheckSelected)
4264 {
4265 aCtx->InitSelected();
4266 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4267 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4268
4269 return 0;
4270 }
4271
4272 if (toPrintEntities)
8e7c8ccf 4273 {
4274 theDI << "Detected entities:\n";
4275 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
f751596e 4276 for (aSelector->InitDetected(); aSelector->MoreDetected(); aSelector->NextDetected())
8e7c8ccf 4277 {
f751596e 4278 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
8e7c8ccf 4279 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4280 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
f751596e 4281 SelectMgr_SelectingVolumeManager aMgr = anObj->HasTransformation() ? aSelector->GetManager().Transform (anObj->InversedTransformation())
4282 : aSelector->GetManager();
4283 SelectBasics_PickResult aResult;
4284 anEntity->Matches (aMgr, aResult);
4285 NCollection_Vec3<Standard_Real> aDetectedPnt = aMgr.DetectedPoint (aResult.Depth());
8e7c8ccf 4286
4287 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4288 aName.LeftJustify (20, ' ');
4289 char anInfoStr[512];
f751596e 4290 Sprintf (anInfoStr,
4291 " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
4292 aResult.Depth(),
4293 aResult.DistToGeomCenter(),
4294 aDetectedPnt.x(), aDetectedPnt.y(), aDetectedPnt.z());
8e7c8ccf 4295 theDI << " " << aName
4296 << anInfoStr
4297 << " (" << anEntity->DynamicType()->Name() << ")"
4298 << "\n";
4299
4300 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4301 if (!aBRepOwner.IsNull())
4302 {
4303 theDI << " Detected Shape: "
4304 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4305 << "\n";
4306 }
4307
4308 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4309 if (!aWire.IsNull())
4310 {
4311 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4312 theDI << " Detected Child: "
4313 << aSen->DynamicType()->Name()
4314 << "\n";
4315 }
4316 }
4317 return 0;
4318 }
4319
cb78155f 4320 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4321 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4322 {
4323 aDetected.Add (aCtx->DetectedCurrentObject());
4324 }
4325
4326 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4327 if (theArgNb >= 2
4328 && !toShowAll)
4329 {
4330 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7fd59977 4331 {
cb78155f 4332 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4333 if (!GetMapOfAIS().IsBound2 (anObjName))
4334 {
4335 theDI << anObjName << " doesn't exist!\n";
4336 continue;
7fd59977 4337 }
4338
cb78155f 4339 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4340 TCollection_AsciiString aName = anObjName;
4341 aName.LeftJustify (20, ' ');
4342 theDI << " " << aName << " ";
4343 objInfo (aDetected, anObjTrans, theDI);
4344 theDI << "\n";
7fd59977 4345 }
cb78155f 4346 return 0;
7fd59977 4347 }
cb78155f 4348
4349 if (aCtx->NbCurrents() > 0
4350 && !toShowAll)
4351 {
4352 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
4353 {
4354 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
4355 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4356 aName.LeftJustify (20, ' ');
4357 theDI << aName << " ";
4358 objInfo (aDetected, anObj, theDI);
4359 theDI << "\n";
7fd59977 4360 }
cb78155f 4361 return 0;
7fd59977 4362 }
4363
cb78155f 4364 theDI << "Neutral-point state:\n";
4365 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4366 anObjIter.More(); anObjIter.Next())
4367 {
4368 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4369 if (anObj.IsNull())
4370 {
4371 continue;
4372 }
4373
4374 TCollection_AsciiString aName = anObjIter.Key2();
4375 aName.LeftJustify (20, ' ');
4376 theDI << " " << aName << " ";
4377 objInfo (aDetected, anObj, theDI);
4378 theDI << "\n";
4379 }
4380 localCtxInfo (theDI);
7fd59977 4381 return 0;
4382}
4383
7fd59977 4384//=======================================================================
4385//function : PickObjects
4386//purpose :
4387//=======================================================================
4388Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4389 const AIS_KindOfInteractive TheType,
4390 const Standard_Integer TheSignature,
4391 const Standard_Integer MaxPick)
4392{
4393 Handle(AIS_InteractiveObject) IO;
4394 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4395
4396 // step 1: prepare the data
4952a30a 4397 if(curindex !=0){
7fd59977 4398 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4399 TheAISContext()->AddFilter(F1);
4400 }
4401
4402 // step 2 : wait for the selection...
4403// Standard_Boolean IsGood (Standard_False);
4404// Standard_Integer NbPick(0);
4405 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
4406 Standard_Integer NbPickFail(0);
4407 Standard_Integer argccc = 5;
4408 const char *bufff[] = { "A", "B", "C","D", "E" };
4409 const char **argvvv = (const char **) bufff;
4410
4411
4412 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4413 while(ViewerMainLoop(argccc,argvvv)){}
4414 Standard_Integer NbStored = TheAISContext()->NbSelected();
4415 if((unsigned int ) NbStored != NbPickGood)
4416 NbPickGood= NbStored;
4417 else
4418 NbPickFail++;
4419 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4420 }
4421
4422 // step3 get result.
4423
4424 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4425
4426 Standard_Integer i(0);
4427 for(TheAISContext()->InitSelected();
4428 TheAISContext()->MoreSelected();
4429 TheAISContext()->NextSelected()){
4430 i++;
4431 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4432 arr->SetValue(i,IO2);
4433 }
4434
4435
4436 if(curindex>0)
4437 TheAISContext()->CloseLocalContext(curindex);
4438
4439 return Standard_True;
4440}
4441
4442
4443//=======================================================================
4444//function : PickObject
4445//purpose :
4446//=======================================================================
4447Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4448 const Standard_Integer TheSignature,
4449 const Standard_Integer MaxPick)
4450{
4451 Handle(AIS_InteractiveObject) IO;
4452 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4453
4454 // step 1: prepare the data
4455
4952a30a 4456 if(curindex !=0){
7fd59977 4457 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4458 TheAISContext()->AddFilter(F1);
4459 }
4460
4461 // step 2 : wait for the selection...
4462 Standard_Boolean IsGood (Standard_False);
4463 Standard_Integer NbPick(0);
4464 Standard_Integer argccc = 5;
4465 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4466 const char **argvvv = (const char **) bufff;
4467
4468
4469 while(!IsGood && NbPick<= MaxPick){
4470 while(ViewerMainLoop(argccc,argvvv)){}
4471 IsGood = (TheAISContext()->NbSelected()>0) ;
4472 NbPick++;
4473 cout<<"Nb Pick :"<<NbPick<<endl;
4474 }
4475
4476
4477 // step3 get result.
4478 if(IsGood){
4479 TheAISContext()->InitSelected();
4480 IO = TheAISContext()->SelectedInteractive();
4481 }
4482
4952a30a 4483 if(curindex!=0)
7fd59977 4484 TheAISContext()->CloseLocalContext(curindex);
4485 return IO;
4486}
4487
4488//=======================================================================
4489//function : PickShape
4490//purpose : First Activate the rightmode + Put Filters to be able to
4491// pick objets that are of type <TheType>...
4492//=======================================================================
4493
4494TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4495 const Standard_Integer MaxPick)
4496{
4497
4498 // step 1: prepare the data
4499
4500 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4501 TopoDS_Shape result;
4502
4503 if(TheType==TopAbs_SHAPE){
4504 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4505 TheAISContext()->AddFilter(F1);
4506 }
4507 else{
4508 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4509 TheAISContext()->AddFilter(TF);
4510 TheAISContext()->ActivateStandardMode(TheType);
4511
4512 }
4513
4514
4515 // step 2 : wait for the selection...
4516 Standard_Boolean NoShape (Standard_True);
4517 Standard_Integer NbPick(0);
4518 Standard_Integer argccc = 5;
4519 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4520 const char **argvvv = (const char **) bufff;
4521
4522
4523 while(NoShape && NbPick<= MaxPick){
4524 while(ViewerMainLoop(argccc,argvvv)){}
4525 NoShape = (TheAISContext()->NbSelected()==0) ;
4526 NbPick++;
4527 cout<<"Nb Pick :"<<NbPick<<endl;
4528 }
4529
4530 // step3 get result.
4531
4532 if(!NoShape){
4533
4534 TheAISContext()->InitSelected();
4535 if(TheAISContext()->HasSelectedShape())
4536 result = TheAISContext()->SelectedShape();
4537 else{
4538 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4539 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
4540 }
4541 }
4542
4543 if(curindex>0)
4544 TheAISContext()->CloseLocalContext(curindex);
4545
4546 return result;
4547}
4548
4549
4550//=======================================================================
4551//function : PickShapes
4552//purpose :
4553//=======================================================================
4554Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4555 Handle(TopTools_HArray1OfShape)& thearr,
4556 const Standard_Integer MaxPick)
4557{
4558
4559 Standard_Integer Taille = thearr->Length();
4560 if(Taille>1)
4561 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
4562
4563 // step 1: prepare the data
4564 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4565 if(TheType==TopAbs_SHAPE){
4566 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4567 TheAISContext()->AddFilter(F1);
4568 }
4569 else{
4570 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4571 TheAISContext()->AddFilter(TF);
4572 TheAISContext()->ActivateStandardMode(TheType);
4573
4574 }
4575
4576 // step 2 : wait for the selection...
4577
4578 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
4579 Standard_Integer NbPickFail(0);
4580 Standard_Integer argccc = 5;
4581 const char *bufff[] = { "A", "B", "C","D", "E" };
4582 const char **argvvv = (const char **) bufff;
4583
4584
4585 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4586 while(ViewerMainLoop(argccc,argvvv)){}
4587 Standard_Integer NbStored = TheAISContext()->NbSelected();
4588 if((unsigned int ) NbStored != NbPickGood)
4589 NbPickGood= NbStored;
4590 else
4591 NbPickFail++;
4592 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4593 }
4594
4595 // step3 get result.
4596
4597 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4598
4599 Standard_Integer i(0);
4600 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4601 i++;
4602 if(TheAISContext()->HasSelectedShape())
4603 thearr->SetValue(i,TheAISContext()->SelectedShape());
4604 else{
4605 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4606 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
4607 }
4608 }
4609
4610 TheAISContext()->CloseLocalContext(curindex);
4611 return Standard_True;
4612}
4613
4614
4615//=======================================================================
4616//function : VPickShape
4617//purpose :
4618//=======================================================================
4619static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4620{
4621 TopoDS_Shape PickSh;
4622 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4623
4624 if(argc==1)
4625 theType = TopAbs_SHAPE;
4626 else{
4627 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4628 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4629 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4630 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4631 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4632 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4633 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4634 }
4635
4636 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4637 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4638
4639 TCollection_AsciiString name;
4640
4641
4642 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4643 if(NbToPick==1){
4644 PickSh = ViewerTest::PickShape(theType);
4645
4646 if(PickSh.IsNull())
4647 return 1;
4648 if(argc>2){
4649 name += argv[2];
4650 }
4651 else{
4652
4653 if(!PickSh.IsNull()){
4654 nbOfSub[Standard_Integer(theType)]++;
4655 name += "Picked_";
4656 name += nameType[Standard_Integer(theType)];
4657 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4658 name +="_";
4659 name+=indxstring;
4660 }
4661 }
4662 // si on avait une petite methode pour voir si la shape
4663 // est deja dans la Double map, ca eviterait de creer....
4664 DBRep::Set(name.ToCString(),PickSh);
4665
4666 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4667 GetMapOfAIS().Bind(newsh, name);
4668 TheAISContext()->Display(newsh);
4669 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4670 }
4671
4672 // Plusieurs objets a picker, vite vite vite....
4673 //
4674 else{
4675 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4676 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4677 if(ViewerTest::PickShapes(theType,arr)){
4678 for(Standard_Integer i=1;i<=NbToPick;i++){
4679 PickSh = arr->Value(i);
4680 if(!PickSh.IsNull()){
4681 if(autonaming){
4682 nbOfSub[Standard_Integer(theType)]++;
4683 name.Clear();
4684 name += "Picked_";
4685 name += nameType[Standard_Integer(theType)];
4686 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4687 name +="_";
4688 name+=indxstring;
4689 }
4690 }
4691 else
4692 name = argv[1+i];
4693
4694 DBRep::Set(name.ToCString(),PickSh);
4695 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4696 GetMapOfAIS().Bind(newsh, name);
4697 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4698 TheAISContext()->Display(newsh);
4699
4700 }
4701 }
4702 }
4703 return 0;
7fd59977 4704}
7fd59977 4705
d8110103 4706//=======================================================================
4707//function : VPickSelected
4708//purpose :
4709//=======================================================================
4710static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4711{
4712 static Standard_Integer aCount = 0;
4713 TCollection_AsciiString aName = "PickedShape_";
4714
4715 if (theArgNb > 1)
4716 {
4717 aName = theArgs[1];
4718 }
4719 else
4720 {
4721 aName = aName + aCount++ + "_";
4722 }
4723
4724 Standard_Integer anIdx = 0;
4725 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4726 {
4727 TopoDS_Shape aShape;
4728 if (TheAISContext()->HasSelectedShape())
4729 {
4730 aShape = TheAISContext()->SelectedShape();
4731 }
4732 else
4733 {
4734 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4735 aShape = (*((Handle(AIS_Shape)*) &IO))->Shape();
4736 }
4737
4738 TCollection_AsciiString aCurrentName = aName;
4739 if (anIdx > 0)
4740 {
4741 aCurrentName += anIdx;
4742 }
4743
4744 DBRep::Set ((aCurrentName).ToCString(), aShape);
4745
4746 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4747 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4748 TheAISContext()->Display (aNewShape);
4749 }
4750
4751 return 0;
4752}
4753
7fd59977 4754//=======================================================================
4755//function : list of known objects
4756//purpose :
4757//=======================================================================
4758static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4759{
4760 // 1234567890 12345678901234567 123456789
4761 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4762 TCollection_AsciiString BlankLine(64,'_');
4763 Standard_Integer i ;
4764
4765 di<<"/n"<<BlankLine.ToCString()<<"\n";
4766
4767 for( i =0;i<=2;i++)
4768 Colum[i].Center(20,' ');
4769 for(i=0;i<=2;i++)
4770 di<<"|"<<Colum[i].ToCString();
4771 di<<"|"<<"\n";
4772
4773 di<<BlankLine.ToCString()<<"\n";
4774
4775 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4776 const char ** names = GetTypeNames();
4777
4778 TCollection_AsciiString curstring;
4779 TCollection_AsciiString curcolum[3];
4780
4781
4782 // les objets de type Datum..
4783 curcolum[1]+="Datum";
4784 for(i =0;i<=6;i++){
4785 curcolum[0].Clear();
4786 curcolum[0] += names[i];
4787
4788 curcolum[2].Clear();
4789 curcolum[2]+=TCollection_AsciiString(i+1);
4790
4791 for(Standard_Integer j =0;j<=2;j++){
4792 curcolum[j].Center(20,' ');
4793 di<<"|"<<curcolum[j].ToCString();
4794 }
4795 di<<"|"<<"\n";
4796 }
4797 di<<BlankLine.ToCString()<<"\n";
4798
4799 // les objets de type shape
4800 curcolum[1].Clear();
4801 curcolum[1]+="Shape";
4802 curcolum[1].Center(20,' ');
4803
4804 for(i=0;i<=2;i++){
4805 curcolum[0].Clear();
4806 curcolum[0] += names[7+i];
4807 curcolum[2].Clear();
4808 curcolum[2]+=TCollection_AsciiString(i);
4809
4810 for(Standard_Integer j =0;j<=2;j++){
4811 curcolum[j].Center(20,' ');
4812 di<<"|"<<curcolum[j].ToCString();
4813 }
4814 di<<"|"<<"\n";
4815 }
4816 di<<BlankLine.ToCString()<<"\n";
4817 // les IO de type objet...
4818 curcolum[1].Clear();
4819 curcolum[1]+="Object";
4820 curcolum[1].Center(20,' ');
4821 for(i=0;i<=1;i++){
4822 curcolum[0].Clear();
4823 curcolum[0] += names[10+i];
4824 curcolum[2].Clear();
4825 curcolum[2]+=TCollection_AsciiString(i);
4826
4827 for(Standard_Integer j =0;j<=2;j++){
4828 curcolum[j].Center(20,' ');
4829 di<<"|"<<curcolum[j].ToCString();
4830 }
4831 di<<"|"<<"\n";
4832 }
4833 di<<BlankLine.ToCString()<<"\n";
4834 // les contraintes et dimensions.
4835 // pour l'instant on separe juste contraintes et dimensions...
4836 // plus tard, on detaillera toutes les sortes...
4837 curcolum[1].Clear();
4838 curcolum[1]+="Relation";
4839 curcolum[1].Center(20,' ');
4840 for(i=0;i<=1;i++){
4841 curcolum[0].Clear();
4842 curcolum[0] += names[12+i];
4843 curcolum[2].Clear();
4844 curcolum[2]+=TCollection_AsciiString(i);
4845
4846 for(Standard_Integer j =0;j<=2;j++){
4847 curcolum[j].Center(20,' ');
4848 di<<"|"<<curcolum[j].ToCString();
4849 }
4850 di<<"|"<<"\n";
4851 }
4852 di<<BlankLine.ToCString()<<"\n";
4853
4854
4855 return 0;
4856}
4857
4858
4859static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4860{
4952a30a 4861 if(argc!=2) return 1;
7fd59977 4862
4863 AIS_KindOfInteractive TheType;
4864 Standard_Integer TheSign(-1);
4865 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4866
4867
4868 AIS_ListOfInteractive LIO;
4869
4870 // en attendant l'amelioration ais pour les dimensions...
4871 //
4872 Standard_Integer dimension_status(-1);
4873 if(TheType==AIS_KOI_Relation){
4874 dimension_status = TheSign ==1 ? 1 : 0;
4875 TheSign=-1;
4876 }
4877
4878 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4879 Handle(AIS_InteractiveObject) curio;
4880 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4881 curio = it.Value();
4882
4883 if(dimension_status == -1)
4884 TheAISContext()->Erase(curio,Standard_False);
4885 else {
4886 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4887 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4888 (dimension_status==1 && KOD != AIS_KOD_NONE))
4889 TheAISContext()->Erase(curio,Standard_False);
4890 }
4891 }
4892 TheAISContext()->UpdateCurrentViewer();
4893 return 0;
4894}
4895static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4896{
4897 if(argc!=2) return 1;
4898
4899 AIS_KindOfInteractive TheType;
4900 Standard_Integer TheSign(-1);
4901 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4902
4903 // en attendant l'amelioration ais pour les dimensions...
4904 //
4905 Standard_Integer dimension_status(-1);
4906 if(TheType==AIS_KOI_Relation){
4907 dimension_status = TheSign ==1 ? 1 : 0;
4908 TheSign=-1;
4909 }
4910
4911 AIS_ListOfInteractive LIO;
4912 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4913 Handle(AIS_InteractiveObject) curio;
4914 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4915 curio = it.Value();
4916 if(dimension_status == -1)
4917 TheAISContext()->Display(curio,Standard_False);
4918 else {
4919 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4920 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4921 (dimension_status==1 && KOD != AIS_KOD_NONE))
4922 TheAISContext()->Display(curio,Standard_False);
4923 }
4924
4925 }
4926
4927 TheAISContext()->UpdateCurrentViewer();
4928 return 0;
4929}
4930
7fd59977 4931static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4932{
4933 ifstream s(a[1]);
4934 BRep_Builder builder;
4935 TopoDS_Shape shape;
4936 BRepTools::Read(shape, s, builder);
4937 DBRep::Set(a[1], shape);
4938 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4939 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4940 Ctx->Display(ais);
4941 return 0;
4942}
7fd59977 4943
f751596e 4944//==============================================================================
4945//function : VLoadSelection
4946//purpose : Adds given objects to map of AIS and loads selection primitives for them
4947//==============================================================================
4948static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
4949 Standard_Integer theArgNb,
4950 const char** theArgVec)
4951{
4952 if (theArgNb < 2)
4953 {
4954 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4955 return 1;
4956 }
4957
4958 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4959 if (aCtx.IsNull())
4960 {
4961 ViewerTest::ViewerInit();
4962 aCtx = ViewerTest::GetAISContext();
4963 }
4964
4965 // Parse input arguments
4966 TColStd_SequenceOfAsciiString aNamesOfIO;
4967 Standard_Boolean isLocal = Standard_False;
4968 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4969 {
4970 const TCollection_AsciiString aName = theArgVec[anArgIter];
4971 TCollection_AsciiString aNameCase = aName;
4972 aNameCase.LowerCase();
4973 if (aNameCase == "-local")
4974 {
4975 isLocal = Standard_True;
4976 }
4977 else
4978 {
4979 aNamesOfIO.Append (aName);
4980 }
4981 }
4982
4983 if (aNamesOfIO.IsEmpty())
4984 {
4985 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4986 return 1;
4987 }
4988
4989 // Prepare context
4990 if (isLocal && !aCtx->HasOpenedContext())
4991 {
4992 aCtx->OpenLocalContext (Standard_False);
4993 }
4994 else if (!isLocal && aCtx->HasOpenedContext())
4995 {
4996 aCtx->CloseAllContexts (Standard_False);
4997 }
4998
4999 // Load selection of interactive objects
5000 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5001 {
5002 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5003
5004 const Handle(AIS_InteractiveObject)& aShape = GetMapOfAIS().IsBound2 (aName) ?
5005 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName)) : GetAISShapeFromName (aName.ToCString());
5006
5007 if (!aShape.IsNull())
5008 {
5009 if (!GetMapOfAIS().IsBound2 (aName))
5010 {
5011 GetMapOfAIS().Bind (aShape, aName);
5012 }
5013
5014 aCtx->Load (aShape, -1, Standard_False);
5015 aCtx->Activate (aShape, aShape->SelectionMode(), Standard_True);
5016 }
5017 }
5018
5019 return 0;
5020}
5021
5022//==============================================================================
5023//function : VAutoActivateSelection
5024//purpose : Activates or deactivates auto computation of selection
5025//==============================================================================
5026static int VAutoActivateSelection (Draw_Interpretor& theDi,
5027 Standard_Integer theArgNb,
5028 const char** theArgVec)
5029{
5030
5031 if (theArgNb > 2)
5032 {
5033 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5034 return 1;
5035 }
5036
5037 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5038 if (aCtx.IsNull())
5039 {
5040 ViewerTest::ViewerInit();
5041 aCtx = ViewerTest::GetAISContext();
5042 }
5043
5044 if (theArgNb == 1)
5045 {
5046 TCollection_AsciiString aSelActivationString;
5047 if (aCtx->GetAutoActivateSelection())
5048 {
5049 aSelActivationString.Copy ("ON");
5050 }
5051 else
5052 {
5053 aSelActivationString.Copy ("OFF");
5054 }
5055
5056 theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
5057 }
5058 else
5059 {
5060 Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]);
5061 aCtx->SetAutoActivateSelection (toActivate);
5062 }
5063
5064 return 0;
5065}
5066
7fd59977 5067//==============================================================================
5068//function : ViewerTest::Commands
5069//purpose : Add all the viewer command in the Draw_Interpretor
5070//==============================================================================
5071
5072void ViewerTest::Commands(Draw_Interpretor& theCommands)
5073{
5074 ViewerTest::ViewerCommands(theCommands);
5075 ViewerTest::RelationCommands(theCommands);
5076 ViewerTest::ObjectCommands(theCommands);
5077 ViewerTest::FilletCommands(theCommands);
5078 ViewerTest::VoxelCommands(theCommands);
3946774d 5079 ViewerTest::OpenGlCommands(theCommands);
7fd59977 5080
5081 const char *group = "AIS_Display";
5082
5083 // display
1c88cbaf 5084 theCommands.Add("visos",
b6d587e3 5085 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5086 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5087 __FILE__, visos, group);
7fd59977 5088
5089 theCommands.Add("vdisplay",
af65fb19 5090 "vdisplay [-noupdate|-update] [-local] [-mutable] [-overlay|-underlay]"
5091 "\n\t\t: [-trsfPers flags] [-trsfPersPos X Y [Z]] [-3d|-2d|-2dTopDown]"
5092 "\n\t\t: [-dispMode mode] [-highMode mode]"
5093 "\n\t\t: name1 [name2] ... [name n]"
519d35d8 5094 "\n\t\t: Displays named objects."
b6d587e3 5095 "\n\t\t: Option -local enables displaying of objects in local"
5096 "\n\t\t: selection context. Local selection context will be opened"
5097 "\n\t\t: if there is not any."
af65fb19 5098 "\n\t\t: -noupdate suppresses viewer redraw call."
5099 "\n\t\t: -mutable enables optimizations for mutable objects."
5100 "\n\t\t: -overlay draws objects in overlay."
5101 "\n\t\t: -underlay draws objects in underlay."
5102 "\n\t\t: -selectable|-noselect controls selection of objects."
5103 "\n\t\t: -trsfPers sets a transform persistence flags."
5104 "\n\t\t: -trsfPersPos sets an anchor point for transform persistence."
5105 "\n\t\t: -2d|-2dTopDown displays object in screen coordinates.",
b6d587e3 5106 __FILE__, VDisplay2, group);
7fd59977 5107
f3889691 5108 theCommands.Add ("vupdate",
5109 "vupdate name1 [name2] ... [name n]"
5110 "\n\t\t: Updates named objects in interactive context",
5111 __FILE__, VUpdate, group);
5112
7fd59977 5113 theCommands.Add("verase",
b6d587e3 5114 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
ac4aaa98 5115 "\n\t\t: Erases selected or named objects."
b6d587e3 5116 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5117 "\n\t\t: Option -local enables erasing of selected or named objects without"
5118 "\n\t\t: closing local selection context.",
5119 __FILE__, VErase, group);
7fd59977 5120
eef7fc64 5121 theCommands.Add("vremove",
b6d587e3 5122 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5123 "or vremove [-context] -all to remove all objects"
eef7fc64 5124 "\n\t\t: Removes selected or named objects."
5125 "\n\t\t If -context is in arguments, the objects are not deleted"
519d35d8 5126 "\n\t\t from the map of objects and names."
b6d587e3 5127 "\n\t\t: Option -local enables removing of selected or named objects without"
5128 "\n\t\t: closing local selection context. Empty local selection context will be"
5129 "\n\t\t: closed."
b7cd4ba7 5130 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5131 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
eef7fc64 5132 __FILE__, VRemove, group);
5133
7fd59977 5134 theCommands.Add("vdonly",
519d35d8 5135 "vdonly [-noupdate|-update] [name1] ... [name n]"
ac4aaa98 5136 "\n\t\t: Displays only selected or named objects",
7fd59977 5137 __FILE__,VDonly2,group);
5138
5139 theCommands.Add("vdisplayall",
b6d587e3 5140 "vidsplayall [-local]"
5141 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5142 "\n\t\t: Option -local enables displaying of the objects in local"
5143 "\n\t\t: selection context.",
5144 __FILE__, VDisplayAll, group);
7fd59977 5145
5146 theCommands.Add("veraseall",
b6d587e3 5147 "veraseall [-local]"
5148 "\n\t\t: Erases all objects displayed in the viewer."
5149 "\n\t\t: Option -local enables erasing of the objects in local"
5150 "\n\t\t: selection context.",
5151 __FILE__, VErase, group);
7fd59977 5152
5153 theCommands.Add("verasetype",
b6d587e3 5154 "verasetype <Type>"
ac4aaa98 5155 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
b6d587e3 5156 __FILE__, VEraseType, group);
c2a388f8 5157 theCommands.Add("vbounding",
5158 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5159 "\n\t\t: [-print] [-hide]"
5160 "\n\t\t: Temporarily display bounding box of specified Interactive"
5161 "\n\t\t: Objects, or print it to console if -print is specified."
5162 "\n\t\t: Already displayed box might be hidden by -hide option.",
5163 __FILE__,VBounding,group);
5164
7fd59977 5165 theCommands.Add("vdisplaytype",
5166 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5167 __FILE__,VDisplayType,group);
5168
5169 theCommands.Add("vdisplaymode",
5170 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
5171 __FILE__,VDispMode,group);
5172
5173 theCommands.Add("verasemode",
5174 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
5175 __FILE__,VDispMode,group);
5176
5177 theCommands.Add("vsetdispmode",
ac4aaa98 5178 "vsetdispmode [name] mode(1,2,..)"
5179 "\n\t\t: Sets display mode for all, selected or named objects.",
7fd59977 5180 __FILE__,VDispMode,group);
5181
5182 theCommands.Add("vunsetdispmode",
ac4aaa98 5183 "vunsetdispmode [name]"
5184 "\n\t\t: Unsets custom display mode for selected or named objects.",
7fd59977 5185 __FILE__,VDispMode,group);
5186
5187 theCommands.Add("vdir",
ac4aaa98 5188 "Lists all objects displayed in 3D viewer",
519d35d8 5189 __FILE__,VDir,group);
7fd59977 5190
5191 theCommands.Add("vdump",
ac4aaa98 5192 #ifdef HAVE_FREEIMAGE
34db9c00 5193 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
5194 "\n\t\t: [width Width=0 height Height=0]"
5195 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
ac4aaa98 5196 #else
34db9c00 5197 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
5198 "\n\t\t: [width Width=0 height Height=0]"
5199 "\n\t\t: Dumps content of the active view into PPM image file",
ac4aaa98 5200 #endif
7fd59977 5201 __FILE__,VDump,group);
5202
5203 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5204 __FILE__,VSubInt,group);
5205
ad3217cd 5206 theCommands.Add("vaspects",
6262338c 5207 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5bffb882 5208 "\n\t\t: [-setvisibility 0|1]"
8316c618 5209 "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
ad3217cd 5210 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
0ae61cf3 5211 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
ad3217cd 5212 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
6262338c 5213 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5214 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5215 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
ad3217cd 5216 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5217 "\n\t\t: Manage presentation properties of all, selected or named objects."
5218 "\n\t\t: When -subshapes is specified than following properties will be"
6262338c 5219 "\n\t\t: assigned to specified sub-shapes."
5220 "\n\t\t: When -defaults is specified than presentation properties will be"
5221 "\n\t\t: assigned to all objects that have not their own specified properties"
5222 "\n\t\t: and to all objects to be displayed in the future."
5223 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
ad3217cd 5224 __FILE__,VAspects,group);
5225
7fd59977 5226 theCommands.Add("vsetcolor",
ad3217cd 5227 "vsetcolor [-noupdate|-update] [name] ColorName"
5228 "\n\t\t: Sets color for all, selected or named objects."
5229 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5230 __FILE__,VAspects,group);
7fd59977 5231
5232 theCommands.Add("vunsetcolor",
ad3217cd 5233 "vunsetcolor [-noupdate|-update] [name]"
5234 "\n\t\t: Resets color for all, selected or named objects."
5235 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5236 __FILE__,VAspects,group);
7fd59977 5237
5238 theCommands.Add("vsettransparency",
ad3217cd 5239 "vsettransparency [-noupdate|-update] [name] Coefficient"
ac4aaa98 5240 "\n\t\t: Sets transparency for all, selected or named objects."
ad3217cd 5241 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5242 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5243 __FILE__,VAspects,group);
7fd59977 5244
5245 theCommands.Add("vunsettransparency",
ad3217cd 5246 "vunsettransparency [-noupdate|-update] [name]"
5247 "\n\t\t: Resets transparency for all, selected or named objects."
5248 "\n\t\t: Alias for vaspects -unsettransp [name].",
5249 __FILE__,VAspects,group);
7fd59977 5250
5251 theCommands.Add("vsetmaterial",
ad3217cd 5252 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5253 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5254 __FILE__,VAspects,group);
7fd59977 5255
5256 theCommands.Add("vunsetmaterial",
ad3217cd 5257 "vunsetmaterial [-noupdate|-update] [name]"
5258 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5259 __FILE__,VAspects,group);
7fd59977 5260
5261 theCommands.Add("vsetwidth",
ad3217cd 5262 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5263 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5264 __FILE__,VAspects,group);
7fd59977 5265
5266 theCommands.Add("vunsetwidth",
ad3217cd 5267 "vunsetwidth [-noupdate|-update] [name]"
5268 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5269 __FILE__,VAspects,group);
7fd59977 5270
99c56d44 5271 theCommands.Add("vsetinteriorstyle",
ad3217cd 5272 "vsetinteriorstyle [-noupdate|-update] [name] style"
5273 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5274 __FILE__,VSetInteriorStyle,group);
99c56d44 5275
7fd59977 5276 theCommands.Add("vsensdis",
5277 "vardisp : display active entities",
5278 __FILE__,VDispSensi,group);
5279 theCommands.Add("vsensera",
5280 "vardisp : erase active entities",
5281 __FILE__,VClearSensi,group);
5282
3c982548 5283 theCommands.Add("vselprecision",
28ee613b 5284 "vselprecision [-unset] [tolerance_value]"
5285 "\n\t\t Manages selection precision or prints current value if no parameter is passed."
5286 "\n\t\t -unset - restores default selection tolerance behavior, based on individual entity tolerance",
3c982548 5287 __FILE__,VSelPrecision,group);
5288
7fd59977 5289 theCommands.Add("vperf",
5290 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
5291 __FILE__,VPerf,group);
5292
5293 theCommands.Add("vanimation",
5294 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5295 __FILE__,VAnimation,group);
5296
5297 theCommands.Add("vsetshading",
5298 "vsetshading : vsetshading name Quality(default=0.0008) ",
5299 __FILE__,VShading,group);
5300
5301 theCommands.Add("vunsetshading",
5302 "vunsetshading :vunsetshading name ",
5303 __FILE__,VShading,group);
5304
d399d3c3 5305 theCommands.Add ("vtexture",
5306 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5307 " [-scale u v] [-scale off]\n"
5308 " [-origin u v] [-origin off]\n"
5309 " [-repeat u v] [-repeat off]\n"
5310 " [-modulate {on | off}]"
5311 " [-default]'\n"
5312 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5313 " specifying one of the predefined textures.\n"
5314 " The options are: \n"
5315 " -scale u v : enable texture scaling and set scale factors\n"
5316 " -scale off : disable texture scaling\n"
5317 " -origin u v : enable texture origin positioning and set the origin\n"
5318 " -origin off : disable texture origin positioning\n"
5319 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5320 " -repeat off : disable texture repeat\n"
5321 " -modulate {on | off} : enable or disable texture modulation\n"
5322 " -default : sets texture mapping default parameters\n"
5323 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5324 "or 'vtexture NameOfShape ?' to list available textures\n",
5325 __FILE__, VTexture, group);
7fd59977 5326
5327 theCommands.Add("vtexscale",
5328 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5329 or 'vtexscale NameOfShape ScaleUV' \n \
5330 or 'vtexscale NameOfShape' to disable scaling\n ",
5331 __FILE__,VTexture,group);
5332
5333 theCommands.Add("vtexorigin",
5334 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5335 or 'vtexorigin NameOfShape UVOrigin' \n \
5336 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5337 __FILE__,VTexture,group);
5338
5339 theCommands.Add("vtexrepeat",
5340 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5341 or 'vtexrepeat NameOfShape UVRepeat \n \
5342 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5343 VTexture,group);
5344
5345 theCommands.Add("vtexdefault",
5346 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5347 VTexture,group);
5348
5349 theCommands.Add("vsetam",
5350 "vsetActivatedModes: vsetam mode(1->7) ",
5351 __FILE__,VActivatedMode,group);
5352
5353 theCommands.Add("vunsetam",
5354 "vunsetActivatedModes: vunsetam ",
5355 __FILE__,VActivatedMode,group);
5356
ac4aaa98 5357 theCommands.Add("vstate",
51023771 5358 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
8e7c8ccf 5359 "\n\t\t: Reports show/hidden state for selected or named objects"
51023771 5360 "\n\t\t: -entities - print low-level information about detected entities"
5361 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
7fd59977 5362 __FILE__,VState,group);
5363
5364 theCommands.Add("vpickshapes",
5365 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5366 __FILE__,VPickShape,group);
5367
5368 theCommands.Add("vtypes",
5369 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5370 VIOTypes,group);
5371
7fd59977 5372 theCommands.Add("vr", "vr : reading of the shape",
5373 __FILE__,vr, group);
5374
d8110103 5375 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5376 __FILE__, VPickSelected, group);
5377
f751596e 5378 theCommands.Add ("vloadselection",
5379 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5380 "\n\t\t: primitives for the shapes with names given without displaying them."
5381 "\n\t\t: -local - open local context before selection computation",
5382 __FILE__, VLoadSelection, group);
5383
5384 theCommands.Add ("vautoactivatesel",
5385 "vautoactivatesel [0|1] : manage or display the option to automatically"
5386 "\n\t\t: activate selection for newly displayed objects"
5387 "\n\t\t: [0|1] - turn off | on auto activation of selection",
5388 __FILE__, VAutoActivateSelection, group);
5389
7fd59977 5390}
5391
5392//=====================================================================
5393//========================= for testing Draft and Rib =================
5394//=====================================================================
5395#include <BRepOffsetAPI_MakeThickSolid.hxx>
5396#include <DBRep.hxx>
5397#include <TopoDS_Face.hxx>
5398#include <gp_Pln.hxx>
5399#include <AIS_KindOfSurface.hxx>
5400#include <BRepOffsetAPI_DraftAngle.hxx>
5401#include <Precision.hxx>
5402#include <BRepAlgo.hxx>
5403#include <OSD_Environment.hxx>
5404#include <DrawTrSurf.hxx>
5405//#include <DbgTools.hxx>
5406//#include <FeatAlgo_MakeLinearForm.hxx>
5407
5408
5409
5410
5411//=======================================================================
5412//function : IsValid
5413//purpose :
5414//=======================================================================
5415static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5416 const TopoDS_Shape& theResult,
5417 const Standard_Boolean closedSolid,
5418 const Standard_Boolean GeomCtrl)
5419{
5420 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5421 TCollection_AsciiString checkValid = check.Value();
5422 Standard_Boolean ToCheck = Standard_True;
5423 if (!checkValid.IsEmpty()) {
0797d9d3 5424#ifdef OCCT_DEBUG
7fd59977 5425 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5426#endif
5427 if ( checkValid=="true" || checkValid=="TRUE" ) {
5428 ToCheck= Standard_False;
5429 }
5430 } else {
0797d9d3 5431#ifdef OCCT_DEBUG
7fd59977 5432 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
5433#endif
5434 }
5435 Standard_Boolean IsValid = Standard_True;
5436 if (ToCheck)
5437 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5438 return IsValid;
5439
5440}
5441
5442//===============================================================================
5443// TDraft : test draft, uses AIS Viewer
5444// Solid Face Plane Angle Reverse
5445//===============================================================================
5446static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5447{
5448 if (argc < 5) return 1;
5449// argv[1] - TopoDS_Shape Solid
5450// argv[2] - TopoDS_Shape Face
5451// argv[3] - TopoDS_Shape Plane
5452// argv[4] - Standard_Real Angle
5453// argv[5] - Standard_Integer Reverse
5454
91322f44 5455// Sprintf(prefix, argv[1]);
7fd59977 5456 Standard_Real anAngle = 0;
5457 Standard_Boolean Rev = Standard_False;
5458 Standard_Integer rev = 0;
5459 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5460 TopoDS_Shape face = GetShapeFromName(argv[2]);
5461 TopoDS_Face Face = TopoDS::Face(face);
5462 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5463 if (Plane.IsNull ()) {
5464 di << "TEST : Plane is NULL" << "\n";
5465 return 1;
5466 }
91322f44 5467 anAngle = Draw::Atof(argv[4]);
c6541a0c 5468 anAngle = 2*M_PI * anAngle / 360.0;
7fd59977 5469 gp_Pln aPln;
5470 Handle( Geom_Surface )aSurf;
5471 AIS_KindOfSurface aSurfType;
5472 Standard_Real Offset;
5473 gp_Dir aDir;
5474 if(argc > 4) { // == 5
91322f44 5475 rev = Draw::Atoi(argv[5]);
7fd59977 5476 Rev = (rev)? Standard_True : Standard_False;
5477 }
5478
5479 TopoDS_Face face2 = TopoDS::Face(Plane);
5480 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5481 {
5482 di << "TEST : Can't find plane" << "\n";
5483 return 1;
5484 }
5485
5486 aDir = aPln.Axis().Direction();
5487 if (!aPln.Direct())
5488 aDir.Reverse();
5489 if (Plane.Orientation() == TopAbs_REVERSED)
5490 aDir.Reverse();
5491 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5492
5493 BRepOffsetAPI_DraftAngle Draft (Solid);
5494
5495 if(Abs(anAngle)< Precision::Angular()) {
5496 di << "TEST : NULL angle" << "\n";
5497 return 1;}
5498
5499 if(Rev) anAngle = - anAngle;
5500 Draft.Add (Face, aDir, anAngle, aPln);
5501 Draft.Build ();
5502 if (!Draft.IsDone()) {
5503 di << "TEST : Draft Not DONE " << "\n";
5504 return 1;
5505 }
5506 TopTools_ListOfShape Larg;
5507 Larg.Append(Solid);
5508 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
5509 di << "TEST : DesignAlgo returns Not valid" << "\n";
5510 return 1;
5511 }
5512
5513 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5514 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
5515
5516 if ( !ais.IsNull() ) {
5517 ais->SetColor(DEFAULT_COLOR);
5518 ais->SetMaterial(DEFAULT_MATERIAL);
5519 // Display the AIS_Shape without redraw
5520 Ctx->Display(ais, Standard_False);
5521
5522 const char *Name = "draft1";
5523 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
5524 if (IsBound) {
5525 Handle(AIS_InteractiveObject) an_object =
5526 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
5527 if (!an_object.IsNull()) {
5528 Ctx->Remove(an_object,
5529 Standard_True) ;
5530 GetMapOfAIS().UnBind2(Name) ;
5531 }
5532 }
5533 GetMapOfAIS().Bind(ais, Name);
5534// DBRep::Set("draft", ais->Shape());
5535 }
5536 Ctx->Display(ais, Standard_True);
5537 return 0;
5538}
5539
1d7ca641 5540//==============================================================================
5541//function : splitParameter
197ac94e 5542//purpose : Split parameter string to parameter name and parameter value
1d7ca641 5543//==============================================================================
5544Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
5545 TCollection_AsciiString& theName,
5546 TCollection_AsciiString& theValue)
5547{
5548 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
5549
5550 if (aParamNameEnd == 0)
5551 {
5552 return Standard_False;
5553 }
5554
5555 TCollection_AsciiString aString (theString);
5556 if (aParamNameEnd != 0)
5557 {
5558 theValue = aString.Split (aParamNameEnd);
5559 aString.Split (aString.Length() - 1);
5560 theName = aString;
5561 }
7fd59977 5562
1d7ca641 5563 return Standard_True;
5564}
7fd59977 5565
5566//============================================================================
5567// MyCommands
5568//============================================================================
5569void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
5570{
5571
5572 DrawTrSurf::BasicCommands(theCommands);
5573 const char* group = "Check Features Operations commands";
5574
5575 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
5576 __FILE__,
5577 &TDraft,group); //Draft_Modification
5578}
5579
5580//==============================================================================
5581// ViewerTest::Factory
5582//==============================================================================
5583void ViewerTest::Factory(Draw_Interpretor& theDI)
5584{
5585 // definition of Viewer Command
128cc8df 5586 ViewerTest::Commands(theDI);
5587 ViewerTest::AviCommands(theDI);
5588
0797d9d3 5589#ifdef OCCT_DEBUG
7fd59977 5590 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
5591#endif
5592}
5593
5594// Declare entry point PLUGINFACTORY
5595DPLUGIN(ViewerTest)