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