| 1 | // Created on: 1997-07-23 |
| 2 | // Created by: Henri JEANNIN |
| 3 | // Copyright (c) 1997-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 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 |
| 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. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display... |
| 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> |
| 31 | #include <TColStd_SequenceOfAsciiString.hxx> |
| 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> |
| 40 | #include <AIS_Drawer.hxx> |
| 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> |
| 47 | #include <AIS_LocalContext.hxx> |
| 48 | #include <AIS_ListOfInteractive.hxx> |
| 49 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
| 50 | #include <Aspect_InteriorStyle.hxx> |
| 51 | #include <Aspect_Window.hxx> |
| 52 | #include <Graphic3d_AspectFillArea3d.hxx> |
| 53 | #include <Graphic3d_AspectLine3d.hxx> |
| 54 | #include <Graphic3d_TextureRoot.hxx> |
| 55 | #include <Image_AlienPixMap.hxx> |
| 56 | #include <Prs3d_ShadingAspect.hxx> |
| 57 | #include <Prs3d_IsoAspect.hxx> |
| 58 | #include <TopTools_MapOfShape.hxx> |
| 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> |
| 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> |
| 82 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); |
| 83 | |
| 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 | |
| 92 | enum 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 |
| 100 | static 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 | |
| 120 | //======================================================================= |
| 121 | //function : GetColorFromName |
| 122 | //purpose : get the Quantity_NameOfColor from a string |
| 123 | //======================================================================= |
| 124 | |
| 125 | Quantity_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) |
| 131 | { |
| 132 | return Quantity_NameOfColor (anIter); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return DEFAULT_COLOR; |
| 137 | } |
| 138 | |
| 139 | //======================================================================= |
| 140 | //function : GetMaterialFromName |
| 141 | //purpose : get the Graphic3d_NameOfMaterial from a string |
| 142 | //======================================================================= |
| 143 | |
| 144 | static 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; |
| 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 | //======================================================================= |
| 175 | static 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 | //======================================================================= |
| 189 | void 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 | |
| 264 | //============================================================================== |
| 265 | // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES |
| 266 | //============================================================================== |
| 267 | Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){ |
| 268 | static ViewerTest_DoubleMapOfInteractiveAndName TheMap; |
| 269 | return TheMap; |
| 270 | } |
| 271 | |
| 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 | //============================================================================== |
| 281 | Standard_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 | |
| 314 | if (theAISObj.IsNull()) |
| 315 | { |
| 316 | // object with specified name already unbound |
| 317 | return Standard_True; |
| 318 | } |
| 319 | |
| 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 | |
| 329 | static TColStd_MapOfInteger theactivatedmodes(8); |
| 330 | static TColStd_ListOfTransient theEventMgrs; |
| 331 | |
| 332 | static 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 | |
| 339 | static Handle(V3d_View)& a3DView() |
| 340 | { |
| 341 | static Handle(V3d_View) Viou; |
| 342 | return Viou; |
| 343 | } |
| 344 | |
| 345 | |
| 346 | Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){ |
| 347 | static Handle(AIS_InteractiveContext) aContext; |
| 348 | return aContext; |
| 349 | } |
| 350 | |
| 351 | const Handle(V3d_View)& ViewerTest::CurrentView() |
| 352 | { |
| 353 | return a3DView(); |
| 354 | } |
| 355 | void ViewerTest::CurrentView(const Handle(V3d_View)& V) |
| 356 | { |
| 357 | a3DView() = V; |
| 358 | } |
| 359 | |
| 360 | Standard_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 | |
| 370 | const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext() |
| 371 | { |
| 372 | return TheAISContext(); |
| 373 | } |
| 374 | |
| 375 | void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx) |
| 376 | { |
| 377 | TheAISContext() = aCtx; |
| 378 | ViewerTest::ResetEventManager(); |
| 379 | } |
| 380 | |
| 381 | Handle(V3d_Viewer) ViewerTest::GetViewerFromContext() |
| 382 | { |
| 383 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
| 384 | } |
| 385 | |
| 386 | Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext() |
| 387 | { |
| 388 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
| 389 | } |
| 390 | |
| 391 | |
| 392 | void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){ |
| 393 | theEventMgrs.Prepend(EM); |
| 394 | } |
| 395 | |
| 396 | void ViewerTest::UnsetEventManager() |
| 397 | { |
| 398 | theEventMgrs.RemoveFirst(); |
| 399 | } |
| 400 | |
| 401 | |
| 402 | void ViewerTest::ResetEventManager() |
| 403 | { |
| 404 | const Handle(NIS_View) aView = |
| 405 | Handle(NIS_View)::DownCast(ViewerTest::CurrentView()); |
| 406 | VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext()); |
| 407 | } |
| 408 | |
| 409 | Handle(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 | |
| 418 | //======================================================================= |
| 419 | //function : Get Context and active view |
| 420 | //purpose : |
| 421 | //======================================================================= |
| 422 | static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx, |
| 423 | Handle(V3d_View)& theView) |
| 424 | { |
| 425 | theCtx = ViewerTest::GetAISContext(); |
| 426 | theView = ViewerTest::CurrentView(); |
| 427 | if (theCtx.IsNull() |
| 428 | || theView.IsNull()) |
| 429 | { |
| 430 | std::cout << "Error: cannot find an active view!\n"; |
| 431 | return Standard_False; |
| 432 | } |
| 433 | return Standard_True; |
| 434 | } |
| 435 | |
| 436 | //============================================================================== |
| 437 | //function : GetShapeFromName |
| 438 | //purpose : Compute an Shape from a draw variable or a file name |
| 439 | //============================================================================== |
| 440 | |
| 441 | static 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 | } |
| 452 | |
| 453 | //============================================================================== |
| 454 | //function : GetAISShapeFromName |
| 455 | //purpose : Compute an AIS_Shape from a draw variable or a file name |
| 456 | //============================================================================== |
| 457 | Handle(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()) { |
| 465 | if(IO->Type()==AIS_KOI_Shape) { |
| 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; |
| 472 | } |
| 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 | //============================================================================== |
| 490 | void 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()); |
| 505 | TheNISContext()->Remove(anObj); |
| 506 | } |
| 507 | it.Next(); |
| 508 | } |
| 509 | TheAISContext()->UpdateCurrentViewer(); |
| 510 | // TheNISContext()->UpdateViews(); |
| 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 | //============================================================================== |
| 520 | void 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; |
| 554 | case 7: cmode = "Compsolid"; break; |
| 555 | case 8: cmode = "Compound"; break; |
| 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 | //============================================================================== |
| 574 | //function : CopyIsoAspect |
| 575 | //purpose : Returns copy Prs3d_IsoAspect with new number of isolines. |
| 576 | //============================================================================== |
| 577 | static 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 | //============================================================================== |
| 598 | static 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; |
| 617 | Standard_Integer aNbUIsos = 0; |
| 618 | Standard_Integer aNbVIsos = 0; |
| 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 | //============================================================================== |
| 690 | //function : VDispAreas,VDispSensitive,... |
| 691 | //purpose : |
| 692 | //============================================================================== |
| 693 | static Standard_Integer VDispAreas (Draw_Interpretor& , |
| 694 | Standard_Integer theArgNb, |
| 695 | Standard_CString* ) |
| 696 | { |
| 697 | if (theArgNb > 1) |
| 698 | { |
| 699 | std::cout << "Error: wrong syntax!\n"; |
| 700 | return 1; |
| 701 | } |
| 702 | |
| 703 | Handle(AIS_InteractiveContext) aCtx; |
| 704 | Handle(V3d_View) aView; |
| 705 | if (!getCtxAndView (aCtx, aView)) |
| 706 | { |
| 707 | return 1; |
| 708 | } |
| 709 | |
| 710 | aCtx->DisplayActiveAreas (aView); |
| 711 | return 0; |
| 712 | } |
| 713 | static Standard_Integer VClearAreas (Draw_Interpretor& , |
| 714 | Standard_Integer theArgNb, |
| 715 | Standard_CString* ) |
| 716 | { |
| 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); |
| 731 | return 0; |
| 732 | |
| 733 | } |
| 734 | static Standard_Integer VDispSensi (Draw_Interpretor& , |
| 735 | Standard_Integer theArgNb, |
| 736 | Standard_CString* ) |
| 737 | { |
| 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); |
| 752 | return 0; |
| 753 | |
| 754 | } |
| 755 | |
| 756 | static Standard_Integer VClearSensi (Draw_Interpretor& , |
| 757 | Standard_Integer theArgNb, |
| 758 | Standard_CString* ) |
| 759 | { |
| 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); |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | //============================================================================== |
| 777 | //function : VDir |
| 778 | //purpose : To list the displayed object with their attributes |
| 779 | //============================================================================== |
| 780 | static int VDir (Draw_Interpretor& theDI, |
| 781 | Standard_Integer , |
| 782 | const char** ) |
| 783 | { |
| 784 | if (!a3DView().IsNull()) |
| 785 | { |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 790 | anIter.More(); anIter.Next()) |
| 791 | { |
| 792 | theDI << "\t" << anIter.Key2().ToCString() << "\n"; |
| 793 | } |
| 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | //============================================================================== |
| 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 | //============================================================================== |
| 805 | static 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 | { |
| 835 | StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] ); |
| 836 | aContext->SetSensitivityMode( aMode ); |
| 837 | if( argc > 2 ) |
| 838 | { |
| 839 | if( aMode == StdSelect_SM_WINDOW ) |
| 840 | { |
| 841 | Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] ); |
| 842 | aContext->SetPixelTolerance( aPixelTolerance ); |
| 843 | } |
| 844 | else if( aMode == StdSelect_SM_VIEW ) |
| 845 | { |
| 846 | Standard_Real aSensitivity = Draw::Atof( argv[2] ); |
| 847 | aContext->SetSensitivity( aSensitivity ); |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | //============================================================================== |
| 855 | //function : VDump |
| 856 | //purpose : To dump the active view snapshot to image file |
| 857 | //============================================================================== |
| 858 | static Standard_Integer VDump (Draw_Interpretor& theDI, |
| 859 | Standard_Integer theArgNb, |
| 860 | Standard_CString* theArgVec) |
| 861 | { |
| 862 | if (theArgNb < 2) |
| 863 | { |
| 864 | std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n"; |
| 865 | return 1; |
| 866 | } |
| 867 | |
| 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) |
| 875 | { |
| 876 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
| 877 | anArg.LowerCase(); |
| 878 | if (anArg == "rgba") |
| 879 | { |
| 880 | aBufferType = Graphic3d_BT_RGBA; |
| 881 | } |
| 882 | else if (anArg == "rgb") |
| 883 | { |
| 884 | aBufferType = Graphic3d_BT_RGB; |
| 885 | } |
| 886 | else if (anArg == "depth") |
| 887 | { |
| 888 | aBufferType = Graphic3d_BT_Depth; |
| 889 | } |
| 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 | } |
| 956 | } |
| 957 | if ((aWidth <= 0 && aHeight > 0) |
| 958 | || (aWidth > 0 && aHeight <= 0)) |
| 959 | { |
| 960 | std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n"; |
| 961 | return 1; |
| 962 | } |
| 963 | |
| 964 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 965 | if (aView.IsNull()) |
| 966 | { |
| 967 | std::cout << "Error: cannot find an active view!\n"; |
| 968 | return 1; |
| 969 | } |
| 970 | |
| 971 | if (aWidth <= 0 || aHeight <= 0) |
| 972 | { |
| 973 | if (aStereoOpts != V3d_SDO_MONO) |
| 974 | { |
| 975 | aView->Window()->Size (aWidth, aHeight); |
| 976 | } |
| 977 | else |
| 978 | { |
| 979 | if (!aView->Dump (aFilePath, aBufferType)) |
| 980 | { |
| 981 | theDI << "Fail: view dump failed!\n"; |
| 982 | } |
| 983 | return 0; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | Image_AlienPixMap aPixMap; |
| 988 | if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts)) |
| 989 | { |
| 990 | theDI << "Fail: view dump failed!\n"; |
| 991 | return 0; |
| 992 | } |
| 993 | |
| 994 | if (aPixMap.SizeX() != Standard_Size(aWidth) |
| 995 | || aPixMap.SizeY() != Standard_Size(aHeight)) |
| 996 | { |
| 997 | theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY() |
| 998 | << " are lesser than requested " << aWidth << "x" << aHeight << "\n"; |
| 999 | } |
| 1000 | if (!aPixMap.Save (aFilePath)) |
| 1001 | { |
| 1002 | theDI << "Fail: image can not be saved!\n"; |
| 1003 | } |
| 1004 | return 0; |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | //============================================================================== |
| 1009 | //function : Displays,Erase... |
| 1010 | //purpose : |
| 1011 | //Draw arg : |
| 1012 | //============================================================================== |
| 1013 | static 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:{ |
| 1025 | Ctx->Erase(IO,Upd); |
| 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 | //======================================================================= |
| 1050 | static 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){ |
| 1092 | Standard_Integer Dmode = Draw::Atoi(argv[1]); |
| 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()) |
| 1115 | VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True); |
| 1116 | } |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | |
| 1121 | //======================================================================= |
| 1122 | //function : |
| 1123 | //purpose : |
| 1124 | //======================================================================= |
| 1125 | static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 1126 | { |
| 1127 | if(argc==1) return 1; |
| 1128 | Standard_Integer On = Draw::Atoi(argv[1]); |
| 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)); |
| 1162 | if (!IO.IsNull()) { |
| 1163 | if(On==1) |
| 1164 | Ctx->SubIntensityOn(IO); |
| 1165 | else |
| 1166 | Ctx->SubIntensityOff(IO); |
| 1167 | } |
| 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 | //============================================================================== |
| 1180 | static 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 ; |
| 1186 | |
| 1187 | const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0); |
| 1188 | if (HaveToSet) { |
| 1189 | if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; } |
| 1190 | ThereIsArgument = (argc != 2); |
| 1191 | } |
| 1192 | else { |
| 1193 | if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; } |
| 1194 | ThereIsArgument = (argc == 2); |
| 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 |
| 1219 | if (HaveToSet) |
| 1220 | di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n"; |
| 1221 | else |
| 1222 | di << "HaveToSet 0\n"; |
| 1223 | #endif |
| 1224 | |
| 1225 | if(HaveToSet) |
| 1226 | TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) ); |
| 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); |
| 1232 | if (!ashape.IsNull()) |
| 1233 | ashape->SetColor (ViewerTest::GetColorFromName(argv[2])); |
| 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 | { |
| 1247 | const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current(); |
| 1248 | if (ashape.IsNull()) |
| 1249 | continue; |
| 1250 | #ifdef DEB |
| 1251 | if (HaveToSet) |
| 1252 | di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n"; |
| 1253 | else |
| 1254 | di << "HaveToSet 0\n"; |
| 1255 | #endif |
| 1256 | if(HaveToSet) |
| 1257 | TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False); |
| 1258 | else |
| 1259 | TheAISContext()->UnsetColor(ashape,Standard_False); |
| 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() ) { |
| 1272 | const Handle(AIS_InteractiveObject) ashape = |
| 1273 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); |
| 1274 | if (!ashape.IsNull()) { |
| 1275 | if(HaveToSet) |
| 1276 | TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False); |
| 1277 | else |
| 1278 | TheAISContext()->UnsetColor(ashape,Standard_False); |
| 1279 | } |
| 1280 | it.Next(); |
| 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 | |
| 1295 | static 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 ; |
| 1301 | |
| 1302 | const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0); |
| 1303 | if (HaveToSet) { |
| 1304 | if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } |
| 1305 | ThereIsArgument = (argc != 2); |
| 1306 | } |
| 1307 | else{ |
| 1308 | if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; } |
| 1309 | ThereIsArgument = (argc == 2); |
| 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) |
| 1333 | TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) ); |
| 1334 | else |
| 1335 | TheAISContext()->UnsetTransparency(ashape); |
| 1336 | } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { |
| 1337 | const Handle(NIS_InteractiveObject) ashape = |
| 1338 | Handle(NIS_InteractiveObject)::DownCast(anObj); |
| 1339 | if(HaveToSet) |
| 1340 | ashape->SetTransparency(Draw::Atof(argv[2]) ); |
| 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 | { |
| 1354 | Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current(); |
| 1355 | if(HaveToSet) |
| 1356 | TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False); |
| 1357 | else |
| 1358 | TheAISContext()->UnsetTransparency(ashape,Standard_False); |
| 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() ) { |
| 1370 | Handle(AIS_InteractiveObject) ashape = |
| 1371 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); |
| 1372 | if (!ashape.IsNull()) { |
| 1373 | if(HaveToSet) |
| 1374 | TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False); |
| 1375 | else |
| 1376 | TheAISContext()->UnsetTransparency(ashape,Standard_False); |
| 1377 | } |
| 1378 | it.Next(); |
| 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 | //============================================================================== |
| 1393 | static 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 | |
| 1400 | const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0); |
| 1401 | if (HaveToSet) { |
| 1402 | if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } |
| 1403 | ThereIsName = (argc != 2); |
| 1404 | } |
| 1405 | else { |
| 1406 | if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; } |
| 1407 | ThereIsName = (argc == 2); |
| 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)); |
| 1429 | if (!ashape.IsNull()) { |
| 1430 | if (HaveToSet) |
| 1431 | TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2])); |
| 1432 | else |
| 1433 | TheAISContext()->UnsetMaterial(ashape); |
| 1434 | } |
| 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 | { |
| 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); |
| 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() ) { |
| 1462 | Handle(AIS_InteractiveObject) ashape = |
| 1463 | Handle(AIS_InteractiveObject)::DownCast (it.Key1()); |
| 1464 | if (!ashape.IsNull()) { |
| 1465 | if (HaveToSet) |
| 1466 | TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False); |
| 1467 | else |
| 1468 | TheAISContext()->UnsetMaterial(ashape,Standard_False); |
| 1469 | } |
| 1470 | it.Next(); |
| 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 | //============================================================================== |
| 1486 | static 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 | |
| 1493 | const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0); |
| 1494 | if (HaveToSet) { |
| 1495 | if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } |
| 1496 | ThereIsArgument = (argc != 2); |
| 1497 | } |
| 1498 | else { |
| 1499 | if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; } |
| 1500 | ThereIsArgument = (argc == 2); |
| 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) |
| 1522 | TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) ); |
| 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()) |
| 1529 | ashape->SetLineWidth ( Draw::Atof (argv[2]) ); |
| 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 | { |
| 1542 | Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current(); |
| 1543 | if (HaveToSet) |
| 1544 | TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False); |
| 1545 | else |
| 1546 | TheAISContext()->UnsetWidth(ashape,Standard_False); |
| 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()); |
| 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(); |
| 1566 | } |
| 1567 | TheAISContext()->UpdateCurrentViewer(); |
| 1568 | } |
| 1569 | } |
| 1570 | return 0; |
| 1571 | } |
| 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 | //============================================================================== |
| 1578 | static 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 | |
| 1595 | static 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)); |
| 1629 | SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di); |
| 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(); |
| 1642 | SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di); |
| 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()) |
| 1655 | SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di); |
| 1656 | it.Next(); |
| 1657 | } |
| 1658 | } |
| 1659 | TheAISContext()->UpdateCurrentViewer(); |
| 1660 | } |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
| 1664 | //============================================================================== |
| 1665 | //function : VDonly2 |
| 1666 | //author : ege |
| 1667 | //purpose : Display only a selected or named object |
| 1668 | // if there is no selected or named object s, nothing is done |
| 1669 | //============================================================================== |
| 1670 | static int VDonly2 (Draw_Interpretor& , |
| 1671 | Standard_Integer theArgNb, |
| 1672 | const char** theArgVec) |
| 1673 | { |
| 1674 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 1675 | if (aCtx.IsNull()) |
| 1676 | { |
| 1677 | std::cerr << "Error: no active view!\n"; |
| 1678 | return 1; |
| 1679 | } |
| 1680 | |
| 1681 | if (aCtx->HasOpenedContext()) |
| 1682 | { |
| 1683 | aCtx->CloseLocalContext(); |
| 1684 | } |
| 1685 | ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto; |
| 1686 | |
| 1687 | Standard_Integer anArgIter = 1; |
| 1688 | for (; anArgIter < theArgNb; ++anArgIter) |
| 1689 | { |
| 1690 | if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate)) |
| 1691 | { |
| 1692 | break; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 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; |
| 1703 | } |
| 1704 | |
| 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); |
| 1728 | } |
| 1729 | aDispSet.Add (anObj); |
| 1730 | } |
| 1731 | } |
| 1732 | } |
| 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 | |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
| 1766 | //============================================================================== |
| 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 | //============================================================================== |
| 1774 | int VRemove (Draw_Interpretor& theDI, |
| 1775 | Standard_Integer theArgNb, |
| 1776 | const char** theArgVec) |
| 1777 | { |
| 1778 | if (a3DView().IsNull()) |
| 1779 | { |
| 1780 | std::cout << "Error: wrong syntax!\n"; |
| 1781 | return 1; |
| 1782 | } |
| 1783 | |
| 1784 | TheAISContext()->CloseAllContexts (Standard_False); |
| 1785 | |
| 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 | |
| 1815 | NCollection_List<TCollection_AsciiString> anIONameList; |
| 1816 | if (toRemoveAll) |
| 1817 | { |
| 1818 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 1819 | anIter.More(); anIter.Next()) |
| 1820 | { |
| 1821 | anIONameList.Append (anIter.Key2()); |
| 1822 | } |
| 1823 | } |
| 1824 | else if (anArgIter < theArgNb) // removed objects names are in argument list |
| 1825 | { |
| 1826 | for (; anArgIter < theArgNb; ++anArgIter) |
| 1827 | { |
| 1828 | TCollection_AsciiString aName = theArgVec[anArgIter]; |
| 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 | { |
| 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()) |
| 1904 | { |
| 1905 | TheNISContext()->Remove (aNisIO); |
| 1906 | theDI << anIter.Value().ToCString() << " was removed\n"; |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 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(); |
| 1923 | } |
| 1924 | |
| 1925 | return 0; |
| 1926 | } |
| 1927 | |
| 1928 | //============================================================================== |
| 1929 | //function : VErase |
| 1930 | //purpose : Erase some selected or named objects |
| 1931 | // if there is no selected or named objects, the whole viewer is erased |
| 1932 | //============================================================================== |
| 1933 | int VErase (Draw_Interpretor& theDI, |
| 1934 | Standard_Integer theArgNb, |
| 1935 | const char** theArgVec) |
| 1936 | { |
| 1937 | if (a3DView().IsNull()) |
| 1938 | { |
| 1939 | std::cout << "Error: no active view!\n"; |
| 1940 | return 1; |
| 1941 | } |
| 1942 | TheAISContext()->CloseAllContexts (Standard_False); |
| 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) |
| 1957 | { |
| 1958 | if (toEraseAll) |
| 1959 | { |
| 1960 | std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n"; |
| 1961 | return 1; |
| 1962 | } |
| 1963 | |
| 1964 | // has a list of names |
| 1965 | for (; anArgIter < theArgNb; ++anArgIter) |
| 1966 | { |
| 1967 | TCollection_AsciiString aName = theArgVec[anArgIter]; |
| 1968 | if (!GetMapOfAIS().IsBound2 (aName)) |
| 1969 | { |
| 1970 | continue; |
| 1971 | } |
| 1972 | |
| 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 | } |
| 1987 | } |
| 1988 | } |
| 1989 | } |
| 1990 | else if (!toEraseAll |
| 1991 | && TheAISContext()->NbCurrents() > 0) |
| 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); |
| 2003 | } |
| 2004 | } |
| 2005 | } |
| 2006 | else |
| 2007 | { |
| 2008 | // erase entire viewer |
| 2009 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 2010 | anIter.More(); anIter.Next()) |
| 2011 | { |
| 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 |
| 2018 | { |
| 2019 | const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1()); |
| 2020 | if (!aNisIO.IsNull()) |
| 2021 | { |
| 2022 | TheNISContext()->Erase (aNisIO); |
| 2023 | } |
| 2024 | } |
| 2025 | } |
| 2026 | } |
| 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 | |
| 2037 | return 0; |
| 2038 | } |
| 2039 | |
| 2040 | //============================================================================== |
| 2041 | //function : VDisplayAll |
| 2042 | //author : ege |
| 2043 | //purpose : Display all the objects of the Map |
| 2044 | //============================================================================== |
| 2045 | static int VDisplayAll (Draw_Interpretor& , |
| 2046 | Standard_Integer theArgNb, |
| 2047 | const char** theArgVec) |
| 2048 | |
| 2049 | { |
| 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; |
| 2064 | } |
| 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); |
| 2104 | } |
| 2105 | } |
| 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 | |
| 2116 | return 0; |
| 2117 | } |
| 2118 | |
| 2119 | //============================================================================== |
| 2120 | //function : VTexture |
| 2121 | //purpose : |
| 2122 | //============================================================================== |
| 2123 | Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv) |
| 2124 | { |
| 2125 | TCollection_AsciiString aCommandName (theArgv[0]); |
| 2126 | |
| 2127 | NCollection_DataMap<TCollection_AsciiString, TColStd_SequenceOfAsciiString> aMapOfArgs; |
| 2128 | if (aCommandName == "vtexture") |
| 2129 | { |
| 2130 | if (theArgsNb < 2) |
| 2131 | { |
| 2132 | std::cout << theArgv[0] << ": " << " invalid arguments.\n"; |
| 2133 | std::cout << "Type help for more information.\n"; |
| 2134 | return 1; |
| 2135 | } |
| 2136 | |
| 2137 | // look for options of vtexture command |
| 2138 | TCollection_AsciiString aParseKey; |
| 2139 | for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt) |
| 2140 | { |
| 2141 | TCollection_AsciiString anArg (theArgv [anArgIt]); |
| 2142 | |
| 2143 | anArg.UpperCase(); |
| 2144 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) |
| 2145 | { |
| 2146 | aParseKey = anArg; |
| 2147 | aParseKey.Remove (1); |
| 2148 | aParseKey.UpperCase(); |
| 2149 | aMapOfArgs.Bind (aParseKey, TColStd_SequenceOfAsciiString()); |
| 2150 | continue; |
| 2151 | } |
| 2152 | |
| 2153 | if (aParseKey.IsEmpty()) |
| 2154 | { |
| 2155 | continue; |
| 2156 | } |
| 2157 | |
| 2158 | aMapOfArgs.ChangeFind (aParseKey).Append (anArg); |
| 2159 | } |
| 2160 | } |
| 2161 | else if (aCommandName == "vtexscale" |
| 2162 | || aCommandName == "vtexorigin" |
| 2163 | || aCommandName == "vtexrepeat") |
| 2164 | { |
| 2165 | // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands |
| 2166 | // equal to -scale, -origin, -repeat options of vtexture command |
| 2167 | if (theArgsNb < 2 || theArgsNb > 4) |
| 2168 | { |
| 2169 | std::cout << theArgv[0] << ": " << " invalid arguments.\n"; |
| 2170 | std::cout << "Type help for more information.\n"; |
| 2171 | return 1; |
| 2172 | } |
| 2173 | |
| 2174 | TColStd_SequenceOfAsciiString anArgs; |
| 2175 | if (theArgsNb == 2) |
| 2176 | { |
| 2177 | anArgs.Append ("OFF"); |
| 2178 | } |
| 2179 | else if (theArgsNb == 4) |
| 2180 | { |
| 2181 | anArgs.Append (TCollection_AsciiString (theArgv[2])); |
| 2182 | anArgs.Append (TCollection_AsciiString (theArgv[3])); |
| 2183 | } |
| 2184 | |
| 2185 | TCollection_AsciiString anArgKey; |
| 2186 | if (aCommandName == "vtexscale") |
| 2187 | { |
| 2188 | anArgKey = "SCALE"; |
| 2189 | } |
| 2190 | else if (aCommandName == "vtexorigin") |
| 2191 | { |
| 2192 | anArgKey = "ORIGIN"; |
| 2193 | } |
| 2194 | else |
| 2195 | { |
| 2196 | anArgKey = "REPEAT"; |
| 2197 | } |
| 2198 | |
| 2199 | aMapOfArgs.Bind (anArgKey, anArgs); |
| 2200 | } |
| 2201 | else if (aCommandName == "vtexdefault") |
| 2202 | { |
| 2203 | // scan for parameters of vtexdefault command |
| 2204 | // equal to -default option of vtexture command |
| 2205 | aMapOfArgs.Bind ("DEFAULT", TColStd_SequenceOfAsciiString()); |
| 2206 | } |
| 2207 | |
| 2208 | // Check arguments for validity |
| 2209 | NCollection_DataMap<TCollection_AsciiString, TColStd_SequenceOfAsciiString>::Iterator aMapIt (aMapOfArgs); |
| 2210 | for (; aMapIt.More(); aMapIt.Next()) |
| 2211 | { |
| 2212 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
| 2213 | const TColStd_SequenceOfAsciiString& anArgs = aMapIt.Value(); |
| 2214 | |
| 2215 | // -scale, -origin, -repeat: one argument "off", or two real values |
| 2216 | if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT")) |
| 2217 | && ((anArgs.Length() == 1 && anArgs (1) == "OFF") |
| 2218 | || (anArgs.Length() == 2 && anArgs (1).IsRealValue() && anArgs (2).IsRealValue()))) |
| 2219 | { |
| 2220 | continue; |
| 2221 | } |
| 2222 | |
| 2223 | // -modulate: single argument "on" / "off" |
| 2224 | if (aKey.IsEqual ("MODULATE") && anArgs.Length() == 1 && (anArgs (1) == "OFF" || anArgs (1) == "ON")) |
| 2225 | { |
| 2226 | continue; |
| 2227 | } |
| 2228 | |
| 2229 | // -default: no arguments |
| 2230 | if (aKey.IsEqual ("DEFAULT") && anArgs.IsEmpty()) |
| 2231 | { |
| 2232 | continue; |
| 2233 | } |
| 2234 | |
| 2235 | TCollection_AsciiString aLowerKey; |
| 2236 | aLowerKey = "-"; |
| 2237 | aLowerKey += aKey; |
| 2238 | aLowerKey.LowerCase(); |
| 2239 | std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; |
| 2240 | std::cout << "Type help for more information.\n"; |
| 2241 | return 1; |
| 2242 | } |
| 2243 | |
| 2244 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); |
| 2245 | if (anAISContext.IsNull()) |
| 2246 | { |
| 2247 | std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n"; |
| 2248 | return 1; |
| 2249 | } |
| 2250 | |
| 2251 | Standard_Integer aPreviousMode = 0; |
| 2252 | |
| 2253 | ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL); |
| 2254 | |
| 2255 | TCollection_AsciiString aShapeName (theArgv[1]); |
| 2256 | Handle(AIS_InteractiveObject) anIO; |
| 2257 | |
| 2258 | const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS(); |
| 2259 | if (aMapOfIO.IsBound2 (aShapeName)) |
| 2260 | { |
| 2261 | anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName)); |
| 2262 | } |
| 2263 | |
| 2264 | if (anIO.IsNull()) |
| 2265 | { |
| 2266 | std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n"; |
| 2267 | return 1; |
| 2268 | } |
| 2269 | |
| 2270 | Handle(AIS_TexturedShape) aTexturedIO; |
| 2271 | if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape))) |
| 2272 | { |
| 2273 | aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO); |
| 2274 | aPreviousMode = aTexturedIO->DisplayMode(); |
| 2275 | } |
| 2276 | else |
| 2277 | { |
| 2278 | anAISContext->Clear (anIO, Standard_False); |
| 2279 | aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1])); |
| 2280 | GetMapOfAIS().UnBind1 (anIO); |
| 2281 | GetMapOfAIS().UnBind2 (aShapeName); |
| 2282 | GetMapOfAIS().Bind (aTexturedIO, aShapeName); |
| 2283 | } |
| 2284 | |
| 2285 | // ------------------------------------------- |
| 2286 | // Turn texturing on/off - only for vtexture |
| 2287 | // ------------------------------------------- |
| 2288 | |
| 2289 | if (aCommandName == "vtexture") |
| 2290 | { |
| 2291 | TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : ""); |
| 2292 | |
| 2293 | if (aTextureArg.IsEmpty()) |
| 2294 | { |
| 2295 | std::cout << aCommandName << ": " << " Texture mapping disabled.\n"; |
| 2296 | std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n"; |
| 2297 | |
| 2298 | anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False); |
| 2299 | if (aPreviousMode == 3) |
| 2300 | { |
| 2301 | anAISContext->RecomputePrsOnly (aTexturedIO); |
| 2302 | } |
| 2303 | |
| 2304 | anAISContext->Display (aTexturedIO, Standard_True); |
| 2305 | return 0; |
| 2306 | } |
| 2307 | else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument |
| 2308 | { |
| 2309 | if (aTextureArg == "?") |
| 2310 | { |
| 2311 | TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder(); |
| 2312 | |
| 2313 | theDi << "\n Files in current directory : \n" << "\n"; |
| 2314 | theDi.Eval ("glob -nocomplain *"); |
| 2315 | |
| 2316 | TCollection_AsciiString aCmnd ("glob -nocomplain "); |
| 2317 | aCmnd += aTextureFolder; |
| 2318 | aCmnd += "/* "; |
| 2319 | |
| 2320 | theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n"; |
| 2321 | theDi.Eval (aCmnd.ToCString()); |
| 2322 | return 0; |
| 2323 | } |
| 2324 | else |
| 2325 | { |
| 2326 | aTexturedIO->SetTextureFileName (aTextureArg); |
| 2327 | } |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | // ------------------------------------ |
| 2332 | // Process other options and commands |
| 2333 | // ------------------------------------ |
| 2334 | |
| 2335 | TColStd_SequenceOfAsciiString aValues; |
| 2336 | if (aMapOfArgs.Find ("DEFAULT", aValues)) |
| 2337 | { |
| 2338 | aTexturedIO->SetTextureRepeat (Standard_False); |
| 2339 | aTexturedIO->SetTextureOrigin (Standard_False); |
| 2340 | aTexturedIO->SetTextureScale (Standard_False); |
| 2341 | aTexturedIO->EnableTextureModulate(); |
| 2342 | } |
| 2343 | else |
| 2344 | { |
| 2345 | if (aMapOfArgs.Find ("SCALE", aValues)) |
| 2346 | { |
| 2347 | if (aValues (1) != "OFF") |
| 2348 | { |
| 2349 | aTexturedIO->SetTextureScale (Standard_True, aValues (1).RealValue(), aValues (2).RealValue()); |
| 2350 | } |
| 2351 | else |
| 2352 | { |
| 2353 | aTexturedIO->SetTextureScale (Standard_False); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | if (aMapOfArgs.Find ("ORIGIN", aValues)) |
| 2358 | { |
| 2359 | if (aValues (1) != "OFF") |
| 2360 | { |
| 2361 | aTexturedIO->SetTextureOrigin (Standard_True, aValues (1).RealValue(), aValues (2).RealValue()); |
| 2362 | } |
| 2363 | else |
| 2364 | { |
| 2365 | aTexturedIO->SetTextureOrigin (Standard_False); |
| 2366 | } |
| 2367 | } |
| 2368 | |
| 2369 | if (aMapOfArgs.Find ("REPEAT", aValues)) |
| 2370 | { |
| 2371 | if (aValues (1) != "OFF") |
| 2372 | { |
| 2373 | aTexturedIO->SetTextureRepeat (Standard_True, aValues (1).RealValue(), aValues (2).RealValue()); |
| 2374 | } |
| 2375 | else |
| 2376 | { |
| 2377 | aTexturedIO->SetTextureRepeat (Standard_False); |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | if (aMapOfArgs.Find ("MODULATE", aValues)) |
| 2382 | { |
| 2383 | if (aValues (1) == "ON") |
| 2384 | { |
| 2385 | aTexturedIO->EnableTextureModulate(); |
| 2386 | } |
| 2387 | else |
| 2388 | { |
| 2389 | aTexturedIO->DisableTextureModulate(); |
| 2390 | } |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3) |
| 2395 | { |
| 2396 | anAISContext->RecomputePrsOnly (aTexturedIO); |
| 2397 | } |
| 2398 | else |
| 2399 | { |
| 2400 | anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False); |
| 2401 | anAISContext->Display (aTexturedIO, Standard_True); |
| 2402 | anAISContext->Update (aTexturedIO,Standard_True); |
| 2403 | } |
| 2404 | |
| 2405 | return 0; |
| 2406 | } |
| 2407 | |
| 2408 | //============================================================================== |
| 2409 | //function : VDisplay2 |
| 2410 | //author : ege |
| 2411 | //purpose : Display an object from its name |
| 2412 | //============================================================================== |
| 2413 | static int VDisplay2 (Draw_Interpretor& theDI, |
| 2414 | Standard_Integer theArgNb, |
| 2415 | const char** theArgVec) |
| 2416 | { |
| 2417 | if (theArgNb < 2) |
| 2418 | { |
| 2419 | std::cout << theArgVec[0] << "Error: wrong syntax!\n"; |
| 2420 | return 1; |
| 2421 | } |
| 2422 | else if (a3DView().IsNull()) |
| 2423 | { |
| 2424 | ViewerTest::ViewerInit(); |
| 2425 | std::cout << "Command vinit should be called before!\n"; |
| 2426 | // return 1; |
| 2427 | } |
| 2428 | |
| 2429 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 2430 | if (aCtx->HasOpenedContext()) |
| 2431 | { |
| 2432 | aCtx->CloseLocalContext(); |
| 2433 | } |
| 2434 | |
| 2435 | ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto; |
| 2436 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 2437 | { |
| 2438 | const TCollection_AsciiString aName = theArgVec[anArgIter]; |
| 2439 | if (parseRedrawMode (aName, aToUpdate)) |
| 2440 | { |
| 2441 | continue; |
| 2442 | } |
| 2443 | else if (!GetMapOfAIS().IsBound2 (aName)) |
| 2444 | { |
| 2445 | // create the AIS_Shape from a name |
| 2446 | const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString()); |
| 2447 | if (!aShape.IsNull()) |
| 2448 | { |
| 2449 | GetMapOfAIS().Bind (aShape, aName); |
| 2450 | aCtx->Display (aShape, Standard_False); |
| 2451 | } |
| 2452 | continue; |
| 2453 | } |
| 2454 | |
| 2455 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); |
| 2456 | if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject))) |
| 2457 | { |
| 2458 | Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj); |
| 2459 | if (aShape->Type() == AIS_KOI_Datum) |
| 2460 | { |
| 2461 | aCtx->Display (aShape, Standard_False); |
| 2462 | } |
| 2463 | else |
| 2464 | { |
| 2465 | theDI << "Display " << aName.ToCString() << "\n"; |
| 2466 | // get the Shape from a name |
| 2467 | TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString()); |
| 2468 | |
| 2469 | // update the Shape in the AIS_Shape |
| 2470 | Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape); |
| 2471 | if (!aShapePrs.IsNull()) |
| 2472 | { |
| 2473 | aShapePrs->Set (aNewShape); |
| 2474 | } |
| 2475 | aCtx->Redisplay (aShape, Standard_False); |
| 2476 | aCtx->Display (aShape, Standard_False); |
| 2477 | } |
| 2478 | aShape.Nullify(); |
| 2479 | } |
| 2480 | else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject))) |
| 2481 | { |
| 2482 | Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj); |
| 2483 | TheNISContext()->Display (aShape); |
| 2484 | } |
| 2485 | } |
| 2486 | |
| 2487 | const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False); |
| 2488 | a3DView()->SetImmediateUpdate (isAutoUpdate); |
| 2489 | if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress) |
| 2490 | || aToUpdate == ViewerTest_RM_RedrawForce) |
| 2491 | { |
| 2492 | // update the screen and redraw the view |
| 2493 | aCtx->UpdateCurrentViewer(); |
| 2494 | } |
| 2495 | return 0; |
| 2496 | } |
| 2497 | |
| 2498 | //=============================================================================================== |
| 2499 | //function : VUpdate |
| 2500 | //purpose : |
| 2501 | //=============================================================================================== |
| 2502 | static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
| 2503 | { |
| 2504 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
| 2505 | if (aContextAIS.IsNull()) |
| 2506 | { |
| 2507 | std::cout << theArgVec[0] << "AIS context is not available.\n"; |
| 2508 | return 1; |
| 2509 | } |
| 2510 | |
| 2511 | if (theArgsNb < 2) |
| 2512 | { |
| 2513 | std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n"; |
| 2514 | return 1; |
| 2515 | } |
| 2516 | |
| 2517 | const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS(); |
| 2518 | |
| 2519 | AIS_ListOfInteractive aListOfIO; |
| 2520 | |
| 2521 | for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
| 2522 | { |
| 2523 | TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]); |
| 2524 | |
| 2525 | Handle(AIS_InteractiveObject) anAISObj; |
| 2526 | if (anAISMap.IsBound2 (aName)) |
| 2527 | { |
| 2528 | anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName)); |
| 2529 | } |
| 2530 | |
| 2531 | if (anAISObj.IsNull()) |
| 2532 | { |
| 2533 | std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n"; |
| 2534 | return 1; |
| 2535 | } |
| 2536 | |
| 2537 | aListOfIO.Append (anAISObj); |
| 2538 | } |
| 2539 | |
| 2540 | AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); |
| 2541 | for (; anIOIt.More(); anIOIt.Next()) |
| 2542 | { |
| 2543 | aContextAIS->Update (anIOIt.Value(), Standard_False); |
| 2544 | } |
| 2545 | |
| 2546 | aContextAIS->UpdateCurrentViewer(); |
| 2547 | |
| 2548 | return 0; |
| 2549 | } |
| 2550 | |
| 2551 | //============================================================================== |
| 2552 | //function : VPerf |
| 2553 | //purpose : Test the annimation of an object along a |
| 2554 | // predifined trajectory |
| 2555 | //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF) |
| 2556 | //============================================================================== |
| 2557 | |
| 2558 | static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) { |
| 2559 | |
| 2560 | OSD_Timer myTimer; |
| 2561 | if (TheAISContext()->HasOpenedContext()) |
| 2562 | TheAISContext()->CloseLocalContext(); |
| 2563 | |
| 2564 | Standard_Real Step=4*M_PI/180; |
| 2565 | Standard_Real Angle=0; |
| 2566 | |
| 2567 | Handle(AIS_InteractiveObject) aIO; |
| 2568 | if (GetMapOfAIS().IsBound2(argv[1])) |
| 2569 | aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1])); |
| 2570 | if (aIO.IsNull()) |
| 2571 | return 1; |
| 2572 | |
| 2573 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO); |
| 2574 | |
| 2575 | myTimer.Start(); |
| 2576 | |
| 2577 | if (Draw::Atoi(argv[3])==1 ) { |
| 2578 | di<<" Primitives sensibles OFF"<<"\n"; |
| 2579 | TheAISContext()->Deactivate(aIO); |
| 2580 | } |
| 2581 | else { |
| 2582 | di<<" Primitives sensibles ON"<<"\n"; |
| 2583 | } |
| 2584 | // Movement par transformation |
| 2585 | if(Draw::Atoi(argv[2]) ==1) { |
| 2586 | di<<" Calcul par Transformation"<<"\n"; |
| 2587 | for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) { |
| 2588 | |
| 2589 | Angle=Step*myAngle; |
| 2590 | gp_Trsf myTransfo; |
| 2591 | myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle ); |
| 2592 | TheAISContext()->SetLocation(aShape,myTransfo); |
| 2593 | TheAISContext() ->UpdateCurrentViewer(); |
| 2594 | |
| 2595 | } |
| 2596 | } |
| 2597 | else { |
| 2598 | di<<" Calcul par Locations"<<"\n"; |
| 2599 | gp_Trsf myAngleTrsf; |
| 2600 | myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step ); |
| 2601 | TopLoc_Location myDeltaAngle (myAngleTrsf); |
| 2602 | TopLoc_Location myTrueLoc; |
| 2603 | |
| 2604 | for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) { |
| 2605 | |
| 2606 | Angle=Step*myAngle; |
| 2607 | myTrueLoc=myTrueLoc*myDeltaAngle; |
| 2608 | TheAISContext()->SetLocation(aShape,myTrueLoc ); |
| 2609 | TheAISContext() ->UpdateCurrentViewer(); |
| 2610 | } |
| 2611 | } |
| 2612 | if (Draw::Atoi(argv[3])==1 ){ |
| 2613 | // On reactive la selection des primitives sensibles |
| 2614 | TheAISContext()->Activate(aIO,0); |
| 2615 | } |
| 2616 | a3DView() -> Redraw(); |
| 2617 | myTimer.Stop(); |
| 2618 | di<<" Temps ecoule "<<"\n"; |
| 2619 | myTimer.Show(); |
| 2620 | return 0; |
| 2621 | } |
| 2622 | |
| 2623 | |
| 2624 | //================================================================================== |
| 2625 | // Function : VAnimation |
| 2626 | //================================================================================== |
| 2627 | static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { |
| 2628 | if (argc != 5) { |
| 2629 | di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n"; |
| 2630 | return 1; |
| 2631 | } |
| 2632 | |
| 2633 | Standard_Real thread = 4; |
| 2634 | Standard_Real angleA=0; |
| 2635 | Standard_Real angleB; |
| 2636 | Standard_Real X; |
| 2637 | gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1)); |
| 2638 | |
| 2639 | BRep_Builder B; |
| 2640 | TopoDS_Shape CrankArm; |
| 2641 | TopoDS_Shape CylinderHead; |
| 2642 | TopoDS_Shape Propeller; |
| 2643 | TopoDS_Shape EngineBlock; |
| 2644 | |
| 2645 | //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B); |
| 2646 | //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B); |
| 2647 | //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B); |
| 2648 | //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B); |
| 2649 | BRepTools::Read(CrankArm,argv[1],B); |
| 2650 | BRepTools::Read(CylinderHead,argv[2],B); |
| 2651 | BRepTools::Read(Propeller,argv[3],B); |
| 2652 | BRepTools::Read(EngineBlock,argv[4],B); |
| 2653 | |
| 2654 | if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";} |
| 2655 | |
| 2656 | |
| 2657 | OSD_Timer myTimer; |
| 2658 | myTimer.Start(); |
| 2659 | |
| 2660 | Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead); |
| 2661 | Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock); |
| 2662 | Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm); |
| 2663 | Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller); |
| 2664 | |
| 2665 | GetMapOfAIS().Bind(myAisCylinderHead,"a"); |
| 2666 | GetMapOfAIS().Bind(myAisEngineBlock,"b"); |
| 2667 | GetMapOfAIS().Bind(myAisCrankArm,"c"); |
| 2668 | GetMapOfAIS().Bind(myAisPropeller,"d"); |
| 2669 | |
| 2670 | TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED); |
| 2671 | TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED); |
| 2672 | TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN); |
| 2673 | |
| 2674 | TheAISContext()->Display(myAisCylinderHead,Standard_False); |
| 2675 | TheAISContext()->Display(myAisEngineBlock,Standard_False ); |
| 2676 | TheAISContext()->Display(myAisCrankArm,Standard_False ); |
| 2677 | TheAISContext()->Display(myAisPropeller,Standard_False); |
| 2678 | |
| 2679 | TheAISContext()->Deactivate(myAisCylinderHead); |
| 2680 | TheAISContext()->Deactivate(myAisEngineBlock ); |
| 2681 | TheAISContext()->Deactivate(myAisCrankArm ); |
| 2682 | TheAISContext()->Deactivate(myAisPropeller ); |
| 2683 | |
| 2684 | // Boucle de mouvement |
| 2685 | for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) { |
| 2686 | |
| 2687 | angleA = thread*myAngle*M_PI/180; |
| 2688 | X = Sin(angleA)*3/8; |
| 2689 | angleB = atan(X / Sqrt(-X * X + 1)); |
| 2690 | Standard_Real decal(25*0.6); |
| 2691 | |
| 2692 | |
| 2693 | //Build a transformation on the display |
| 2694 | gp_Trsf aPropellerTrsf; |
| 2695 | aPropellerTrsf.SetRotation(Ax1,angleA); |
| 2696 | TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf); |
| 2697 | |
| 2698 | 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)); |
| 2699 | gp_Trsf aCrankArmTrsf; |
| 2700 | aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB)); |
| 2701 | TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf); |
| 2702 | |
| 2703 | TheAISContext()->UpdateCurrentViewer(); |
| 2704 | } |
| 2705 | |
| 2706 | TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() ); |
| 2707 | TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() ); |
| 2708 | |
| 2709 | myAisCrankArm ->ResetLocation(); |
| 2710 | myAisPropeller->ResetLocation(); |
| 2711 | |
| 2712 | myAisCrankArm -> Set(myNewCrankArm ); |
| 2713 | myAisPropeller -> Set(myNewPropeller); |
| 2714 | |
| 2715 | TheAISContext()->Activate(myAisCylinderHead,0); |
| 2716 | TheAISContext()->Activate(myAisEngineBlock,0 ); |
| 2717 | TheAISContext()->Activate(myAisCrankArm ,0 ); |
| 2718 | TheAISContext()->Activate(myAisPropeller ,0 ); |
| 2719 | |
| 2720 | myTimer.Stop(); |
| 2721 | myTimer.Show(); |
| 2722 | myTimer.Start(); |
| 2723 | |
| 2724 | TheAISContext()->Redisplay(myAisCrankArm ,Standard_False); |
| 2725 | TheAISContext()->Redisplay(myAisPropeller,Standard_False); |
| 2726 | |
| 2727 | TheAISContext()->UpdateCurrentViewer(); |
| 2728 | a3DView()->Redraw(); |
| 2729 | |
| 2730 | myTimer.Stop(); |
| 2731 | myTimer.Show(); |
| 2732 | |
| 2733 | return 0; |
| 2734 | |
| 2735 | } |
| 2736 | |
| 2737 | //============================================================================== |
| 2738 | //function : VShading |
| 2739 | //purpose : Sharpen or roughten the quality of the shading |
| 2740 | //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg |
| 2741 | //============================================================================== |
| 2742 | static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv) |
| 2743 | { |
| 2744 | Standard_Real myDevCoef; |
| 2745 | Handle(AIS_InteractiveObject) TheAisIO; |
| 2746 | |
| 2747 | // Verifications |
| 2748 | const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0); |
| 2749 | |
| 2750 | if (TheAISContext()->HasOpenedContext()) |
| 2751 | TheAISContext()->CloseLocalContext(); |
| 2752 | |
| 2753 | if (argc < 3) { |
| 2754 | myDevCoef = 0.0008; |
| 2755 | } else { |
| 2756 | myDevCoef =Draw::Atof(argv[2]); |
| 2757 | } |
| 2758 | |
| 2759 | TCollection_AsciiString name=argv[1]; |
| 2760 | if (GetMapOfAIS().IsBound2(name )) |
| 2761 | TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); |
| 2762 | if (TheAisIO.IsNull()) |
| 2763 | TheAisIO=GetAISShapeFromName((const char *)name.ToCString()); |
| 2764 | |
| 2765 | if (HaveToSet) |
| 2766 | TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True); |
| 2767 | else |
| 2768 | TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True); |
| 2769 | |
| 2770 | TheAISContext()->Redisplay(TheAisIO); |
| 2771 | return 0; |
| 2772 | } |
| 2773 | //============================================================================== |
| 2774 | //function : HaveMode |
| 2775 | //use : VActivatedModes |
| 2776 | //============================================================================== |
| 2777 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
| 2778 | |
| 2779 | Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode ) |
| 2780 | { |
| 2781 | TColStd_ListOfInteger List; |
| 2782 | TheAISContext()->ActivatedModes (TheAisIO,List); |
| 2783 | TColStd_ListIteratorOfListOfInteger it; |
| 2784 | Standard_Boolean Found=Standard_False; |
| 2785 | for (it.Initialize(List); it.More()&&!Found; it.Next() ){ |
| 2786 | if (it.Value()==mode ) Found=Standard_True; |
| 2787 | } |
| 2788 | return Found; |
| 2789 | } |
| 2790 | |
| 2791 | |
| 2792 | |
| 2793 | //============================================================================== |
| 2794 | //function : VActivatedMode |
| 2795 | //author : ege |
| 2796 | //purpose : permet d'attribuer a chacune des shapes un mode d'activation |
| 2797 | // (edges,vertex...)qui lui est propre et le mode de selection standard. |
| 2798 | // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer) |
| 2799 | // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise |
| 2800 | // qu'un nom et qu'un mode. |
| 2801 | //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7) |
| 2802 | //============================================================================== |
| 2803 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
| 2804 | |
| 2805 | static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 2806 | |
| 2807 | { |
| 2808 | Standard_Boolean ThereIsName = Standard_False ; |
| 2809 | |
| 2810 | if(!a3DView().IsNull()){ |
| 2811 | |
| 2812 | const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0); |
| 2813 | // verification des arguments |
| 2814 | if (HaveToSet) { |
| 2815 | if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;} |
| 2816 | ThereIsName = (argc == 3); |
| 2817 | } |
| 2818 | else { |
| 2819 | // vunsetam |
| 2820 | if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;} |
| 2821 | else { |
| 2822 | di<<" R.A.Z de tous les modes de selecion"<<"\n"; |
| 2823 | di<<" Fermeture du Context local"<<"\n"; |
| 2824 | if (TheAISContext()->HasOpenedContext()) |
| 2825 | TheAISContext()->CloseLocalContext(); |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | // IL n'y a aps de nom de shape passe en argument |
| 2830 | if (HaveToSet && !ThereIsName){ |
| 2831 | Standard_Integer aMode=Draw::Atoi(argv [1]); |
| 2832 | |
| 2833 | const char *cmode="???"; |
| 2834 | switch (aMode) { |
| 2835 | case 0: cmode = "Shape"; break; |
| 2836 | case 1: cmode = "Vertex"; break; |
| 2837 | case 2: cmode = "Edge"; break; |
| 2838 | case 3: cmode = "Wire"; break; |
| 2839 | case 4: cmode = "Face"; break; |
| 2840 | case 5: cmode = "Shell"; break; |
| 2841 | case 6: cmode = "Solid"; break; |
| 2842 | case 7: cmode = "Compound"; break; |
| 2843 | } |
| 2844 | |
| 2845 | if( !TheAISContext()->HasOpenedContext() ) { |
| 2846 | // il n'y a pas de Context local d'ouvert |
| 2847 | // on en ouvre un et on charge toutes les shapes displayees |
| 2848 | // on load tous les objets displayees et on Activate les objets de la liste |
| 2849 | AIS_ListOfInteractive ListOfIO; |
| 2850 | // on sauve dans une AISListOfInteractive tous les objets currents |
| 2851 | if (TheAISContext()->NbCurrents()>0 ){ |
| 2852 | TheAISContext()->UnhilightCurrents(Standard_False); |
| 2853 | |
| 2854 | for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){ |
| 2855 | ListOfIO.Append(TheAISContext()->Current() ); |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | TheAISContext()->OpenLocalContext(Standard_False); |
| 2860 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName |
| 2861 | it (GetMapOfAIS()); |
| 2862 | while(it.More()){ |
| 2863 | Handle(AIS_InteractiveObject) aIO = |
| 2864 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); |
| 2865 | if (!aIO.IsNull()) |
| 2866 | TheAISContext()->Load(aIO,0,Standard_False); |
| 2867 | it.Next(); |
| 2868 | } |
| 2869 | // traitement des objets qui etaient currents dans le Contexte global |
| 2870 | if (!ListOfIO.IsEmpty() ) { |
| 2871 | // il y avait des objets currents |
| 2872 | AIS_ListIteratorOfListOfInteractive iter; |
| 2873 | for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) { |
| 2874 | Handle(AIS_InteractiveObject) aIO=iter.Value(); |
| 2875 | TheAISContext()->Activate(aIO,aMode); |
| 2876 | di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; |
| 2877 | } |
| 2878 | } |
| 2879 | else { |
| 2880 | // On applique le mode a tous les objets displayes |
| 2881 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName |
| 2882 | it2 (GetMapOfAIS()); |
| 2883 | while(it2.More()){ |
| 2884 | Handle(AIS_InteractiveObject) aIO = |
| 2885 | Handle(AIS_InteractiveObject)::DownCast(it2.Key1()); |
| 2886 | if (!aIO.IsNull()) { |
| 2887 | di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n"; |
| 2888 | TheAISContext()->Activate(aIO,aMode); |
| 2889 | } |
| 2890 | it2.Next(); |
| 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | } |
| 2895 | |
| 2896 | else { |
| 2897 | // un Context local est deja ouvert |
| 2898 | // Traitement des objets du Context local |
| 2899 | if (TheAISContext()->NbSelected()>0 ){ |
| 2900 | TheAISContext()->UnhilightSelected(Standard_False); |
| 2901 | // il y a des objets selected,on les parcourt |
| 2902 | for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){ |
| 2903 | Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive(); |
| 2904 | |
| 2905 | |
| 2906 | if (HaveMode(aIO,aMode) ) { |
| 2907 | di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; |
| 2908 | TheAISContext()->Deactivate(aIO,aMode); |
| 2909 | } |
| 2910 | else{ |
| 2911 | di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; |
| 2912 | TheAISContext()->Activate(aIO,aMode); |
| 2913 | } |
| 2914 | |
| 2915 | } |
| 2916 | } |
| 2917 | else{ |
| 2918 | // il n'y a pas d'objets selected |
| 2919 | // tous les objets diplayes sont traites |
| 2920 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName |
| 2921 | it (GetMapOfAIS()); |
| 2922 | while(it.More()){ |
| 2923 | Handle(AIS_InteractiveObject) aIO = |
| 2924 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); |
| 2925 | if (!aIO.IsNull()) { |
| 2926 | if (HaveMode(aIO,aMode) ) { |
| 2927 | di<<" Mode: "<<cmode<<" OFF pour " |
| 2928 | <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; |
| 2929 | TheAISContext()->Deactivate(aIO,aMode); |
| 2930 | } |
| 2931 | else{ |
| 2932 | di<<" Mode: "<<cmode<<" ON pour" |
| 2933 | <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; |
| 2934 | TheAISContext()->Activate(aIO,aMode); |
| 2935 | } |
| 2936 | } |
| 2937 | it.Next(); |
| 2938 | } |
| 2939 | } |
| 2940 | } |
| 2941 | } |
| 2942 | else if (HaveToSet && ThereIsName){ |
| 2943 | Standard_Integer aMode=Draw::Atoi(argv [2]); |
| 2944 | Handle(AIS_InteractiveObject) aIO = |
| 2945 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1])); |
| 2946 | |
| 2947 | if (!aIO.IsNull()) { |
| 2948 | const char *cmode="???"; |
| 2949 | |
| 2950 | switch (aMode) { |
| 2951 | case 0: cmode = "Shape"; break; |
| 2952 | case 1: cmode = "Vertex"; break; |
| 2953 | case 2: cmode = "Edge"; break; |
| 2954 | case 3: cmode = "Wire"; break; |
| 2955 | case 4: cmode = "Face"; break; |
| 2956 | case 5: cmode = "Shell"; break; |
| 2957 | case 6: cmode = "Solid"; break; |
| 2958 | case 7: cmode = "Compound"; break; |
| 2959 | } |
| 2960 | |
| 2961 | if( !TheAISContext()->HasOpenedContext() ) { |
| 2962 | TheAISContext()->OpenLocalContext(Standard_False); |
| 2963 | // On charge tous les objets de la map |
| 2964 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS()); |
| 2965 | while(it.More()){ |
| 2966 | Handle(AIS_InteractiveObject) aShape= |
| 2967 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); |
| 2968 | if (!aShape.IsNull()) |
| 2969 | TheAISContext()->Load(aShape,0,Standard_False); |
| 2970 | it.Next(); |
| 2971 | } |
| 2972 | TheAISContext()->Activate(aIO,aMode); |
| 2973 | di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n"; |
| 2974 | } |
| 2975 | |
| 2976 | else { |
| 2977 | // un Context local est deja ouvert |
| 2978 | if (HaveMode(aIO,aMode) ) { |
| 2979 | di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n"; |
| 2980 | TheAISContext()->Deactivate(aIO,aMode); |
| 2981 | } |
| 2982 | else{ |
| 2983 | di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n"; |
| 2984 | TheAISContext()->Activate(aIO,aMode); |
| 2985 | } |
| 2986 | } |
| 2987 | } |
| 2988 | } |
| 2989 | } |
| 2990 | return 0; |
| 2991 | } |
| 2992 | |
| 2993 | //! Auxiliary method to print Interactive Object information |
| 2994 | static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected, |
| 2995 | const Handle(Standard_Transient)& theObject, |
| 2996 | Draw_Interpretor& theDI) |
| 2997 | { |
| 2998 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject); |
| 2999 | if (anObj.IsNull()) |
| 3000 | { |
| 3001 | theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n"; |
| 3002 | return; |
| 3003 | } |
| 3004 | |
| 3005 | theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ") |
| 3006 | << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ") |
| 3007 | << (theDetected.Contains (anObj) ? " Detected" : " ") |
| 3008 | << " Type: "; |
| 3009 | if (anObj->Type() == AIS_KOI_Datum) |
| 3010 | { |
| 3011 | // AIS_Datum |
| 3012 | if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; } |
| 3013 | else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; } |
| 3014 | else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; } |
| 3015 | else if (anObj->Signature() == 5) { theDI << " AIS_Line"; } |
| 3016 | else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; } |
| 3017 | else if (anObj->Signature() == 1) { theDI << " AIS_Point"; } |
| 3018 | else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; } |
| 3019 | } |
| 3020 | // AIS_Shape |
| 3021 | else if (anObj->Type() == AIS_KOI_Shape |
| 3022 | && anObj->Signature() == 0) |
| 3023 | { |
| 3024 | theDI << " AIS_Shape"; |
| 3025 | } |
| 3026 | else if (anObj->Type() == AIS_KOI_Relation) |
| 3027 | { |
| 3028 | // AIS_Dimention and AIS_Relation |
| 3029 | Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj); |
| 3030 | switch (aRelation->KindOfDimension()) |
| 3031 | { |
| 3032 | case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break; |
| 3033 | case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break; |
| 3034 | case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break; |
| 3035 | case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break; |
| 3036 | //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break; |
| 3037 | case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break; |
| 3038 | case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break; |
| 3039 | default: theDI << " UNKNOWN dimension"; break; |
| 3040 | } |
| 3041 | } |
| 3042 | else |
| 3043 | { |
| 3044 | theDI << " UserPrs"; |
| 3045 | } |
| 3046 | theDI << " (" << theObject->DynamicType()->Name() << ")"; |
| 3047 | } |
| 3048 | |
| 3049 | //! Print information about locally selected sub-shapes |
| 3050 | static void localCtxInfo (Draw_Interpretor& theDI) |
| 3051 | { |
| 3052 | Handle(AIS_InteractiveContext) aCtx = TheAISContext(); |
| 3053 | if (!aCtx->HasOpenedContext()) |
| 3054 | { |
| 3055 | return; |
| 3056 | } |
| 3057 | |
| 3058 | TCollection_AsciiString aPrevName; |
| 3059 | Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext(); |
| 3060 | for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected()) |
| 3061 | { |
| 3062 | const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape(); |
| 3063 | const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive()); |
| 3064 | if (aSubShape.IsNull() |
| 3065 | || aShapeIO.IsNull() |
| 3066 | || !GetMapOfAIS().IsBound1 (aShapeIO)) |
| 3067 | { |
| 3068 | continue; |
| 3069 | } |
| 3070 | |
| 3071 | const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO); |
| 3072 | TopTools_MapOfShape aFilter; |
| 3073 | Standard_Integer aNumber = 0; |
| 3074 | const TopoDS_Shape aShape = aShapeIO->Shape(); |
| 3075 | for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType()); |
| 3076 | anIter.More(); anIter.Next()) |
| 3077 | { |
| 3078 | if (!aFilter.Add (anIter.Current())) |
| 3079 | { |
| 3080 | continue; // filter duplicates |
| 3081 | } |
| 3082 | |
| 3083 | ++aNumber; |
| 3084 | if (!anIter.Current().IsSame (aSubShape)) |
| 3085 | { |
| 3086 | continue; |
| 3087 | } |
| 3088 | |
| 3089 | Standard_CString aShapeName = NULL; |
| 3090 | switch (aSubShape.ShapeType()) |
| 3091 | { |
| 3092 | case TopAbs_COMPOUND: aShapeName = " Compound"; break; |
| 3093 | case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break; |
| 3094 | case TopAbs_SOLID: aShapeName = " Solid"; break; |
| 3095 | case TopAbs_SHELL: aShapeName = " Shell"; break; |
| 3096 | case TopAbs_FACE: aShapeName = " Face"; break; |
| 3097 | case TopAbs_WIRE: aShapeName = " Wire"; break; |
| 3098 | case TopAbs_EDGE: aShapeName = " Edge"; break; |
| 3099 | case TopAbs_VERTEX: aShapeName = " Vertex"; break; |
| 3100 | default: |
| 3101 | case TopAbs_SHAPE: aShapeName = " Shape"; break; |
| 3102 | } |
| 3103 | |
| 3104 | if (aParentName != aPrevName) |
| 3105 | { |
| 3106 | theDI << "Locally selected sub-shapes within " << aParentName << ":\n"; |
| 3107 | aPrevName = aParentName; |
| 3108 | } |
| 3109 | theDI << " " << aShapeName << " #" << aNumber << "\n"; |
| 3110 | break; |
| 3111 | } |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | //============================================================================== |
| 3116 | //function : VState |
| 3117 | //purpose : |
| 3118 | //Draw arg : vstate [nameA] ... [nameN] |
| 3119 | //============================================================================== |
| 3120 | static Standard_Integer VState (Draw_Interpretor& theDI, |
| 3121 | Standard_Integer theArgNb, |
| 3122 | Standard_CString* theArgVec) |
| 3123 | { |
| 3124 | Handle(AIS_InteractiveContext) aCtx = TheAISContext(); |
| 3125 | if (aCtx.IsNull()) |
| 3126 | { |
| 3127 | std::cerr << "Error: No opened viewer!\n"; |
| 3128 | return 1; |
| 3129 | } |
| 3130 | |
| 3131 | NCollection_Map<Handle(AIS_InteractiveObject)> aDetected; |
| 3132 | for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected()) |
| 3133 | { |
| 3134 | aDetected.Add (aCtx->DetectedCurrentObject()); |
| 3135 | } |
| 3136 | |
| 3137 | const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*'); |
| 3138 | if (theArgNb >= 2 |
| 3139 | && !toShowAll) |
| 3140 | { |
| 3141 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 3142 | { |
| 3143 | const TCollection_AsciiString anObjName = theArgVec[anArgIter]; |
| 3144 | if (!GetMapOfAIS().IsBound2 (anObjName)) |
| 3145 | { |
| 3146 | theDI << anObjName << " doesn't exist!\n"; |
| 3147 | continue; |
| 3148 | } |
| 3149 | |
| 3150 | const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName); |
| 3151 | TCollection_AsciiString aName = anObjName; |
| 3152 | aName.LeftJustify (20, ' '); |
| 3153 | theDI << " " << aName << " "; |
| 3154 | objInfo (aDetected, anObjTrans, theDI); |
| 3155 | theDI << "\n"; |
| 3156 | } |
| 3157 | return 0; |
| 3158 | } |
| 3159 | |
| 3160 | if (aCtx->NbCurrents() > 0 |
| 3161 | && !toShowAll) |
| 3162 | { |
| 3163 | for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent()) |
| 3164 | { |
| 3165 | Handle(AIS_InteractiveObject) anObj = aCtx->Current(); |
| 3166 | TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj); |
| 3167 | aName.LeftJustify (20, ' '); |
| 3168 | theDI << aName << " "; |
| 3169 | objInfo (aDetected, anObj, theDI); |
| 3170 | theDI << "\n"; |
| 3171 | } |
| 3172 | return 0; |
| 3173 | } |
| 3174 | |
| 3175 | theDI << "Neutral-point state:\n"; |
| 3176 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); |
| 3177 | anObjIter.More(); anObjIter.Next()) |
| 3178 | { |
| 3179 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1()); |
| 3180 | if (anObj.IsNull()) |
| 3181 | { |
| 3182 | continue; |
| 3183 | } |
| 3184 | |
| 3185 | TCollection_AsciiString aName = anObjIter.Key2(); |
| 3186 | aName.LeftJustify (20, ' '); |
| 3187 | theDI << " " << aName << " "; |
| 3188 | objInfo (aDetected, anObj, theDI); |
| 3189 | theDI << "\n"; |
| 3190 | } |
| 3191 | localCtxInfo (theDI); |
| 3192 | return 0; |
| 3193 | } |
| 3194 | |
| 3195 | //======================================================================= |
| 3196 | //function : PickObjects |
| 3197 | //purpose : |
| 3198 | //======================================================================= |
| 3199 | Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr, |
| 3200 | const AIS_KindOfInteractive TheType, |
| 3201 | const Standard_Integer TheSignature, |
| 3202 | const Standard_Integer MaxPick) |
| 3203 | { |
| 3204 | Handle(AIS_InteractiveObject) IO; |
| 3205 | Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext(); |
| 3206 | |
| 3207 | // step 1: prepare the data |
| 3208 | if(curindex !=0){ |
| 3209 | Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature); |
| 3210 | TheAISContext()->AddFilter(F1); |
| 3211 | } |
| 3212 | |
| 3213 | // step 2 : wait for the selection... |
| 3214 | // Standard_Boolean IsGood (Standard_False); |
| 3215 | // Standard_Integer NbPick(0); |
| 3216 | Standard_Boolean NbPickGood (0),NbToReach(arr->Length()); |
| 3217 | Standard_Integer NbPickFail(0); |
| 3218 | Standard_Integer argccc = 5; |
| 3219 | const char *bufff[] = { "A", "B", "C","D", "E" }; |
| 3220 | const char **argvvv = (const char **) bufff; |
| 3221 | |
| 3222 | |
| 3223 | while(NbPickGood<NbToReach && NbPickFail <= MaxPick){ |
| 3224 | while(ViewerMainLoop(argccc,argvvv)){} |
| 3225 | Standard_Integer NbStored = TheAISContext()->NbSelected(); |
| 3226 | if((unsigned int ) NbStored != NbPickGood) |
| 3227 | NbPickGood= NbStored; |
| 3228 | else |
| 3229 | NbPickFail++; |
| 3230 | cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl; |
| 3231 | } |
| 3232 | |
| 3233 | // step3 get result. |
| 3234 | |
| 3235 | if((unsigned int ) NbPickFail >= NbToReach) return Standard_False; |
| 3236 | |
| 3237 | Standard_Integer i(0); |
| 3238 | for(TheAISContext()->InitSelected(); |
| 3239 | TheAISContext()->MoreSelected(); |
| 3240 | TheAISContext()->NextSelected()){ |
| 3241 | i++; |
| 3242 | Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive(); |
| 3243 | arr->SetValue(i,IO2); |
| 3244 | } |
| 3245 | |
| 3246 | |
| 3247 | if(curindex>0) |
| 3248 | TheAISContext()->CloseLocalContext(curindex); |
| 3249 | |
| 3250 | return Standard_True; |
| 3251 | } |
| 3252 | |
| 3253 | |
| 3254 | //======================================================================= |
| 3255 | //function : PickObject |
| 3256 | //purpose : |
| 3257 | //======================================================================= |
| 3258 | Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType, |
| 3259 | const Standard_Integer TheSignature, |
| 3260 | const Standard_Integer MaxPick) |
| 3261 | { |
| 3262 | Handle(AIS_InteractiveObject) IO; |
| 3263 | Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext(); |
| 3264 | |
| 3265 | // step 1: prepare the data |
| 3266 | |
| 3267 | if(curindex !=0){ |
| 3268 | Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature); |
| 3269 | TheAISContext()->AddFilter(F1); |
| 3270 | } |
| 3271 | |
| 3272 | // step 2 : wait for the selection... |
| 3273 | Standard_Boolean IsGood (Standard_False); |
| 3274 | Standard_Integer NbPick(0); |
| 3275 | Standard_Integer argccc = 5; |
| 3276 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
| 3277 | const char **argvvv = (const char **) bufff; |
| 3278 | |
| 3279 | |
| 3280 | while(!IsGood && NbPick<= MaxPick){ |
| 3281 | while(ViewerMainLoop(argccc,argvvv)){} |
| 3282 | IsGood = (TheAISContext()->NbSelected()>0) ; |
| 3283 | NbPick++; |
| 3284 | cout<<"Nb Pick :"<<NbPick<<endl; |
| 3285 | } |
| 3286 | |
| 3287 | |
| 3288 | // step3 get result. |
| 3289 | if(IsGood){ |
| 3290 | TheAISContext()->InitSelected(); |
| 3291 | IO = TheAISContext()->SelectedInteractive(); |
| 3292 | } |
| 3293 | |
| 3294 | if(curindex!=0) |
| 3295 | TheAISContext()->CloseLocalContext(curindex); |
| 3296 | return IO; |
| 3297 | } |
| 3298 | |
| 3299 | //======================================================================= |
| 3300 | //function : PickShape |
| 3301 | //purpose : First Activate the rightmode + Put Filters to be able to |
| 3302 | // pick objets that are of type <TheType>... |
| 3303 | //======================================================================= |
| 3304 | |
| 3305 | TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType, |
| 3306 | const Standard_Integer MaxPick) |
| 3307 | { |
| 3308 | |
| 3309 | // step 1: prepare the data |
| 3310 | |
| 3311 | Standard_Integer curindex = TheAISContext()->OpenLocalContext(); |
| 3312 | TopoDS_Shape result; |
| 3313 | |
| 3314 | if(TheType==TopAbs_SHAPE){ |
| 3315 | Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape); |
| 3316 | TheAISContext()->AddFilter(F1); |
| 3317 | } |
| 3318 | else{ |
| 3319 | Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType); |
| 3320 | TheAISContext()->AddFilter(TF); |
| 3321 | TheAISContext()->ActivateStandardMode(TheType); |
| 3322 | |
| 3323 | } |
| 3324 | |
| 3325 | |
| 3326 | // step 2 : wait for the selection... |
| 3327 | Standard_Boolean NoShape (Standard_True); |
| 3328 | Standard_Integer NbPick(0); |
| 3329 | Standard_Integer argccc = 5; |
| 3330 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
| 3331 | const char **argvvv = (const char **) bufff; |
| 3332 | |
| 3333 | |
| 3334 | while(NoShape && NbPick<= MaxPick){ |
| 3335 | while(ViewerMainLoop(argccc,argvvv)){} |
| 3336 | NoShape = (TheAISContext()->NbSelected()==0) ; |
| 3337 | NbPick++; |
| 3338 | cout<<"Nb Pick :"<<NbPick<<endl; |
| 3339 | } |
| 3340 | |
| 3341 | // step3 get result. |
| 3342 | |
| 3343 | if(!NoShape){ |
| 3344 | |
| 3345 | TheAISContext()->InitSelected(); |
| 3346 | if(TheAISContext()->HasSelectedShape()) |
| 3347 | result = TheAISContext()->SelectedShape(); |
| 3348 | else{ |
| 3349 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); |
| 3350 | result = (*((Handle(AIS_Shape)*) &IO))->Shape(); |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | if(curindex>0) |
| 3355 | TheAISContext()->CloseLocalContext(curindex); |
| 3356 | |
| 3357 | return result; |
| 3358 | } |
| 3359 | |
| 3360 | |
| 3361 | //======================================================================= |
| 3362 | //function : PickShapes |
| 3363 | //purpose : |
| 3364 | //======================================================================= |
| 3365 | Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType, |
| 3366 | Handle(TopTools_HArray1OfShape)& thearr, |
| 3367 | const Standard_Integer MaxPick) |
| 3368 | { |
| 3369 | |
| 3370 | Standard_Integer Taille = thearr->Length(); |
| 3371 | if(Taille>1) |
| 3372 | cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n"; |
| 3373 | |
| 3374 | // step 1: prepare the data |
| 3375 | Standard_Integer curindex = TheAISContext()->OpenLocalContext(); |
| 3376 | if(TheType==TopAbs_SHAPE){ |
| 3377 | Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape); |
| 3378 | TheAISContext()->AddFilter(F1); |
| 3379 | } |
| 3380 | else{ |
| 3381 | Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType); |
| 3382 | TheAISContext()->AddFilter(TF); |
| 3383 | TheAISContext()->ActivateStandardMode(TheType); |
| 3384 | |
| 3385 | } |
| 3386 | |
| 3387 | // step 2 : wait for the selection... |
| 3388 | |
| 3389 | Standard_Boolean NbPickGood (0),NbToReach(thearr->Length()); |
| 3390 | Standard_Integer NbPickFail(0); |
| 3391 | Standard_Integer argccc = 5; |
| 3392 | const char *bufff[] = { "A", "B", "C","D", "E" }; |
| 3393 | const char **argvvv = (const char **) bufff; |
| 3394 | |
| 3395 | |
| 3396 | while(NbPickGood<NbToReach && NbPickFail <= MaxPick){ |
| 3397 | while(ViewerMainLoop(argccc,argvvv)){} |
| 3398 | Standard_Integer NbStored = TheAISContext()->NbSelected(); |
| 3399 | if((unsigned int ) NbStored != NbPickGood) |
| 3400 | NbPickGood= NbStored; |
| 3401 | else |
| 3402 | NbPickFail++; |
| 3403 | cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n"; |
| 3404 | } |
| 3405 | |
| 3406 | // step3 get result. |
| 3407 | |
| 3408 | if((unsigned int ) NbPickFail >= NbToReach) return Standard_False; |
| 3409 | |
| 3410 | Standard_Integer i(0); |
| 3411 | for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){ |
| 3412 | i++; |
| 3413 | if(TheAISContext()->HasSelectedShape()) |
| 3414 | thearr->SetValue(i,TheAISContext()->SelectedShape()); |
| 3415 | else{ |
| 3416 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); |
| 3417 | thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape()); |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | TheAISContext()->CloseLocalContext(curindex); |
| 3422 | return Standard_True; |
| 3423 | } |
| 3424 | |
| 3425 | |
| 3426 | //======================================================================= |
| 3427 | //function : VPickShape |
| 3428 | //purpose : |
| 3429 | //======================================================================= |
| 3430 | static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 3431 | { |
| 3432 | TopoDS_Shape PickSh; |
| 3433 | TopAbs_ShapeEnum theType = TopAbs_COMPOUND; |
| 3434 | |
| 3435 | if(argc==1) |
| 3436 | theType = TopAbs_SHAPE; |
| 3437 | else{ |
| 3438 | if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX; |
| 3439 | else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE; |
| 3440 | else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE; |
| 3441 | else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE; |
| 3442 | else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE; |
| 3443 | else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL; |
| 3444 | else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID; |
| 3445 | } |
| 3446 | |
| 3447 | static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0}; |
| 3448 | static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"}; |
| 3449 | |
| 3450 | TCollection_AsciiString name; |
| 3451 | |
| 3452 | |
| 3453 | Standard_Integer NbToPick = argc>2 ? argc-2 : 1; |
| 3454 | if(NbToPick==1){ |
| 3455 | PickSh = ViewerTest::PickShape(theType); |
| 3456 | |
| 3457 | if(PickSh.IsNull()) |
| 3458 | return 1; |
| 3459 | if(argc>2){ |
| 3460 | name += argv[2]; |
| 3461 | } |
| 3462 | else{ |
| 3463 | |
| 3464 | if(!PickSh.IsNull()){ |
| 3465 | nbOfSub[Standard_Integer(theType)]++; |
| 3466 | name += "Picked_"; |
| 3467 | name += nameType[Standard_Integer(theType)]; |
| 3468 | TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]); |
| 3469 | name +="_"; |
| 3470 | name+=indxstring; |
| 3471 | } |
| 3472 | } |
| 3473 | // si on avait une petite methode pour voir si la shape |
| 3474 | // est deja dans la Double map, ca eviterait de creer.... |
| 3475 | DBRep::Set(name.ToCString(),PickSh); |
| 3476 | |
| 3477 | Handle(AIS_Shape) newsh = new AIS_Shape(PickSh); |
| 3478 | GetMapOfAIS().Bind(newsh, name); |
| 3479 | TheAISContext()->Display(newsh); |
| 3480 | di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n"; |
| 3481 | } |
| 3482 | |
| 3483 | // Plusieurs objets a picker, vite vite vite.... |
| 3484 | // |
| 3485 | else{ |
| 3486 | Standard_Boolean autonaming = !strcasecmp(argv[2],"."); |
| 3487 | Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick); |
| 3488 | if(ViewerTest::PickShapes(theType,arr)){ |
| 3489 | for(Standard_Integer i=1;i<=NbToPick;i++){ |
| 3490 | PickSh = arr->Value(i); |
| 3491 | if(!PickSh.IsNull()){ |
| 3492 | if(autonaming){ |
| 3493 | nbOfSub[Standard_Integer(theType)]++; |
| 3494 | name.Clear(); |
| 3495 | name += "Picked_"; |
| 3496 | name += nameType[Standard_Integer(theType)]; |
| 3497 | TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]); |
| 3498 | name +="_"; |
| 3499 | name+=indxstring; |
| 3500 | } |
| 3501 | } |
| 3502 | else |
| 3503 | name = argv[1+i]; |
| 3504 | |
| 3505 | DBRep::Set(name.ToCString(),PickSh); |
| 3506 | Handle(AIS_Shape) newsh = new AIS_Shape(PickSh); |
| 3507 | GetMapOfAIS().Bind(newsh, name); |
| 3508 | di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n"; |
| 3509 | TheAISContext()->Display(newsh); |
| 3510 | |
| 3511 | } |
| 3512 | } |
| 3513 | } |
| 3514 | return 0; |
| 3515 | } |
| 3516 | |
| 3517 | //======================================================================= |
| 3518 | //function : list of known objects |
| 3519 | //purpose : |
| 3520 | //======================================================================= |
| 3521 | static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** ) |
| 3522 | { |
| 3523 | // 1234567890 12345678901234567 123456789 |
| 3524 | TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"}; |
| 3525 | TCollection_AsciiString BlankLine(64,'_'); |
| 3526 | Standard_Integer i ; |
| 3527 | |
| 3528 | di<<"/n"<<BlankLine.ToCString()<<"\n"; |
| 3529 | |
| 3530 | for( i =0;i<=2;i++) |
| 3531 | Colum[i].Center(20,' '); |
| 3532 | for(i=0;i<=2;i++) |
| 3533 | di<<"|"<<Colum[i].ToCString(); |
| 3534 | di<<"|"<<"\n"; |
| 3535 | |
| 3536 | di<<BlankLine.ToCString()<<"\n"; |
| 3537 | |
| 3538 | // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"}; |
| 3539 | const char ** names = GetTypeNames(); |
| 3540 | |
| 3541 | TCollection_AsciiString curstring; |
| 3542 | TCollection_AsciiString curcolum[3]; |
| 3543 | |
| 3544 | |
| 3545 | // les objets de type Datum.. |
| 3546 | curcolum[1]+="Datum"; |
| 3547 | for(i =0;i<=6;i++){ |
| 3548 | curcolum[0].Clear(); |
| 3549 | curcolum[0] += names[i]; |
| 3550 | |
| 3551 | curcolum[2].Clear(); |
| 3552 | curcolum[2]+=TCollection_AsciiString(i+1); |
| 3553 | |
| 3554 | for(Standard_Integer j =0;j<=2;j++){ |
| 3555 | curcolum[j].Center(20,' '); |
| 3556 | di<<"|"<<curcolum[j].ToCString(); |
| 3557 | } |
| 3558 | di<<"|"<<"\n"; |
| 3559 | } |
| 3560 | di<<BlankLine.ToCString()<<"\n"; |
| 3561 | |
| 3562 | // les objets de type shape |
| 3563 | curcolum[1].Clear(); |
| 3564 | curcolum[1]+="Shape"; |
| 3565 | curcolum[1].Center(20,' '); |
| 3566 | |
| 3567 | for(i=0;i<=2;i++){ |
| 3568 | curcolum[0].Clear(); |
| 3569 | curcolum[0] += names[7+i]; |
| 3570 | curcolum[2].Clear(); |
| 3571 | curcolum[2]+=TCollection_AsciiString(i); |
| 3572 | |
| 3573 | for(Standard_Integer j =0;j<=2;j++){ |
| 3574 | curcolum[j].Center(20,' '); |
| 3575 | di<<"|"<<curcolum[j].ToCString(); |
| 3576 | } |
| 3577 | di<<"|"<<"\n"; |
| 3578 | } |
| 3579 | di<<BlankLine.ToCString()<<"\n"; |
| 3580 | // les IO de type objet... |
| 3581 | curcolum[1].Clear(); |
| 3582 | curcolum[1]+="Object"; |
| 3583 | curcolum[1].Center(20,' '); |
| 3584 | for(i=0;i<=1;i++){ |
| 3585 | curcolum[0].Clear(); |
| 3586 | curcolum[0] += names[10+i]; |
| 3587 | curcolum[2].Clear(); |
| 3588 | curcolum[2]+=TCollection_AsciiString(i); |
| 3589 | |
| 3590 | for(Standard_Integer j =0;j<=2;j++){ |
| 3591 | curcolum[j].Center(20,' '); |
| 3592 | di<<"|"<<curcolum[j].ToCString(); |
| 3593 | } |
| 3594 | di<<"|"<<"\n"; |
| 3595 | } |
| 3596 | di<<BlankLine.ToCString()<<"\n"; |
| 3597 | // les contraintes et dimensions. |
| 3598 | // pour l'instant on separe juste contraintes et dimensions... |
| 3599 | // plus tard, on detaillera toutes les sortes... |
| 3600 | curcolum[1].Clear(); |
| 3601 | curcolum[1]+="Relation"; |
| 3602 | curcolum[1].Center(20,' '); |
| 3603 | for(i=0;i<=1;i++){ |
| 3604 | curcolum[0].Clear(); |
| 3605 | curcolum[0] += names[12+i]; |
| 3606 | curcolum[2].Clear(); |
| 3607 | curcolum[2]+=TCollection_AsciiString(i); |
| 3608 | |
| 3609 | for(Standard_Integer j =0;j<=2;j++){ |
| 3610 | curcolum[j].Center(20,' '); |
| 3611 | di<<"|"<<curcolum[j].ToCString(); |
| 3612 | } |
| 3613 | di<<"|"<<"\n"; |
| 3614 | } |
| 3615 | di<<BlankLine.ToCString()<<"\n"; |
| 3616 | |
| 3617 | |
| 3618 | return 0; |
| 3619 | } |
| 3620 | |
| 3621 | |
| 3622 | static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv) |
| 3623 | { |
| 3624 | if(argc!=2) return 1; |
| 3625 | |
| 3626 | AIS_KindOfInteractive TheType; |
| 3627 | Standard_Integer TheSign(-1); |
| 3628 | GetTypeAndSignfromString(argv[1],TheType,TheSign); |
| 3629 | |
| 3630 | |
| 3631 | AIS_ListOfInteractive LIO; |
| 3632 | |
| 3633 | // en attendant l'amelioration ais pour les dimensions... |
| 3634 | // |
| 3635 | Standard_Integer dimension_status(-1); |
| 3636 | if(TheType==AIS_KOI_Relation){ |
| 3637 | dimension_status = TheSign ==1 ? 1 : 0; |
| 3638 | TheSign=-1; |
| 3639 | } |
| 3640 | |
| 3641 | TheAISContext()->DisplayedObjects(TheType,TheSign,LIO); |
| 3642 | Handle(AIS_InteractiveObject) curio; |
| 3643 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ |
| 3644 | curio = it.Value(); |
| 3645 | |
| 3646 | if(dimension_status == -1) |
| 3647 | TheAISContext()->Erase(curio,Standard_False); |
| 3648 | else { |
| 3649 | AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension(); |
| 3650 | if ((dimension_status==0 && KOD == AIS_KOD_NONE)|| |
| 3651 | (dimension_status==1 && KOD != AIS_KOD_NONE)) |
| 3652 | TheAISContext()->Erase(curio,Standard_False); |
| 3653 | } |
| 3654 | } |
| 3655 | TheAISContext()->UpdateCurrentViewer(); |
| 3656 | return 0; |
| 3657 | } |
| 3658 | static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv) |
| 3659 | { |
| 3660 | if(argc!=2) return 1; |
| 3661 | |
| 3662 | AIS_KindOfInteractive TheType; |
| 3663 | Standard_Integer TheSign(-1); |
| 3664 | GetTypeAndSignfromString(argv[1],TheType,TheSign); |
| 3665 | |
| 3666 | // en attendant l'amelioration ais pour les dimensions... |
| 3667 | // |
| 3668 | Standard_Integer dimension_status(-1); |
| 3669 | if(TheType==AIS_KOI_Relation){ |
| 3670 | dimension_status = TheSign ==1 ? 1 : 0; |
| 3671 | TheSign=-1; |
| 3672 | } |
| 3673 | |
| 3674 | AIS_ListOfInteractive LIO; |
| 3675 | TheAISContext()->ObjectsInside(LIO,TheType,TheSign); |
| 3676 | Handle(AIS_InteractiveObject) curio; |
| 3677 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ |
| 3678 | curio = it.Value(); |
| 3679 | if(dimension_status == -1) |
| 3680 | TheAISContext()->Display(curio,Standard_False); |
| 3681 | else { |
| 3682 | AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension(); |
| 3683 | if ((dimension_status==0 && KOD == AIS_KOD_NONE)|| |
| 3684 | (dimension_status==1 && KOD != AIS_KOD_NONE)) |
| 3685 | TheAISContext()->Display(curio,Standard_False); |
| 3686 | } |
| 3687 | |
| 3688 | } |
| 3689 | |
| 3690 | TheAISContext()->UpdateCurrentViewer(); |
| 3691 | return 0; |
| 3692 | } |
| 3693 | |
| 3694 | //============================================================================== |
| 3695 | //function : VSetTransMode |
| 3696 | //purpose : |
| 3697 | //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z] |
| 3698 | //============================================================================== |
| 3699 | |
| 3700 | static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { |
| 3701 | // Verification des arguments |
| 3702 | if ( a3DView().IsNull() ) { |
| 3703 | ViewerTest::ViewerInit(); |
| 3704 | di << "La commande vinit n'a pas ete appele avant" << "\n"; |
| 3705 | } |
| 3706 | |
| 3707 | if ( argc < 3 || argc > 8 ) { |
| 3708 | di << argv[0] << " Invalid number of arguments" << "\n"; |
| 3709 | return 1; |
| 3710 | } |
| 3711 | |
| 3712 | TCollection_AsciiString shapeName; |
| 3713 | shapeName = argv[1]; |
| 3714 | Standard_Integer persFlag1 = Draw::Atoi(argv[2]); |
| 3715 | Standard_Integer persFlag2 = 0; |
| 3716 | Standard_Integer persFlag3 = 0; |
| 3717 | gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 ); |
| 3718 | if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) { |
| 3719 | persFlag2 = Draw::Atoi(argv[3]); |
| 3720 | } |
| 3721 | if ( argc == 5 || argc == 8 ) { |
| 3722 | persFlag3 = Draw::Atoi(argv[4]); |
| 3723 | } |
| 3724 | if ( argc >= 6 ) { |
| 3725 | origin.SetX( Draw::Atof(argv[argc - 3]) ); |
| 3726 | origin.SetY( Draw::Atof(argv[argc - 2]) ); |
| 3727 | origin.SetZ( Draw::Atof(argv[argc - 1]) ); |
| 3728 | } |
| 3729 | |
| 3730 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName); |
| 3731 | Handle(Standard_Transient) anObj; |
| 3732 | if ( IsBound ) { |
| 3733 | anObj = GetMapOfAIS().Find2(shapeName); |
| 3734 | if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) { |
| 3735 | Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj); |
| 3736 | aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin ); |
| 3737 | if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) { |
| 3738 | di << argv[0] << " All persistence modifiers were removed" << "\n"; |
| 3739 | } |
| 3740 | } else { |
| 3741 | di << argv[0] << " Wrong object type" << "\n"; |
| 3742 | return 1; |
| 3743 | } |
| 3744 | } else { // Create the AIS_Shape from a name |
| 3745 | const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString()); |
| 3746 | if ( !aShape.IsNull() ) { |
| 3747 | GetMapOfAIS().Bind( aShape, shapeName ); |
| 3748 | aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin ); |
| 3749 | TheAISContext()->Display( aShape, Standard_False ); |
| 3750 | } else { |
| 3751 | di << argv[0] << " Object not found" << "\n"; |
| 3752 | return 1; |
| 3753 | } |
| 3754 | } |
| 3755 | |
| 3756 | // Upadate the screen and redraw the view |
| 3757 | TheAISContext()->UpdateCurrentViewer(); |
| 3758 | return 0; |
| 3759 | } |
| 3760 | |
| 3761 | static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a) |
| 3762 | { |
| 3763 | ifstream s(a[1]); |
| 3764 | BRep_Builder builder; |
| 3765 | TopoDS_Shape shape; |
| 3766 | BRepTools::Read(shape, s, builder); |
| 3767 | DBRep::Set(a[1], shape); |
| 3768 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
| 3769 | Handle(AIS_Shape) ais = new AIS_Shape(shape); |
| 3770 | Ctx->Display(ais); |
| 3771 | return 0; |
| 3772 | } |
| 3773 | |
| 3774 | //============================================================================== |
| 3775 | //function : ViewerTest::Commands |
| 3776 | //purpose : Add all the viewer command in the Draw_Interpretor |
| 3777 | //============================================================================== |
| 3778 | |
| 3779 | void ViewerTest::Commands(Draw_Interpretor& theCommands) |
| 3780 | { |
| 3781 | ViewerTest::ViewerCommands(theCommands); |
| 3782 | ViewerTest::RelationCommands(theCommands); |
| 3783 | ViewerTest::ObjectCommands(theCommands); |
| 3784 | ViewerTest::FilletCommands(theCommands); |
| 3785 | ViewerTest::VoxelCommands(theCommands); |
| 3786 | ViewerTest::OpenGlCommands(theCommands); |
| 3787 | |
| 3788 | const char *group = "AIS_Display"; |
| 3789 | |
| 3790 | // display |
| 3791 | theCommands.Add("visos", |
| 3792 | "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n" |
| 3793 | "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n", |
| 3794 | __FILE__, visos, group); |
| 3795 | |
| 3796 | theCommands.Add("vdisplay", |
| 3797 | "vdisplay [-noupdate|-update] name1 [name2] ... [name n]" |
| 3798 | "\n\t\t: Displays named objects." |
| 3799 | "\n\t\t: Option -noupdate suppresses viewer redraw call." |
| 3800 | __FILE__,VDisplay2,group); |
| 3801 | |
| 3802 | theCommands.Add ("vupdate", |
| 3803 | "vupdate name1 [name2] ... [name n]" |
| 3804 | "\n\t\t: Updates named objects in interactive context", |
| 3805 | __FILE__, VUpdate, group); |
| 3806 | |
| 3807 | theCommands.Add("verase", |
| 3808 | "verase [-noupdate|-update] [name1] ... [name n]" |
| 3809 | "\n\t\t: Erases selected or named objects." |
| 3810 | "\n\t\t: If there are no selected or named objects the whole viewer is erased.", |
| 3811 | __FILE__, VErase, group); |
| 3812 | |
| 3813 | theCommands.Add("vremove", |
| 3814 | "vremove [-noupdate|-update] [-context] [-all] [name1] ... [name n]" |
| 3815 | "or vremove [-context] -all to remove all objects" |
| 3816 | "\n\t\t: Removes selected or named objects." |
| 3817 | "\n\t\t If -context is in arguments, the objects are not deleted" |
| 3818 | "\n\t\t from the map of objects and names." |
| 3819 | "\n\t\t: Option -noupdate suppresses viewer redraw call.", |
| 3820 | __FILE__, VRemove, group); |
| 3821 | |
| 3822 | theCommands.Add("vdonly", |
| 3823 | "vdonly [-noupdate|-update] [name1] ... [name n]" |
| 3824 | "\n\t\t: Displays only selected or named objects", |
| 3825 | __FILE__,VDonly2,group); |
| 3826 | |
| 3827 | theCommands.Add("vdisplayall", |
| 3828 | "Displays all erased interactive objects (see vdir and vstate)", |
| 3829 | __FILE__,VDisplayAll,group); |
| 3830 | |
| 3831 | theCommands.Add("veraseall", |
| 3832 | "Erases all objects displayed in the viewer", |
| 3833 | __FILE__, VErase, group); |
| 3834 | |
| 3835 | theCommands.Add("verasetype", |
| 3836 | "verasetype <Type>" |
| 3837 | "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)", |
| 3838 | __FILE__,VEraseType,group); |
| 3839 | |
| 3840 | theCommands.Add("vdisplaytype", |
| 3841 | "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ", |
| 3842 | __FILE__,VDisplayType,group); |
| 3843 | |
| 3844 | theCommands.Add("vdisplaymode", |
| 3845 | "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ", |
| 3846 | __FILE__,VDispMode,group); |
| 3847 | |
| 3848 | theCommands.Add("verasemode", |
| 3849 | "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects", |
| 3850 | __FILE__,VDispMode,group); |
| 3851 | |
| 3852 | theCommands.Add("vsetdispmode", |
| 3853 | "vsetdispmode [name] mode(1,2,..)" |
| 3854 | "\n\t\t: Sets display mode for all, selected or named objects.", |
| 3855 | __FILE__,VDispMode,group); |
| 3856 | |
| 3857 | theCommands.Add("vunsetdispmode", |
| 3858 | "vunsetdispmode [name]" |
| 3859 | "\n\t\t: Unsets custom display mode for selected or named objects.", |
| 3860 | __FILE__,VDispMode,group); |
| 3861 | |
| 3862 | theCommands.Add("vdir", |
| 3863 | "Lists all objects displayed in 3D viewer", |
| 3864 | __FILE__,VDir,group); |
| 3865 | |
| 3866 | theCommands.Add("vdump", |
| 3867 | #ifdef HAVE_FREEIMAGE |
| 3868 | "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]" |
| 3869 | "\n\t\t: [width Width=0 height Height=0]" |
| 3870 | "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file", |
| 3871 | #else |
| 3872 | "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]" |
| 3873 | "\n\t\t: [width Width=0 height Height=0]" |
| 3874 | "\n\t\t: Dumps content of the active view into PPM image file", |
| 3875 | #endif |
| 3876 | __FILE__,VDump,group); |
| 3877 | |
| 3878 | theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects", |
| 3879 | __FILE__,VSubInt,group); |
| 3880 | |
| 3881 | theCommands.Add("vsetcolor", |
| 3882 | "vsetcolor [name] ColorName" |
| 3883 | "\n\t\t: Sets color for all, selected or named objects.", |
| 3884 | __FILE__,VColor2,group); |
| 3885 | |
| 3886 | theCommands.Add("vunsetcolor", |
| 3887 | "vunsetcolor [name]" |
| 3888 | "\n\t\t: Resets color for all, selected or named objects.", |
| 3889 | __FILE__,VColor2,group); |
| 3890 | |
| 3891 | theCommands.Add("vsettransparency", |
| 3892 | "vsettransparency [name] Coefficient" |
| 3893 | "\n\t\t: Sets transparency for all, selected or named objects." |
| 3894 | "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).", |
| 3895 | __FILE__,VTransparency,group); |
| 3896 | |
| 3897 | theCommands.Add("vunsettransparency", |
| 3898 | "vunsettransparency [name]" |
| 3899 | "\n\t\t: Resets transparency for all, selected or named objects.", |
| 3900 | __FILE__,VTransparency,group); |
| 3901 | |
| 3902 | theCommands.Add("vsetmaterial", |
| 3903 | "vmaterial : vmaterial [name of shape] MaterialName", |
| 3904 | __FILE__,VMaterial,group); |
| 3905 | |
| 3906 | theCommands.Add("vunsetmaterial", |
| 3907 | "vmaterial : vmaterial [name of shape]", |
| 3908 | __FILE__,VMaterial,group); |
| 3909 | |
| 3910 | theCommands.Add("vsetwidth", |
| 3911 | "vsetwidth : vwidth [name of shape] width(0->10)", |
| 3912 | __FILE__,VWidth,group); |
| 3913 | |
| 3914 | theCommands.Add("vunsetwidth", |
| 3915 | "vunsetwidth : vwidth [name of shape]", |
| 3916 | __FILE__,VWidth,group); |
| 3917 | |
| 3918 | theCommands.Add("vsetinteriorstyle", |
| 3919 | "vsetinteriorstyle : vsetinteriorstyle [name of shape] style", |
| 3920 | __FILE__,VInteriorStyle,group); |
| 3921 | |
| 3922 | theCommands.Add("vardis", |
| 3923 | "vardis : display activeareas", |
| 3924 | __FILE__,VDispAreas,group); |
| 3925 | |
| 3926 | theCommands.Add("varera", |
| 3927 | "varera : erase activeareas", |
| 3928 | __FILE__,VClearAreas,group); |
| 3929 | |
| 3930 | theCommands.Add("vsensdis", |
| 3931 | "vardisp : display active entities", |
| 3932 | __FILE__,VDispSensi,group); |
| 3933 | theCommands.Add("vsensera", |
| 3934 | "vardisp : erase active entities", |
| 3935 | __FILE__,VClearSensi,group); |
| 3936 | |
| 3937 | theCommands.Add("vselprecision", |
| 3938 | "vselprecision : vselprecision [precision_mode [tolerance_value]]", |
| 3939 | __FILE__,VSelPrecision,group); |
| 3940 | |
| 3941 | theCommands.Add("vperf", |
| 3942 | "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)", |
| 3943 | __FILE__,VPerf,group); |
| 3944 | |
| 3945 | theCommands.Add("vanimation", |
| 3946 | "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile", |
| 3947 | __FILE__,VAnimation,group); |
| 3948 | |
| 3949 | theCommands.Add("vsetshading", |
| 3950 | "vsetshading : vsetshading name Quality(default=0.0008) ", |
| 3951 | __FILE__,VShading,group); |
| 3952 | |
| 3953 | theCommands.Add("vunsetshading", |
| 3954 | "vunsetshading :vunsetshading name ", |
| 3955 | __FILE__,VShading,group); |
| 3956 | |
| 3957 | theCommands.Add ("vtexture", |
| 3958 | "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n" |
| 3959 | " [-scale u v] [-scale off]\n" |
| 3960 | " [-origin u v] [-origin off]\n" |
| 3961 | " [-repeat u v] [-repeat off]\n" |
| 3962 | " [-modulate {on | off}]" |
| 3963 | " [-default]'\n" |
| 3964 | " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n" |
| 3965 | " specifying one of the predefined textures.\n" |
| 3966 | " The options are: \n" |
| 3967 | " -scale u v : enable texture scaling and set scale factors\n" |
| 3968 | " -scale off : disable texture scaling\n" |
| 3969 | " -origin u v : enable texture origin positioning and set the origin\n" |
| 3970 | " -origin off : disable texture origin positioning\n" |
| 3971 | " -repeat u v : enable texture repeat and set texture coordinate scaling\n" |
| 3972 | " -repeat off : disable texture repeat\n" |
| 3973 | " -modulate {on | off} : enable or disable texture modulation\n" |
| 3974 | " -default : sets texture mapping default parameters\n" |
| 3975 | "or 'vtexture NameOfShape' if you want to disable texture mapping\n" |
| 3976 | "or 'vtexture NameOfShape ?' to list available textures\n", |
| 3977 | __FILE__, VTexture, group); |
| 3978 | |
| 3979 | theCommands.Add("vtexscale", |
| 3980 | "'vtexscale NameOfShape ScaleU ScaleV' \n \ |
| 3981 | or 'vtexscale NameOfShape ScaleUV' \n \ |
| 3982 | or 'vtexscale NameOfShape' to disable scaling\n ", |
| 3983 | __FILE__,VTexture,group); |
| 3984 | |
| 3985 | theCommands.Add("vtexorigin", |
| 3986 | "'vtexorigin NameOfShape UOrigin VOrigin' \n \ |
| 3987 | or 'vtexorigin NameOfShape UVOrigin' \n \ |
| 3988 | or 'vtexorigin NameOfShape' to disable origin positioning\n ", |
| 3989 | __FILE__,VTexture,group); |
| 3990 | |
| 3991 | theCommands.Add("vtexrepeat", |
| 3992 | "'vtexrepeat NameOfShape URepeat VRepeat' \n \ |
| 3993 | or 'vtexrepeat NameOfShape UVRepeat \n \ |
| 3994 | or 'vtexrepeat NameOfShape' to disable texture repeat \n ", |
| 3995 | VTexture,group); |
| 3996 | |
| 3997 | theCommands.Add("vtexdefault", |
| 3998 | "'vtexdefault NameOfShape' to set texture mapping default parameters \n", |
| 3999 | VTexture,group); |
| 4000 | |
| 4001 | theCommands.Add("vsetam", |
| 4002 | "vsetActivatedModes: vsetam mode(1->7) ", |
| 4003 | __FILE__,VActivatedMode,group); |
| 4004 | |
| 4005 | theCommands.Add("vunsetam", |
| 4006 | "vunsetActivatedModes: vunsetam ", |
| 4007 | __FILE__,VActivatedMode,group); |
| 4008 | |
| 4009 | theCommands.Add("vstate", |
| 4010 | "vstate [name1] ... [nameN]" |
| 4011 | "\n\t\t: Reports show/hidden state for selected or named objects", |
| 4012 | __FILE__,VState,group); |
| 4013 | |
| 4014 | theCommands.Add("vpickshapes", |
| 4015 | "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]", |
| 4016 | __FILE__,VPickShape,group); |
| 4017 | |
| 4018 | theCommands.Add("vtypes", |
| 4019 | "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters", |
| 4020 | VIOTypes,group); |
| 4021 | |
| 4022 | theCommands.Add("vsettransmode", |
| 4023 | "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]", |
| 4024 | __FILE__,VSetTransMode,group); |
| 4025 | |
| 4026 | theCommands.Add("vr", "vr : reading of the shape", |
| 4027 | __FILE__,vr, group); |
| 4028 | |
| 4029 | } |
| 4030 | |
| 4031 | //===================================================================== |
| 4032 | //========================= for testing Draft and Rib ================= |
| 4033 | //===================================================================== |
| 4034 | #include <BRepOffsetAPI_MakeThickSolid.hxx> |
| 4035 | #include <DBRep.hxx> |
| 4036 | #include <TopoDS_Face.hxx> |
| 4037 | #include <gp_Pln.hxx> |
| 4038 | #include <AIS_KindOfSurface.hxx> |
| 4039 | #include <BRepOffsetAPI_DraftAngle.hxx> |
| 4040 | #include <Precision.hxx> |
| 4041 | #include <BRepAlgo.hxx> |
| 4042 | #include <OSD_Environment.hxx> |
| 4043 | #include <DrawTrSurf.hxx> |
| 4044 | //#include <DbgTools.hxx> |
| 4045 | //#include <FeatAlgo_MakeLinearForm.hxx> |
| 4046 | |
| 4047 | |
| 4048 | |
| 4049 | |
| 4050 | //======================================================================= |
| 4051 | //function : IsValid |
| 4052 | //purpose : |
| 4053 | //======================================================================= |
| 4054 | static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs, |
| 4055 | const TopoDS_Shape& theResult, |
| 4056 | const Standard_Boolean closedSolid, |
| 4057 | const Standard_Boolean GeomCtrl) |
| 4058 | { |
| 4059 | OSD_Environment check ("DONT_SWITCH_IS_VALID") ; |
| 4060 | TCollection_AsciiString checkValid = check.Value(); |
| 4061 | Standard_Boolean ToCheck = Standard_True; |
| 4062 | if (!checkValid.IsEmpty()) { |
| 4063 | #ifdef DEB |
| 4064 | cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n"; |
| 4065 | #endif |
| 4066 | if ( checkValid=="true" || checkValid=="TRUE" ) { |
| 4067 | ToCheck= Standard_False; |
| 4068 | } |
| 4069 | } else { |
| 4070 | #ifdef DEB |
| 4071 | cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n"; |
| 4072 | #endif |
| 4073 | } |
| 4074 | Standard_Boolean IsValid = Standard_True; |
| 4075 | if (ToCheck) |
| 4076 | IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ; |
| 4077 | return IsValid; |
| 4078 | |
| 4079 | } |
| 4080 | |
| 4081 | //=============================================================================== |
| 4082 | // TDraft : test draft, uses AIS Viewer |
| 4083 | // Solid Face Plane Angle Reverse |
| 4084 | //=============================================================================== |
| 4085 | static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 4086 | { |
| 4087 | if (argc < 5) return 1; |
| 4088 | // argv[1] - TopoDS_Shape Solid |
| 4089 | // argv[2] - TopoDS_Shape Face |
| 4090 | // argv[3] - TopoDS_Shape Plane |
| 4091 | // argv[4] - Standard_Real Angle |
| 4092 | // argv[5] - Standard_Integer Reverse |
| 4093 | |
| 4094 | // Sprintf(prefix, argv[1]); |
| 4095 | Standard_Real anAngle = 0; |
| 4096 | Standard_Boolean Rev = Standard_False; |
| 4097 | Standard_Integer rev = 0; |
| 4098 | TopoDS_Shape Solid = GetShapeFromName(argv[1]); |
| 4099 | TopoDS_Shape face = GetShapeFromName(argv[2]); |
| 4100 | TopoDS_Face Face = TopoDS::Face(face); |
| 4101 | TopoDS_Shape Plane = GetShapeFromName(argv[3]); |
| 4102 | if (Plane.IsNull ()) { |
| 4103 | di << "TEST : Plane is NULL" << "\n"; |
| 4104 | return 1; |
| 4105 | } |
| 4106 | anAngle = Draw::Atof(argv[4]); |
| 4107 | anAngle = 2*M_PI * anAngle / 360.0; |
| 4108 | gp_Pln aPln; |
| 4109 | Handle( Geom_Surface )aSurf; |
| 4110 | AIS_KindOfSurface aSurfType; |
| 4111 | Standard_Real Offset; |
| 4112 | gp_Dir aDir; |
| 4113 | if(argc > 4) { // == 5 |
| 4114 | rev = Draw::Atoi(argv[5]); |
| 4115 | Rev = (rev)? Standard_True : Standard_False; |
| 4116 | } |
| 4117 | |
| 4118 | TopoDS_Face face2 = TopoDS::Face(Plane); |
| 4119 | if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset)) |
| 4120 | { |
| 4121 | di << "TEST : Can't find plane" << "\n"; |
| 4122 | return 1; |
| 4123 | } |
| 4124 | |
| 4125 | aDir = aPln.Axis().Direction(); |
| 4126 | if (!aPln.Direct()) |
| 4127 | aDir.Reverse(); |
| 4128 | if (Plane.Orientation() == TopAbs_REVERSED) |
| 4129 | aDir.Reverse(); |
| 4130 | di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n"; |
| 4131 | |
| 4132 | BRepOffsetAPI_DraftAngle Draft (Solid); |
| 4133 | |
| 4134 | if(Abs(anAngle)< Precision::Angular()) { |
| 4135 | di << "TEST : NULL angle" << "\n"; |
| 4136 | return 1;} |
| 4137 | |
| 4138 | if(Rev) anAngle = - anAngle; |
| 4139 | Draft.Add (Face, aDir, anAngle, aPln); |
| 4140 | Draft.Build (); |
| 4141 | if (!Draft.IsDone()) { |
| 4142 | di << "TEST : Draft Not DONE " << "\n"; |
| 4143 | return 1; |
| 4144 | } |
| 4145 | TopTools_ListOfShape Larg; |
| 4146 | Larg.Append(Solid); |
| 4147 | if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) { |
| 4148 | di << "TEST : DesignAlgo returns Not valid" << "\n"; |
| 4149 | return 1; |
| 4150 | } |
| 4151 | |
| 4152 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
| 4153 | Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape()); |
| 4154 | |
| 4155 | if ( !ais.IsNull() ) { |
| 4156 | ais->SetColor(DEFAULT_COLOR); |
| 4157 | ais->SetMaterial(DEFAULT_MATERIAL); |
| 4158 | // Display the AIS_Shape without redraw |
| 4159 | Ctx->Display(ais, Standard_False); |
| 4160 | |
| 4161 | const char *Name = "draft1"; |
| 4162 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name); |
| 4163 | if (IsBound) { |
| 4164 | Handle(AIS_InteractiveObject) an_object = |
| 4165 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name)); |
| 4166 | if (!an_object.IsNull()) { |
| 4167 | Ctx->Remove(an_object, |
| 4168 | Standard_True) ; |
| 4169 | GetMapOfAIS().UnBind2(Name) ; |
| 4170 | } |
| 4171 | } |
| 4172 | GetMapOfAIS().Bind(ais, Name); |
| 4173 | // DBRep::Set("draft", ais->Shape()); |
| 4174 | } |
| 4175 | Ctx->Display(ais, Standard_True); |
| 4176 | return 0; |
| 4177 | } |
| 4178 | |
| 4179 | //============================================================================== |
| 4180 | //function : splitParameter |
| 4181 | //purpose : Split parameter string to parameter name and parameter value |
| 4182 | //============================================================================== |
| 4183 | Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString, |
| 4184 | TCollection_AsciiString& theName, |
| 4185 | TCollection_AsciiString& theValue) |
| 4186 | { |
| 4187 | Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length()); |
| 4188 | |
| 4189 | if (aParamNameEnd == 0) |
| 4190 | { |
| 4191 | return Standard_False; |
| 4192 | } |
| 4193 | |
| 4194 | TCollection_AsciiString aString (theString); |
| 4195 | if (aParamNameEnd != 0) |
| 4196 | { |
| 4197 | theValue = aString.Split (aParamNameEnd); |
| 4198 | aString.Split (aString.Length() - 1); |
| 4199 | theName = aString; |
| 4200 | } |
| 4201 | |
| 4202 | return Standard_True; |
| 4203 | } |
| 4204 | |
| 4205 | //============================================================================ |
| 4206 | // MyCommands |
| 4207 | //============================================================================ |
| 4208 | void ViewerTest::MyCommands( Draw_Interpretor& theCommands) |
| 4209 | { |
| 4210 | |
| 4211 | DrawTrSurf::BasicCommands(theCommands); |
| 4212 | const char* group = "Check Features Operations commands"; |
| 4213 | |
| 4214 | theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse", |
| 4215 | __FILE__, |
| 4216 | &TDraft,group); //Draft_Modification |
| 4217 | } |
| 4218 | |
| 4219 | //============================================================================== |
| 4220 | // ViewerTest::Factory |
| 4221 | //============================================================================== |
| 4222 | void ViewerTest::Factory(Draw_Interpretor& theDI) |
| 4223 | { |
| 4224 | // definition of Viewer Command |
| 4225 | ViewerTest::Commands(theDI); |
| 4226 | ViewerTest::AviCommands(theDI); |
| 4227 | |
| 4228 | #ifdef DEB |
| 4229 | theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n"; |
| 4230 | #endif |
| 4231 | } |
| 4232 | |
| 4233 | // Declare entry point PLUGINFACTORY |
| 4234 | DPLUGIN(ViewerTest) |