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