| 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 | #include <Standard_Stream.hxx> |
| 18 | |
| 19 | #include <ViewerTest.hxx> |
| 20 | #include <ViewerTest_CmdParser.hxx> |
| 21 | |
| 22 | #include <Draw.hxx> |
| 23 | #include <TopLoc_Location.hxx> |
| 24 | #include <TopTools_HArray1OfShape.hxx> |
| 25 | #include <TColStd_HArray1OfTransient.hxx> |
| 26 | #include <TColStd_SequenceOfAsciiString.hxx> |
| 27 | #include <TColStd_HSequenceOfAsciiString.hxx> |
| 28 | #include <TColStd_MapOfTransient.hxx> |
| 29 | #include <OSD_Timer.hxx> |
| 30 | #include <Geom_Axis2Placement.hxx> |
| 31 | #include <Geom_Axis1Placement.hxx> |
| 32 | #include <gp_Trsf.hxx> |
| 33 | #include <TopExp_Explorer.hxx> |
| 34 | #include <BRepAdaptor_Curve.hxx> |
| 35 | #include <StdSelect_ShapeTypeFilter.hxx> |
| 36 | #include <AIS.hxx> |
| 37 | #include <AIS_ColoredShape.hxx> |
| 38 | #include <AIS_InteractiveObject.hxx> |
| 39 | #include <AIS_Trihedron.hxx> |
| 40 | #include <AIS_Axis.hxx> |
| 41 | #include <AIS_Relation.hxx> |
| 42 | #include <AIS_TypeFilter.hxx> |
| 43 | #include <AIS_SignatureFilter.hxx> |
| 44 | #include <AIS_ListOfInteractive.hxx> |
| 45 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
| 46 | #include <Aspect_InteriorStyle.hxx> |
| 47 | #include <Aspect_Window.hxx> |
| 48 | #include <Graphic3d_AspectFillArea3d.hxx> |
| 49 | #include <Graphic3d_AspectLine3d.hxx> |
| 50 | #include <Graphic3d_CStructure.hxx> |
| 51 | #include <Graphic3d_Texture2Dmanual.hxx> |
| 52 | #include <Graphic3d_GraphicDriver.hxx> |
| 53 | #include <Graphic3d_MediaTextureSet.hxx> |
| 54 | #include <Image_AlienPixMap.hxx> |
| 55 | #include <OSD_File.hxx> |
| 56 | #include <Prs3d_Drawer.hxx> |
| 57 | #include <Prs3d_ShadingAspect.hxx> |
| 58 | #include <Prs3d_IsoAspect.hxx> |
| 59 | #include <Prs3d_PointAspect.hxx> |
| 60 | #include <Select3D_SensitiveWire.hxx> |
| 61 | #include <Select3D_SensitivePrimitiveArray.hxx> |
| 62 | #include <SelectMgr_EntityOwner.hxx> |
| 63 | #include <StdSelect_BRepOwner.hxx> |
| 64 | #include <StdSelect_ViewerSelector3d.hxx> |
| 65 | #include <TopTools_MapOfShape.hxx> |
| 66 | #include <ViewerTest_AutoUpdater.hxx> |
| 67 | |
| 68 | #include <stdio.h> |
| 69 | |
| 70 | #include <Draw_Interpretor.hxx> |
| 71 | #include <TCollection_AsciiString.hxx> |
| 72 | #include <Draw_PluginMacro.hxx> |
| 73 | |
| 74 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); |
| 75 | |
| 76 | #include <Quantity_Color.hxx> |
| 77 | #include <Quantity_NameOfColor.hxx> |
| 78 | |
| 79 | #include <Graphic3d_NameOfMaterial.hxx> |
| 80 | |
| 81 | #define DEFAULT_COLOR Quantity_NOC_GOLDENROD |
| 82 | #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN |
| 83 | #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS |
| 84 | |
| 85 | namespace |
| 86 | { |
| 87 | |
| 88 | const Standard_Integer THE_MAX_INTEGER_COLOR_COMPONENT = 255; |
| 89 | |
| 90 | const Standard_ShortReal THE_MAX_REAL_COLOR_COMPONENT = 1.0f; |
| 91 | |
| 92 | //! Parses string and get an integer color component (only values within range 0 .. 255 are allowed) |
| 93 | //! @param theColorComponentString the string representing the color component |
| 94 | //! @param theIntegerColorComponent an integer color component that is a result of parsing |
| 95 | //! @return true if parsing was successful, or false otherwise |
| 96 | static bool parseNumericalColorComponent (const Standard_CString theColorComponentString, |
| 97 | Standard_Integer& theIntegerColorComponent) |
| 98 | { |
| 99 | Standard_Integer anIntegerColorComponent; |
| 100 | if (!Draw::ParseInteger (theColorComponentString, anIntegerColorComponent)) |
| 101 | { |
| 102 | return false; |
| 103 | } |
| 104 | if ((anIntegerColorComponent < 0) || (anIntegerColorComponent > THE_MAX_INTEGER_COLOR_COMPONENT)) |
| 105 | { |
| 106 | return false; |
| 107 | } |
| 108 | theIntegerColorComponent = anIntegerColorComponent; |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | //! Parses the string and gets a real color component from it (only values within range 0.0 .. 1.0 are allowed) |
| 113 | //! @param theColorComponentString the string representing the color component |
| 114 | //! @param theRealColorComponent a real color component that is a result of parsing |
| 115 | //! @return true if parsing was successful, or false otherwise |
| 116 | static bool parseNumericalColorComponent (const Standard_CString theColorComponentString, |
| 117 | Standard_ShortReal& theRealColorComponent) |
| 118 | { |
| 119 | Standard_Real aRealColorComponent; |
| 120 | if (!Draw::ParseReal (theColorComponentString, aRealColorComponent)) |
| 121 | { |
| 122 | return false; |
| 123 | } |
| 124 | const Standard_ShortReal aShortRealColorComponent = static_cast<Standard_ShortReal> (aRealColorComponent); |
| 125 | if ((aShortRealColorComponent < 0.0f) || (aShortRealColorComponent > THE_MAX_REAL_COLOR_COMPONENT)) |
| 126 | { |
| 127 | return false; |
| 128 | } |
| 129 | theRealColorComponent = aShortRealColorComponent; |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | //! Parses the string and gets a real color component from it (integer values 2 .. 255 are scaled to the 0.0 .. 1.0 |
| 134 | //! range, values 0 and 1 are leaved as they are) |
| 135 | //! @param theColorComponentString the string representing the color component |
| 136 | //! @param theColorComponent a color component that is a result of parsing |
| 137 | //! @return true if parsing was successful, or false otherwise |
| 138 | static bool parseColorComponent (const Standard_CString theColorComponentString, |
| 139 | Standard_ShortReal& theColorComponent) |
| 140 | { |
| 141 | Standard_Integer anIntegerColorComponent; |
| 142 | if (parseNumericalColorComponent (theColorComponentString, anIntegerColorComponent)) |
| 143 | { |
| 144 | if (anIntegerColorComponent == 1) |
| 145 | { |
| 146 | theColorComponent = THE_MAX_REAL_COLOR_COMPONENT; |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | theColorComponent = anIntegerColorComponent * 1.0f / THE_MAX_INTEGER_COLOR_COMPONENT; |
| 151 | } |
| 152 | return true; |
| 153 | } |
| 154 | return parseNumericalColorComponent (theColorComponentString, theColorComponent); |
| 155 | } |
| 156 | |
| 157 | //! Parses the array of strings and gets an integer color (only values within range 0 .. 255 are allowed and at least |
| 158 | //! one of components must be greater than 1) |
| 159 | //! @tparam TheNumber the type of resulting color vector elements |
| 160 | //! @param theNumberOfColorComponents the number of color components |
| 161 | //! @param theColorComponentStrings the array of strings representing color components |
| 162 | //! @param theNumericalColor a 4-component vector that is a result of parsing |
| 163 | //! @return true if parsing was successful, or false otherwise |
| 164 | template <typename TheNumber> |
| 165 | static bool parseNumericalColor (Standard_Integer& theNumberOfColorComponents, |
| 166 | const char* const* const theColorComponentStrings, |
| 167 | NCollection_Vec4<TheNumber>& theNumericalColor) |
| 168 | { |
| 169 | for (Standard_Integer aColorComponentIndex = 0; aColorComponentIndex < theNumberOfColorComponents; |
| 170 | ++aColorComponentIndex) |
| 171 | { |
| 172 | const char* const aColorComponentString = theColorComponentStrings[aColorComponentIndex]; |
| 173 | TheNumber aNumericalColorComponent; |
| 174 | if (parseNumericalColorComponent (aColorComponentString, aNumericalColorComponent)) |
| 175 | { |
| 176 | theNumericalColor[aColorComponentIndex] = aNumericalColorComponent; |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | if (aColorComponentIndex == 3) |
| 181 | { |
| 182 | theNumberOfColorComponents = 3; |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | return false; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | return true; |
| 191 | } |
| 192 | |
| 193 | //! Parses an array of strings and get an integer color (only values within range 0 .. 255 are allowed and at least |
| 194 | //! one of components must be greater than 1) |
| 195 | //! @param theNumberOfColorComponents the number of color components |
| 196 | //! @param theColorComponentStrings the array of strings representing color components |
| 197 | //! @param theColor a color that is a result of parsing |
| 198 | //! @return true if parsing was successful, or false otherwise |
| 199 | static bool parseIntegerColor (Standard_Integer& theNumberOfColorComponents, |
| 200 | const char* const* const theColorComponentStrings, |
| 201 | Quantity_ColorRGBA& theColor) |
| 202 | { |
| 203 | const Standard_Integer THE_COLOR_COMPONENT_NOT_PARSED = -1; |
| 204 | Graphic3d_Vec4i anIntegerColor (THE_COLOR_COMPONENT_NOT_PARSED); |
| 205 | if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor) |
| 206 | || anIntegerColor.maxComp() <= 1) |
| 207 | { |
| 208 | return false; |
| 209 | } |
| 210 | if (anIntegerColor.a() == THE_COLOR_COMPONENT_NOT_PARSED) |
| 211 | { |
| 212 | anIntegerColor.a() = THE_MAX_INTEGER_COLOR_COMPONENT; |
| 213 | } |
| 214 | |
| 215 | const Graphic3d_Vec4 aRealColor = Graphic3d_Vec4 (anIntegerColor) / static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT); |
| 216 | theColor = Quantity_ColorRGBA (Quantity_ColorRGBA::Convert_sRGB_To_LinearRGB (aRealColor)); |
| 217 | return true; |
| 218 | } |
| 219 | |
| 220 | //! Parses an array of strings and get a real color (only values within range 0.0 .. 1.0 are allowed) |
| 221 | //! @param theNumberOfColorComponents the number of color components |
| 222 | //! @param theColorComponentStrings the array of strings representing color components |
| 223 | //! @param theColor a color that is a result of parsing |
| 224 | //! @return true if parsing was successful, or false otherwise |
| 225 | static bool parseRealColor (Standard_Integer& theNumberOfColorComponents, |
| 226 | const char* const* const theColorComponentStrings, |
| 227 | Quantity_ColorRGBA& theColor) |
| 228 | { |
| 229 | Graphic3d_Vec4 aRealColor (THE_MAX_REAL_COLOR_COMPONENT); |
| 230 | if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, aRealColor)) |
| 231 | { |
| 232 | return false; |
| 233 | } |
| 234 | theColor = Quantity_ColorRGBA (aRealColor); |
| 235 | return true; |
| 236 | } |
| 237 | |
| 238 | } // namespace |
| 239 | |
| 240 | //======================================================================= |
| 241 | // function : GetColorFromName |
| 242 | // purpose : get the Quantity_NameOfColor from a string |
| 243 | //======================================================================= |
| 244 | |
| 245 | Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName) |
| 246 | { |
| 247 | Quantity_NameOfColor aColor = DEFAULT_COLOR; |
| 248 | Quantity_Color::ColorFromName (theName, aColor); |
| 249 | return aColor; |
| 250 | } |
| 251 | |
| 252 | //======================================================================= |
| 253 | // function : parseColor |
| 254 | // purpose : |
| 255 | //======================================================================= |
| 256 | Standard_Integer ViewerTest::parseColor (const Standard_Integer theArgNb, |
| 257 | const char* const* const theArgVec, |
| 258 | Quantity_ColorRGBA& theColor, |
| 259 | const bool theToParseAlpha) |
| 260 | { |
| 261 | if ((theArgNb >= 1) && Quantity_ColorRGBA::ColorFromHex (theArgVec[0], theColor, !theToParseAlpha)) |
| 262 | { |
| 263 | return 1; |
| 264 | } |
| 265 | if (theArgNb >= 1 && Quantity_ColorRGBA::ColorFromName (theArgVec[0], theColor)) |
| 266 | { |
| 267 | if (theArgNb >= 2 && theToParseAlpha) |
| 268 | { |
| 269 | const Standard_CString anAlphaStr = theArgVec[1]; |
| 270 | Standard_ShortReal anAlphaComponent; |
| 271 | if (parseColorComponent (anAlphaStr, anAlphaComponent)) |
| 272 | { |
| 273 | theColor.SetAlpha (anAlphaComponent); |
| 274 | return 2; |
| 275 | } |
| 276 | } |
| 277 | return 1; |
| 278 | } |
| 279 | if (theArgNb >= 3) |
| 280 | { |
| 281 | const Standard_Integer aNumberOfColorComponentsToParse = Min (theArgNb, theToParseAlpha ? 4 : 3); |
| 282 | Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse; |
| 283 | if (parseIntegerColor (aNumberOfColorComponentsParsed, theArgVec, theColor)) |
| 284 | { |
| 285 | return aNumberOfColorComponentsParsed; |
| 286 | } |
| 287 | aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse; |
| 288 | if (parseRealColor (aNumberOfColorComponentsParsed, theArgVec, theColor)) |
| 289 | { |
| 290 | return aNumberOfColorComponentsParsed; |
| 291 | } |
| 292 | return 0; |
| 293 | } |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | //======================================================================= |
| 298 | //function : ParseOnOff |
| 299 | //purpose : |
| 300 | //======================================================================= |
| 301 | Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg, |
| 302 | Standard_Boolean& theIsOn) |
| 303 | { |
| 304 | TCollection_AsciiString aFlag(theArg); |
| 305 | aFlag.LowerCase(); |
| 306 | if (aFlag == "on" |
| 307 | || aFlag == "1") |
| 308 | { |
| 309 | theIsOn = Standard_True; |
| 310 | return Standard_True; |
| 311 | } |
| 312 | else if (aFlag == "off" |
| 313 | || aFlag == "0") |
| 314 | { |
| 315 | theIsOn = Standard_False; |
| 316 | return Standard_True; |
| 317 | } |
| 318 | return Standard_False; |
| 319 | } |
| 320 | |
| 321 | //======================================================================= |
| 322 | //function : GetSelectedShapes |
| 323 | //purpose : |
| 324 | //======================================================================= |
| 325 | void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes) |
| 326 | { |
| 327 | for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected()) |
| 328 | { |
| 329 | TopoDS_Shape aShape = GetAISContext()->SelectedShape(); |
| 330 | if (!aShape.IsNull()) |
| 331 | { |
| 332 | theSelectedShapes.Append (aShape); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | //======================================================================= |
| 338 | //function : ParseLineType |
| 339 | //purpose : |
| 340 | //======================================================================= |
| 341 | Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg, |
| 342 | Aspect_TypeOfLine& theType) |
| 343 | { |
| 344 | TCollection_AsciiString aTypeStr (theArg); |
| 345 | aTypeStr.LowerCase(); |
| 346 | if (aTypeStr == "empty") |
| 347 | { |
| 348 | theType = Aspect_TOL_EMPTY; |
| 349 | } |
| 350 | else if (aTypeStr == "solid") |
| 351 | { |
| 352 | theType = Aspect_TOL_SOLID; |
| 353 | } |
| 354 | else if (aTypeStr == "dot") |
| 355 | { |
| 356 | theType = Aspect_TOL_DOT; |
| 357 | } |
| 358 | else if (aTypeStr == "dash") |
| 359 | { |
| 360 | theType = Aspect_TOL_DASH; |
| 361 | } |
| 362 | else if (aTypeStr == "dotdash") |
| 363 | { |
| 364 | theType = Aspect_TOL_DOTDASH; |
| 365 | } |
| 366 | else if (aTypeStr.IsIntegerValue()) |
| 367 | { |
| 368 | const int aTypeInt = aTypeStr.IntegerValue(); |
| 369 | if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED) |
| 370 | { |
| 371 | return Standard_False; |
| 372 | } |
| 373 | theType = (Aspect_TypeOfLine )aTypeInt; |
| 374 | } |
| 375 | else |
| 376 | { |
| 377 | return Standard_False; |
| 378 | } |
| 379 | return Standard_True; |
| 380 | } |
| 381 | |
| 382 | //======================================================================= |
| 383 | //function : ParseMarkerType |
| 384 | //purpose : |
| 385 | //======================================================================= |
| 386 | Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg, |
| 387 | Aspect_TypeOfMarker& theType, |
| 388 | Handle(Image_PixMap)& theImage) |
| 389 | { |
| 390 | theImage.Nullify(); |
| 391 | TCollection_AsciiString aTypeStr (theArg); |
| 392 | aTypeStr.LowerCase(); |
| 393 | if (aTypeStr == "empty") |
| 394 | { |
| 395 | theType = Aspect_TOM_EMPTY; |
| 396 | } |
| 397 | else if (aTypeStr == "point" |
| 398 | || aTypeStr == "dot" |
| 399 | || aTypeStr == ".") |
| 400 | { |
| 401 | theType = Aspect_TOM_POINT; |
| 402 | } |
| 403 | else if (aTypeStr == "plus" |
| 404 | || aTypeStr == "+") |
| 405 | { |
| 406 | theType = Aspect_TOM_PLUS; |
| 407 | } |
| 408 | else if (aTypeStr == "star" |
| 409 | || aTypeStr == "*") |
| 410 | { |
| 411 | theType = Aspect_TOM_STAR; |
| 412 | } |
| 413 | else if (aTypeStr == "cross" |
| 414 | || aTypeStr == "x") |
| 415 | { |
| 416 | theType = Aspect_TOM_X; |
| 417 | } |
| 418 | else if (aTypeStr == "circle" |
| 419 | || aTypeStr == "o") |
| 420 | { |
| 421 | theType = Aspect_TOM_O; |
| 422 | } |
| 423 | else if (aTypeStr == "pointincircle") |
| 424 | { |
| 425 | theType = Aspect_TOM_O_POINT; |
| 426 | } |
| 427 | else if (aTypeStr == "plusincircle") |
| 428 | { |
| 429 | theType = Aspect_TOM_O_PLUS; |
| 430 | } |
| 431 | else if (aTypeStr == "starincircle") |
| 432 | { |
| 433 | theType = Aspect_TOM_O_STAR; |
| 434 | } |
| 435 | else if (aTypeStr == "crossincircle" |
| 436 | || aTypeStr == "xcircle") |
| 437 | { |
| 438 | theType = Aspect_TOM_O_X; |
| 439 | } |
| 440 | else if (aTypeStr == "ring1") |
| 441 | { |
| 442 | theType = Aspect_TOM_RING1; |
| 443 | } |
| 444 | else if (aTypeStr == "ring2") |
| 445 | { |
| 446 | theType = Aspect_TOM_RING2; |
| 447 | } |
| 448 | else if (aTypeStr == "ring" |
| 449 | || aTypeStr == "ring3") |
| 450 | { |
| 451 | theType = Aspect_TOM_RING3; |
| 452 | } |
| 453 | else if (aTypeStr == "ball") |
| 454 | { |
| 455 | theType = Aspect_TOM_BALL; |
| 456 | } |
| 457 | else if (aTypeStr.IsIntegerValue()) |
| 458 | { |
| 459 | const int aTypeInt = aTypeStr.IntegerValue(); |
| 460 | if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED) |
| 461 | { |
| 462 | return Standard_False; |
| 463 | } |
| 464 | theType = (Aspect_TypeOfMarker )aTypeInt; |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | theType = Aspect_TOM_USERDEFINED; |
| 469 | Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap(); |
| 470 | if (!anImage->Load (theArg)) |
| 471 | { |
| 472 | return Standard_False; |
| 473 | } |
| 474 | if (anImage->Format() == Image_Format_Gray) |
| 475 | { |
| 476 | anImage->SetFormat (Image_Format_Alpha); |
| 477 | } |
| 478 | else if (anImage->Format() == Image_Format_GrayF) |
| 479 | { |
| 480 | anImage->SetFormat (Image_Format_AlphaF); |
| 481 | } |
| 482 | theImage = anImage; |
| 483 | } |
| 484 | return Standard_True; |
| 485 | } |
| 486 | |
| 487 | //======================================================================= |
| 488 | //function : ParseShadingModel |
| 489 | //purpose : |
| 490 | //======================================================================= |
| 491 | Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg, |
| 492 | Graphic3d_TypeOfShadingModel& theModel) |
| 493 | { |
| 494 | TCollection_AsciiString aTypeStr (theArg); |
| 495 | aTypeStr.LowerCase(); |
| 496 | if (aTypeStr == "unlit" |
| 497 | || aTypeStr == "color" |
| 498 | || aTypeStr == "none") |
| 499 | { |
| 500 | theModel = Graphic3d_TOSM_UNLIT; |
| 501 | } |
| 502 | else if (aTypeStr == "flat" |
| 503 | || aTypeStr == "facet") |
| 504 | { |
| 505 | theModel = Graphic3d_TOSM_FACET; |
| 506 | } |
| 507 | else if (aTypeStr == "gouraud" |
| 508 | || aTypeStr == "vertex" |
| 509 | || aTypeStr == "vert") |
| 510 | { |
| 511 | theModel = Graphic3d_TOSM_VERTEX; |
| 512 | } |
| 513 | else if (aTypeStr == "phong" |
| 514 | || aTypeStr == "fragment" |
| 515 | || aTypeStr == "frag" |
| 516 | || aTypeStr == "pixel") |
| 517 | { |
| 518 | theModel = Graphic3d_TOSM_FRAGMENT; |
| 519 | } |
| 520 | else if (aTypeStr == "pbr") |
| 521 | { |
| 522 | theModel = Graphic3d_TOSM_PBR; |
| 523 | } |
| 524 | else if (aTypeStr == "pbr_facet") |
| 525 | { |
| 526 | theModel = Graphic3d_TOSM_PBR_FACET; |
| 527 | } |
| 528 | else if (aTypeStr == "default" |
| 529 | || aTypeStr == "def") |
| 530 | { |
| 531 | theModel = Graphic3d_TOSM_DEFAULT; |
| 532 | } |
| 533 | else if (aTypeStr.IsIntegerValue()) |
| 534 | { |
| 535 | const int aTypeInt = aTypeStr.IntegerValue(); |
| 536 | if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB) |
| 537 | { |
| 538 | return Standard_False; |
| 539 | } |
| 540 | theModel = (Graphic3d_TypeOfShadingModel)aTypeInt; |
| 541 | } |
| 542 | else |
| 543 | { |
| 544 | return Standard_False; |
| 545 | } |
| 546 | return Standard_True; |
| 547 | } |
| 548 | |
| 549 | //======================================================================= |
| 550 | //function : parseZLayer |
| 551 | //purpose : |
| 552 | //======================================================================= |
| 553 | Standard_Boolean ViewerTest::parseZLayer (Standard_CString theArg, |
| 554 | Standard_Boolean theToAllowInteger, |
| 555 | Graphic3d_ZLayerId& theLayer) |
| 556 | { |
| 557 | TCollection_AsciiString aName (theArg); |
| 558 | aName.LowerCase(); |
| 559 | if (aName == "default" |
| 560 | || aName == "def") |
| 561 | { |
| 562 | theLayer = Graphic3d_ZLayerId_Default; |
| 563 | } |
| 564 | else if (aName == "top") |
| 565 | { |
| 566 | theLayer = Graphic3d_ZLayerId_Top; |
| 567 | } |
| 568 | else if (aName == "topmost") |
| 569 | { |
| 570 | theLayer = Graphic3d_ZLayerId_Topmost; |
| 571 | } |
| 572 | else if (aName == "overlay" |
| 573 | || aName == "toposd") |
| 574 | { |
| 575 | theLayer = Graphic3d_ZLayerId_TopOSD; |
| 576 | } |
| 577 | else if (aName == "underlay" |
| 578 | || aName == "botosd") |
| 579 | { |
| 580 | theLayer = Graphic3d_ZLayerId_BotOSD; |
| 581 | } |
| 582 | else if (aName == "undefined") |
| 583 | { |
| 584 | theLayer = Graphic3d_ZLayerId_UNKNOWN; |
| 585 | } |
| 586 | else if (!GetAISContext().IsNull()) |
| 587 | { |
| 588 | const Handle(V3d_Viewer)& aViewer = ViewerTest::GetAISContext()->CurrentViewer(); |
| 589 | TColStd_SequenceOfInteger aLayers; |
| 590 | aViewer->GetAllZLayers (aLayers); |
| 591 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) |
| 592 | { |
| 593 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); |
| 594 | if (TCollection_AsciiString::IsSameString (aSettings.Name(), aName, Standard_False)) |
| 595 | { |
| 596 | theLayer = aLayeriter.Value(); |
| 597 | return true; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | if (!theToAllowInteger |
| 602 | || !aName.IsIntegerValue()) |
| 603 | { |
| 604 | return false; |
| 605 | } |
| 606 | Graphic3d_ZLayerId aLayer = aName.IntegerValue(); |
| 607 | if (aLayer == Graphic3d_ZLayerId_UNKNOWN |
| 608 | || std::find (aLayers.begin(), aLayers.end(), aLayer) != aLayers.end()) |
| 609 | { |
| 610 | theLayer = aLayer; |
| 611 | return true; |
| 612 | } |
| 613 | return false; |
| 614 | } |
| 615 | return true; |
| 616 | } |
| 617 | |
| 618 | //======================================================================= |
| 619 | //function : GetTypeNames |
| 620 | //purpose : |
| 621 | //======================================================================= |
| 622 | static const char** GetTypeNames() |
| 623 | { |
| 624 | static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane", |
| 625 | "Shape","ConnectedShape","MultiConn.Shape", |
| 626 | "ConnectedInter.","MultiConn.", |
| 627 | "Constraint","Dimension"}; |
| 628 | static const char** ThePointer = names; |
| 629 | return ThePointer; |
| 630 | } |
| 631 | |
| 632 | //======================================================================= |
| 633 | //function : GetTypeAndSignfromString |
| 634 | //purpose : |
| 635 | //======================================================================= |
| 636 | void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign) |
| 637 | { |
| 638 | const char ** thefullnames = GetTypeNames(); |
| 639 | Standard_Integer index(-1); |
| 640 | |
| 641 | for(Standard_Integer i=0;i<=13 && index==-1;i++) |
| 642 | if(!strcasecmp(name,thefullnames[i])) |
| 643 | index = i; |
| 644 | |
| 645 | if(index ==-1){ |
| 646 | TheType = AIS_KOI_None; |
| 647 | TheSign = -1; |
| 648 | return; |
| 649 | } |
| 650 | |
| 651 | if(index<=6){ |
| 652 | TheType = AIS_KOI_Datum; |
| 653 | TheSign = index+1; |
| 654 | } |
| 655 | else if (index <=9){ |
| 656 | TheType = AIS_KOI_Shape; |
| 657 | TheSign = index-7; |
| 658 | } |
| 659 | else if(index<=11){ |
| 660 | TheType = AIS_KOI_Object; |
| 661 | TheSign = index-10; |
| 662 | } |
| 663 | else{ |
| 664 | TheType = AIS_KOI_Relation; |
| 665 | TheSign = index-12; |
| 666 | } |
| 667 | |
| 668 | } |
| 669 | |
| 670 | |
| 671 | |
| 672 | #include <string.h> |
| 673 | #include <Draw_Interpretor.hxx> |
| 674 | #include <Draw.hxx> |
| 675 | #include <Draw_Appli.hxx> |
| 676 | #include <DBRep.hxx> |
| 677 | |
| 678 | |
| 679 | #include <TCollection_AsciiString.hxx> |
| 680 | #include <V3d_Viewer.hxx> |
| 681 | #include <V3d_View.hxx> |
| 682 | #include <V3d.hxx> |
| 683 | |
| 684 | #include <AIS_InteractiveContext.hxx> |
| 685 | #include <AIS_Shape.hxx> |
| 686 | #include <AIS_DisplayMode.hxx> |
| 687 | #include <TColStd_MapOfInteger.hxx> |
| 688 | #include <AIS_MapOfInteractive.hxx> |
| 689 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
| 690 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
| 691 | #include <ViewerTest_EventManager.hxx> |
| 692 | |
| 693 | #include <TopoDS_Solid.hxx> |
| 694 | #include <BRepTools.hxx> |
| 695 | #include <BRep_Builder.hxx> |
| 696 | #include <TopAbs_ShapeEnum.hxx> |
| 697 | |
| 698 | #include <TopoDS.hxx> |
| 699 | #include <BRep_Tool.hxx> |
| 700 | |
| 701 | |
| 702 | #include <Draw_Window.hxx> |
| 703 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
| 704 | #include <AIS_ListOfInteractive.hxx> |
| 705 | #include <AIS_DisplayMode.hxx> |
| 706 | #include <TopTools_ListOfShape.hxx> |
| 707 | #include <BRepOffsetAPI_MakeThickSolid.hxx> |
| 708 | |
| 709 | //============================================================================== |
| 710 | // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES |
| 711 | //============================================================================== |
| 712 | Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){ |
| 713 | static ViewerTest_DoubleMapOfInteractiveAndName TheMap; |
| 714 | return TheMap; |
| 715 | } |
| 716 | |
| 717 | //======================================================================= |
| 718 | //function : Display |
| 719 | //purpose : |
| 720 | //======================================================================= |
| 721 | Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName, |
| 722 | const Handle(AIS_InteractiveObject)& theObject, |
| 723 | const Standard_Boolean theToUpdate, |
| 724 | const Standard_Boolean theReplaceIfExists) |
| 725 | { |
| 726 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); |
| 727 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 728 | if (aCtx.IsNull()) |
| 729 | { |
| 730 | std::cout << "Error: AIS context is not available.\n"; |
| 731 | return Standard_False; |
| 732 | } |
| 733 | |
| 734 | if (aMap.IsBound2 (theName)) |
| 735 | { |
| 736 | if (!theReplaceIfExists) |
| 737 | { |
| 738 | std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n" |
| 739 | << "Please use another name.\n"; |
| 740 | return Standard_False; |
| 741 | } |
| 742 | |
| 743 | if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName)) |
| 744 | { |
| 745 | aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate); |
| 746 | } |
| 747 | aMap.UnBind2 (theName); |
| 748 | } |
| 749 | |
| 750 | if (theObject.IsNull()) |
| 751 | { |
| 752 | // object with specified name has been already unbound |
| 753 | return Standard_True; |
| 754 | } |
| 755 | |
| 756 | // unbind AIS object if it was bound with another name |
| 757 | aMap.UnBind1 (theObject); |
| 758 | |
| 759 | // can be registered without rebinding |
| 760 | aMap.Bind (theObject, theName); |
| 761 | aCtx->Display (theObject, theToUpdate); |
| 762 | return Standard_True; |
| 763 | } |
| 764 | |
| 765 | //! Alias for ViewerTest::Display(), compatibility with old code. |
| 766 | Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
| 767 | const Handle(AIS_InteractiveObject)& theObject, |
| 768 | Standard_Boolean theReplaceIfExists = Standard_True) |
| 769 | { |
| 770 | return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists); |
| 771 | } |
| 772 | |
| 773 | static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs; |
| 774 | |
| 775 | static Handle(V3d_View)& a3DView() |
| 776 | { |
| 777 | static Handle(V3d_View) Viou; |
| 778 | return Viou; |
| 779 | } |
| 780 | |
| 781 | |
| 782 | Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){ |
| 783 | static Handle(AIS_InteractiveContext) aContext; |
| 784 | return aContext; |
| 785 | } |
| 786 | |
| 787 | const Handle(V3d_View)& ViewerTest::CurrentView() |
| 788 | { |
| 789 | return a3DView(); |
| 790 | } |
| 791 | void ViewerTest::CurrentView(const Handle(V3d_View)& V) |
| 792 | { |
| 793 | a3DView() = V; |
| 794 | } |
| 795 | |
| 796 | const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext() |
| 797 | { |
| 798 | return TheAISContext(); |
| 799 | } |
| 800 | |
| 801 | void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx) |
| 802 | { |
| 803 | TheAISContext() = aCtx; |
| 804 | ViewerTest::ResetEventManager(); |
| 805 | } |
| 806 | |
| 807 | Handle(V3d_Viewer) ViewerTest::GetViewerFromContext() |
| 808 | { |
| 809 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
| 810 | } |
| 811 | |
| 812 | Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext() |
| 813 | { |
| 814 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
| 815 | } |
| 816 | |
| 817 | |
| 818 | void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){ |
| 819 | theEventMgrs.Prepend(EM); |
| 820 | } |
| 821 | |
| 822 | void ViewerTest::UnsetEventManager() |
| 823 | { |
| 824 | theEventMgrs.RemoveFirst(); |
| 825 | } |
| 826 | |
| 827 | |
| 828 | void ViewerTest::ResetEventManager() |
| 829 | { |
| 830 | theEventMgrs.Clear(); |
| 831 | theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext())); |
| 832 | } |
| 833 | |
| 834 | Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager() |
| 835 | { |
| 836 | return !theEventMgrs.IsEmpty() |
| 837 | ? theEventMgrs.First() |
| 838 | : Handle(ViewerTest_EventManager)(); |
| 839 | } |
| 840 | |
| 841 | //======================================================================= |
| 842 | //function : Get Context and active view |
| 843 | //purpose : |
| 844 | //======================================================================= |
| 845 | static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx, |
| 846 | Handle(V3d_View)& theView) |
| 847 | { |
| 848 | theCtx = ViewerTest::GetAISContext(); |
| 849 | theView = ViewerTest::CurrentView(); |
| 850 | if (theCtx.IsNull() |
| 851 | || theView.IsNull()) |
| 852 | { |
| 853 | std::cout << "Error: cannot find an active view!\n"; |
| 854 | return Standard_False; |
| 855 | } |
| 856 | return Standard_True; |
| 857 | } |
| 858 | |
| 859 | //============================================================================== |
| 860 | //function : Clear |
| 861 | //purpose : Remove all the object from the viewer |
| 862 | //============================================================================== |
| 863 | void ViewerTest::Clear() |
| 864 | { |
| 865 | if (a3DView().IsNull()) |
| 866 | { |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved; |
| 871 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next()) |
| 872 | { |
| 873 | const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1(); |
| 874 | if (anObj->GetContext() != TheAISContext()) |
| 875 | { |
| 876 | continue; |
| 877 | } |
| 878 | |
| 879 | std::cout << "Remove " << anObjIter.Key2() << std::endl; |
| 880 | TheAISContext()->Remove (anObj, Standard_False); |
| 881 | aListRemoved.Append (anObj); |
| 882 | } |
| 883 | |
| 884 | TheAISContext()->RebuildSelectionStructs(); |
| 885 | TheAISContext()->UpdateCurrentViewer(); |
| 886 | if (aListRemoved.Size() == GetMapOfAIS().Extent()) |
| 887 | { |
| 888 | GetMapOfAIS().Clear(); |
| 889 | } |
| 890 | else |
| 891 | { |
| 892 | for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next()) |
| 893 | { |
| 894 | GetMapOfAIS().UnBind1 (anObjIter.Value()); |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | //============================================================================== |
| 900 | //function : CopyIsoAspect |
| 901 | //purpose : Returns copy Prs3d_IsoAspect with new number of isolines. |
| 902 | //============================================================================== |
| 903 | static Handle(Prs3d_IsoAspect) CopyIsoAspect |
| 904 | (const Handle(Prs3d_IsoAspect) &theIsoAspect, |
| 905 | const Standard_Integer theNbIsos) |
| 906 | { |
| 907 | Quantity_Color aColor = theIsoAspect->Aspect()->Color(); |
| 908 | Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type(); |
| 909 | Standard_Real aWidth = theIsoAspect->Aspect()->Width(); |
| 910 | |
| 911 | Handle(Prs3d_IsoAspect) aResult = |
| 912 | new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos); |
| 913 | |
| 914 | return aResult; |
| 915 | } |
| 916 | |
| 917 | //============================================================================== |
| 918 | //function : visos |
| 919 | //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag |
| 920 | //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)] |
| 921 | //============================================================================== |
| 922 | static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 923 | { |
| 924 | if (TheAISContext().IsNull()) { |
| 925 | di << argv[0] << " Call 'vinit' before!\n"; |
| 926 | return 1; |
| 927 | } |
| 928 | |
| 929 | if (argc <= 1) { |
| 930 | di << "Current number of isos : " << |
| 931 | TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " << |
| 932 | TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n"; |
| 933 | di << "IsoOnPlane mode is " << |
| 934 | (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n"; |
| 935 | di << "IsoOnTriangulation mode is " << |
| 936 | (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n"; |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | Standard_Integer aLastInd = argc - 1; |
| 941 | Standard_Boolean isChanged = Standard_False; |
| 942 | Standard_Integer aNbUIsos = 0; |
| 943 | Standard_Integer aNbVIsos = 0; |
| 944 | |
| 945 | if (aLastInd >= 3) { |
| 946 | Standard_Boolean isIsoOnPlane = Standard_False; |
| 947 | |
| 948 | if (strcmp(argv[aLastInd], "1") == 0) { |
| 949 | isIsoOnPlane = Standard_True; |
| 950 | isChanged = Standard_True; |
| 951 | } else if (strcmp(argv[aLastInd], "0") == 0) { |
| 952 | isIsoOnPlane = Standard_False; |
| 953 | isChanged = Standard_True; |
| 954 | } |
| 955 | |
| 956 | if (isChanged) { |
| 957 | aNbVIsos = Draw::Atoi(argv[aLastInd - 1]); |
| 958 | aNbUIsos = Draw::Atoi(argv[aLastInd - 2]); |
| 959 | aLastInd -= 3; |
| 960 | |
| 961 | di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n"; |
| 962 | di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n"; |
| 963 | |
| 964 | TheAISContext()->IsoOnPlane(isIsoOnPlane); |
| 965 | |
| 966 | if (aLastInd == 0) { |
| 967 | // If there are no shapes provided set the default numbers. |
| 968 | TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU); |
| 969 | TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV); |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | Standard_Integer i; |
| 975 | |
| 976 | for (i = 1; i <= aLastInd; i++) |
| 977 | { |
| 978 | TCollection_AsciiString name(argv[i]); |
| 979 | Handle(AIS_InteractiveObject) aShape; |
| 980 | GetMapOfAIS().Find2(name, aShape); |
| 981 | if (aShape.IsNull()) |
| 982 | { |
| 983 | std::cout << "Syntax error: object '" << name << "' is not found\n"; |
| 984 | return 1; |
| 985 | } |
| 986 | |
| 987 | Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes(); |
| 988 | Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect(); |
| 989 | Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect(); |
| 990 | if (isChanged) |
| 991 | { |
| 992 | CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos)); |
| 993 | CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos)); |
| 994 | TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False); |
| 995 | TheAISContext()->Redisplay (aShape, Standard_False); |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | di << "Number of isos for " << argv[i] << " : " |
| 1000 | << aUIso->Number() << " " << aVIso->Number() << "\n"; |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | if (isChanged) { |
| 1005 | TheAISContext()->UpdateCurrentViewer(); |
| 1006 | } |
| 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | static Standard_Integer VDispSensi (Draw_Interpretor& , |
| 1012 | Standard_Integer theArgNb, |
| 1013 | Standard_CString* ) |
| 1014 | { |
| 1015 | if (theArgNb > 1) |
| 1016 | { |
| 1017 | std::cout << "Error: wrong syntax!\n"; |
| 1018 | return 1; |
| 1019 | } |
| 1020 | |
| 1021 | Handle(AIS_InteractiveContext) aCtx; |
| 1022 | Handle(V3d_View) aView; |
| 1023 | if (!getCtxAndView (aCtx, aView)) |
| 1024 | { |
| 1025 | return 1; |
| 1026 | } |
| 1027 | |
| 1028 | aCtx->DisplayActiveSensitive (aView); |
| 1029 | return 0; |
| 1030 | |
| 1031 | } |
| 1032 | |
| 1033 | static Standard_Integer VClearSensi (Draw_Interpretor& , |
| 1034 | Standard_Integer theArgNb, |
| 1035 | Standard_CString* ) |
| 1036 | { |
| 1037 | if (theArgNb > 1) |
| 1038 | { |
| 1039 | std::cout << "Error: wrong syntax!\n"; |
| 1040 | return 1; |
| 1041 | } |
| 1042 | |
| 1043 | Handle(AIS_InteractiveContext) aCtx; |
| 1044 | Handle(V3d_View) aView; |
| 1045 | if (!getCtxAndView (aCtx, aView)) |
| 1046 | { |
| 1047 | return 1; |
| 1048 | } |
| 1049 | aCtx->ClearActiveSensitive (aView); |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
| 1053 | //============================================================================== |
| 1054 | //function : VDir |
| 1055 | //purpose : To list the displayed object with their attributes |
| 1056 | //============================================================================== |
| 1057 | static int VDir (Draw_Interpretor& theDI, |
| 1058 | Standard_Integer theNbArgs, |
| 1059 | const char** theArgVec) |
| 1060 | { |
| 1061 | TCollection_AsciiString aMatch; |
| 1062 | Standard_Boolean toFormat = Standard_False; |
| 1063 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) |
| 1064 | { |
| 1065 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); |
| 1066 | anArgCase.LowerCase(); |
| 1067 | if (anArgCase == "-list" |
| 1068 | || anArgCase == "-format") |
| 1069 | { |
| 1070 | toFormat = Standard_True; |
| 1071 | } |
| 1072 | else if (aMatch.IsEmpty()) |
| 1073 | { |
| 1074 | aMatch = theArgVec[anArgIter]; |
| 1075 | } |
| 1076 | else |
| 1077 | { |
| 1078 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; |
| 1079 | return 1; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | TCollection_AsciiString aRes; |
| 1084 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next()) |
| 1085 | { |
| 1086 | if (!aMatch.IsEmpty()) |
| 1087 | { |
| 1088 | const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'"; |
| 1089 | if (theDI.Eval (aCheck.ToCString()) == 0 |
| 1090 | && *theDI.Result() != '1') |
| 1091 | { |
| 1092 | continue; |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | if (toFormat) |
| 1097 | { |
| 1098 | aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n"; |
| 1099 | } |
| 1100 | else |
| 1101 | { |
| 1102 | aRes += anIter.Key2() + " "; |
| 1103 | } |
| 1104 | } |
| 1105 | theDI.Reset(); |
| 1106 | theDI << aRes; |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | //! Auxiliary enumeration |
| 1111 | enum ViewerTest_StereoPair |
| 1112 | { |
| 1113 | ViewerTest_SP_Single, |
| 1114 | ViewerTest_SP_SideBySide, |
| 1115 | ViewerTest_SP_OverUnder |
| 1116 | }; |
| 1117 | |
| 1118 | //============================================================================== |
| 1119 | //function : VDump |
| 1120 | //purpose : To dump the active view snapshot to image file |
| 1121 | //============================================================================== |
| 1122 | static Standard_Integer VDump (Draw_Interpretor& theDI, |
| 1123 | Standard_Integer theArgNb, |
| 1124 | Standard_CString* theArgVec) |
| 1125 | { |
| 1126 | if (theArgNb < 2) |
| 1127 | { |
| 1128 | std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n"; |
| 1129 | return 1; |
| 1130 | } |
| 1131 | |
| 1132 | Standard_Integer anArgIter = 1; |
| 1133 | Standard_CString aFilePath = theArgVec[anArgIter++]; |
| 1134 | ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single; |
| 1135 | V3d_ImageDumpOptions aParams; |
| 1136 | aParams.BufferType = Graphic3d_BT_RGB; |
| 1137 | aParams.StereoOptions = V3d_SDO_MONO; |
| 1138 | for (; anArgIter < theArgNb; ++anArgIter) |
| 1139 | { |
| 1140 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
| 1141 | anArg.LowerCase(); |
| 1142 | if (anArg == "-buffer") |
| 1143 | { |
| 1144 | if (++anArgIter >= theArgNb) |
| 1145 | { |
| 1146 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; |
| 1147 | return 1; |
| 1148 | } |
| 1149 | |
| 1150 | TCollection_AsciiString aBufArg (theArgVec[anArgIter]); |
| 1151 | aBufArg.LowerCase(); |
| 1152 | if (aBufArg == "rgba") |
| 1153 | { |
| 1154 | aParams.BufferType = Graphic3d_BT_RGBA; |
| 1155 | } |
| 1156 | else if (aBufArg == "rgb") |
| 1157 | { |
| 1158 | aParams.BufferType = Graphic3d_BT_RGB; |
| 1159 | } |
| 1160 | else if (aBufArg == "red") |
| 1161 | { |
| 1162 | aParams.BufferType = Graphic3d_BT_Red; |
| 1163 | } |
| 1164 | else if (aBufArg == "depth") |
| 1165 | { |
| 1166 | aParams.BufferType = Graphic3d_BT_Depth; |
| 1167 | } |
| 1168 | else |
| 1169 | { |
| 1170 | std::cout << "Error: unknown buffer '" << aBufArg << "'\n"; |
| 1171 | return 1; |
| 1172 | } |
| 1173 | } |
| 1174 | else if (anArg == "-stereo") |
| 1175 | { |
| 1176 | if (++anArgIter >= theArgNb) |
| 1177 | { |
| 1178 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; |
| 1179 | return 1; |
| 1180 | } |
| 1181 | |
| 1182 | TCollection_AsciiString aStereoArg (theArgVec[anArgIter]); |
| 1183 | aStereoArg.LowerCase(); |
| 1184 | if (aStereoArg == "l" |
| 1185 | || aStereoArg == "left") |
| 1186 | { |
| 1187 | aParams.StereoOptions = V3d_SDO_LEFT_EYE; |
| 1188 | } |
| 1189 | else if (aStereoArg == "r" |
| 1190 | || aStereoArg == "right") |
| 1191 | { |
| 1192 | aParams.StereoOptions = V3d_SDO_RIGHT_EYE; |
| 1193 | } |
| 1194 | else if (aStereoArg == "mono") |
| 1195 | { |
| 1196 | aParams.StereoOptions = V3d_SDO_MONO; |
| 1197 | } |
| 1198 | else if (aStereoArg == "blended" |
| 1199 | || aStereoArg == "blend" |
| 1200 | || aStereoArg == "stereo") |
| 1201 | { |
| 1202 | aParams.StereoOptions = V3d_SDO_BLENDED; |
| 1203 | } |
| 1204 | else if (aStereoArg == "sbs" |
| 1205 | || aStereoArg == "sidebyside") |
| 1206 | { |
| 1207 | aStereoPair = ViewerTest_SP_SideBySide; |
| 1208 | } |
| 1209 | else if (aStereoArg == "ou" |
| 1210 | || aStereoArg == "overunder") |
| 1211 | { |
| 1212 | aStereoPair = ViewerTest_SP_OverUnder; |
| 1213 | } |
| 1214 | else |
| 1215 | { |
| 1216 | std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n"; |
| 1217 | return 1; |
| 1218 | } |
| 1219 | } |
| 1220 | else if (anArg == "-rgba" |
| 1221 | || anArg == "rgba") |
| 1222 | { |
| 1223 | aParams.BufferType = Graphic3d_BT_RGBA; |
| 1224 | } |
| 1225 | else if (anArg == "-rgb" |
| 1226 | || anArg == "rgb") |
| 1227 | { |
| 1228 | aParams.BufferType = Graphic3d_BT_RGB; |
| 1229 | } |
| 1230 | else if (anArg == "-red" |
| 1231 | || anArg == "red") |
| 1232 | { |
| 1233 | aParams.BufferType = Graphic3d_BT_Red; |
| 1234 | } |
| 1235 | else if (anArg == "-depth" |
| 1236 | || anArg == "depth") |
| 1237 | { |
| 1238 | aParams.BufferType = Graphic3d_BT_Depth; |
| 1239 | } |
| 1240 | else if (anArg == "-width" |
| 1241 | || anArg == "width" |
| 1242 | || anArg == "sizex") |
| 1243 | { |
| 1244 | if (aParams.Width != 0) |
| 1245 | { |
| 1246 | std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n"; |
| 1247 | return 1; |
| 1248 | } |
| 1249 | else if (++anArgIter >= theArgNb) |
| 1250 | { |
| 1251 | std::cout << "Error: integer value is expected right after 'width'\n"; |
| 1252 | return 1; |
| 1253 | } |
| 1254 | aParams.Width = Draw::Atoi (theArgVec[anArgIter]); |
| 1255 | } |
| 1256 | else if (anArg == "-height" |
| 1257 | || anArg == "height" |
| 1258 | || anArg == "-sizey") |
| 1259 | { |
| 1260 | if (aParams.Height != 0) |
| 1261 | { |
| 1262 | std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n"; |
| 1263 | return 1; |
| 1264 | } |
| 1265 | else if (++anArgIter >= theArgNb) |
| 1266 | { |
| 1267 | std::cout << "Error: integer value is expected right after 'height'\n"; |
| 1268 | return 1; |
| 1269 | } |
| 1270 | aParams.Height = Draw::Atoi (theArgVec[anArgIter]); |
| 1271 | } |
| 1272 | else if (anArg == "-tile" |
| 1273 | || anArg == "-tilesize") |
| 1274 | { |
| 1275 | if (++anArgIter >= theArgNb) |
| 1276 | { |
| 1277 | std::cout << "Error: integer value is expected right after 'tileSize'\n"; |
| 1278 | return 1; |
| 1279 | } |
| 1280 | aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]); |
| 1281 | } |
| 1282 | else |
| 1283 | { |
| 1284 | std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n"; |
| 1285 | return 1; |
| 1286 | } |
| 1287 | } |
| 1288 | if ((aParams.Width <= 0 && aParams.Height > 0) |
| 1289 | || (aParams.Width > 0 && aParams.Height <= 0)) |
| 1290 | { |
| 1291 | std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n"; |
| 1292 | return 1; |
| 1293 | } |
| 1294 | |
| 1295 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 1296 | if (aView.IsNull()) |
| 1297 | { |
| 1298 | std::cout << "Error: cannot find an active view!\n"; |
| 1299 | return 1; |
| 1300 | } |
| 1301 | |
| 1302 | if (aParams.Width <= 0 || aParams.Height <= 0) |
| 1303 | { |
| 1304 | aView->Window()->Size (aParams.Width, aParams.Height); |
| 1305 | } |
| 1306 | |
| 1307 | Image_AlienPixMap aPixMap; |
| 1308 | Image_Format aFormat = Image_Format_UNKNOWN; |
| 1309 | switch (aParams.BufferType) |
| 1310 | { |
| 1311 | case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break; |
| 1312 | case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break; |
| 1313 | case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break; |
| 1314 | case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break; |
| 1315 | case Graphic3d_BT_Red: aFormat = Image_Format_Gray; break; |
| 1316 | } |
| 1317 | |
| 1318 | switch (aStereoPair) |
| 1319 | { |
| 1320 | case ViewerTest_SP_Single: |
| 1321 | { |
| 1322 | if (!aView->ToPixMap (aPixMap, aParams)) |
| 1323 | { |
| 1324 | theDI << "Fail: view dump failed!\n"; |
| 1325 | return 0; |
| 1326 | } |
| 1327 | else if (aPixMap.SizeX() != Standard_Size(aParams.Width) |
| 1328 | || aPixMap.SizeY() != Standard_Size(aParams.Height)) |
| 1329 | { |
| 1330 | theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY() |
| 1331 | << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n"; |
| 1332 | } |
| 1333 | break; |
| 1334 | } |
| 1335 | case ViewerTest_SP_SideBySide: |
| 1336 | { |
| 1337 | if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height)) |
| 1338 | { |
| 1339 | theDI << "Fail: not enough memory for image allocation!\n"; |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | Image_PixMap aPixMapL, aPixMapR; |
| 1344 | aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(), |
| 1345 | aParams.Width, aParams.Height, aPixMap.SizeRowBytes()); |
| 1346 | aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width, |
| 1347 | aParams.Width, aParams.Height, aPixMap.SizeRowBytes()); |
| 1348 | |
| 1349 | aParams.StereoOptions = V3d_SDO_LEFT_EYE; |
| 1350 | Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams); |
| 1351 | aParams.StereoOptions = V3d_SDO_RIGHT_EYE; |
| 1352 | isOk = isOk && aView->ToPixMap (aPixMapR, aParams); |
| 1353 | if (!isOk) |
| 1354 | { |
| 1355 | theDI << "Fail: view dump failed!\n"; |
| 1356 | return 0; |
| 1357 | } |
| 1358 | break; |
| 1359 | } |
| 1360 | case ViewerTest_SP_OverUnder: |
| 1361 | { |
| 1362 | if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2)) |
| 1363 | { |
| 1364 | theDI << "Fail: not enough memory for image allocation!\n"; |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
| 1368 | Image_PixMap aPixMapL, aPixMapR; |
| 1369 | aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(), |
| 1370 | aParams.Width, aParams.Height, aPixMap.SizeRowBytes()); |
| 1371 | aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height, |
| 1372 | aParams.Width, aParams.Height, aPixMap.SizeRowBytes()); |
| 1373 | |
| 1374 | aParams.StereoOptions = V3d_SDO_LEFT_EYE; |
| 1375 | Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams); |
| 1376 | aParams.StereoOptions = V3d_SDO_RIGHT_EYE; |
| 1377 | isOk = isOk && aView->ToPixMap (aPixMapR, aParams); |
| 1378 | if (!isOk) |
| 1379 | { |
| 1380 | theDI << "Fail: view dump failed!\n"; |
| 1381 | return 0; |
| 1382 | } |
| 1383 | break; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | if (!aPixMap.Save (aFilePath)) |
| 1388 | { |
| 1389 | theDI << "Fail: image can not be saved!\n"; |
| 1390 | } |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
| 1394 | enum TypeOfDispOperation |
| 1395 | { |
| 1396 | TypeOfDispOperation_SetDispMode, |
| 1397 | TypeOfDispOperation_UnsetDispMode |
| 1398 | }; |
| 1399 | |
| 1400 | //! Displays,Erase... |
| 1401 | static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs, |
| 1402 | const Standard_Integer theMode, |
| 1403 | const TypeOfDispOperation theType, |
| 1404 | const Standard_Boolean theToUpdate) |
| 1405 | { |
| 1406 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 1407 | switch (theType) |
| 1408 | { |
| 1409 | case TypeOfDispOperation_SetDispMode: |
| 1410 | { |
| 1411 | if (!thePrs.IsNull()) |
| 1412 | { |
| 1413 | aCtx->SetDisplayMode (thePrs, theMode, theToUpdate); |
| 1414 | } |
| 1415 | else |
| 1416 | { |
| 1417 | aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate); |
| 1418 | } |
| 1419 | break; |
| 1420 | } |
| 1421 | case TypeOfDispOperation_UnsetDispMode: |
| 1422 | { |
| 1423 | if (!thePrs.IsNull()) |
| 1424 | { |
| 1425 | aCtx->UnsetDisplayMode (thePrs, theToUpdate); |
| 1426 | } |
| 1427 | else |
| 1428 | { |
| 1429 | aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate); |
| 1430 | } |
| 1431 | break; |
| 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | //======================================================================= |
| 1437 | //function : |
| 1438 | //purpose : |
| 1439 | //======================================================================= |
| 1440 | static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
| 1441 | { |
| 1442 | if (argc < 1 |
| 1443 | || argc > 3) |
| 1444 | { |
| 1445 | std::cout << "Syntax error: wrong number of arguments\n"; |
| 1446 | return 1; |
| 1447 | } |
| 1448 | |
| 1449 | TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode" |
| 1450 | ? TypeOfDispOperation_UnsetDispMode |
| 1451 | : TypeOfDispOperation_SetDispMode; |
| 1452 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 1453 | if (aType == TypeOfDispOperation_UnsetDispMode) |
| 1454 | { |
| 1455 | if (argc == 1) |
| 1456 | { |
| 1457 | if (aCtx->NbSelected() == 0) |
| 1458 | { |
| 1459 | VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False); |
| 1460 | } |
| 1461 | else |
| 1462 | { |
| 1463 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
| 1464 | { |
| 1465 | VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False); |
| 1466 | } |
| 1467 | } |
| 1468 | aCtx->UpdateCurrentViewer(); |
| 1469 | } |
| 1470 | else |
| 1471 | { |
| 1472 | TCollection_AsciiString aName = argv[1]; |
| 1473 | Handle(AIS_InteractiveObject) aPrs; |
| 1474 | if (GetMapOfAIS().Find2 (aName, aPrs) |
| 1475 | && !aPrs.IsNull()) |
| 1476 | { |
| 1477 | VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True); |
| 1478 | } |
| 1479 | } |
| 1480 | } |
| 1481 | else if (argc == 2) |
| 1482 | { |
| 1483 | Standard_Integer aDispMode = Draw::Atoi (argv[1]); |
| 1484 | if (aCtx->NbSelected() == 0 |
| 1485 | && aType == TypeOfDispOperation_SetDispMode) |
| 1486 | { |
| 1487 | VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True); |
| 1488 | } |
| 1489 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
| 1490 | { |
| 1491 | VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False); |
| 1492 | } |
| 1493 | aCtx->UpdateCurrentViewer(); |
| 1494 | } |
| 1495 | else |
| 1496 | { |
| 1497 | Handle(AIS_InteractiveObject) aPrs; |
| 1498 | TCollection_AsciiString aName (argv[1]); |
| 1499 | if (GetMapOfAIS().Find2 (aName, aPrs) |
| 1500 | && !aPrs.IsNull()) |
| 1501 | { |
| 1502 | VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True); |
| 1503 | } |
| 1504 | } |
| 1505 | return 0; |
| 1506 | } |
| 1507 | |
| 1508 | |
| 1509 | //======================================================================= |
| 1510 | //function : |
| 1511 | //purpose : |
| 1512 | //======================================================================= |
| 1513 | static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 1514 | { |
| 1515 | if(argc==1) return 1; |
| 1516 | Standard_Integer On = Draw::Atoi(argv[1]); |
| 1517 | const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext(); |
| 1518 | |
| 1519 | if(argc==2) |
| 1520 | { |
| 1521 | TCollection_AsciiString isOnOff = On == 1 ? "on" : "off"; |
| 1522 | di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n"; |
| 1523 | for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected()) |
| 1524 | { |
| 1525 | if(On==1) |
| 1526 | { |
| 1527 | Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False); |
| 1528 | } |
| 1529 | else |
| 1530 | { |
| 1531 | Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False); |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | Ctx->UpdateCurrentViewer(); |
| 1536 | } |
| 1537 | else { |
| 1538 | Handle(AIS_InteractiveObject) IO; |
| 1539 | TCollection_AsciiString name = argv[2]; |
| 1540 | if (GetMapOfAIS().Find2 (name, IO) |
| 1541 | && !IO.IsNull()) |
| 1542 | { |
| 1543 | if(On==1) |
| 1544 | Ctx->SubIntensityOn(IO, Standard_True); |
| 1545 | else |
| 1546 | Ctx->SubIntensityOff(IO, Standard_True); |
| 1547 | } |
| 1548 | else return 1; |
| 1549 | } |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
| 1553 | //! Auxiliary class to iterate presentations from different collections. |
| 1554 | class ViewTest_PrsIter |
| 1555 | { |
| 1556 | public: |
| 1557 | |
| 1558 | //! Create and initialize iterator object. |
| 1559 | ViewTest_PrsIter (const TCollection_AsciiString& theName) |
| 1560 | : mySource (IterSource_All) |
| 1561 | { |
| 1562 | NCollection_Sequence<TCollection_AsciiString> aNames; |
| 1563 | if (!theName.IsEmpty()) |
| 1564 | aNames.Append (theName); |
| 1565 | Init (aNames); |
| 1566 | } |
| 1567 | |
| 1568 | //! Create and initialize iterator object. |
| 1569 | ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames) |
| 1570 | : mySource (IterSource_All) |
| 1571 | { |
| 1572 | Init (theNames); |
| 1573 | } |
| 1574 | |
| 1575 | //! Initialize the iterator. |
| 1576 | void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames) |
| 1577 | { |
| 1578 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 1579 | mySeq = theNames; |
| 1580 | mySelIter.Nullify(); |
| 1581 | myCurrent.Nullify(); |
| 1582 | myCurrentTrs.Nullify(); |
| 1583 | if (!mySeq.IsEmpty()) |
| 1584 | { |
| 1585 | mySource = IterSource_List; |
| 1586 | mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq); |
| 1587 | } |
| 1588 | else if (aCtx->NbSelected() > 0) |
| 1589 | { |
| 1590 | mySource = IterSource_Selected; |
| 1591 | mySelIter = aCtx; |
| 1592 | mySelIter->InitSelected(); |
| 1593 | } |
| 1594 | else |
| 1595 | { |
| 1596 | mySource = IterSource_All; |
| 1597 | myMapIter.Initialize (GetMapOfAIS()); |
| 1598 | } |
| 1599 | initCurrent(); |
| 1600 | } |
| 1601 | |
| 1602 | const TCollection_AsciiString& CurrentName() const |
| 1603 | { |
| 1604 | return myCurrentName; |
| 1605 | } |
| 1606 | |
| 1607 | const Handle(AIS_InteractiveObject)& Current() const |
| 1608 | { |
| 1609 | return myCurrent; |
| 1610 | } |
| 1611 | |
| 1612 | const Handle(Standard_Transient)& CurrentTrs() const |
| 1613 | { |
| 1614 | return myCurrentTrs; |
| 1615 | } |
| 1616 | |
| 1617 | //! @return true if iterator points to valid object within collection |
| 1618 | Standard_Boolean More() const |
| 1619 | { |
| 1620 | switch (mySource) |
| 1621 | { |
| 1622 | case IterSource_All: return myMapIter.More(); |
| 1623 | case IterSource_List: return mySeqIter.More(); |
| 1624 | case IterSource_Selected: return mySelIter->MoreSelected(); |
| 1625 | } |
| 1626 | return Standard_False; |
| 1627 | } |
| 1628 | |
| 1629 | //! Go to the next item. |
| 1630 | void Next() |
| 1631 | { |
| 1632 | myCurrentName.Clear(); |
| 1633 | myCurrentTrs.Nullify(); |
| 1634 | myCurrent.Nullify(); |
| 1635 | switch (mySource) |
| 1636 | { |
| 1637 | case IterSource_All: |
| 1638 | { |
| 1639 | myMapIter.Next(); |
| 1640 | break; |
| 1641 | } |
| 1642 | case IterSource_List: |
| 1643 | { |
| 1644 | mySeqIter.Next(); |
| 1645 | break; |
| 1646 | } |
| 1647 | case IterSource_Selected: |
| 1648 | { |
| 1649 | mySelIter->NextSelected(); |
| 1650 | break; |
| 1651 | } |
| 1652 | } |
| 1653 | initCurrent(); |
| 1654 | } |
| 1655 | |
| 1656 | private: |
| 1657 | |
| 1658 | void initCurrent() |
| 1659 | { |
| 1660 | switch (mySource) |
| 1661 | { |
| 1662 | case IterSource_All: |
| 1663 | { |
| 1664 | if (myMapIter.More()) |
| 1665 | { |
| 1666 | myCurrentName = myMapIter.Key2(); |
| 1667 | myCurrentTrs = myMapIter.Key1(); |
| 1668 | myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs); |
| 1669 | } |
| 1670 | break; |
| 1671 | } |
| 1672 | case IterSource_List: |
| 1673 | { |
| 1674 | if (mySeqIter.More()) |
| 1675 | { |
| 1676 | if (!GetMapOfAIS().IsBound2 (mySeqIter.Value())) |
| 1677 | { |
| 1678 | std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n"; |
| 1679 | return; |
| 1680 | } |
| 1681 | myCurrentName = mySeqIter.Value(); |
| 1682 | myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value()); |
| 1683 | myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs); |
| 1684 | } |
| 1685 | break; |
| 1686 | } |
| 1687 | case IterSource_Selected: |
| 1688 | { |
| 1689 | if (mySelIter->MoreSelected()) |
| 1690 | { |
| 1691 | myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive()); |
| 1692 | myCurrent = mySelIter->SelectedInteractive(); |
| 1693 | } |
| 1694 | break; |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | private: |
| 1700 | |
| 1701 | enum IterSource |
| 1702 | { |
| 1703 | IterSource_All, |
| 1704 | IterSource_List, |
| 1705 | IterSource_Selected |
| 1706 | }; |
| 1707 | |
| 1708 | private: |
| 1709 | |
| 1710 | Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected) |
| 1711 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All) |
| 1712 | NCollection_Sequence<TCollection_AsciiString> mySeq; |
| 1713 | NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter; |
| 1714 | |
| 1715 | TCollection_AsciiString myCurrentName;//!< current item name |
| 1716 | Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object) |
| 1717 | Handle(AIS_InteractiveObject) myCurrent; //!< current item |
| 1718 | |
| 1719 | IterSource mySource; //!< iterated collection |
| 1720 | |
| 1721 | }; |
| 1722 | |
| 1723 | //! Parse interior style name. |
| 1724 | static bool parseInteriorStyle (const TCollection_AsciiString& theArg, |
| 1725 | Aspect_InteriorStyle& theStyle) |
| 1726 | { |
| 1727 | TCollection_AsciiString anArg (theArg); |
| 1728 | anArg.LowerCase(); |
| 1729 | if (anArg == "empty") |
| 1730 | { |
| 1731 | theStyle = Aspect_IS_EMPTY; |
| 1732 | } |
| 1733 | else if (anArg == "hollow") |
| 1734 | { |
| 1735 | theStyle = Aspect_IS_HOLLOW; |
| 1736 | } |
| 1737 | else if (anArg == "solid") |
| 1738 | { |
| 1739 | theStyle = Aspect_IS_SOLID; |
| 1740 | } |
| 1741 | else if (anArg == "hatch") |
| 1742 | { |
| 1743 | theStyle = Aspect_IS_HATCH; |
| 1744 | } |
| 1745 | else if (anArg == "hiddenline" |
| 1746 | || anArg == "hidden-line" |
| 1747 | || anArg == "hidden_line") |
| 1748 | { |
| 1749 | theStyle = Aspect_IS_HIDDENLINE; |
| 1750 | } |
| 1751 | else if (anArg == "point") |
| 1752 | { |
| 1753 | theStyle = Aspect_IS_POINT; |
| 1754 | } |
| 1755 | else if (theArg.IsIntegerValue()) |
| 1756 | { |
| 1757 | const Standard_Integer anIntStyle = theArg.IntegerValue(); |
| 1758 | if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT) |
| 1759 | { |
| 1760 | return false; |
| 1761 | } |
| 1762 | theStyle = (Aspect_InteriorStyle)anIntStyle; |
| 1763 | } |
| 1764 | else |
| 1765 | { |
| 1766 | return false; |
| 1767 | } |
| 1768 | return true; |
| 1769 | } |
| 1770 | |
| 1771 | //! Auxiliary structure for VAspects |
| 1772 | struct ViewerTest_AspectsChangeSet |
| 1773 | { |
| 1774 | Standard_Integer ToSetVisibility; |
| 1775 | Standard_Integer Visibility; |
| 1776 | |
| 1777 | Standard_Integer ToSetColor; |
| 1778 | Quantity_Color Color; |
| 1779 | Standard_Integer ToSetBackFaceColor; |
| 1780 | Quantity_Color BackFaceColor; |
| 1781 | |
| 1782 | Standard_Integer ToSetLineWidth; |
| 1783 | Standard_Real LineWidth; |
| 1784 | |
| 1785 | Standard_Integer ToSetTypeOfLine; |
| 1786 | Aspect_TypeOfLine TypeOfLine; |
| 1787 | |
| 1788 | Standard_Integer ToSetTypeOfMarker; |
| 1789 | Aspect_TypeOfMarker TypeOfMarker; |
| 1790 | Handle(Image_PixMap) MarkerImage; |
| 1791 | |
| 1792 | Standard_Integer ToSetMarkerSize; |
| 1793 | Standard_Real MarkerSize; |
| 1794 | |
| 1795 | Standard_Integer ToSetTransparency; |
| 1796 | Standard_Real Transparency; |
| 1797 | |
| 1798 | Standard_Integer ToSetAlphaMode; |
| 1799 | Graphic3d_AlphaMode AlphaMode; |
| 1800 | Standard_ShortReal AlphaCutoff; |
| 1801 | |
| 1802 | Standard_Integer ToSetMaterial; |
| 1803 | Graphic3d_NameOfMaterial Material; |
| 1804 | TCollection_AsciiString MatName; |
| 1805 | |
| 1806 | NCollection_Sequence<TopoDS_Shape> SubShapes; |
| 1807 | |
| 1808 | Standard_Integer ToSetShowFreeBoundary; |
| 1809 | Standard_Integer ToSetFreeBoundaryWidth; |
| 1810 | Standard_Real FreeBoundaryWidth; |
| 1811 | Standard_Integer ToSetFreeBoundaryColor; |
| 1812 | Quantity_Color FreeBoundaryColor; |
| 1813 | |
| 1814 | Standard_Integer ToEnableIsoOnTriangulation; |
| 1815 | |
| 1816 | Standard_Integer ToSetFaceBoundaryDraw; |
| 1817 | Standard_Integer ToSetFaceBoundaryUpperContinuity; |
| 1818 | GeomAbs_Shape FaceBoundaryUpperContinuity; |
| 1819 | |
| 1820 | Standard_Integer ToSetFaceBoundaryColor; |
| 1821 | Quantity_Color FaceBoundaryColor; |
| 1822 | |
| 1823 | Standard_Integer ToSetFaceBoundaryWidth; |
| 1824 | Standard_Real FaceBoundaryWidth; |
| 1825 | |
| 1826 | Standard_Integer ToSetTypeOfFaceBoundaryLine; |
| 1827 | Aspect_TypeOfLine TypeOfFaceBoundaryLine; |
| 1828 | |
| 1829 | Standard_Integer ToSetMaxParamValue; |
| 1830 | Standard_Real MaxParamValue; |
| 1831 | |
| 1832 | Standard_Integer ToSetSensitivity; |
| 1833 | Standard_Integer SelectionMode; |
| 1834 | Standard_Integer Sensitivity; |
| 1835 | |
| 1836 | Standard_Integer ToSetHatch; |
| 1837 | Standard_Integer StdHatchStyle; |
| 1838 | TCollection_AsciiString PathToHatchPattern; |
| 1839 | |
| 1840 | Standard_Integer ToSetShadingModel; |
| 1841 | Graphic3d_TypeOfShadingModel ShadingModel; |
| 1842 | TCollection_AsciiString ShadingModelName; |
| 1843 | |
| 1844 | Standard_Integer ToSetInterior; |
| 1845 | Aspect_InteriorStyle InteriorStyle; |
| 1846 | |
| 1847 | Standard_Integer ToSetDrawSilhouette; |
| 1848 | |
| 1849 | Standard_Integer ToSetDrawEdges; |
| 1850 | Standard_Integer ToSetQuadEdges; |
| 1851 | |
| 1852 | Standard_Integer ToSetEdgeColor; |
| 1853 | Quantity_ColorRGBA EdgeColor; |
| 1854 | |
| 1855 | Standard_Integer ToSetEdgeWidth; |
| 1856 | Standard_Real EdgeWidth; |
| 1857 | |
| 1858 | Standard_Integer ToSetTypeOfEdge; |
| 1859 | Aspect_TypeOfLine TypeOfEdge; |
| 1860 | |
| 1861 | //! Empty constructor |
| 1862 | ViewerTest_AspectsChangeSet() |
| 1863 | : ToSetVisibility (0), |
| 1864 | Visibility (1), |
| 1865 | ToSetColor (0), |
| 1866 | Color (DEFAULT_COLOR), |
| 1867 | ToSetBackFaceColor(0), |
| 1868 | BackFaceColor (DEFAULT_COLOR), |
| 1869 | ToSetLineWidth (0), |
| 1870 | LineWidth (1.0), |
| 1871 | ToSetTypeOfLine (0), |
| 1872 | TypeOfLine (Aspect_TOL_SOLID), |
| 1873 | ToSetTypeOfMarker (0), |
| 1874 | TypeOfMarker (Aspect_TOM_PLUS), |
| 1875 | ToSetMarkerSize (0), |
| 1876 | MarkerSize (1.0), |
| 1877 | ToSetTransparency (0), |
| 1878 | Transparency (0.0), |
| 1879 | ToSetAlphaMode (0), |
| 1880 | AlphaMode (Graphic3d_AlphaMode_BlendAuto), |
| 1881 | AlphaCutoff (0.5f), |
| 1882 | ToSetMaterial (0), |
| 1883 | Material (Graphic3d_NOM_DEFAULT), |
| 1884 | ToSetShowFreeBoundary (0), |
| 1885 | ToSetFreeBoundaryWidth (0), |
| 1886 | FreeBoundaryWidth (1.0), |
| 1887 | ToSetFreeBoundaryColor (0), |
| 1888 | FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR), |
| 1889 | ToEnableIsoOnTriangulation (0), |
| 1890 | // |
| 1891 | ToSetFaceBoundaryDraw (0), |
| 1892 | ToSetFaceBoundaryUpperContinuity (0), |
| 1893 | FaceBoundaryUpperContinuity(GeomAbs_CN), |
| 1894 | ToSetFaceBoundaryColor (0), |
| 1895 | FaceBoundaryColor (Quantity_NOC_BLACK), |
| 1896 | ToSetFaceBoundaryWidth (0), |
| 1897 | FaceBoundaryWidth (1.0f), |
| 1898 | ToSetTypeOfFaceBoundaryLine(0), |
| 1899 | TypeOfFaceBoundaryLine (Aspect_TOL_SOLID), |
| 1900 | // |
| 1901 | ToSetMaxParamValue (0), |
| 1902 | MaxParamValue (500000), |
| 1903 | ToSetSensitivity (0), |
| 1904 | SelectionMode (-1), |
| 1905 | Sensitivity (-1), |
| 1906 | ToSetHatch (0), |
| 1907 | StdHatchStyle (-1), |
| 1908 | ToSetShadingModel (0), |
| 1909 | ShadingModel (Graphic3d_TOSM_DEFAULT), |
| 1910 | ToSetInterior (0), |
| 1911 | InteriorStyle (Aspect_IS_SOLID), |
| 1912 | ToSetDrawSilhouette (0), |
| 1913 | ToSetDrawEdges (0), |
| 1914 | ToSetQuadEdges (0), |
| 1915 | ToSetEdgeColor (0), |
| 1916 | ToSetEdgeWidth (0), |
| 1917 | EdgeWidth (1.0), |
| 1918 | ToSetTypeOfEdge (0), |
| 1919 | TypeOfEdge (Aspect_TOL_SOLID) |
| 1920 | {} |
| 1921 | |
| 1922 | //! @return true if no changes have been requested |
| 1923 | Standard_Boolean IsEmpty() const |
| 1924 | { |
| 1925 | return ToSetVisibility == 0 |
| 1926 | && ToSetLineWidth == 0 |
| 1927 | && ToSetTransparency == 0 |
| 1928 | && ToSetAlphaMode == 0 |
| 1929 | && ToSetColor == 0 |
| 1930 | && ToSetBackFaceColor == 0 |
| 1931 | && ToSetMaterial == 0 |
| 1932 | && ToSetShowFreeBoundary == 0 |
| 1933 | && ToSetFreeBoundaryColor == 0 |
| 1934 | && ToSetFreeBoundaryWidth == 0 |
| 1935 | && ToEnableIsoOnTriangulation == 0 |
| 1936 | && ToSetFaceBoundaryDraw == 0 |
| 1937 | && ToSetFaceBoundaryUpperContinuity == 0 |
| 1938 | && ToSetFaceBoundaryColor == 0 |
| 1939 | && ToSetFaceBoundaryWidth == 0 |
| 1940 | && ToSetTypeOfFaceBoundaryLine == 0 |
| 1941 | && ToSetMaxParamValue == 0 |
| 1942 | && ToSetSensitivity == 0 |
| 1943 | && ToSetHatch == 0 |
| 1944 | && ToSetShadingModel == 0 |
| 1945 | && ToSetInterior == 0 |
| 1946 | && ToSetDrawSilhouette == 0 |
| 1947 | && ToSetDrawEdges == 0 |
| 1948 | && ToSetQuadEdges == 0 |
| 1949 | && ToSetEdgeColor == 0 |
| 1950 | && ToSetEdgeWidth == 0 |
| 1951 | && ToSetTypeOfEdge == 0; |
| 1952 | } |
| 1953 | |
| 1954 | //! @return true if properties are valid |
| 1955 | Standard_Boolean Validate() const |
| 1956 | { |
| 1957 | Standard_Boolean isOk = Standard_True; |
| 1958 | if (Visibility != 0 && Visibility != 1) |
| 1959 | { |
| 1960 | std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n"; |
| 1961 | isOk = Standard_False; |
| 1962 | } |
| 1963 | if (LineWidth <= 0.0 |
| 1964 | || LineWidth > 10.0) |
| 1965 | { |
| 1966 | std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n"; |
| 1967 | isOk = Standard_False; |
| 1968 | } |
| 1969 | if (Transparency < 0.0 |
| 1970 | || Transparency > 1.0) |
| 1971 | { |
| 1972 | std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n"; |
| 1973 | isOk = Standard_False; |
| 1974 | } |
| 1975 | if (ToSetAlphaMode == 1 |
| 1976 | && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f)) |
| 1977 | { |
| 1978 | std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n"; |
| 1979 | isOk = Standard_False; |
| 1980 | } |
| 1981 | if (FreeBoundaryWidth <= 0.0 |
| 1982 | || FreeBoundaryWidth > 10.0) |
| 1983 | { |
| 1984 | std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n"; |
| 1985 | isOk = Standard_False; |
| 1986 | } |
| 1987 | if (MaxParamValue < 0.0) |
| 1988 | { |
| 1989 | std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n"; |
| 1990 | isOk = Standard_False; |
| 1991 | } |
| 1992 | if (Sensitivity <= 0 && ToSetSensitivity) |
| 1993 | { |
| 1994 | std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n"; |
| 1995 | isOk = Standard_False; |
| 1996 | } |
| 1997 | if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "") |
| 1998 | { |
| 1999 | std::cout << "Error: hatch style must be specified\n"; |
| 2000 | isOk = Standard_False; |
| 2001 | } |
| 2002 | if (ToSetShadingModel == 1 |
| 2003 | && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_PBR_FACET)) |
| 2004 | { |
| 2005 | std::cout << "Error: unknown shading model " << ShadingModelName << ".\n"; |
| 2006 | isOk = Standard_False; |
| 2007 | } |
| 2008 | return isOk; |
| 2009 | } |
| 2010 | |
| 2011 | //! Apply aspects to specified drawer. |
| 2012 | bool Apply (const Handle(Prs3d_Drawer)& theDrawer) |
| 2013 | { |
| 2014 | bool toRecompute = false; |
| 2015 | const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer(); |
| 2016 | if (ToSetShowFreeBoundary != 0) |
| 2017 | { |
| 2018 | theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1); |
| 2019 | toRecompute = true; |
| 2020 | } |
| 2021 | if (ToSetFreeBoundaryWidth != 0) |
| 2022 | { |
| 2023 | if (ToSetFreeBoundaryWidth != -1 |
| 2024 | || theDrawer->HasOwnFreeBoundaryAspect()) |
| 2025 | { |
| 2026 | if (!theDrawer->HasOwnFreeBoundaryAspect()) |
| 2027 | { |
| 2028 | Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0); |
| 2029 | *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect(); |
| 2030 | theDrawer->SetFreeBoundaryAspect (aBoundaryAspect); |
| 2031 | toRecompute = true; |
| 2032 | } |
| 2033 | theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth); |
| 2034 | } |
| 2035 | } |
| 2036 | if (ToSetFreeBoundaryColor != 0) |
| 2037 | { |
| 2038 | Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0); |
| 2039 | *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect(); |
| 2040 | aBoundaryAspect->SetColor (FreeBoundaryColor); |
| 2041 | theDrawer->SetFreeBoundaryAspect (aBoundaryAspect); |
| 2042 | toRecompute = true; |
| 2043 | } |
| 2044 | if (ToSetTypeOfLine != 0) |
| 2045 | { |
| 2046 | if (ToSetTypeOfLine != -1 |
| 2047 | || theDrawer->HasOwnLineAspect() |
| 2048 | || theDrawer->HasOwnWireAspect() |
| 2049 | || theDrawer->HasOwnFreeBoundaryAspect() |
| 2050 | || theDrawer->HasOwnUnFreeBoundaryAspect() |
| 2051 | || theDrawer->HasOwnSeenLineAspect()) |
| 2052 | { |
| 2053 | toRecompute = theDrawer->SetOwnLineAspects() || toRecompute; |
| 2054 | theDrawer->LineAspect()->SetTypeOfLine (TypeOfLine); |
| 2055 | theDrawer->WireAspect()->SetTypeOfLine (TypeOfLine); |
| 2056 | theDrawer->FreeBoundaryAspect()->SetTypeOfLine (TypeOfLine); |
| 2057 | theDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (TypeOfLine); |
| 2058 | theDrawer->SeenLineAspect()->SetTypeOfLine (TypeOfLine); |
| 2059 | } |
| 2060 | } |
| 2061 | if (ToSetTypeOfMarker != 0) |
| 2062 | { |
| 2063 | if (ToSetTypeOfMarker != -1 |
| 2064 | || theDrawer->HasOwnPointAspect()) |
| 2065 | { |
| 2066 | toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute; |
| 2067 | theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker); |
| 2068 | theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage)); |
| 2069 | } |
| 2070 | } |
| 2071 | if (ToSetMarkerSize != 0) |
| 2072 | { |
| 2073 | if (ToSetMarkerSize != -1 |
| 2074 | || theDrawer->HasOwnPointAspect()) |
| 2075 | { |
| 2076 | toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute; |
| 2077 | theDrawer->PointAspect()->SetScale (MarkerSize); |
| 2078 | toRecompute = true; |
| 2079 | } |
| 2080 | } |
| 2081 | if (ToSetMaxParamValue != 0) |
| 2082 | { |
| 2083 | if (ToSetMaxParamValue != -1 |
| 2084 | || theDrawer->HasOwnMaximalParameterValue()) |
| 2085 | { |
| 2086 | theDrawer->SetMaximalParameterValue (MaxParamValue); |
| 2087 | toRecompute = true; |
| 2088 | } |
| 2089 | } |
| 2090 | if (ToSetFaceBoundaryDraw != 0) |
| 2091 | { |
| 2092 | if (ToSetFaceBoundaryDraw != -1 |
| 2093 | || theDrawer->HasOwnFaceBoundaryDraw()) |
| 2094 | { |
| 2095 | toRecompute = true; |
| 2096 | theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1); |
| 2097 | } |
| 2098 | } |
| 2099 | if (ToSetFaceBoundaryUpperContinuity != 0) |
| 2100 | { |
| 2101 | if (ToSetFaceBoundaryUpperContinuity != -1 |
| 2102 | || theDrawer->HasOwnFaceBoundaryUpperContinuity()) |
| 2103 | { |
| 2104 | toRecompute = true; |
| 2105 | if (ToSetFaceBoundaryUpperContinuity == -1) |
| 2106 | { |
| 2107 | theDrawer->UnsetFaceBoundaryUpperContinuity(); |
| 2108 | } |
| 2109 | else |
| 2110 | { |
| 2111 | theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity); |
| 2112 | } |
| 2113 | } |
| 2114 | } |
| 2115 | if (ToSetFaceBoundaryColor != 0) |
| 2116 | { |
| 2117 | if (ToSetFaceBoundaryColor != -1 |
| 2118 | || theDrawer->HasOwnFaceBoundaryAspect()) |
| 2119 | { |
| 2120 | if (ToSetFaceBoundaryColor == -1) |
| 2121 | { |
| 2122 | toRecompute = true; |
| 2123 | theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)()); |
| 2124 | } |
| 2125 | else |
| 2126 | { |
| 2127 | toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute; |
| 2128 | theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor); |
| 2129 | } |
| 2130 | } |
| 2131 | } |
| 2132 | if (ToSetFaceBoundaryWidth != 0) |
| 2133 | { |
| 2134 | if (ToSetFaceBoundaryWidth != -1 |
| 2135 | || theDrawer->HasOwnFaceBoundaryAspect()) |
| 2136 | { |
| 2137 | toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute; |
| 2138 | theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth); |
| 2139 | } |
| 2140 | } |
| 2141 | if (ToSetTypeOfFaceBoundaryLine != 0) |
| 2142 | { |
| 2143 | if (ToSetTypeOfFaceBoundaryLine != -1 |
| 2144 | || theDrawer->HasOwnFaceBoundaryAspect()) |
| 2145 | { |
| 2146 | toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute; |
| 2147 | theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine); |
| 2148 | } |
| 2149 | } |
| 2150 | if (ToSetShadingModel != 0) |
| 2151 | { |
| 2152 | if (ToSetShadingModel != -1 |
| 2153 | || theDrawer->HasOwnShadingAspect()) |
| 2154 | { |
| 2155 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2156 | theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel); |
| 2157 | } |
| 2158 | } |
| 2159 | if (ToSetBackFaceColor != 0) |
| 2160 | { |
| 2161 | if (ToSetBackFaceColor != -1 |
| 2162 | || theDrawer->HasOwnShadingAspect()) |
| 2163 | { |
| 2164 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2165 | theDrawer->ShadingAspect()->SetColor (BackFaceColor, Aspect_TOFM_BACK_SIDE); |
| 2166 | } |
| 2167 | } |
| 2168 | if (ToSetAlphaMode != 0) |
| 2169 | { |
| 2170 | if (ToSetAlphaMode != -1 |
| 2171 | || theDrawer->HasOwnShadingAspect()) |
| 2172 | { |
| 2173 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2174 | theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff); |
| 2175 | } |
| 2176 | } |
| 2177 | if (ToSetHatch != 0) |
| 2178 | { |
| 2179 | if (ToSetHatch != -1 |
| 2180 | || theDrawer->HasOwnShadingAspect()) |
| 2181 | { |
| 2182 | theDrawer->SetupOwnShadingAspect (aDefDrawer); |
| 2183 | Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect(); |
| 2184 | if (ToSetHatch == -1) |
| 2185 | { |
| 2186 | anAsp->SetInteriorStyle (Aspect_IS_SOLID); |
| 2187 | } |
| 2188 | else |
| 2189 | { |
| 2190 | anAsp->SetInteriorStyle (Aspect_IS_HATCH); |
| 2191 | if (!PathToHatchPattern.IsEmpty()) |
| 2192 | { |
| 2193 | Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap(); |
| 2194 | if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString()))) |
| 2195 | { |
| 2196 | anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage)); |
| 2197 | } |
| 2198 | else |
| 2199 | { |
| 2200 | std::cout << "Error: cannot load the following image: " << PathToHatchPattern << "\n"; |
| 2201 | } |
| 2202 | } |
| 2203 | else if (StdHatchStyle != -1) |
| 2204 | { |
| 2205 | anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle)); |
| 2206 | } |
| 2207 | } |
| 2208 | toRecompute = true; |
| 2209 | } |
| 2210 | } |
| 2211 | if (ToSetInterior != 0) |
| 2212 | { |
| 2213 | if (ToSetInterior != -1 |
| 2214 | || theDrawer->HasOwnShadingAspect()) |
| 2215 | { |
| 2216 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2217 | theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle); |
| 2218 | if (InteriorStyle == Aspect_IS_HATCH |
| 2219 | && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull()) |
| 2220 | { |
| 2221 | theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL); |
| 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | if (ToSetDrawSilhouette != 0) |
| 2226 | { |
| 2227 | if (ToSetDrawSilhouette != -1 |
| 2228 | || theDrawer->HasOwnShadingAspect()) |
| 2229 | { |
| 2230 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2231 | theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1); |
| 2232 | } |
| 2233 | } |
| 2234 | if (ToSetDrawEdges != 0) |
| 2235 | { |
| 2236 | if (ToSetDrawEdges != -1 |
| 2237 | || theDrawer->HasOwnShadingAspect()) |
| 2238 | { |
| 2239 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2240 | theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1); |
| 2241 | } |
| 2242 | } |
| 2243 | if (ToSetQuadEdges != 0) |
| 2244 | { |
| 2245 | if (ToSetQuadEdges != -1 |
| 2246 | || theDrawer->HasOwnShadingAspect()) |
| 2247 | { |
| 2248 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2249 | theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1); |
| 2250 | } |
| 2251 | } |
| 2252 | if (ToSetEdgeWidth != 0) |
| 2253 | { |
| 2254 | if (ToSetEdgeWidth != -1 |
| 2255 | || theDrawer->HasOwnShadingAspect()) |
| 2256 | { |
| 2257 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2258 | theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth); |
| 2259 | } |
| 2260 | } |
| 2261 | if (ToSetTypeOfEdge != 0) |
| 2262 | { |
| 2263 | if (ToSetTypeOfEdge != -1 |
| 2264 | || theDrawer->HasOwnShadingAspect()) |
| 2265 | { |
| 2266 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2267 | theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge); |
| 2268 | if (ToSetInterior == 0) |
| 2269 | { |
| 2270 | theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1 |
| 2271 | && TypeOfEdge != Aspect_TOL_EMPTY); |
| 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | if (ToSetEdgeColor != 0) |
| 2276 | { |
| 2277 | if (ToSetEdgeColor != -1 |
| 2278 | || theDrawer->HasOwnShadingAspect()) |
| 2279 | { |
| 2280 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; |
| 2281 | if (ToSetEdgeColor == -1) |
| 2282 | { |
| 2283 | theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor()); |
| 2284 | } |
| 2285 | else |
| 2286 | { |
| 2287 | theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor); |
| 2288 | } |
| 2289 | } |
| 2290 | } |
| 2291 | return toRecompute; |
| 2292 | } |
| 2293 | }; |
| 2294 | |
| 2295 | //============================================================================== |
| 2296 | //function : VAspects |
| 2297 | //purpose : |
| 2298 | //============================================================================== |
| 2299 | static Standard_Integer VAspects (Draw_Interpretor& theDI, |
| 2300 | Standard_Integer theArgNb, |
| 2301 | const char** theArgVec) |
| 2302 | { |
| 2303 | TCollection_AsciiString aCmdName (theArgVec[0]); |
| 2304 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 2305 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
| 2306 | if (aCtx.IsNull()) |
| 2307 | { |
| 2308 | std::cerr << "Error: no active view!\n"; |
| 2309 | return 1; |
| 2310 | } |
| 2311 | |
| 2312 | Standard_Integer anArgIter = 1; |
| 2313 | Standard_Boolean isDefaults = Standard_False; |
| 2314 | NCollection_Sequence<TCollection_AsciiString> aNames; |
| 2315 | for (; anArgIter < theArgNb; ++anArgIter) |
| 2316 | { |
| 2317 | TCollection_AsciiString anArg = theArgVec[anArgIter]; |
| 2318 | if (anUpdateTool.parseRedrawMode (anArg)) |
| 2319 | { |
| 2320 | continue; |
| 2321 | } |
| 2322 | else if (!anArg.IsEmpty() |
| 2323 | && anArg.Value (1) != '-') |
| 2324 | { |
| 2325 | aNames.Append (anArg); |
| 2326 | } |
| 2327 | else |
| 2328 | { |
| 2329 | if (anArg == "-defaults") |
| 2330 | { |
| 2331 | isDefaults = Standard_True; |
| 2332 | ++anArgIter; |
| 2333 | } |
| 2334 | break; |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | if (!aNames.IsEmpty() && isDefaults) |
| 2339 | { |
| 2340 | std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n"; |
| 2341 | return 1; |
| 2342 | } |
| 2343 | |
| 2344 | NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges; |
| 2345 | aChanges.Append (ViewerTest_AspectsChangeSet()); |
| 2346 | ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast(); |
| 2347 | |
| 2348 | // parse syntax of legacy commands |
| 2349 | bool toParseAliasArgs = false; |
| 2350 | Standard_Boolean toDump = 0; |
| 2351 | Standard_Boolean toCompactDump = 0; |
| 2352 | Standard_Integer aDumpDepth = -1; |
| 2353 | if (aCmdName == "vsetwidth") |
| 2354 | { |
| 2355 | if (aNames.IsEmpty() |
| 2356 | || !aNames.Last().IsRealValue()) |
| 2357 | { |
| 2358 | std::cout << "Error: not enough arguments!\n"; |
| 2359 | return 1; |
| 2360 | } |
| 2361 | aChangeSet->ToSetLineWidth = 1; |
| 2362 | aChangeSet->LineWidth = aNames.Last().RealValue(); |
| 2363 | aNames.Remove (aNames.Length()); |
| 2364 | } |
| 2365 | else if (aCmdName == "vunsetwidth") |
| 2366 | { |
| 2367 | aChangeSet->ToSetLineWidth = -1; |
| 2368 | } |
| 2369 | else if (aCmdName == "vsetcolor") |
| 2370 | { |
| 2371 | if (aNames.IsEmpty()) |
| 2372 | { |
| 2373 | std::cout << "Error: not enough arguments!\n"; |
| 2374 | return 1; |
| 2375 | } |
| 2376 | aChangeSet->ToSetColor = 1; |
| 2377 | |
| 2378 | Quantity_NameOfColor aColor = Quantity_NOC_BLACK; |
| 2379 | Standard_Boolean isOk = Standard_False; |
| 2380 | if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor)) |
| 2381 | { |
| 2382 | aChangeSet->Color = aColor; |
| 2383 | aNames.Remove (aNames.Length()); |
| 2384 | isOk = Standard_True; |
| 2385 | } |
| 2386 | else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color)) |
| 2387 | { |
| 2388 | aNames.Remove (aNames.Length()); |
| 2389 | isOk = Standard_True; |
| 2390 | } |
| 2391 | else if (aNames.Length() >= 3) |
| 2392 | { |
| 2393 | const char* anArgVec[3] = |
| 2394 | { |
| 2395 | aNames.Value (aNames.Upper() - 2).ToCString(), |
| 2396 | aNames.Value (aNames.Upper() - 1).ToCString(), |
| 2397 | aNames.Value (aNames.Upper() - 0).ToCString(), |
| 2398 | }; |
| 2399 | |
| 2400 | Standard_Integer aNbParsed = ViewerTest::ParseColor (3, anArgVec, aChangeSet->Color); |
| 2401 | isOk = aNbParsed == 3; |
| 2402 | aNames.Remove (aNames.Length()); |
| 2403 | aNames.Remove (aNames.Length()); |
| 2404 | aNames.Remove (aNames.Length()); |
| 2405 | } |
| 2406 | if (!isOk) |
| 2407 | { |
| 2408 | std::cout << "Error: not enough arguments!\n"; |
| 2409 | return 1; |
| 2410 | } |
| 2411 | } |
| 2412 | else if (aCmdName == "vunsetcolor") |
| 2413 | { |
| 2414 | aChangeSet->ToSetColor = -1; |
| 2415 | } |
| 2416 | else if (aCmdName == "vsettransparency") |
| 2417 | { |
| 2418 | if (aNames.IsEmpty() |
| 2419 | || !aNames.Last().IsRealValue()) |
| 2420 | { |
| 2421 | std::cout << "Error: not enough arguments!\n"; |
| 2422 | return 1; |
| 2423 | } |
| 2424 | aChangeSet->ToSetTransparency = 1; |
| 2425 | aChangeSet->Transparency = aNames.Last().RealValue(); |
| 2426 | aNames.Remove (aNames.Length()); |
| 2427 | } |
| 2428 | else if (aCmdName == "vunsettransparency") |
| 2429 | { |
| 2430 | aChangeSet->ToSetTransparency = -1; |
| 2431 | } |
| 2432 | else if (aCmdName == "vsetmaterial") |
| 2433 | { |
| 2434 | if (aNames.IsEmpty()) |
| 2435 | { |
| 2436 | std::cout << "Error: not enough arguments!\n"; |
| 2437 | return 1; |
| 2438 | } |
| 2439 | aChangeSet->ToSetMaterial = 1; |
| 2440 | aChangeSet->MatName = aNames.Last(); |
| 2441 | aNames.Remove (aNames.Length()); |
| 2442 | if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material)) |
| 2443 | { |
| 2444 | std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n"; |
| 2445 | return 1; |
| 2446 | } |
| 2447 | } |
| 2448 | else if (aCmdName == "vunsetmaterial") |
| 2449 | { |
| 2450 | aChangeSet->ToSetMaterial = -1; |
| 2451 | } |
| 2452 | else if (aCmdName == "vsetinteriorstyle") |
| 2453 | { |
| 2454 | if (aNames.IsEmpty() |
| 2455 | || !aNames.Last().IsRealValue()) |
| 2456 | { |
| 2457 | std::cout << "Error: not enough arguments!\n"; |
| 2458 | return 1; |
| 2459 | } |
| 2460 | aChangeSet->ToSetInterior = 1; |
| 2461 | if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle)) |
| 2462 | { |
| 2463 | std::cout << "Error: wrong syntax at " << aNames.Last() << "\n"; |
| 2464 | return 1; |
| 2465 | } |
| 2466 | aNames.Remove (aNames.Length()); |
| 2467 | } |
| 2468 | else if (aCmdName == "vsetedgetype") |
| 2469 | { |
| 2470 | aChangeSet->ToSetDrawEdges = 1; |
| 2471 | toParseAliasArgs = true; |
| 2472 | } |
| 2473 | else if (aCmdName == "vunsetedgetype") |
| 2474 | { |
| 2475 | aChangeSet->ToSetDrawEdges = -1; |
| 2476 | aChangeSet->ToSetEdgeColor = -1; |
| 2477 | aChangeSet->ToSetTypeOfEdge = -1; |
| 2478 | aChangeSet->TypeOfEdge = Aspect_TOL_SOLID; |
| 2479 | } |
| 2480 | else if (aCmdName == "vshowfaceboundary") |
| 2481 | { |
| 2482 | aChangeSet->ToSetFaceBoundaryDraw = 1; |
| 2483 | toParseAliasArgs = true; |
| 2484 | if (aNames.Size() >= 2 |
| 2485 | && aNames.Value (2).IsIntegerValue()) |
| 2486 | { |
| 2487 | if (aNames.Size() == 7) |
| 2488 | { |
| 2489 | if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine)) |
| 2490 | { |
| 2491 | aChangeSet->ToSetTypeOfFaceBoundaryLine = 1; |
| 2492 | aNames.Remove (7); |
| 2493 | } |
| 2494 | } |
| 2495 | if (aNames.Size() == 6 |
| 2496 | && aNames.Value (6).IsRealValue()) |
| 2497 | { |
| 2498 | aChangeSet->ToSetFaceBoundaryWidth = 1; |
| 2499 | aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue(); |
| 2500 | aNames.Remove (6); |
| 2501 | } |
| 2502 | if (aNames.Size() == 5 |
| 2503 | && aNames.Value (3).IsIntegerValue() |
| 2504 | && aNames.Value (4).IsIntegerValue() |
| 2505 | && aNames.Value (5).IsIntegerValue()) |
| 2506 | { |
| 2507 | aChangeSet->ToSetFaceBoundaryColor = 1; |
| 2508 | aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0, |
| 2509 | aNames.Value (4).IntegerValue() / 255.0, |
| 2510 | aNames.Value (5).IntegerValue() / 255.0, |
| 2511 | Quantity_TOC_sRGB); |
| 2512 | aNames.Remove (5); |
| 2513 | aNames.Remove (4); |
| 2514 | aNames.Remove (3); |
| 2515 | } |
| 2516 | if (aNames.Size() == 2) |
| 2517 | { |
| 2518 | toParseAliasArgs = false; |
| 2519 | aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1; |
| 2520 | aNames.Remove (2); |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | else if (anArgIter >= theArgNb) |
| 2525 | { |
| 2526 | std::cout << "Error: not enough arguments!\n"; |
| 2527 | return 1; |
| 2528 | } |
| 2529 | |
| 2530 | if (!aChangeSet->IsEmpty() |
| 2531 | && !toParseAliasArgs) |
| 2532 | { |
| 2533 | anArgIter = theArgNb; |
| 2534 | } |
| 2535 | for (; anArgIter < theArgNb; ++anArgIter) |
| 2536 | { |
| 2537 | TCollection_AsciiString anArg = theArgVec[anArgIter]; |
| 2538 | anArg.LowerCase(); |
| 2539 | if (anArg == "-setwidth" |
| 2540 | || anArg == "-width" |
| 2541 | || anArg == "-setlinewidth" |
| 2542 | || anArg == "-linewidth" |
| 2543 | || anArg == "-setedgewidth" |
| 2544 | || anArg == "-setedgeswidth" |
| 2545 | || anArg == "-edgewidth" |
| 2546 | || anArg == "-edgeswidth" |
| 2547 | || anArg == "-setfaceboundarywidth" |
| 2548 | || anArg == "-setboundarywidth" |
| 2549 | || anArg == "-faceboundarywidth" |
| 2550 | || anArg == "-boundarywidth") |
| 2551 | { |
| 2552 | if (++anArgIter >= theArgNb) |
| 2553 | { |
| 2554 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2555 | return 1; |
| 2556 | } |
| 2557 | |
| 2558 | const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]); |
| 2559 | if (anArg == "-setedgewidth" |
| 2560 | || anArg == "-setedgeswidth" |
| 2561 | || anArg == "-edgewidth" |
| 2562 | || anArg == "-edgeswidth" |
| 2563 | || aCmdName == "vsetedgetype") |
| 2564 | { |
| 2565 | aChangeSet->ToSetEdgeWidth = 1; |
| 2566 | aChangeSet->EdgeWidth = aWidth; |
| 2567 | } |
| 2568 | else if (anArg == "-setfaceboundarywidth" |
| 2569 | || anArg == "-setboundarywidth" |
| 2570 | || anArg == "-faceboundarywidth" |
| 2571 | || anArg == "-boundarywidth" |
| 2572 | || aCmdName == "vshowfaceboundary") |
| 2573 | { |
| 2574 | aChangeSet->ToSetFaceBoundaryWidth = 1; |
| 2575 | aChangeSet->FaceBoundaryWidth = aWidth; |
| 2576 | } |
| 2577 | else |
| 2578 | { |
| 2579 | aChangeSet->ToSetLineWidth = 1; |
| 2580 | aChangeSet->LineWidth = aWidth; |
| 2581 | } |
| 2582 | } |
| 2583 | else if (anArg == "-unsetwidth" |
| 2584 | || anArg == "-unsetlinewidth" |
| 2585 | || anArg == "-unsetedgewidth") |
| 2586 | { |
| 2587 | if (anArg == "-unsetedgewidth") |
| 2588 | { |
| 2589 | aChangeSet->ToSetEdgeWidth = -1; |
| 2590 | aChangeSet->EdgeWidth = 1.0; |
| 2591 | } |
| 2592 | else |
| 2593 | { |
| 2594 | aChangeSet->ToSetLineWidth = -1; |
| 2595 | aChangeSet->LineWidth = 1.0; |
| 2596 | } |
| 2597 | } |
| 2598 | else if (anArg == "-settransp" |
| 2599 | || anArg == "-settransparency" |
| 2600 | || anArg == "-transparency" |
| 2601 | || anArg == "-transp") |
| 2602 | { |
| 2603 | if (++anArgIter >= theArgNb) |
| 2604 | { |
| 2605 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2606 | return 1; |
| 2607 | } |
| 2608 | aChangeSet->ToSetTransparency = 1; |
| 2609 | aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]); |
| 2610 | if (aChangeSet->Transparency >= 0.0 |
| 2611 | && aChangeSet->Transparency <= Precision::Confusion()) |
| 2612 | { |
| 2613 | aChangeSet->ToSetTransparency = -1; |
| 2614 | aChangeSet->Transparency = 0.0; |
| 2615 | } |
| 2616 | } |
| 2617 | else if (anArg == "-setalphamode" |
| 2618 | || anArg == "-alphamode") |
| 2619 | { |
| 2620 | if (++anArgIter >= theArgNb) |
| 2621 | { |
| 2622 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2623 | return 1; |
| 2624 | } |
| 2625 | aChangeSet->ToSetAlphaMode = 1; |
| 2626 | aChangeSet->AlphaCutoff = 0.5f; |
| 2627 | { |
| 2628 | TCollection_AsciiString aParam (theArgVec[anArgIter]); |
| 2629 | aParam.LowerCase(); |
| 2630 | if (aParam == "opaque") |
| 2631 | { |
| 2632 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque; |
| 2633 | } |
| 2634 | else if (aParam == "mask") |
| 2635 | { |
| 2636 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask; |
| 2637 | } |
| 2638 | else if (aParam == "blend") |
| 2639 | { |
| 2640 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend; |
| 2641 | } |
| 2642 | else if (aParam == "blendauto" |
| 2643 | || aParam == "auto") |
| 2644 | { |
| 2645 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto; |
| 2646 | } |
| 2647 | else |
| 2648 | { |
| 2649 | std::cout << "Error: wrong syntax at " << aParam << "\n"; |
| 2650 | return 1; |
| 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | if (anArgIter + 1 < theArgNb |
| 2655 | && theArgVec[anArgIter + 1][0] != '-') |
| 2656 | { |
| 2657 | TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]); |
| 2658 | if (aParam2.IsRealValue()) |
| 2659 | { |
| 2660 | aChangeSet->AlphaCutoff = (float )aParam2.RealValue(); |
| 2661 | ++anArgIter; |
| 2662 | } |
| 2663 | } |
| 2664 | } |
| 2665 | else if (anArg == "-setvis" |
| 2666 | || anArg == "-setvisibility" |
| 2667 | || anArg == "-visibility") |
| 2668 | { |
| 2669 | if (++anArgIter >= theArgNb) |
| 2670 | { |
| 2671 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2672 | return 1; |
| 2673 | } |
| 2674 | |
| 2675 | aChangeSet->ToSetVisibility = 1; |
| 2676 | aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]); |
| 2677 | } |
| 2678 | else if (anArg == "-setalpha" |
| 2679 | || anArg == "-alpha") |
| 2680 | { |
| 2681 | if (++anArgIter >= theArgNb) |
| 2682 | { |
| 2683 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2684 | return 1; |
| 2685 | } |
| 2686 | aChangeSet->ToSetTransparency = 1; |
| 2687 | aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]); |
| 2688 | if (aChangeSet->Transparency < 0.0 |
| 2689 | || aChangeSet->Transparency > 1.0) |
| 2690 | { |
| 2691 | std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n"; |
| 2692 | return 1; |
| 2693 | } |
| 2694 | aChangeSet->Transparency = 1.0 - aChangeSet->Transparency; |
| 2695 | if (aChangeSet->Transparency >= 0.0 |
| 2696 | && aChangeSet->Transparency <= Precision::Confusion()) |
| 2697 | { |
| 2698 | aChangeSet->ToSetTransparency = -1; |
| 2699 | aChangeSet->Transparency = 0.0; |
| 2700 | } |
| 2701 | } |
| 2702 | else if (anArg == "-unsettransp" |
| 2703 | || anArg == "-unsettransparency" |
| 2704 | || anArg == "-unsetalpha" |
| 2705 | || anArg == "-opaque") |
| 2706 | { |
| 2707 | aChangeSet->ToSetTransparency = -1; |
| 2708 | aChangeSet->Transparency = 0.0; |
| 2709 | } |
| 2710 | else if (anArg == "-setcolor" |
| 2711 | || anArg == "-color" |
| 2712 | || anArg == "-setbackfacecolor" |
| 2713 | || anArg == "-backfacecolor" |
| 2714 | || anArg == "-setbackcolor" |
| 2715 | || anArg == "-backcolor" |
| 2716 | || anArg == "-setfaceboundarycolor" |
| 2717 | || anArg == "-setboundarycolor" |
| 2718 | || anArg == "-faceboundarycolor" |
| 2719 | || anArg == "-boundarycolor") |
| 2720 | { |
| 2721 | Quantity_Color aColor; |
| 2722 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
| 2723 | theArgVec + anArgIter + 1, |
| 2724 | aColor); |
| 2725 | if (aNbParsed == 0) |
| 2726 | { |
| 2727 | std::cout << "Syntax error at '" << anArg << "'\n"; |
| 2728 | return 1; |
| 2729 | } |
| 2730 | anArgIter += aNbParsed; |
| 2731 | if (aCmdName == "vsetedgetype") |
| 2732 | { |
| 2733 | aChangeSet->ToSetEdgeColor = 1; |
| 2734 | aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor); |
| 2735 | } |
| 2736 | else if (aCmdName == "vshowfaceboundary" |
| 2737 | || anArg == "-setfaceboundarycolor" |
| 2738 | || anArg == "-setboundarycolor" |
| 2739 | || anArg == "-faceboundarycolor" |
| 2740 | || anArg == "-boundarycolor") |
| 2741 | { |
| 2742 | aChangeSet->ToSetFaceBoundaryColor = 1; |
| 2743 | aChangeSet->FaceBoundaryColor = aColor; |
| 2744 | } |
| 2745 | else if (anArg == "-setbackfacecolor" |
| 2746 | || anArg == "-backfacecolor" |
| 2747 | || anArg == "-setbackcolor" |
| 2748 | || anArg == "-backcolor") |
| 2749 | { |
| 2750 | aChangeSet->ToSetBackFaceColor = 1; |
| 2751 | aChangeSet->BackFaceColor = aColor; |
| 2752 | } |
| 2753 | else |
| 2754 | { |
| 2755 | aChangeSet->ToSetColor = 1; |
| 2756 | aChangeSet->Color = aColor; |
| 2757 | } |
| 2758 | } |
| 2759 | else if (anArg == "-setlinetype" |
| 2760 | || anArg == "-linetype" |
| 2761 | || anArg == "-setedgetype" |
| 2762 | || anArg == "-setedgestype" |
| 2763 | || anArg == "-edgetype" |
| 2764 | || anArg == "-edgestype" |
| 2765 | || anArg == "-setfaceboundarystyle" |
| 2766 | || anArg == "-faceboundarystyle" |
| 2767 | || anArg == "-boundarystyle" |
| 2768 | || anArg == "-setfaceboundarytype" |
| 2769 | || anArg == "-faceboundarytype" |
| 2770 | || anArg == "-setboundarytype" |
| 2771 | || anArg == "-boundarytype" |
| 2772 | || anArg == "-type") |
| 2773 | { |
| 2774 | if (++anArgIter >= theArgNb) |
| 2775 | { |
| 2776 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2777 | return 1; |
| 2778 | } |
| 2779 | Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY; |
| 2780 | if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType)) |
| 2781 | { |
| 2782 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2783 | return 1; |
| 2784 | } |
| 2785 | if (anArg == "-setedgetype" |
| 2786 | || anArg == "-setedgestype" |
| 2787 | || anArg == "-edgetype" |
| 2788 | || anArg == "-edgestype" |
| 2789 | || aCmdName == "vsetedgetype") |
| 2790 | { |
| 2791 | aChangeSet->TypeOfEdge = aLineType; |
| 2792 | aChangeSet->ToSetTypeOfEdge = 1; |
| 2793 | } |
| 2794 | else if (anArg == "-setfaceboundarystyle" |
| 2795 | || anArg == "-faceboundarystyle" |
| 2796 | || anArg == "-boundarystyle" |
| 2797 | || anArg == "-setfaceboundarytype" |
| 2798 | || anArg == "-faceboundarytype" |
| 2799 | || anArg == "-setboundarytype" |
| 2800 | || anArg == "-boundarytype" |
| 2801 | || aCmdName == "vshowfaceboundary") |
| 2802 | { |
| 2803 | aChangeSet->TypeOfFaceBoundaryLine = aLineType; |
| 2804 | aChangeSet->ToSetTypeOfFaceBoundaryLine = 1; |
| 2805 | } |
| 2806 | else |
| 2807 | { |
| 2808 | aChangeSet->TypeOfLine = aLineType; |
| 2809 | aChangeSet->ToSetTypeOfLine = 1; |
| 2810 | } |
| 2811 | } |
| 2812 | else if (anArg == "-unsetlinetype" |
| 2813 | || anArg == "-unsetedgetype" |
| 2814 | || anArg == "-unsetedgestype") |
| 2815 | { |
| 2816 | if (anArg == "-unsetedgetype" |
| 2817 | || anArg == "-unsetedgestype") |
| 2818 | { |
| 2819 | aChangeSet->ToSetTypeOfEdge = -1; |
| 2820 | } |
| 2821 | else |
| 2822 | { |
| 2823 | aChangeSet->ToSetTypeOfLine = -1; |
| 2824 | } |
| 2825 | } |
| 2826 | else if (anArg == "-setmarkertype" |
| 2827 | || anArg == "-markertype" |
| 2828 | || anArg == "-setpointtype" |
| 2829 | || anArg == "-pointtype") |
| 2830 | { |
| 2831 | if (++anArgIter >= theArgNb) |
| 2832 | { |
| 2833 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2834 | return 1; |
| 2835 | } |
| 2836 | if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage)) |
| 2837 | { |
| 2838 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2839 | return 1; |
| 2840 | } |
| 2841 | |
| 2842 | aChangeSet->ToSetTypeOfMarker = 1; |
| 2843 | } |
| 2844 | else if (anArg == "-unsetmarkertype" |
| 2845 | || anArg == "-unsetpointtype") |
| 2846 | { |
| 2847 | aChangeSet->ToSetTypeOfMarker = -1; |
| 2848 | } |
| 2849 | else if (anArg == "-setmarkersize" |
| 2850 | || anArg == "-markersize" |
| 2851 | || anArg == "-setpointsize" |
| 2852 | || anArg == "-pointsize") |
| 2853 | { |
| 2854 | if (++anArgIter >= theArgNb) |
| 2855 | { |
| 2856 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2857 | return 1; |
| 2858 | } |
| 2859 | aChangeSet->ToSetMarkerSize = 1; |
| 2860 | aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]); |
| 2861 | } |
| 2862 | else if (anArg == "-unsetmarkersize" |
| 2863 | || anArg == "-unsetpointsize") |
| 2864 | { |
| 2865 | aChangeSet->ToSetMarkerSize = -1; |
| 2866 | aChangeSet->MarkerSize = 1.0; |
| 2867 | } |
| 2868 | else if (anArg == "-unsetcolor") |
| 2869 | { |
| 2870 | aChangeSet->ToSetColor = -1; |
| 2871 | aChangeSet->Color = DEFAULT_COLOR; |
| 2872 | } |
| 2873 | else if (anArg == "-setmat" |
| 2874 | || anArg == "-mat" |
| 2875 | || anArg == "-setmaterial" |
| 2876 | || anArg == "-material") |
| 2877 | { |
| 2878 | if (++anArgIter >= theArgNb) |
| 2879 | { |
| 2880 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2881 | return 1; |
| 2882 | } |
| 2883 | aChangeSet->ToSetMaterial = 1; |
| 2884 | aChangeSet->MatName = theArgVec[anArgIter]; |
| 2885 | if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material)) |
| 2886 | { |
| 2887 | std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n"; |
| 2888 | return 1; |
| 2889 | } |
| 2890 | } |
| 2891 | else if (anArg == "-unsetmat" |
| 2892 | || anArg == "-unsetmaterial") |
| 2893 | { |
| 2894 | aChangeSet->ToSetMaterial = -1; |
| 2895 | aChangeSet->Material = Graphic3d_NOM_DEFAULT; |
| 2896 | } |
| 2897 | else if (anArg == "-subshape" |
| 2898 | || anArg == "-subshapes") |
| 2899 | { |
| 2900 | if (isDefaults) |
| 2901 | { |
| 2902 | std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n"; |
| 2903 | return 1; |
| 2904 | } |
| 2905 | |
| 2906 | if (aNames.IsEmpty()) |
| 2907 | { |
| 2908 | std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n"; |
| 2909 | return 1; |
| 2910 | } |
| 2911 | |
| 2912 | aChanges.Append (ViewerTest_AspectsChangeSet()); |
| 2913 | aChangeSet = &aChanges.ChangeLast(); |
| 2914 | |
| 2915 | for (++anArgIter; anArgIter < theArgNb; ++anArgIter) |
| 2916 | { |
| 2917 | Standard_CString aSubShapeName = theArgVec[anArgIter]; |
| 2918 | if (*aSubShapeName == '-') |
| 2919 | { |
| 2920 | --anArgIter; |
| 2921 | break; |
| 2922 | } |
| 2923 | |
| 2924 | TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName); |
| 2925 | if (aSubShape.IsNull()) |
| 2926 | { |
| 2927 | std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n"; |
| 2928 | return 1; |
| 2929 | } |
| 2930 | aChangeSet->SubShapes.Append (aSubShape); |
| 2931 | } |
| 2932 | |
| 2933 | if (aChangeSet->SubShapes.IsEmpty()) |
| 2934 | { |
| 2935 | std::cerr << "Error: empty list is specified after -subshapes!\n"; |
| 2936 | return 1; |
| 2937 | } |
| 2938 | } |
| 2939 | else if (anArg == "-setfreeboundary" |
| 2940 | || anArg == "-freeboundary" |
| 2941 | || anArg == "-setfb" |
| 2942 | || anArg == "-fb") |
| 2943 | { |
| 2944 | bool toEnable = true; |
| 2945 | if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable)) |
| 2946 | { |
| 2947 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2948 | return 1; |
| 2949 | } |
| 2950 | ++anArgIter; |
| 2951 | aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1; |
| 2952 | } |
| 2953 | else if (anArg == "-setfreeboundarywidth" |
| 2954 | || anArg == "-freeboundarywidth" |
| 2955 | || anArg == "-setfbwidth" |
| 2956 | || anArg == "-fbwidth") |
| 2957 | { |
| 2958 | if (++anArgIter >= theArgNb) |
| 2959 | { |
| 2960 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 2961 | return 1; |
| 2962 | } |
| 2963 | aChangeSet->ToSetFreeBoundaryWidth = 1; |
| 2964 | aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]); |
| 2965 | } |
| 2966 | else if (anArg == "-unsetfreeboundarywidth" |
| 2967 | || anArg == "-unsetfbwidth") |
| 2968 | { |
| 2969 | aChangeSet->ToSetFreeBoundaryWidth = -1; |
| 2970 | aChangeSet->FreeBoundaryWidth = 1.0; |
| 2971 | } |
| 2972 | else if (anArg == "-setfreeboundarycolor" |
| 2973 | || anArg == "-freeboundarycolor" |
| 2974 | || anArg == "-setfbcolor" |
| 2975 | || anArg == "-fbcolor") |
| 2976 | { |
| 2977 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
| 2978 | theArgVec + anArgIter + 1, |
| 2979 | aChangeSet->FreeBoundaryColor); |
| 2980 | if (aNbParsed == 0) |
| 2981 | { |
| 2982 | std::cout << "Syntax error at '" << anArg << "'\n"; |
| 2983 | return 1; |
| 2984 | } |
| 2985 | anArgIter += aNbParsed; |
| 2986 | aChangeSet->ToSetFreeBoundaryColor = 1; |
| 2987 | } |
| 2988 | else if (anArg == "-unsetfreeboundarycolor" |
| 2989 | || anArg == "-unsetfbcolor") |
| 2990 | { |
| 2991 | aChangeSet->ToSetFreeBoundaryColor = -1; |
| 2992 | aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR; |
| 2993 | } |
| 2994 | else if (anArg == "-setisoontriangulation" |
| 2995 | || anArg == "-isoontriangulation" |
| 2996 | || anArg == "-setisoontriang" |
| 2997 | || anArg == "-isoontriang") |
| 2998 | { |
| 2999 | bool toEnable = true; |
| 3000 | if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable)) |
| 3001 | { |
| 3002 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3003 | return 1; |
| 3004 | } |
| 3005 | ++anArgIter; |
| 3006 | aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1; |
| 3007 | } |
| 3008 | else if (anArg == "-setfaceboundarydraw" |
| 3009 | || anArg == "-setdrawfaceboundary" |
| 3010 | || anArg == "-setdrawfaceboundaries" |
| 3011 | || anArg == "-setshowfaceboundary" |
| 3012 | || anArg == "-setshowfaceboundaries" |
| 3013 | || anArg == "-setdrawfaceedges" |
| 3014 | || anArg == "-faceboundarydraw" |
| 3015 | || anArg == "-drawfaceboundary" |
| 3016 | || anArg == "-drawfaceboundaries" |
| 3017 | || anArg == "-showfaceboundary" |
| 3018 | || anArg == "-showfaceboundaries" |
| 3019 | || anArg == "-drawfaceedges" |
| 3020 | || anArg == "-faceboundary" |
| 3021 | || anArg == "-faceboundaries" |
| 3022 | || anArg == "-faceedges") |
| 3023 | { |
| 3024 | bool toEnable = true; |
| 3025 | if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable)) |
| 3026 | { |
| 3027 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3028 | return 1; |
| 3029 | } |
| 3030 | ++anArgIter; |
| 3031 | aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1; |
| 3032 | } |
| 3033 | else if (anArg == "-unsetfaceboundary" |
| 3034 | || anArg == "-unsetboundary") |
| 3035 | { |
| 3036 | aChangeSet->ToSetFaceBoundaryDraw = -1; |
| 3037 | aChangeSet->ToSetFaceBoundaryColor = -1; |
| 3038 | } |
| 3039 | else if (anArg == "-setmostcontinuity" |
| 3040 | || anArg == "-mostcontinuity") |
| 3041 | { |
| 3042 | TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : ""); |
| 3043 | aClassArg.LowerCase(); |
| 3044 | GeomAbs_Shape aClass = GeomAbs_CN; |
| 3045 | if (aClassArg == "c0" |
| 3046 | || aClassArg == "0") |
| 3047 | { |
| 3048 | aClass = GeomAbs_C0; |
| 3049 | } |
| 3050 | else if (aClassArg == "c1" |
| 3051 | || aClassArg == "1") |
| 3052 | { |
| 3053 | aClass = GeomAbs_C1; |
| 3054 | } |
| 3055 | else if (aClassArg == "c2" |
| 3056 | || aClassArg == "2") |
| 3057 | { |
| 3058 | aClass = GeomAbs_C2; |
| 3059 | } |
| 3060 | else if (aClassArg == "c3" |
| 3061 | || aClassArg == "3") |
| 3062 | { |
| 3063 | aClass = GeomAbs_C3; |
| 3064 | } |
| 3065 | else if (aClassArg == "cn" |
| 3066 | || aClassArg == "n") |
| 3067 | { |
| 3068 | aClass = GeomAbs_CN; |
| 3069 | } |
| 3070 | else |
| 3071 | { |
| 3072 | std::cout << "Syntax error at '" << anArg << "'\n"; |
| 3073 | return 1; |
| 3074 | } |
| 3075 | |
| 3076 | ++anArgIter; |
| 3077 | aChangeSet->ToSetFaceBoundaryUpperContinuity = 1; |
| 3078 | aChangeSet->FaceBoundaryUpperContinuity = aClass; |
| 3079 | } |
| 3080 | else if (anArg == "-setmaxparamvalue" |
| 3081 | || anArg == "-maxparamvalue") |
| 3082 | { |
| 3083 | if (++anArgIter >= theArgNb) |
| 3084 | { |
| 3085 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3086 | return 1; |
| 3087 | } |
| 3088 | aChangeSet->ToSetMaxParamValue = 1; |
| 3089 | aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]); |
| 3090 | } |
| 3091 | else if (anArg == "-setsensitivity" |
| 3092 | || anArg == "-sensitivity") |
| 3093 | { |
| 3094 | if (isDefaults) |
| 3095 | { |
| 3096 | std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n"; |
| 3097 | return 1; |
| 3098 | } |
| 3099 | |
| 3100 | if (aNames.IsEmpty()) |
| 3101 | { |
| 3102 | std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n"; |
| 3103 | return 1; |
| 3104 | } |
| 3105 | |
| 3106 | if (anArgIter + 2 >= theArgNb) |
| 3107 | { |
| 3108 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3109 | return 1; |
| 3110 | } |
| 3111 | aChangeSet->ToSetSensitivity = 1; |
| 3112 | aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]); |
| 3113 | aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]); |
| 3114 | } |
| 3115 | else if (anArg == "-sethatch" |
| 3116 | || anArg == "-hatch") |
| 3117 | { |
| 3118 | if (isDefaults) |
| 3119 | { |
| 3120 | std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n"; |
| 3121 | return 1; |
| 3122 | } |
| 3123 | |
| 3124 | if (aNames.IsEmpty()) |
| 3125 | { |
| 3126 | std::cout << "Error: object should be specified explicitly when -setHatch is used!\n"; |
| 3127 | return 1; |
| 3128 | } |
| 3129 | |
| 3130 | aChangeSet->ToSetHatch = 1; |
| 3131 | TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]); |
| 3132 | if (anArgHatch.Length() <= 2) |
| 3133 | { |
| 3134 | const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString()); |
| 3135 | if (anIntStyle < 0 |
| 3136 | || anIntStyle >= Aspect_HS_NB) |
| 3137 | { |
| 3138 | std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n"; |
| 3139 | return 1; |
| 3140 | } |
| 3141 | aChangeSet->StdHatchStyle = anIntStyle; |
| 3142 | } |
| 3143 | else |
| 3144 | { |
| 3145 | aChangeSet->PathToHatchPattern = anArgHatch; |
| 3146 | } |
| 3147 | } |
| 3148 | else if (anArg == "-setshadingmodel" |
| 3149 | || anArg == "-setshading" |
| 3150 | || anArg == "-shadingmodel" |
| 3151 | || anArg == "-shading") |
| 3152 | { |
| 3153 | if (++anArgIter >= theArgNb) |
| 3154 | { |
| 3155 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3156 | return 1; |
| 3157 | } |
| 3158 | aChangeSet->ToSetShadingModel = 1; |
| 3159 | aChangeSet->ShadingModelName = theArgVec[anArgIter]; |
| 3160 | if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel)) |
| 3161 | { |
| 3162 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3163 | return 1; |
| 3164 | } |
| 3165 | } |
| 3166 | else if (anArg == "-unsetshadingmodel") |
| 3167 | { |
| 3168 | aChangeSet->ToSetShadingModel = -1; |
| 3169 | aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT; |
| 3170 | } |
| 3171 | else if (anArg == "-setinterior" |
| 3172 | || anArg == "-setinteriorstyle" |
| 3173 | || anArg == "-interior" |
| 3174 | || anArg == "-interiorstyle") |
| 3175 | { |
| 3176 | if (++anArgIter >= theArgNb) |
| 3177 | { |
| 3178 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3179 | return 1; |
| 3180 | } |
| 3181 | aChangeSet->ToSetInterior = 1; |
| 3182 | if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle)) |
| 3183 | { |
| 3184 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3185 | return 1; |
| 3186 | } |
| 3187 | } |
| 3188 | else if (anArg == "-unsetinterior") |
| 3189 | { |
| 3190 | aChangeSet->ToSetInterior = -1; |
| 3191 | aChangeSet->InteriorStyle = Aspect_IS_SOLID; |
| 3192 | } |
| 3193 | else if (anArg == "-setdrawoutline" |
| 3194 | || anArg == "-setdrawsilhouette" |
| 3195 | || anArg == "-setoutline" |
| 3196 | || anArg == "-setsilhouette" |
| 3197 | || anArg == "-outline" |
| 3198 | || anArg == "-outlined" |
| 3199 | || anArg == "-silhouette") |
| 3200 | { |
| 3201 | bool toDrawOutline = true; |
| 3202 | if (anArgIter + 1 < theArgNb |
| 3203 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline)) |
| 3204 | { |
| 3205 | ++anArgIter; |
| 3206 | } |
| 3207 | aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1; |
| 3208 | } |
| 3209 | else if (anArg == "-setdrawedges" |
| 3210 | || anArg == "-setdrawedge" |
| 3211 | || anArg == "-drawedges" |
| 3212 | || anArg == "-drawedge" |
| 3213 | || anArg == "-edges") |
| 3214 | { |
| 3215 | bool toDrawEdges = true; |
| 3216 | if (anArgIter + 1 < theArgNb |
| 3217 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges)) |
| 3218 | { |
| 3219 | ++anArgIter; |
| 3220 | } |
| 3221 | aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1; |
| 3222 | } |
| 3223 | else if (anArg == "-setquadedges" |
| 3224 | || anArg == "-setquads" |
| 3225 | || anArg == "-quads" |
| 3226 | || anArg == "-skipfirstedge") |
| 3227 | { |
| 3228 | bool isQuadMode = true; |
| 3229 | if (anArgIter + 1 < theArgNb |
| 3230 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode)) |
| 3231 | { |
| 3232 | ++anArgIter; |
| 3233 | } |
| 3234 | aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1; |
| 3235 | } |
| 3236 | else if (anArg == "-setedgecolor" |
| 3237 | || anArg == "-setedgescolor" |
| 3238 | || anArg == "-edgecolor" |
| 3239 | || anArg == "-edgescolor") |
| 3240 | { |
| 3241 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
| 3242 | theArgVec + anArgIter + 1, |
| 3243 | aChangeSet->EdgeColor); |
| 3244 | if (aNbParsed == 0) |
| 3245 | { |
| 3246 | std::cout << "Syntax error at '" << anArg << "'\n"; |
| 3247 | return 1; |
| 3248 | } |
| 3249 | anArgIter += aNbParsed; |
| 3250 | aChangeSet->ToSetEdgeColor = 1; |
| 3251 | } |
| 3252 | else if (anArg == "-unset") |
| 3253 | { |
| 3254 | aChangeSet->ToSetVisibility = 1; |
| 3255 | aChangeSet->Visibility = 1; |
| 3256 | aChangeSet->ToSetLineWidth = -1; |
| 3257 | aChangeSet->LineWidth = 1.0; |
| 3258 | aChangeSet->ToSetTypeOfLine = -1; |
| 3259 | aChangeSet->TypeOfLine = Aspect_TOL_SOLID; |
| 3260 | aChangeSet->ToSetTypeOfMarker = -1; |
| 3261 | aChangeSet->TypeOfMarker = Aspect_TOM_PLUS; |
| 3262 | aChangeSet->ToSetMarkerSize = -1; |
| 3263 | aChangeSet->MarkerSize = 1.0; |
| 3264 | aChangeSet->ToSetTransparency = -1; |
| 3265 | aChangeSet->Transparency = 0.0; |
| 3266 | aChangeSet->ToSetAlphaMode = -1; |
| 3267 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto; |
| 3268 | aChangeSet->AlphaCutoff = 0.5f; |
| 3269 | aChangeSet->ToSetColor = -1; |
| 3270 | aChangeSet->Color = DEFAULT_COLOR; |
| 3271 | //aChangeSet->ToSetBackFaceColor = -1; // should be reset by ToSetColor |
| 3272 | //aChangeSet->BackFaceColor = DEFAULT_COLOR; |
| 3273 | aChangeSet->ToSetMaterial = -1; |
| 3274 | aChangeSet->Material = Graphic3d_NOM_DEFAULT; |
| 3275 | aChangeSet->ToSetShowFreeBoundary = -1; |
| 3276 | aChangeSet->ToSetFreeBoundaryColor = -1; |
| 3277 | aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR; |
| 3278 | aChangeSet->ToSetFreeBoundaryWidth = -1; |
| 3279 | aChangeSet->FreeBoundaryWidth = 1.0; |
| 3280 | aChangeSet->ToEnableIsoOnTriangulation = -1; |
| 3281 | // |
| 3282 | aChangeSet->ToSetFaceBoundaryDraw = -1; |
| 3283 | aChangeSet->ToSetFaceBoundaryUpperContinuity = -1; |
| 3284 | aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN; |
| 3285 | aChangeSet->ToSetFaceBoundaryColor = -1; |
| 3286 | aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK; |
| 3287 | aChangeSet->ToSetFaceBoundaryWidth = -1; |
| 3288 | aChangeSet->FaceBoundaryWidth = 1.0f; |
| 3289 | aChangeSet->ToSetTypeOfFaceBoundaryLine = -1; |
| 3290 | aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID; |
| 3291 | // |
| 3292 | aChangeSet->ToSetHatch = -1; |
| 3293 | aChangeSet->StdHatchStyle = -1; |
| 3294 | aChangeSet->PathToHatchPattern.Clear(); |
| 3295 | aChangeSet->ToSetShadingModel = -1; |
| 3296 | aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT; |
| 3297 | aChangeSet->ToSetInterior = -1; |
| 3298 | aChangeSet->InteriorStyle = Aspect_IS_SOLID; |
| 3299 | aChangeSet->ToSetDrawSilhouette = -1; |
| 3300 | aChangeSet->ToSetDrawEdges = -1; |
| 3301 | aChangeSet->ToSetQuadEdges = -1; |
| 3302 | aChangeSet->ToSetEdgeColor = -1; |
| 3303 | aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR); |
| 3304 | aChangeSet->ToSetEdgeWidth = -1; |
| 3305 | aChangeSet->EdgeWidth = 1.0; |
| 3306 | aChangeSet->ToSetTypeOfEdge = -1; |
| 3307 | aChangeSet->TypeOfEdge = Aspect_TOL_SOLID; |
| 3308 | } |
| 3309 | else if (anArg == "-dumpjson") |
| 3310 | { |
| 3311 | toDump = Standard_True; |
| 3312 | } |
| 3313 | else if (anArg == "-dumpcompact") |
| 3314 | { |
| 3315 | toCompactDump = Standard_False; |
| 3316 | if (++anArgIter >= theArgNb && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toCompactDump)) |
| 3317 | ++anArgIter; |
| 3318 | } |
| 3319 | else if (anArg == "-dumpdepth") |
| 3320 | { |
| 3321 | if (++anArgIter >= theArgNb) |
| 3322 | { |
| 3323 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3324 | return 1; |
| 3325 | } |
| 3326 | aDumpDepth = Draw::Atoi (theArgVec[anArgIter]); |
| 3327 | } |
| 3328 | else |
| 3329 | { |
| 3330 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 3331 | return 1; |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges); |
| 3336 | aChangesIter.More(); aChangesIter.Next()) |
| 3337 | { |
| 3338 | if (!aChangesIter.Value().Validate()) |
| 3339 | { |
| 3340 | return 1; |
| 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | // special case for -defaults parameter. |
| 3345 | // all changed values will be set to DefaultDrawer. |
| 3346 | if (isDefaults) |
| 3347 | { |
| 3348 | const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer(); |
| 3349 | aChangeSet->Apply (aDrawer); |
| 3350 | if (aChangeSet->ToSetLineWidth != 0) |
| 3351 | { |
| 3352 | aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth); |
| 3353 | aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth); |
| 3354 | aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth); |
| 3355 | aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth); |
| 3356 | } |
| 3357 | if (aChangeSet->ToSetColor != 0) |
| 3358 | { |
| 3359 | aDrawer->ShadingAspect()->SetColor (aChangeSet->Color); |
| 3360 | aDrawer->LineAspect()->SetColor (aChangeSet->Color); |
| 3361 | aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color); |
| 3362 | aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color); |
| 3363 | aDrawer->WireAspect()->SetColor (aChangeSet->Color); |
| 3364 | aDrawer->PointAspect()->SetColor (aChangeSet->Color); |
| 3365 | } |
| 3366 | if (aChangeSet->ToSetTransparency != 0) |
| 3367 | { |
| 3368 | aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency); |
| 3369 | } |
| 3370 | if (aChangeSet->ToSetMaterial != 0) |
| 3371 | { |
| 3372 | aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material); |
| 3373 | } |
| 3374 | if (aChangeSet->ToEnableIsoOnTriangulation != 0) |
| 3375 | { |
| 3376 | aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1); |
| 3377 | } |
| 3378 | |
| 3379 | // redisplay all objects in context |
| 3380 | for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next()) |
| 3381 | { |
| 3382 | Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current(); |
| 3383 | if (!aPrs.IsNull()) |
| 3384 | { |
| 3385 | aCtx->Redisplay (aPrs, Standard_False); |
| 3386 | } |
| 3387 | } |
| 3388 | if (toDump) |
| 3389 | { |
| 3390 | Standard_SStream aStream; |
| 3391 | aDrawer->DumpJson (aStream, aDumpDepth); |
| 3392 | |
| 3393 | if (toCompactDump) |
| 3394 | theDI << Standard_Dump::Text (aStream); |
| 3395 | else |
| 3396 | theDI << Standard_Dump::FormatJson (aStream); |
| 3397 | } |
| 3398 | return 0; |
| 3399 | } |
| 3400 | |
| 3401 | for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next()) |
| 3402 | { |
| 3403 | const TCollection_AsciiString& aName = aPrsIter.CurrentName(); |
| 3404 | Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current(); |
| 3405 | if (aPrs.IsNull()) |
| 3406 | { |
| 3407 | return 1; |
| 3408 | } |
| 3409 | |
| 3410 | Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes(); |
| 3411 | Handle(AIS_ColoredShape) aColoredPrs; |
| 3412 | Standard_Boolean toDisplay = Standard_False; |
| 3413 | Standard_Boolean toRedisplay = Standard_False; |
| 3414 | if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1) |
| 3415 | { |
| 3416 | Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs); |
| 3417 | if (aShapePrs.IsNull()) |
| 3418 | { |
| 3419 | std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n"; |
| 3420 | return 1; |
| 3421 | } |
| 3422 | aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs); |
| 3423 | if (aColoredPrs.IsNull()) |
| 3424 | { |
| 3425 | aColoredPrs = new AIS_ColoredShape (aShapePrs); |
| 3426 | if (aShapePrs->HasDisplayMode()) |
| 3427 | { |
| 3428 | aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode()); |
| 3429 | } |
| 3430 | aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation()); |
| 3431 | aCtx->Remove (aShapePrs, Standard_False); |
| 3432 | GetMapOfAIS().UnBind2 (aName); |
| 3433 | GetMapOfAIS().Bind (aColoredPrs, aName); |
| 3434 | toDisplay = Standard_True; |
| 3435 | aShapePrs = aColoredPrs; |
| 3436 | aPrs = aColoredPrs; |
| 3437 | } |
| 3438 | } |
| 3439 | |
| 3440 | if (!aPrs.IsNull()) |
| 3441 | { |
| 3442 | NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges); |
| 3443 | aChangeSet = &aChangesIter.ChangeValue(); |
| 3444 | if (aChangeSet->ToSetVisibility == 1) |
| 3445 | { |
| 3446 | Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape()); |
| 3447 | aColDrawer->SetHidden (aChangeSet->Visibility == 0); |
| 3448 | } |
| 3449 | else if (aChangeSet->ToSetMaterial == 1) |
| 3450 | { |
| 3451 | aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False); |
| 3452 | } |
| 3453 | else if (aChangeSet->ToSetMaterial == -1) |
| 3454 | { |
| 3455 | aCtx->UnsetMaterial (aPrs, Standard_False); |
| 3456 | } |
| 3457 | if (aChangeSet->ToSetColor == 1) |
| 3458 | { |
| 3459 | aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False); |
| 3460 | } |
| 3461 | else if (aChangeSet->ToSetColor == -1) |
| 3462 | { |
| 3463 | aCtx->UnsetColor (aPrs, Standard_False); |
| 3464 | } |
| 3465 | if (aChangeSet->ToSetTransparency == 1) |
| 3466 | { |
| 3467 | aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False); |
| 3468 | } |
| 3469 | else if (aChangeSet->ToSetTransparency == -1) |
| 3470 | { |
| 3471 | aCtx->UnsetTransparency (aPrs, Standard_False); |
| 3472 | } |
| 3473 | if (aChangeSet->ToSetLineWidth == 1) |
| 3474 | { |
| 3475 | aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False); |
| 3476 | } |
| 3477 | else if (aChangeSet->ToSetLineWidth == -1) |
| 3478 | { |
| 3479 | aCtx->UnsetWidth (aPrs, Standard_False); |
| 3480 | } |
| 3481 | else if (aChangeSet->ToEnableIsoOnTriangulation != 0) |
| 3482 | { |
| 3483 | aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs); |
| 3484 | toRedisplay = Standard_True; |
| 3485 | } |
| 3486 | else if (aChangeSet->ToSetSensitivity != 0) |
| 3487 | { |
| 3488 | aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity); |
| 3489 | } |
| 3490 | if (!aDrawer.IsNull()) |
| 3491 | { |
| 3492 | toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay; |
| 3493 | } |
| 3494 | |
| 3495 | for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next()) |
| 3496 | { |
| 3497 | aChangeSet = &aChangesIter.ChangeValue(); |
| 3498 | for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes); |
| 3499 | aSubShapeIter.More(); aSubShapeIter.Next()) |
| 3500 | { |
| 3501 | const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); |
| 3502 | if (!aChangeSet->IsEmpty()) |
| 3503 | { |
| 3504 | Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape); |
| 3505 | aChangeSet->Apply (aCurColDrawer); |
| 3506 | } |
| 3507 | if (aChangeSet->ToSetVisibility == 1) |
| 3508 | { |
| 3509 | Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape); |
| 3510 | aCurColDrawer->SetHidden (aChangeSet->Visibility == 0); |
| 3511 | } |
| 3512 | if (aChangeSet->ToSetColor == 1) |
| 3513 | { |
| 3514 | aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color); |
| 3515 | } |
| 3516 | if (aChangeSet->ToSetTransparency == 1) |
| 3517 | { |
| 3518 | aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency); |
| 3519 | } |
| 3520 | if (aChangeSet->ToSetLineWidth == 1) |
| 3521 | { |
| 3522 | aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth); |
| 3523 | } |
| 3524 | if (aChangeSet->ToSetColor == -1 |
| 3525 | || aChangeSet->ToSetLineWidth == -1) |
| 3526 | { |
| 3527 | aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True); |
| 3528 | } |
| 3529 | if (aChangeSet->ToSetSensitivity != 0) |
| 3530 | { |
| 3531 | aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity); |
| 3532 | } |
| 3533 | } |
| 3534 | } |
| 3535 | if (toDisplay) |
| 3536 | { |
| 3537 | aCtx->Display (aPrs, Standard_False); |
| 3538 | } |
| 3539 | if (toRedisplay) |
| 3540 | { |
| 3541 | aCtx->Redisplay (aPrs, Standard_False); |
| 3542 | } |
| 3543 | else if (!aColoredPrs.IsNull()) |
| 3544 | { |
| 3545 | aCtx->Redisplay (aColoredPrs, Standard_False); |
| 3546 | } |
| 3547 | else |
| 3548 | { |
| 3549 | aPrs->SynchronizeAspects(); |
| 3550 | } |
| 3551 | |
| 3552 | if (toDump) |
| 3553 | { |
| 3554 | Standard_SStream aStream; |
| 3555 | aDrawer->DumpJson (aStream); |
| 3556 | |
| 3557 | theDI << aName << ": \n"; |
| 3558 | theDI << Standard_Dump::FormatJson (aStream); |
| 3559 | theDI << "\n"; |
| 3560 | } |
| 3561 | } |
| 3562 | } |
| 3563 | return 0; |
| 3564 | } |
| 3565 | |
| 3566 | //============================================================================== |
| 3567 | //function : VDonly2 |
| 3568 | //author : ege |
| 3569 | //purpose : Display only a selected or named object |
| 3570 | // if there is no selected or named object s, nothing is done |
| 3571 | //============================================================================== |
| 3572 | static int VDonly2 (Draw_Interpretor& , |
| 3573 | Standard_Integer theArgNb, |
| 3574 | const char** theArgVec) |
| 3575 | { |
| 3576 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 3577 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
| 3578 | if (aCtx.IsNull()) |
| 3579 | { |
| 3580 | std::cerr << "Error: no active view!\n"; |
| 3581 | return 1; |
| 3582 | } |
| 3583 | |
| 3584 | Standard_Integer anArgIter = 1; |
| 3585 | for (; anArgIter < theArgNb; ++anArgIter) |
| 3586 | { |
| 3587 | if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) |
| 3588 | { |
| 3589 | break; |
| 3590 | } |
| 3591 | } |
| 3592 | |
| 3593 | NCollection_Map<Handle(Standard_Transient)> aDispSet; |
| 3594 | if (anArgIter >= theArgNb) |
| 3595 | { |
| 3596 | // display only selected objects |
| 3597 | if (aCtx->NbSelected() < 1) |
| 3598 | { |
| 3599 | return 0; |
| 3600 | } |
| 3601 | |
| 3602 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
| 3603 | { |
| 3604 | aDispSet.Add (aCtx->SelectedInteractive()); |
| 3605 | } |
| 3606 | } |
| 3607 | else |
| 3608 | { |
| 3609 | // display only specified objects |
| 3610 | for (; anArgIter < theArgNb; ++anArgIter) |
| 3611 | { |
| 3612 | TCollection_AsciiString aName = theArgVec[anArgIter]; |
| 3613 | Handle(AIS_InteractiveObject) aShape; |
| 3614 | if (GetMapOfAIS().Find2 (aName, aShape) |
| 3615 | && !aShape.IsNull()) |
| 3616 | { |
| 3617 | aCtx->Display (aShape, Standard_False); |
| 3618 | aDispSet.Add (aShape); |
| 3619 | } |
| 3620 | } |
| 3621 | } |
| 3622 | |
| 3623 | // weed out other objects |
| 3624 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next()) |
| 3625 | { |
| 3626 | if (aDispSet.Contains (anIter.Key1())) |
| 3627 | { |
| 3628 | continue; |
| 3629 | } |
| 3630 | |
| 3631 | if (Handle(AIS_InteractiveObject) aShape = anIter.Key1()) |
| 3632 | { |
| 3633 | aCtx->Erase (aShape, Standard_False); |
| 3634 | } |
| 3635 | } |
| 3636 | return 0; |
| 3637 | } |
| 3638 | |
| 3639 | //============================================================================== |
| 3640 | //function : VRemove |
| 3641 | //purpose : Removes selected or named objects. |
| 3642 | // If there is no selected or named objects, |
| 3643 | // all objects in the viewer can be removed with argument -all. |
| 3644 | // If -context is in arguments, the object is not deleted from the map of |
| 3645 | // objects (deleted only from the current context). |
| 3646 | //============================================================================== |
| 3647 | int VRemove (Draw_Interpretor& theDI, |
| 3648 | Standard_Integer theArgNb, |
| 3649 | const char** theArgVec) |
| 3650 | { |
| 3651 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 3652 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
| 3653 | if (aCtx.IsNull()) |
| 3654 | { |
| 3655 | std::cerr << "Error: no active view!\n"; |
| 3656 | return 1; |
| 3657 | } |
| 3658 | |
| 3659 | Standard_Boolean isContextOnly = Standard_False; |
| 3660 | Standard_Boolean toRemoveAll = Standard_False; |
| 3661 | Standard_Boolean toPrintInfo = Standard_True; |
| 3662 | Standard_Boolean toFailOnError = Standard_True; |
| 3663 | |
| 3664 | Standard_Integer anArgIter = 1; |
| 3665 | for (; anArgIter < theArgNb; ++anArgIter) |
| 3666 | { |
| 3667 | TCollection_AsciiString anArg = theArgVec[anArgIter]; |
| 3668 | anArg.LowerCase(); |
| 3669 | if (anArg == "-context") |
| 3670 | { |
| 3671 | isContextOnly = Standard_True; |
| 3672 | } |
| 3673 | else if (anArg == "-all") |
| 3674 | { |
| 3675 | toRemoveAll = Standard_True; |
| 3676 | } |
| 3677 | else if (anArg == "-noinfo") |
| 3678 | { |
| 3679 | toPrintInfo = Standard_False; |
| 3680 | } |
| 3681 | else if (anArg == "-noerror" |
| 3682 | || anArg == "-nofail") |
| 3683 | { |
| 3684 | toFailOnError = Standard_False; |
| 3685 | } |
| 3686 | else if (anUpdateTool.parseRedrawMode (anArg)) |
| 3687 | { |
| 3688 | continue; |
| 3689 | } |
| 3690 | else |
| 3691 | { |
| 3692 | break; |
| 3693 | } |
| 3694 | } |
| 3695 | if (toRemoveAll |
| 3696 | && anArgIter < theArgNb) |
| 3697 | { |
| 3698 | std::cerr << "Error: wrong syntax!\n"; |
| 3699 | return 1; |
| 3700 | } |
| 3701 | |
| 3702 | NCollection_List<TCollection_AsciiString> anIONameList; |
| 3703 | if (toRemoveAll) |
| 3704 | { |
| 3705 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 3706 | anIter.More(); anIter.Next()) |
| 3707 | { |
| 3708 | anIONameList.Append (anIter.Key2()); |
| 3709 | } |
| 3710 | } |
| 3711 | else if (anArgIter < theArgNb) // removed objects names are in argument list |
| 3712 | { |
| 3713 | for (; anArgIter < theArgNb; ++anArgIter) |
| 3714 | { |
| 3715 | const TCollection_AsciiString aName (theArgVec[anArgIter]); |
| 3716 | if (aName.Search ("*") != -1) |
| 3717 | { |
| 3718 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next()) |
| 3719 | { |
| 3720 | if (aPrsIter.Key1()->GetContext() != aCtx) |
| 3721 | { |
| 3722 | continue; |
| 3723 | } |
| 3724 | const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'"; |
| 3725 | if (theDI.Eval (aCheck.ToCString()) == 0 |
| 3726 | && *theDI.Result() == '1') |
| 3727 | { |
| 3728 | anIONameList.Append (aPrsIter.Key2()); |
| 3729 | } |
| 3730 | } |
| 3731 | theDI.Reset(); |
| 3732 | continue; |
| 3733 | } |
| 3734 | |
| 3735 | Handle(AIS_InteractiveObject) anIO; |
| 3736 | if (!GetMapOfAIS().Find2 (aName, anIO)) |
| 3737 | { |
| 3738 | if (toFailOnError) |
| 3739 | { |
| 3740 | std::cout << "Syntax error: '" << aName << "' was not bound to some object.\n"; |
| 3741 | return 1; |
| 3742 | } |
| 3743 | } |
| 3744 | else if (anIO->GetContext() != aCtx) |
| 3745 | { |
| 3746 | if (toFailOnError) |
| 3747 | { |
| 3748 | std::cout << "Syntax error: '" << aName << "' was not displayed in current context.\n" |
| 3749 | << "Please activate view with this object displayed and try again.\n"; |
| 3750 | return 1; |
| 3751 | } |
| 3752 | } |
| 3753 | else |
| 3754 | { |
| 3755 | anIONameList.Append (aName); |
| 3756 | } |
| 3757 | } |
| 3758 | } |
| 3759 | else if (aCtx->NbSelected() > 0) |
| 3760 | { |
| 3761 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 3762 | anIter.More(); anIter.Next()) |
| 3763 | { |
| 3764 | if (!aCtx->IsSelected (anIter.Key1())) |
| 3765 | { |
| 3766 | continue; |
| 3767 | } |
| 3768 | |
| 3769 | anIONameList.Append (anIter.Key2()); |
| 3770 | continue; |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | // Unbind all removed objects from the map of displayed IO. |
| 3775 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList); |
| 3776 | anIter.More(); anIter.Next()) |
| 3777 | { |
| 3778 | const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value()); |
| 3779 | aCtx->Remove (anIO, Standard_False); |
| 3780 | if (toPrintInfo) |
| 3781 | { |
| 3782 | theDI << anIter.Value() << " "; |
| 3783 | } |
| 3784 | if (!isContextOnly) |
| 3785 | { |
| 3786 | GetMapOfAIS().UnBind2 (anIter.Value()); |
| 3787 | } |
| 3788 | } |
| 3789 | return 0; |
| 3790 | } |
| 3791 | |
| 3792 | //============================================================================== |
| 3793 | //function : VErase |
| 3794 | //purpose : Erase some selected or named objects |
| 3795 | // if there is no selected or named objects, the whole viewer is erased |
| 3796 | //============================================================================== |
| 3797 | int VErase (Draw_Interpretor& theDI, |
| 3798 | Standard_Integer theArgNb, |
| 3799 | const char** theArgVec) |
| 3800 | { |
| 3801 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 3802 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); |
| 3803 | ViewerTest_AutoUpdater anUpdateTool (aCtx, aView); |
| 3804 | if (aCtx.IsNull()) |
| 3805 | { |
| 3806 | std::cerr << "Error: no active view!\n"; |
| 3807 | return 1; |
| 3808 | } |
| 3809 | |
| 3810 | const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall"; |
| 3811 | |
| 3812 | Standard_Integer anArgIter = 1; |
| 3813 | Standard_Boolean toEraseInView = Standard_False; |
| 3814 | Standard_Boolean toFailOnError = Standard_True; |
| 3815 | TColStd_SequenceOfAsciiString aNamesOfEraseIO; |
| 3816 | for (; anArgIter < theArgNb; ++anArgIter) |
| 3817 | { |
| 3818 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); |
| 3819 | anArgCase.LowerCase(); |
| 3820 | if (anUpdateTool.parseRedrawMode (anArgCase)) |
| 3821 | { |
| 3822 | continue; |
| 3823 | } |
| 3824 | else if (anArgCase == "-view" |
| 3825 | || anArgCase == "-inview") |
| 3826 | { |
| 3827 | toEraseInView = Standard_True; |
| 3828 | } |
| 3829 | else if (anArgCase == "-noerror" |
| 3830 | || anArgCase == "-nofail") |
| 3831 | { |
| 3832 | toFailOnError = Standard_False; |
| 3833 | } |
| 3834 | else |
| 3835 | { |
| 3836 | aNamesOfEraseIO.Append (theArgVec[anArgIter]); |
| 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | if (!aNamesOfEraseIO.IsEmpty() && toEraseAll) |
| 3841 | { |
| 3842 | std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n"; |
| 3843 | return 1; |
| 3844 | } |
| 3845 | |
| 3846 | if (!aNamesOfEraseIO.IsEmpty()) |
| 3847 | { |
| 3848 | // Erase named objects |
| 3849 | NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList; |
| 3850 | for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next()) |
| 3851 | { |
| 3852 | const TCollection_AsciiString& aName = anIter.Value(); |
| 3853 | if (aName.Search ("*") != -1) |
| 3854 | { |
| 3855 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next()) |
| 3856 | { |
| 3857 | const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'"; |
| 3858 | if (theDI.Eval (aCheck.ToCString()) == 0 |
| 3859 | && *theDI.Result() == '1') |
| 3860 | { |
| 3861 | aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2()); |
| 3862 | } |
| 3863 | } |
| 3864 | theDI.Reset(); |
| 3865 | } |
| 3866 | else |
| 3867 | { |
| 3868 | Handle(AIS_InteractiveObject) anIO; |
| 3869 | if (!GetMapOfAIS().Find2 (aName, anIO)) |
| 3870 | { |
| 3871 | if (toFailOnError) |
| 3872 | { |
| 3873 | std::cout << "Syntax error: '" << aName << "' is not found\n"; |
| 3874 | return 1; |
| 3875 | } |
| 3876 | } |
| 3877 | else |
| 3878 | { |
| 3879 | aPrsList.Add (anIO, aName); |
| 3880 | } |
| 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next()) |
| 3885 | { |
| 3886 | theDI << anIter.Value() << " "; |
| 3887 | if (toEraseInView) |
| 3888 | { |
| 3889 | aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False); |
| 3890 | } |
| 3891 | else |
| 3892 | { |
| 3893 | aCtx->Erase (anIter.Key(), Standard_False); |
| 3894 | } |
| 3895 | } |
| 3896 | } |
| 3897 | else if (!toEraseAll && aCtx->NbSelected() > 0) |
| 3898 | { |
| 3899 | // Erase selected objects |
| 3900 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 3901 | anIter.More(); anIter.Next()) |
| 3902 | { |
| 3903 | const Handle(AIS_InteractiveObject) anIO = anIter.Key1(); |
| 3904 | if (!anIO.IsNull() |
| 3905 | && aCtx->IsSelected (anIO)) |
| 3906 | { |
| 3907 | theDI << anIter.Key2() << " "; |
| 3908 | if (toEraseInView) |
| 3909 | { |
| 3910 | aCtx->SetViewAffinity (anIO, aView, Standard_False); |
| 3911 | } |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | if (!toEraseInView) |
| 3916 | { |
| 3917 | aCtx->EraseSelected (Standard_False); |
| 3918 | } |
| 3919 | } |
| 3920 | else |
| 3921 | { |
| 3922 | // Erase all objects |
| 3923 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 3924 | anIter.More(); anIter.Next()) |
| 3925 | { |
| 3926 | Handle(AIS_InteractiveObject) anIO = anIter.Key1(); |
| 3927 | if (!anIO.IsNull()) |
| 3928 | { |
| 3929 | if (toEraseInView) |
| 3930 | { |
| 3931 | aCtx->SetViewAffinity (anIO, aView, Standard_False); |
| 3932 | } |
| 3933 | else |
| 3934 | { |
| 3935 | aCtx->Erase (anIO, Standard_False); |
| 3936 | } |
| 3937 | } |
| 3938 | } |
| 3939 | } |
| 3940 | |
| 3941 | return 0; |
| 3942 | } |
| 3943 | |
| 3944 | //============================================================================== |
| 3945 | //function : VDisplayAll |
| 3946 | //purpose : Display all the objects of the Map |
| 3947 | //============================================================================== |
| 3948 | static int VDisplayAll (Draw_Interpretor& , |
| 3949 | Standard_Integer theArgNb, |
| 3950 | const char** theArgVec) |
| 3951 | |
| 3952 | { |
| 3953 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 3954 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
| 3955 | if (aCtx.IsNull()) |
| 3956 | { |
| 3957 | std::cerr << "Error: no active view!\n"; |
| 3958 | return 1; |
| 3959 | } |
| 3960 | |
| 3961 | Standard_Integer anArgIter = 1; |
| 3962 | for (; anArgIter < theArgNb; ++anArgIter) |
| 3963 | { |
| 3964 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); |
| 3965 | anArgCase.LowerCase(); |
| 3966 | if (anUpdateTool.parseRedrawMode (anArgCase)) |
| 3967 | { |
| 3968 | continue; |
| 3969 | } |
| 3970 | else |
| 3971 | { |
| 3972 | break; |
| 3973 | } |
| 3974 | } |
| 3975 | if (anArgIter < theArgNb) |
| 3976 | { |
| 3977 | std::cout << theArgVec[0] << "Error: wrong syntax\n"; |
| 3978 | return 1; |
| 3979 | } |
| 3980 | |
| 3981 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 3982 | anIter.More(); anIter.Next()) |
| 3983 | { |
| 3984 | aCtx->Erase (anIter.Key1(), Standard_False); |
| 3985 | } |
| 3986 | |
| 3987 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 3988 | anIter.More(); anIter.Next()) |
| 3989 | { |
| 3990 | aCtx->Display (anIter.Key1(), Standard_False); |
| 3991 | } |
| 3992 | return 0; |
| 3993 | } |
| 3994 | |
| 3995 | //! Auxiliary method to check if presentation exists |
| 3996 | inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx, |
| 3997 | const Handle(AIS_InteractiveObject)& theIO, |
| 3998 | const Standard_Integer theMode) |
| 3999 | { |
| 4000 | if (theIO.IsNull() || theCtx.IsNull()) |
| 4001 | { |
| 4002 | return -1; |
| 4003 | } |
| 4004 | |
| 4005 | if (theMode != -1) |
| 4006 | { |
| 4007 | if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode)) |
| 4008 | { |
| 4009 | return theMode; |
| 4010 | } |
| 4011 | } |
| 4012 | else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode())) |
| 4013 | { |
| 4014 | return theIO->DisplayMode(); |
| 4015 | } |
| 4016 | else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode())) |
| 4017 | { |
| 4018 | return theCtx->DisplayMode(); |
| 4019 | } |
| 4020 | |
| 4021 | return -1; |
| 4022 | } |
| 4023 | |
| 4024 | enum ViewerTest_BndAction |
| 4025 | { |
| 4026 | BndAction_Hide, |
| 4027 | BndAction_Show, |
| 4028 | BndAction_Print |
| 4029 | }; |
| 4030 | |
| 4031 | //! Auxiliary method to print bounding box of presentation |
| 4032 | inline void bndPresentation (Draw_Interpretor& theDI, |
| 4033 | const Handle(PrsMgr_PresentationManager)& theMgr, |
| 4034 | const Handle(AIS_InteractiveObject)& theObj, |
| 4035 | const Standard_Integer theDispMode, |
| 4036 | const TCollection_AsciiString& theName, |
| 4037 | const ViewerTest_BndAction theAction, |
| 4038 | const Handle(Prs3d_Drawer)& theStyle) |
| 4039 | { |
| 4040 | switch (theAction) |
| 4041 | { |
| 4042 | case BndAction_Hide: |
| 4043 | { |
| 4044 | theMgr->Unhighlight (theObj); |
| 4045 | break; |
| 4046 | } |
| 4047 | case BndAction_Show: |
| 4048 | { |
| 4049 | theMgr->Color (theObj, theStyle, theDispMode); |
| 4050 | break; |
| 4051 | } |
| 4052 | case BndAction_Print: |
| 4053 | { |
| 4054 | Bnd_Box aBox; |
| 4055 | for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next()) |
| 4056 | { |
| 4057 | if (aPrsIter.Value()->Mode() != theDispMode) |
| 4058 | continue; |
| 4059 | |
| 4060 | aBox = aPrsIter.Value()->MinMaxValues(); |
| 4061 | } |
| 4062 | gp_Pnt aMin = aBox.CornerMin(); |
| 4063 | gp_Pnt aMax = aBox.CornerMax(); |
| 4064 | theDI << theName << "\n" |
| 4065 | << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " " |
| 4066 | << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n"; |
| 4067 | break; |
| 4068 | } |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | //============================================================================== |
| 4073 | //function : VBounding |
| 4074 | //purpose : |
| 4075 | //============================================================================== |
| 4076 | int VBounding (Draw_Interpretor& theDI, |
| 4077 | Standard_Integer theArgNb, |
| 4078 | const char** theArgVec) |
| 4079 | { |
| 4080 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 4081 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
| 4082 | if (aCtx.IsNull()) |
| 4083 | { |
| 4084 | std::cout << "Error: no active view!\n"; |
| 4085 | return 1; |
| 4086 | } |
| 4087 | |
| 4088 | ViewerTest_BndAction anAction = BndAction_Show; |
| 4089 | Standard_Integer aMode = -1; |
| 4090 | |
| 4091 | Handle(Prs3d_Drawer) aStyle; |
| 4092 | |
| 4093 | Standard_Integer anArgIter = 1; |
| 4094 | for (; anArgIter < theArgNb; ++anArgIter) |
| 4095 | { |
| 4096 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
| 4097 | anArg.LowerCase(); |
| 4098 | if (anArg == "-print") |
| 4099 | { |
| 4100 | anAction = BndAction_Print; |
| 4101 | } |
| 4102 | else if (anArg == "-show") |
| 4103 | { |
| 4104 | anAction = BndAction_Show; |
| 4105 | } |
| 4106 | else if (anArg == "-hide") |
| 4107 | { |
| 4108 | anAction = BndAction_Hide; |
| 4109 | } |
| 4110 | else if (anArg == "-mode") |
| 4111 | { |
| 4112 | if (++anArgIter >= theArgNb) |
| 4113 | { |
| 4114 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
| 4115 | return 1; |
| 4116 | } |
| 4117 | aMode = Draw::Atoi (theArgVec[anArgIter]); |
| 4118 | } |
| 4119 | else if (!anUpdateTool.parseRedrawMode (anArg)) |
| 4120 | { |
| 4121 | break; |
| 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | if (anAction == BndAction_Show) |
| 4126 | { |
| 4127 | aStyle = new Prs3d_Drawer(); |
| 4128 | aStyle->SetMethod (Aspect_TOHM_BOUNDBOX); |
| 4129 | aStyle->SetColor (Quantity_NOC_GRAY99); |
| 4130 | } |
| 4131 | |
| 4132 | Standard_Integer aHighlightedMode = -1; |
| 4133 | if (anArgIter < theArgNb) |
| 4134 | { |
| 4135 | // has a list of names |
| 4136 | for (; anArgIter < theArgNb; ++anArgIter) |
| 4137 | { |
| 4138 | TCollection_AsciiString aName = theArgVec[anArgIter]; |
| 4139 | Handle(AIS_InteractiveObject) anIO; |
| 4140 | if (!GetMapOfAIS().Find2 (aName, anIO)) |
| 4141 | { |
| 4142 | std::cout << "Error: presentation " << aName << " does not exist\n"; |
| 4143 | return 1; |
| 4144 | } |
| 4145 | |
| 4146 | aHighlightedMode = checkMode (aCtx, anIO, aMode); |
| 4147 | if (aHighlightedMode == -1) |
| 4148 | { |
| 4149 | std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl; |
| 4150 | return 1; |
| 4151 | } |
| 4152 | bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle); |
| 4153 | } |
| 4154 | } |
| 4155 | else if (aCtx->NbSelected() > 0) |
| 4156 | { |
| 4157 | // remove all currently selected objects |
| 4158 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
| 4159 | { |
| 4160 | Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive(); |
| 4161 | aHighlightedMode = checkMode (aCtx, anIO, aMode); |
| 4162 | if (aHighlightedMode != -1) |
| 4163 | { |
| 4164 | bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, |
| 4165 | GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle); |
| 4166 | } |
| 4167 | } |
| 4168 | } |
| 4169 | else |
| 4170 | { |
| 4171 | // all objects |
| 4172 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
| 4173 | anIter.More(); anIter.Next()) |
| 4174 | { |
| 4175 | Handle(AIS_InteractiveObject) anIO = anIter.Key1(); |
| 4176 | aHighlightedMode = checkMode (aCtx, anIO, aMode); |
| 4177 | if (aHighlightedMode != -1) |
| 4178 | { |
| 4179 | bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle); |
| 4180 | } |
| 4181 | } |
| 4182 | } |
| 4183 | return 0; |
| 4184 | } |
| 4185 | |
| 4186 | //============================================================================== |
| 4187 | //function : VTexture |
| 4188 | //purpose : |
| 4189 | //============================================================================== |
| 4190 | Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
| 4191 | { |
| 4192 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
| 4193 | if (aCtx.IsNull()) |
| 4194 | { |
| 4195 | std::cout << "Error: no active view!\n"; |
| 4196 | return 1; |
| 4197 | } |
| 4198 | |
| 4199 | int toModulate = -1; |
| 4200 | bool toSetFilter = false; |
| 4201 | bool toSetAniso = false; |
| 4202 | bool toSetTrsfAngle = false; |
| 4203 | bool toSetTrsfTrans = false; |
| 4204 | bool toSetTrsfScale = false; |
| 4205 | Standard_ShortReal aTrsfRotAngle = 0.0f; |
| 4206 | Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f); |
| 4207 | Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f); |
| 4208 | Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST; |
| 4209 | Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF; |
| 4210 | |
| 4211 | Handle(AIS_InteractiveObject) aTexturedIO; |
| 4212 | Handle(AIS_Shape) aTexturedShape; |
| 4213 | Handle(Graphic3d_TextureSet) aTextureSetOld; |
| 4214 | NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew; |
| 4215 | bool toSetGenRepeat = false; |
| 4216 | bool toSetGenScale = false; |
| 4217 | bool toSetGenOrigin = false; |
| 4218 | bool toSetImage = false; |
| 4219 | bool toComputeUV = false; |
| 4220 | |
| 4221 | const TCollection_AsciiString aCommandName (theArgVec[0]); |
| 4222 | bool toSetDefaults = aCommandName == "vtexdefault"; |
| 4223 | |
| 4224 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
| 4225 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
| 4226 | { |
| 4227 | const TCollection_AsciiString aName = theArgVec[anArgIter]; |
| 4228 | TCollection_AsciiString aNameCase = aName; |
| 4229 | aNameCase.LowerCase(); |
| 4230 | if (anUpdateTool.parseRedrawMode (aName)) |
| 4231 | { |
| 4232 | continue; |
| 4233 | } |
| 4234 | else if (aTexturedIO.IsNull()) |
| 4235 | { |
| 4236 | const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS(); |
| 4237 | if (aMapOfIO.IsBound2 (aName)) |
| 4238 | { |
| 4239 | aTexturedIO = aMapOfIO.Find2 (aName); |
| 4240 | aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO); |
| 4241 | } |
| 4242 | if (aTexturedIO.IsNull()) |
| 4243 | { |
| 4244 | std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n"; |
| 4245 | return 1; |
| 4246 | } |
| 4247 | |
| 4248 | if (aTexturedIO->Attributes()->HasOwnShadingAspect()) |
| 4249 | { |
| 4250 | aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet(); |
| 4251 | } |
| 4252 | } |
| 4253 | else if (!aTexturedShape.IsNull() |
| 4254 | && (aNameCase == "-scale" |
| 4255 | || aNameCase == "-setscale" |
| 4256 | || aCommandName == "vtexscale")) |
| 4257 | { |
| 4258 | if (aCommandName != "vtexscale") |
| 4259 | { |
| 4260 | ++anArgIter; |
| 4261 | } |
| 4262 | if (anArgIter < theArgsNb) |
| 4263 | { |
| 4264 | TCollection_AsciiString aValU (theArgVec[anArgIter]); |
| 4265 | TCollection_AsciiString aValUCase = aValU; |
| 4266 | aValUCase.LowerCase(); |
| 4267 | toSetGenScale = true; |
| 4268 | if (aValUCase == "off") |
| 4269 | { |
| 4270 | aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0)); |
| 4271 | continue; |
| 4272 | } |
| 4273 | else if (anArgIter + 1 < theArgsNb) |
| 4274 | { |
| 4275 | TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); |
| 4276 | if (aValU.IsRealValue() |
| 4277 | && aValV.IsRealValue()) |
| 4278 | { |
| 4279 | aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); |
| 4280 | ++anArgIter; |
| 4281 | continue; |
| 4282 | } |
| 4283 | } |
| 4284 | } |
| 4285 | std::cout << "Syntax error: unexpected argument '" << aName << "'\n"; |
| 4286 | return 1; |
| 4287 | } |
| 4288 | else if (!aTexturedShape.IsNull() |
| 4289 | && (aNameCase == "-origin" |
| 4290 | || aNameCase == "-setorigin" |
| 4291 | || aCommandName == "vtexorigin")) |
| 4292 | { |
| 4293 | if (aCommandName != "vtexorigin") |
| 4294 | { |
| 4295 | ++anArgIter; |
| 4296 | } |
| 4297 | if (anArgIter < theArgsNb) |
| 4298 | { |
| 4299 | TCollection_AsciiString aValU (theArgVec[anArgIter]); |
| 4300 | TCollection_AsciiString aValUCase = aValU; |
| 4301 | aValUCase.LowerCase(); |
| 4302 | toSetGenOrigin = true; |
| 4303 | if (aValUCase == "off") |
| 4304 | { |
| 4305 | aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0)); |
| 4306 | continue; |
| 4307 | } |
| 4308 | else if (anArgIter + 1 < theArgsNb) |
| 4309 | { |
| 4310 | TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); |
| 4311 | if (aValU.IsRealValue() |
| 4312 | && aValV.IsRealValue()) |
| 4313 | { |
| 4314 | aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); |
| 4315 | ++anArgIter; |
| 4316 | continue; |
| 4317 | } |
| 4318 | } |
| 4319 | } |
| 4320 | std::cout << "Syntax error: unexpected argument '" << aName << "'\n"; |
| 4321 | return 1; |
| 4322 | } |
| 4323 | else if (!aTexturedShape.IsNull() |
| 4324 | && (aNameCase == "-repeat" |
| 4325 | || aNameCase == "-setrepeat" |
| 4326 | || aCommandName == "vtexrepeat")) |
| 4327 | { |
| 4328 | if (aCommandName != "vtexrepeat") |
| 4329 | { |
| 4330 | ++anArgIter; |
| 4331 | } |
| 4332 | if (anArgIter < theArgsNb) |
| 4333 | { |
| 4334 | TCollection_AsciiString aValU (theArgVec[anArgIter]); |
| 4335 | TCollection_AsciiString aValUCase = aValU; |
| 4336 | aValUCase.LowerCase(); |
| 4337 | toSetGenRepeat = true; |
| 4338 | if (aValUCase == "off") |
| 4339 | { |
| 4340 | aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0)); |
| 4341 | continue; |
| 4342 | } |
| 4343 | else if (anArgIter + 1 < theArgsNb) |
| 4344 | { |
| 4345 | TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); |
| 4346 | if (aValU.IsRealValue() |
| 4347 | && aValV.IsRealValue()) |
| 4348 | { |
| 4349 | aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); |
| 4350 | ++anArgIter; |
| 4351 | continue; |
| 4352 | } |
| 4353 | } |
| 4354 | } |
| 4355 | std::cout << "Syntax error: unexpected argument '" << aName << "'\n"; |
| 4356 | return 1; |
| 4357 | } |
| 4358 | else if (aNameCase == "-modulate") |
| 4359 | { |
| 4360 | bool toModulateBool = true; |
| 4361 | if (anArgIter + 1 < theArgsNb |
| 4362 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool)) |
| 4363 | { |
| 4364 | ++anArgIter; |
| 4365 | } |
| 4366 | toModulate = toModulateBool ? 1 : 0; |
| 4367 | } |
| 4368 | else if ((aNameCase == "-setfilter" |
| 4369 | || aNameCase == "-filter") |
| 4370 | && anArgIter + 1 < theArgsNb) |
| 4371 | { |
| 4372 | TCollection_AsciiString aValue (theArgVec[anArgIter + 1]); |
| 4373 | aValue.LowerCase(); |
| 4374 | ++anArgIter; |
| 4375 | toSetFilter = true; |
| 4376 | if (aValue == "nearest") |
| 4377 | { |
| 4378 | aFilter = Graphic3d_TOTF_NEAREST; |
| 4379 | } |
| 4380 | else if (aValue == "bilinear") |
| 4381 | { |
| 4382 | aFilter = Graphic3d_TOTF_BILINEAR; |
| 4383 | } |
| 4384 | else if (aValue == "trilinear") |
| 4385 | { |
| 4386 | aFilter = Graphic3d_TOTF_TRILINEAR; |
| 4387 | } |
| 4388 | else |
| 4389 | { |
| 4390 | std::cout << "Syntax error: unexpected argument '" << aValue << "'\n"; |
| 4391 | return 1; |
| 4392 | } |
| 4393 | } |
| 4394 | else if ((aNameCase == "-setaniso" |
| 4395 | || aNameCase == "-setanisofilter" |
| 4396 | || aNameCase == "-aniso" |
| 4397 | || aNameCase == "-anisofilter") |
| 4398 | && anArgIter + 1 < theArgsNb) |
| 4399 | { |
| 4400 | TCollection_AsciiString aValue (theArgVec[anArgIter + 1]); |
| 4401 | aValue.LowerCase(); |
| 4402 | ++anArgIter; |
| 4403 | toSetAniso = true; |
| 4404 | if (aValue == "off") |
| 4405 | { |
| 4406 | anAnisoFilter = Graphic3d_LOTA_OFF; |
| 4407 | } |
| 4408 | else if (aValue == "fast") |
| 4409 | { |
| 4410 | anAnisoFilter = Graphic3d_LOTA_FAST; |
| 4411 | } |
| 4412 | else if (aValue == "middle") |
| 4413 | { |
| 4414 | anAnisoFilter = Graphic3d_LOTA_MIDDLE; |
| 4415 | } |
| 4416 | else if (aValue == "quality" |
| 4417 | || aValue == "high") |
| 4418 | { |
| 4419 | anAnisoFilter = Graphic3d_LOTA_QUALITY; |
| 4420 | } |
| 4421 | else |
| 4422 | { |
| 4423 | std::cout << "Syntax error: unexpected argument '" << aValue << "'\n"; |
| 4424 | return 1; |
| 4425 | } |
| 4426 | } |
| 4427 | else if ((aNameCase == "-rotateangle" |
| 4428 | || aNameCase == "-rotangle" |
| 4429 | || aNameCase == "-rotate" |
| 4430 | || aNameCase == "-angle" |
| 4431 | || aNameCase == "-trsfangle") |
| 4432 | && anArgIter + 1 < theArgsNb) |
| 4433 | { |
| 4434 | aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); |
| 4435 | toSetTrsfAngle = true; |
| 4436 | ++anArgIter; |
| 4437 | } |
| 4438 | else if ((aNameCase == "-trsftrans" |
| 4439 | || aNameCase == "-trsftranslate" |
| 4440 | || aNameCase == "-translate" |
| 4441 | || aNameCase == "-translation") |
| 4442 | && anArgIter + 2 < theArgsNb) |
| 4443 | { |
| 4444 | aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); |
| 4445 | aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2])); |
| 4446 | toSetTrsfTrans = true; |
| 4447 | anArgIter += 2; |
| 4448 | } |
| 4449 | else if ((aNameCase == "-trsfscale") |
| 4450 | && anArgIter + 2 < theArgsNb) |
| 4451 | { |
| 4452 | aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); |
| 4453 | aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2])); |
| 4454 | toSetTrsfScale = true; |
| 4455 | anArgIter += 2; |
| 4456 | } |
| 4457 | else if (aNameCase == "-default" |
| 4458 | || aNameCase == "-defaults") |
| 4459 | { |
| 4460 | toSetDefaults = true; |
| 4461 | } |
| 4462 | else if ((aNameCase == "-video") |
| 4463 | && anArgIter + 1 < theArgsNb) |
| 4464 | { |
| 4465 | const TCollection_AsciiString anInput (theArgVec[++anArgIter]); |
| 4466 | Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld); |
| 4467 | if (aMedia.IsNull()) |
| 4468 | { |
| 4469 | aMedia = new Graphic3d_MediaTextureSet(); |
| 4470 | } |
| 4471 | if (aMedia->Input() != anInput) |
| 4472 | { |
| 4473 | aMedia->OpenInput (anInput, false); |
| 4474 | } |
| 4475 | else |
| 4476 | { |
| 4477 | if (aMedia->SwapFrames() |
| 4478 | && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate()) |
| 4479 | { |
| 4480 | ViewerTest::CurrentView()->Invalidate(); |
| 4481 | } |
| 4482 | } |
| 4483 | if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer()) |
| 4484 | && aTexturedShape.IsNull()) |
| 4485 | { |
| 4486 | aTexturedIO->SetToUpdate(); |
| 4487 | } |
| 4488 | |
| 4489 | toComputeUV = aTextureSetOld.IsNull(); |
| 4490 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true); |
| 4491 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia); |
| 4492 | aTextureSetOld.Nullify(); |
| 4493 | } |
| 4494 | else if (aCommandName == "vtexture" |
| 4495 | && (aTextureVecNew.IsEmpty() |
| 4496 | || aNameCase.StartsWith ("-tex"))) |
| 4497 | { |
| 4498 | Standard_Integer aTexIndex = 0; |
| 4499 | TCollection_AsciiString aTexName = aName; |
| 4500 | if (aNameCase.StartsWith ("-tex")) |
| 4501 | { |
| 4502 | if (anArgIter + 1 >= theArgsNb |
| 4503 | || aNameCase.Length() < 5) |
| 4504 | { |
| 4505 | std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n"; |
| 4506 | return 1; |
| 4507 | } |
| 4508 | |
| 4509 | TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length()); |
| 4510 | if (!aTexIndexStr.IsIntegerValue()) |
| 4511 | { |
| 4512 | std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n"; |
| 4513 | return 1; |
| 4514 | } |
| 4515 | |
| 4516 | aTexIndex = aTexIndexStr.IntegerValue(); |
| 4517 | aTexName = theArgVec[anArgIter + 1]; |
| 4518 | ++anArgIter; |
| 4519 | } |
| 4520 | if (aTexIndex >= Graphic3d_TextureUnit_NB |
| 4521 | || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits)) |
| 4522 | { |
| 4523 | std::cout << "Error: too many textures specified\n"; |
| 4524 | return 1; |
| 4525 | } |
| 4526 | |
| 4527 | toSetImage = true; |
| 4528 | if (aTexName.IsIntegerValue()) |
| 4529 | { |
| 4530 | const Standard_Integer aValue = aTexName.IntegerValue(); |
| 4531 | if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures()) |
| 4532 | { |
| 4533 | std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n"; |
| 4534 | return 1; |
| 4535 | } |
| 4536 | aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue))); |
| 4537 | } |
| 4538 | else if (aTexName == "?") |
| 4539 | { |
| 4540 | const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder(); |
| 4541 | |
| 4542 | theDi << "\n Files in current directory : \n\n"; |
| 4543 | theDi.Eval ("glob -nocomplain *"); |
| 4544 | |
| 4545 | TCollection_AsciiString aCmnd ("glob -nocomplain "); |
| 4546 | aCmnd += aTextureFolder; |
| 4547 | aCmnd += "/* "; |
| 4548 | |
| 4549 | theDi << "Files in " << aTextureFolder << " : \n\n"; |
| 4550 | theDi.Eval (aCmnd.ToCString()); |
| 4551 | return 0; |
| 4552 | } |
| 4553 | else if (aTexName != "off") |
| 4554 | { |
| 4555 | if (!OSD_File (aTexName).Exists()) |
| 4556 | { |
| 4557 | std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n"; |
| 4558 | return 1; |
| 4559 | } |
| 4560 | aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName)); |
| 4561 | } |
| 4562 | else |
| 4563 | { |
| 4564 | aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)()); |
| 4565 | } |
| 4566 | |
| 4567 | if (aTextureVecNew.Value (aTexIndex)) |
| 4568 | { |
| 4569 | aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex); |
| 4570 | } |
| 4571 | } |
| 4572 | else |
| 4573 | { |
| 4574 | std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n"; |
| 4575 | return 1; |
| 4576 | } |
| 4577 | } |
| 4578 | |
| 4579 | if (toSetImage) |
| 4580 | { |
| 4581 | // check if new image set is equal to already set one |
| 4582 | Standard_Integer aNbChanged = 0; |
| 4583 | Handle(Graphic3d_TextureSet) aTextureSetNew; |
| 4584 | if (!aTextureVecNew.IsEmpty()) |
| 4585 | { |
| 4586 | aNbChanged = aTextureVecNew.Size(); |
| 4587 | aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size()); |
| 4588 | for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter) |
| 4589 | { |
| 4590 | Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter); |
| 4591 | Handle(Graphic3d_TextureRoot) aTextureOld; |
| 4592 | if (!aTextureSetOld.IsNull() |
| 4593 | && aTexIter < aTextureSetOld->Size()) |
| 4594 | { |
| 4595 | aTextureOld = aTextureSetOld->Value (aTexIter); |
| 4596 | } |
| 4597 | |
| 4598 | if (!aTextureOld.IsNull() |
| 4599 | && !aTextureNew.IsNull()) |
| 4600 | { |
| 4601 | *aTextureNew->GetParams() = *aTextureOld->GetParams(); |
| 4602 | if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld)) |
| 4603 | { |
| 4604 | TCollection_AsciiString aFilePathOld, aFilePathNew; |
| 4605 | aTextureOld->Path().SystemName (aFilePathOld); |
| 4606 | aTextureNew->Path().SystemName (aFilePathNew); |
| 4607 | if (aTextureNew->Name() == anOldManualTex->Name() |
| 4608 | && aFilePathOld == aFilePathNew |
| 4609 | && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN)) |
| 4610 | { |
| 4611 | --aNbChanged; |
| 4612 | aTextureNew = anOldManualTex; |
| 4613 | } |
| 4614 | } |
| 4615 | } |
| 4616 | aTextureSetNew->SetValue (aTexIter, aTextureNew); |
| 4617 | } |
| 4618 | } |
| 4619 | if (aNbChanged == 0 |
| 4620 | && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull()) |
| 4621 | || (aTextureSetOld->Size() == aTextureSetNew->Size()))) |
| 4622 | { |
| 4623 | aTextureSetNew = aTextureSetOld; |
| 4624 | } |
| 4625 | |
| 4626 | if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer()) |
| 4627 | && aTexturedShape.IsNull()) |
| 4628 | { |
| 4629 | aTexturedIO->SetToUpdate(); |
| 4630 | } |
| 4631 | |
| 4632 | toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull(); |
| 4633 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull()); |
| 4634 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew); |
| 4635 | aTextureSetOld.Nullify(); |
| 4636 | } |
| 4637 | |
| 4638 | if (toSetDefaults) |
| 4639 | { |
| 4640 | if (toModulate != -1) |
| 4641 | { |
| 4642 | toModulate = 1; |
| 4643 | } |
| 4644 | if (!toSetFilter) |
| 4645 | { |
| 4646 | toSetFilter = true; |
| 4647 | aFilter = Graphic3d_TOTF_BILINEAR; |
| 4648 | } |
| 4649 | if (!toSetAniso) |
| 4650 | { |
| 4651 | toSetAniso = true; |
| 4652 | anAnisoFilter = Graphic3d_LOTA_OFF; |
| 4653 | } |
| 4654 | if (!toSetTrsfAngle) |
| 4655 | { |
| 4656 | toSetTrsfAngle = true; |
| 4657 | aTrsfRotAngle = 0.0f; |
| 4658 | } |
| 4659 | if (!toSetTrsfTrans) |
| 4660 | { |
| 4661 | toSetTrsfTrans = true; |
| 4662 | aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f); |
| 4663 | } |
| 4664 | if (!toSetTrsfScale) |
| 4665 | { |
| 4666 | toSetTrsfScale = true; |
| 4667 | aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f); |
| 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | if (aCommandName == "vtexture" |
| 4672 | && theArgsNb == 2) |
| 4673 | { |
| 4674 | if (!aTextureSetOld.IsNull()) |
| 4675 | { |
| 4676 | //toComputeUV = true; // we can keep UV vertex attributes |
| 4677 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff(); |
| 4678 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)()); |
| 4679 | aTextureSetOld.Nullify(); |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | if (aTexturedIO->Attributes()->HasOwnShadingAspect() |
| 4684 | && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull()) |
| 4685 | { |
| 4686 | if (toModulate != -1) |
| 4687 | { |
| 4688 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1); |
| 4689 | } |
| 4690 | if (toSetTrsfAngle) |
| 4691 | { |
| 4692 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees |
| 4693 | } |
| 4694 | if (toSetTrsfTrans) |
| 4695 | { |
| 4696 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans); |
| 4697 | } |
| 4698 | if (toSetTrsfScale) |
| 4699 | { |
| 4700 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale); |
| 4701 | } |
| 4702 | if (toSetFilter) |
| 4703 | { |
| 4704 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter); |
| 4705 | } |
| 4706 | if (toSetAniso) |
| 4707 | { |
| 4708 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter); |
| 4709 | } |
| 4710 | } |
| 4711 | |
| 4712 | // set default values if requested |
| 4713 | if (!toSetGenRepeat |
| 4714 | && (aCommandName == "vtexrepeat" |
| 4715 | || toSetDefaults)) |
| 4716 | { |
| 4717 | if (!aTexturedShape.IsNull()) |
| 4718 | { |
| 4719 | aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0)); |
| 4720 | } |
| 4721 | toSetGenRepeat = true; |
| 4722 | } |
| 4723 | if (!toSetGenOrigin |
| 4724 | && (aCommandName == "vtexorigin" |
| 4725 | || toSetDefaults)) |
| 4726 | { |
| 4727 | if (!aTexturedShape.IsNull()) |
| 4728 | { |
| 4729 | aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0)); |
| 4730 | } |
| 4731 | toSetGenOrigin = true; |
| 4732 | } |
| 4733 | if (!toSetGenScale |
| 4734 | && (aCommandName == "vtexscale" |
| 4735 | || toSetDefaults)) |
| 4736 | { |
| 4737 | if (!aTexturedShape.IsNull()) |
| 4738 | { |
| 4739 | aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0)); |
| 4740 | } |
| 4741 | toSetGenScale = true; |
| 4742 | } |
| 4743 | |
| 4744 | if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV) |
| 4745 | { |
| 4746 | if (!aTexturedShape.IsNull()) |
| 4747 | { |
| 4748 | aTexturedShape->SetToUpdate (AIS_Shaded); |
| 4749 | if (toSetImage) |
| 4750 | { |
| 4751 | if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded) |
| 4752 | || aCtx->DisplayMode() != AIS_Shaded) |
| 4753 | { |
| 4754 | aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false); |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | } |
| 4759 | aCtx->Display (aTexturedIO, false); |
| 4760 | aTexturedIO->SynchronizeAspects(); |
| 4761 | return 0; |
| 4762 | } |
| 4763 | |
| 4764 | //! Auxiliary method to parse transformation persistence flags |
| 4765 | inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString, |
| 4766 | Graphic3d_TransModeFlags& theFlags) |
| 4767 | { |
| 4768 | if (theFlagString == "zoom") |
| 4769 | { |
| 4770 | theFlags = Graphic3d_TMF_ZoomPers; |
| 4771 | } |
| 4772 | else if (theFlagString == "rotate") |
| 4773 | { |
| 4774 | theFlags = Graphic3d_TMF_RotatePers; |
| 4775 | } |
| 4776 | else if (theFlagString == "zoomrotate") |
| 4777 | { |
| 4778 | theFlags = Graphic3d_TMF_ZoomRotatePers; |
| 4779 | } |
| 4780 | else if (theFlagString == "trihedron" |
| 4781 | || theFlagString == "triedron") |
| 4782 | { |
| 4783 | theFlags = Graphic3d_TMF_TriedronPers; |
| 4784 | } |
| 4785 | else if (theFlagString == "none") |
| 4786 | { |
| 4787 | theFlags = Graphic3d_TMF_None; |
| 4788 | } |
| 4789 | else |
| 4790 | { |
| 4791 | return Standard_False; |
| 4792 | } |
| 4793 | |
| 4794 | return Standard_True; |
| 4795 | } |
| 4796 | |
| 4797 | //! Auxiliary method to parse transformation persistence flags |
| 4798 | inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString, |
| 4799 | Aspect_TypeOfTriedronPosition& theCorner) |
| 4800 | { |
| 4801 | TCollection_AsciiString aString (theString); |
| 4802 | aString.LowerCase(); |
| 4803 | if (aString == "center") |
| 4804 | { |
| 4805 | theCorner = Aspect_TOTP_CENTER; |
| 4806 | } |
| 4807 | else if (aString == "top" |
| 4808 | || aString == "upper") |
| 4809 | { |
| 4810 | theCorner = Aspect_TOTP_TOP; |
| 4811 | } |
| 4812 | else if (aString == "bottom" |
| 4813 | || aString == "lower") |
| 4814 | { |
| 4815 | theCorner = Aspect_TOTP_BOTTOM; |
| 4816 | } |
| 4817 | else if (aString == "left") |
| 4818 | { |
| 4819 | theCorner = Aspect_TOTP_LEFT; |
| 4820 | } |
| 4821 | else if (aString == "right") |
| 4822 | { |
| 4823 | theCorner = Aspect_TOTP_RIGHT; |
| 4824 | } |
| 4825 | else if (aString == "topleft" |
| 4826 | || aString == "leftupper" |
| 4827 | || aString == "upperleft") |
| 4828 | { |
| 4829 | theCorner = Aspect_TOTP_LEFT_UPPER; |
| 4830 | } |
| 4831 | else if (aString == "bottomleft" |
| 4832 | || aString == "leftlower" |
| 4833 | || aString == "lowerleft") |
| 4834 | { |
| 4835 | theCorner = Aspect_TOTP_LEFT_LOWER; |
| 4836 | } |
| 4837 | else if (aString == "topright" |
| 4838 | || aString == "rightupper" |
| 4839 | || aString == "upperright") |
| 4840 | { |
| 4841 | theCorner = Aspect_TOTP_RIGHT_UPPER; |
| 4842 | } |
| 4843 | else if (aString == "bottomright" |
| 4844 | || aString == "lowerright" |
| 4845 | || aString == "rightlower") |
| 4846 | { |
| 4847 | theCorner = Aspect_TOTP_RIGHT_LOWER; |
| 4848 | } |
| 4849 | else |
| 4850 | { |
| 4851 | return Standard_False; |
| 4852 | } |
| 4853 | |
| 4854 | return Standard_True; |
| 4855 | } |
| 4856 | |
| 4857 | //============================================================================== |
| 4858 | //function : VDisplay2 |
| 4859 | //author : ege |
| 4860 | //purpose : Display an object from its name |
| 4861 | //============================================================================== |
| 4862 | static int VDisplay2 (Draw_Interpretor& theDI, |
| 4863 | Standard_Integer theArgNb, |
| 4864 | const char** theArgVec) |
| 4865 | { |
| 4866 | if (theArgNb < 2) |
| 4867 | { |
| 4868 | std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n"; |
| 4869 | return 1; |
| 4870 | } |
| 4871 | if (theArgNb == 2 |
| 4872 | && TCollection_AsciiString (theArgVec[1]) == "*") |
| 4873 | { |
| 4874 | // alias |
| 4875 | return VDisplayAll (theDI, 1, theArgVec); |
| 4876 | } |
| 4877 | |
| 4878 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 4879 | if (aCtx.IsNull()) |
| 4880 | { |
| 4881 | ViewerTest::ViewerInit(); |
| 4882 | aCtx = ViewerTest::GetAISContext(); |
| 4883 | } |
| 4884 | |
| 4885 | // Parse input arguments |
| 4886 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
| 4887 | Standard_Integer isMutable = -1; |
| 4888 | Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN; |
| 4889 | Standard_Boolean toReDisplay = Standard_False; |
| 4890 | Standard_Integer isSelectable = -1; |
| 4891 | Standard_Integer anObjDispMode = -2; |
| 4892 | Standard_Integer anObjHighMode = -2; |
| 4893 | Standard_Boolean toSetTrsfPers = Standard_False; |
| 4894 | Handle(Graphic3d_TransformPers) aTrsfPers; |
| 4895 | TColStd_SequenceOfAsciiString aNamesOfDisplayIO; |
| 4896 | AIS_DisplayStatus aDispStatus = AIS_DS_None; |
| 4897 | Standard_Integer toDisplayInView = Standard_False; |
| 4898 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 4899 | { |
| 4900 | const TCollection_AsciiString aName = theArgVec[anArgIter]; |
| 4901 | TCollection_AsciiString aNameCase = aName; |
| 4902 | aNameCase.LowerCase(); |
| 4903 | if (anUpdateTool.parseRedrawMode (aName)) |
| 4904 | { |
| 4905 | continue; |
| 4906 | } |
| 4907 | else if (aNameCase == "-mutable") |
| 4908 | { |
| 4909 | isMutable = 1; |
| 4910 | } |
| 4911 | else if (aNameCase == "-neutral") |
| 4912 | { |
| 4913 | aDispStatus = AIS_DS_Displayed; |
| 4914 | } |
| 4915 | else if (aNameCase == "-immediate" |
| 4916 | || aNameCase == "-top") |
| 4917 | { |
| 4918 | aZLayer = Graphic3d_ZLayerId_Top; |
| 4919 | } |
| 4920 | else if (aNameCase == "-topmost") |
| 4921 | { |
| 4922 | aZLayer = Graphic3d_ZLayerId_Topmost; |
| 4923 | } |
| 4924 | else if (aNameCase == "-osd" |
| 4925 | || aNameCase == "-toposd" |
| 4926 | || aNameCase == "-overlay") |
| 4927 | { |
| 4928 | aZLayer = Graphic3d_ZLayerId_TopOSD; |
| 4929 | } |
| 4930 | else if (aNameCase == "-botosd" |
| 4931 | || aNameCase == "-underlay") |
| 4932 | { |
| 4933 | aZLayer = Graphic3d_ZLayerId_BotOSD; |
| 4934 | } |
| 4935 | else if (aNameCase == "-select" |
| 4936 | || aNameCase == "-selectable") |
| 4937 | { |
| 4938 | isSelectable = 1; |
| 4939 | } |
| 4940 | else if (aNameCase == "-noselect" |
| 4941 | || aNameCase == "-noselection") |
| 4942 | { |
| 4943 | isSelectable = 0; |
| 4944 | } |
| 4945 | else if (aNameCase == "-dispmode" |
| 4946 | || aNameCase == "-displaymode") |
| 4947 | { |
| 4948 | if (++anArgIter >= theArgNb) |
| 4949 | { |
| 4950 | std::cerr << "Error: wrong syntax at " << aName << ".\n"; |
| 4951 | return 1; |
| 4952 | } |
| 4953 | |
| 4954 | anObjDispMode = Draw::Atoi (theArgVec [anArgIter]); |
| 4955 | } |
| 4956 | else if (aNameCase == "-himode" |
| 4957 | || aNameCase == "-highmode" |
| 4958 | || aNameCase == "-highlightmode") |
| 4959 | { |
| 4960 | if (++anArgIter >= theArgNb) |
| 4961 | { |
| 4962 | std::cerr << "Error: wrong syntax at " << aName << ".\n"; |
| 4963 | return 1; |
| 4964 | } |
| 4965 | |
| 4966 | anObjHighMode = Draw::Atoi (theArgVec [anArgIter]); |
| 4967 | } |
| 4968 | else if (aNameCase == "-3d") |
| 4969 | { |
| 4970 | toSetTrsfPers = Standard_True; |
| 4971 | aTrsfPers.Nullify(); |
| 4972 | } |
| 4973 | else if (aNameCase == "-2d" |
| 4974 | || aNameCase == "-trihedron" |
| 4975 | || aNameCase == "-triedron") |
| 4976 | { |
| 4977 | toSetTrsfPers = Standard_True; |
| 4978 | aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER); |
| 4979 | |
| 4980 | if (anArgIter + 1 < theArgNb) |
| 4981 | { |
| 4982 | Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER; |
| 4983 | if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner)) |
| 4984 | { |
| 4985 | ++anArgIter; |
| 4986 | aTrsfPers->SetCorner2d (aCorner); |
| 4987 | |
| 4988 | if (anArgIter + 2 < theArgNb) |
| 4989 | { |
| 4990 | TCollection_AsciiString anX (theArgVec[anArgIter + 1]); |
| 4991 | TCollection_AsciiString anY (theArgVec[anArgIter + 2]); |
| 4992 | if (anX.IsIntegerValue() |
| 4993 | && anY.IsIntegerValue()) |
| 4994 | { |
| 4995 | anArgIter += 2; |
| 4996 | aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue())); |
| 4997 | } |
| 4998 | } |
| 4999 | } |
| 5000 | } |
| 5001 | } |
| 5002 | else if (aNameCase == "-trsfpers" |
| 5003 | || aNameCase == "-pers") |
| 5004 | { |
| 5005 | if (++anArgIter >= theArgNb |
| 5006 | || !aTrsfPers.IsNull()) |
| 5007 | { |
| 5008 | std::cerr << "Error: wrong syntax at " << aName << ".\n"; |
| 5009 | return 1; |
| 5010 | } |
| 5011 | |
| 5012 | toSetTrsfPers = Standard_True; |
| 5013 | Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None; |
| 5014 | TCollection_AsciiString aPersFlags (theArgVec [anArgIter]); |
| 5015 | aPersFlags.LowerCase(); |
| 5016 | if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags)) |
| 5017 | { |
| 5018 | std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n"; |
| 5019 | return 1; |
| 5020 | } |
| 5021 | |
| 5022 | if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers) |
| 5023 | { |
| 5024 | aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER); |
| 5025 | } |
| 5026 | else if (aTrsfPersFlags != Graphic3d_TMF_None) |
| 5027 | { |
| 5028 | aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt()); |
| 5029 | } |
| 5030 | } |
| 5031 | else if (aNameCase == "-trsfperspos" |
| 5032 | || aNameCase == "-perspos") |
| 5033 | { |
| 5034 | if (anArgIter + 2 >= theArgNb |
| 5035 | || aTrsfPers.IsNull()) |
| 5036 | { |
| 5037 | std::cerr << "Error: wrong syntax at " << aName << ".\n"; |
| 5038 | return 1; |
| 5039 | } |
| 5040 | |
| 5041 | TCollection_AsciiString aX (theArgVec[++anArgIter]); |
| 5042 | TCollection_AsciiString aY (theArgVec[++anArgIter]); |
| 5043 | TCollection_AsciiString aZ = "0"; |
| 5044 | if (!aX.IsRealValue() |
| 5045 | || !aY.IsRealValue()) |
| 5046 | { |
| 5047 | std::cerr << "Error: wrong syntax at " << aName << ".\n"; |
| 5048 | return 1; |
| 5049 | } |
| 5050 | if (anArgIter + 1 < theArgNb) |
| 5051 | { |
| 5052 | TCollection_AsciiString aTemp = theArgVec[anArgIter + 1]; |
| 5053 | if (aTemp.IsRealValue()) |
| 5054 | { |
| 5055 | aZ = aTemp; |
| 5056 | ++anArgIter; |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue()); |
| 5061 | if (aTrsfPers->IsZoomOrRotate()) |
| 5062 | { |
| 5063 | aTrsfPers->SetAnchorPoint (aPnt); |
| 5064 | } |
| 5065 | else if (aTrsfPers->IsTrihedronOr2d()) |
| 5066 | { |
| 5067 | aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt); |
| 5068 | } |
| 5069 | } |
| 5070 | else if (aNameCase == "-layer" |
| 5071 | || aNameCase == "-zlayer") |
| 5072 | { |
| 5073 | ++anArgIter; |
| 5074 | if (anArgIter >= theArgNb |
| 5075 | || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer) |
| 5076 | || aZLayer == Graphic3d_ZLayerId_UNKNOWN) |
| 5077 | { |
| 5078 | std::cerr << "Error: wrong syntax at " << aName << ".\n"; |
| 5079 | return 1; |
| 5080 | } |
| 5081 | } |
| 5082 | else if (aNameCase == "-view" |
| 5083 | || aNameCase == "-inview") |
| 5084 | { |
| 5085 | toDisplayInView = Standard_True; |
| 5086 | } |
| 5087 | else if (aNameCase == "-redisplay") |
| 5088 | { |
| 5089 | toReDisplay = Standard_True; |
| 5090 | } |
| 5091 | else if (aNameCase == "-erased" |
| 5092 | || aNameCase == "-load") |
| 5093 | { |
| 5094 | aDispStatus = AIS_DS_Erased; |
| 5095 | } |
| 5096 | else |
| 5097 | { |
| 5098 | aNamesOfDisplayIO.Append (aName); |
| 5099 | } |
| 5100 | } |
| 5101 | |
| 5102 | if (aNamesOfDisplayIO.IsEmpty()) |
| 5103 | { |
| 5104 | std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n"; |
| 5105 | return 1; |
| 5106 | } |
| 5107 | |
| 5108 | // Display interactive objects |
| 5109 | for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter) |
| 5110 | { |
| 5111 | const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter); |
| 5112 | Handle(AIS_InteractiveObject) aShape; |
| 5113 | if (!GetMapOfAIS().Find2 (aName, aShape)) |
| 5114 | { |
| 5115 | // create the AIS_Shape from a name |
| 5116 | TopoDS_Shape aDrawShape = DBRep::GetExisting (aName); |
| 5117 | if (!aDrawShape.IsNull()) |
| 5118 | { |
| 5119 | aShape = new AIS_Shape (aDrawShape); |
| 5120 | if (isMutable != -1) |
| 5121 | { |
| 5122 | aShape->SetMutable (isMutable == 1); |
| 5123 | } |
| 5124 | if (aZLayer != Graphic3d_ZLayerId_UNKNOWN) |
| 5125 | { |
| 5126 | aShape->SetZLayer (aZLayer); |
| 5127 | } |
| 5128 | if (toSetTrsfPers) |
| 5129 | { |
| 5130 | aCtx->SetTransformPersistence (aShape, aTrsfPers); |
| 5131 | } |
| 5132 | if (anObjDispMode != -2) |
| 5133 | { |
| 5134 | if (anObjDispMode == -1) |
| 5135 | { |
| 5136 | aShape->UnsetDisplayMode(); |
| 5137 | } |
| 5138 | if (!aShape->AcceptDisplayMode (anObjDispMode)) |
| 5139 | { |
| 5140 | std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode\n"; |
| 5141 | return 1; |
| 5142 | } |
| 5143 | else |
| 5144 | { |
| 5145 | aShape->SetDisplayMode (anObjDispMode); |
| 5146 | } |
| 5147 | } |
| 5148 | if (anObjHighMode != -2) |
| 5149 | { |
| 5150 | if (anObjHighMode != -1 |
| 5151 | && !aShape->AcceptDisplayMode (anObjHighMode)) |
| 5152 | { |
| 5153 | std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode\n"; |
| 5154 | return 1; |
| 5155 | } |
| 5156 | aShape->SetHilightMode (anObjHighMode); |
| 5157 | } |
| 5158 | |
| 5159 | GetMapOfAIS().Bind (aShape, aName); |
| 5160 | Standard_Integer aDispMode = aShape->HasDisplayMode() |
| 5161 | ? aShape->DisplayMode() |
| 5162 | : (aShape->AcceptDisplayMode (aCtx->DisplayMode()) |
| 5163 | ? aCtx->DisplayMode() |
| 5164 | : 0); |
| 5165 | Standard_Integer aSelMode = -1; |
| 5166 | if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection())) |
| 5167 | { |
| 5168 | aSelMode = aShape->GlobalSelectionMode(); |
| 5169 | } |
| 5170 | |
| 5171 | aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus); |
| 5172 | if (toDisplayInView) |
| 5173 | { |
| 5174 | for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next()) |
| 5175 | { |
| 5176 | aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False); |
| 5177 | } |
| 5178 | aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True); |
| 5179 | } |
| 5180 | } |
| 5181 | else |
| 5182 | { |
| 5183 | std::cerr << "Error: object with name '" << aName << "' does not exist!\n"; |
| 5184 | } |
| 5185 | continue; |
| 5186 | } |
| 5187 | |
| 5188 | if (isMutable != -1) |
| 5189 | { |
| 5190 | aShape->SetMutable (isMutable == 1); |
| 5191 | } |
| 5192 | if (aZLayer != Graphic3d_ZLayerId_UNKNOWN) |
| 5193 | { |
| 5194 | aShape->SetZLayer (aZLayer); |
| 5195 | } |
| 5196 | if (toSetTrsfPers) |
| 5197 | { |
| 5198 | aCtx->SetTransformPersistence (aShape, aTrsfPers); |
| 5199 | } |
| 5200 | if (anObjDispMode != -2) |
| 5201 | { |
| 5202 | aShape->SetDisplayMode (anObjDispMode); |
| 5203 | } |
| 5204 | if (anObjHighMode != -2) |
| 5205 | { |
| 5206 | aShape->SetHilightMode (anObjHighMode); |
| 5207 | } |
| 5208 | Standard_Integer aDispMode = aShape->HasDisplayMode() |
| 5209 | ? aShape->DisplayMode() |
| 5210 | : (aShape->AcceptDisplayMode (aCtx->DisplayMode()) |
| 5211 | ? aCtx->DisplayMode() |
| 5212 | : 0); |
| 5213 | Standard_Integer aSelMode = -1; |
| 5214 | if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection())) |
| 5215 | { |
| 5216 | aSelMode = aShape->GlobalSelectionMode(); |
| 5217 | } |
| 5218 | |
| 5219 | if (aShape->Type() == AIS_KOI_Datum) |
| 5220 | { |
| 5221 | aCtx->Display (aShape, Standard_False); |
| 5222 | } |
| 5223 | else |
| 5224 | { |
| 5225 | theDI << "Display " << aName << "\n"; |
| 5226 | |
| 5227 | // update the Shape in the AIS_Shape |
| 5228 | TopoDS_Shape aNewShape = DBRep::GetExisting (aName); |
| 5229 | Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape); |
| 5230 | if (!aShapePrs.IsNull()) |
| 5231 | { |
| 5232 | if (!aShapePrs->Shape().IsEqual (aNewShape)) |
| 5233 | { |
| 5234 | toReDisplay = Standard_True; |
| 5235 | } |
| 5236 | aShapePrs->Set (aNewShape); |
| 5237 | } |
| 5238 | if (toReDisplay) |
| 5239 | { |
| 5240 | aCtx->Redisplay (aShape, Standard_False); |
| 5241 | } |
| 5242 | |
| 5243 | if (aSelMode == -1) |
| 5244 | { |
| 5245 | aCtx->Erase (aShape, Standard_False); |
| 5246 | } |
| 5247 | aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus); |
| 5248 | if (toDisplayInView) |
| 5249 | { |
| 5250 | aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True); |
| 5251 | } |
| 5252 | } |
| 5253 | } |
| 5254 | |
| 5255 | return 0; |
| 5256 | } |
| 5257 | |
| 5258 | //======================================================================= |
| 5259 | //function : VNbDisplayed |
| 5260 | //purpose : Returns number of displayed objects |
| 5261 | //======================================================================= |
| 5262 | static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi, |
| 5263 | Standard_Integer theArgsNb, |
| 5264 | const char** theArgVec) |
| 5265 | { |
| 5266 | if(theArgsNb != 1) |
| 5267 | { |
| 5268 | theDi << "Usage : " << theArgVec[0] << "\n"; |
| 5269 | return 1; |
| 5270 | } |
| 5271 | |
| 5272 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
| 5273 | if (aContextAIS.IsNull()) |
| 5274 | { |
| 5275 | std::cout << theArgVec[0] << "AIS context is not available.\n"; |
| 5276 | return 1; |
| 5277 | } |
| 5278 | |
| 5279 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 5280 | if(aContext.IsNull()) |
| 5281 | { |
| 5282 | theDi << "use 'vinit' command before " << theArgVec[0] << "\n"; |
| 5283 | return 1; |
| 5284 | } |
| 5285 | |
| 5286 | AIS_ListOfInteractive aListOfIO; |
| 5287 | aContextAIS->DisplayedObjects (aListOfIO); |
| 5288 | |
| 5289 | theDi << aListOfIO.Extent() << "\n"; |
| 5290 | return 0; |
| 5291 | } |
| 5292 | |
| 5293 | //=============================================================================================== |
| 5294 | //function : VUpdate |
| 5295 | //purpose : |
| 5296 | //=============================================================================================== |
| 5297 | static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
| 5298 | { |
| 5299 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
| 5300 | if (aContextAIS.IsNull()) |
| 5301 | { |
| 5302 | std::cout << theArgVec[0] << "AIS context is not available.\n"; |
| 5303 | return 1; |
| 5304 | } |
| 5305 | |
| 5306 | if (theArgsNb < 2) |
| 5307 | { |
| 5308 | std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n"; |
| 5309 | return 1; |
| 5310 | } |
| 5311 | |
| 5312 | AIS_ListOfInteractive aListOfIO; |
| 5313 | for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
| 5314 | { |
| 5315 | TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]); |
| 5316 | |
| 5317 | Handle(AIS_InteractiveObject) anAISObj; |
| 5318 | GetMapOfAIS().Find2 (aName, anAISObj); |
| 5319 | if (anAISObj.IsNull()) |
| 5320 | { |
| 5321 | std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n"; |
| 5322 | return 1; |
| 5323 | } |
| 5324 | |
| 5325 | aListOfIO.Append (anAISObj); |
| 5326 | } |
| 5327 | |
| 5328 | AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); |
| 5329 | for (; anIOIt.More(); anIOIt.Next()) |
| 5330 | { |
| 5331 | aContextAIS->Update (anIOIt.Value(), Standard_False); |
| 5332 | } |
| 5333 | |
| 5334 | aContextAIS->UpdateCurrentViewer(); |
| 5335 | |
| 5336 | return 0; |
| 5337 | } |
| 5338 | |
| 5339 | //============================================================================== |
| 5340 | //function : VShading |
| 5341 | //purpose : Sharpen or roughten the quality of the shading |
| 5342 | //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg |
| 5343 | //============================================================================== |
| 5344 | static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv) |
| 5345 | { |
| 5346 | Standard_Real myDevCoef; |
| 5347 | Handle(AIS_InteractiveObject) TheAisIO; |
| 5348 | |
| 5349 | // Verifications |
| 5350 | const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0); |
| 5351 | if (argc < 3) { |
| 5352 | myDevCoef = 0.0008; |
| 5353 | } else { |
| 5354 | myDevCoef =Draw::Atof(argv[2]); |
| 5355 | } |
| 5356 | |
| 5357 | TCollection_AsciiString name=argv[1]; |
| 5358 | GetMapOfAIS().Find2(name, TheAisIO); |
| 5359 | if (TheAisIO.IsNull()) |
| 5360 | { |
| 5361 | TopoDS_Shape aDrawShape = DBRep::GetExisting (name); |
| 5362 | if (!aDrawShape.IsNull()) |
| 5363 | { |
| 5364 | TheAisIO = new AIS_Shape (aDrawShape); |
| 5365 | } |
| 5366 | } |
| 5367 | |
| 5368 | if (HaveToSet) |
| 5369 | TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True); |
| 5370 | else |
| 5371 | TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True); |
| 5372 | |
| 5373 | TheAISContext()->Redisplay (TheAisIO, Standard_True); |
| 5374 | return 0; |
| 5375 | } |
| 5376 | |
| 5377 | //! Auxiliary method to print Interactive Object information |
| 5378 | static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected, |
| 5379 | const Handle(AIS_InteractiveObject)& theObj, |
| 5380 | Draw_Interpretor& theDI) |
| 5381 | { |
| 5382 | if (theObj.IsNull()) |
| 5383 | { |
| 5384 | theDI << "NULL presentation\n"; |
| 5385 | return; |
| 5386 | } |
| 5387 | |
| 5388 | theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ") |
| 5389 | << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ") |
| 5390 | << (theDetected.Contains (theObj) ? " Detected" : " ") |
| 5391 | << " Type: "; |
| 5392 | if (theObj->Type() == AIS_KOI_Datum) |
| 5393 | { |
| 5394 | // AIS_Datum |
| 5395 | if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; } |
| 5396 | else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; } |
| 5397 | else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; } |
| 5398 | else if (theObj->Signature() == 5) { theDI << " AIS_Line"; } |
| 5399 | else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; } |
| 5400 | else if (theObj->Signature() == 1) { theDI << " AIS_Point"; } |
| 5401 | else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; } |
| 5402 | } |
| 5403 | // AIS_Shape |
| 5404 | else if (theObj->Type() == AIS_KOI_Shape |
| 5405 | && theObj->Signature() == 0) |
| 5406 | { |
| 5407 | theDI << " AIS_Shape"; |
| 5408 | } |
| 5409 | else if (theObj->Type() == AIS_KOI_Relation) |
| 5410 | { |
| 5411 | // AIS_Dimention and AIS_Relation |
| 5412 | Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj); |
| 5413 | switch (aRelation->KindOfDimension()) |
| 5414 | { |
| 5415 | case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break; |
| 5416 | case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break; |
| 5417 | case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break; |
| 5418 | case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break; |
| 5419 | //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break; |
| 5420 | case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break; |
| 5421 | case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break; |
| 5422 | default: theDI << " UNKNOWN dimension"; break; |
| 5423 | } |
| 5424 | } |
| 5425 | else |
| 5426 | { |
| 5427 | theDI << " UserPrs"; |
| 5428 | } |
| 5429 | theDI << " (" << theObj->DynamicType()->Name() << ")"; |
| 5430 | } |
| 5431 | |
| 5432 | //! Print information about locally selected sub-shapes |
| 5433 | template <typename T> |
| 5434 | static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI) |
| 5435 | { |
| 5436 | const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext)); |
| 5437 | TCollection_AsciiString aPrevName; |
| 5438 | for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) |
| 5439 | { |
| 5440 | const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive()); |
| 5441 | const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner(); |
| 5442 | if (aShapeIO.IsNull() || anOwner.IsNull()) |
| 5443 | continue; |
| 5444 | if (isGlobalCtx) |
| 5445 | { |
| 5446 | if (anOwner == aShapeIO->GlobalSelOwner()) |
| 5447 | continue; |
| 5448 | } |
| 5449 | const TopoDS_Shape aSubShape = theContext->SelectedShape(); |
| 5450 | if (aSubShape.IsNull() |
| 5451 | || aShapeIO.IsNull() |
| 5452 | || !GetMapOfAIS().IsBound1 (aShapeIO)) |
| 5453 | { |
| 5454 | continue; |
| 5455 | } |
| 5456 | |
| 5457 | const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO); |
| 5458 | TopTools_MapOfShape aFilter; |
| 5459 | Standard_Integer aNumber = 0; |
| 5460 | const TopoDS_Shape aShape = aShapeIO->Shape(); |
| 5461 | for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType()); |
| 5462 | anIter.More(); anIter.Next()) |
| 5463 | { |
| 5464 | if (!aFilter.Add (anIter.Current())) |
| 5465 | { |
| 5466 | continue; // filter duplicates |
| 5467 | } |
| 5468 | |
| 5469 | ++aNumber; |
| 5470 | if (!anIter.Current().IsSame (aSubShape)) |
| 5471 | { |
| 5472 | continue; |
| 5473 | } |
| 5474 | |
| 5475 | Standard_CString aShapeName = NULL; |
| 5476 | switch (aSubShape.ShapeType()) |
| 5477 | { |
| 5478 | case TopAbs_COMPOUND: aShapeName = " Compound"; break; |
| 5479 | case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break; |
| 5480 | case TopAbs_SOLID: aShapeName = " Solid"; break; |
| 5481 | case TopAbs_SHELL: aShapeName = " Shell"; break; |
| 5482 | case TopAbs_FACE: aShapeName = " Face"; break; |
| 5483 | case TopAbs_WIRE: aShapeName = " Wire"; break; |
| 5484 | case TopAbs_EDGE: aShapeName = " Edge"; break; |
| 5485 | case TopAbs_VERTEX: aShapeName = " Vertex"; break; |
| 5486 | default: |
| 5487 | case TopAbs_SHAPE: aShapeName = " Shape"; break; |
| 5488 | } |
| 5489 | |
| 5490 | if (aParentName != aPrevName) |
| 5491 | { |
| 5492 | theDI << "Locally selected sub-shapes within " << aParentName << ":\n"; |
| 5493 | aPrevName = aParentName; |
| 5494 | } |
| 5495 | theDI << " " << aShapeName << " #" << aNumber << "\n"; |
| 5496 | break; |
| 5497 | } |
| 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | //============================================================================== |
| 5502 | //function : VState |
| 5503 | //purpose : |
| 5504 | //============================================================================== |
| 5505 | static Standard_Integer VState (Draw_Interpretor& theDI, |
| 5506 | Standard_Integer theArgNb, |
| 5507 | Standard_CString* theArgVec) |
| 5508 | { |
| 5509 | Handle(AIS_InteractiveContext) aCtx = TheAISContext(); |
| 5510 | if (aCtx.IsNull()) |
| 5511 | { |
| 5512 | std::cerr << "Error: No opened viewer!\n"; |
| 5513 | return 1; |
| 5514 | } |
| 5515 | |
| 5516 | Standard_Boolean toPrintEntities = Standard_False; |
| 5517 | Standard_Boolean toCheckSelected = Standard_False; |
| 5518 | |
| 5519 | for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx) |
| 5520 | { |
| 5521 | TCollection_AsciiString anOption (theArgVec[anArgIdx]); |
| 5522 | anOption.LowerCase(); |
| 5523 | if (anOption == "-detectedentities" |
| 5524 | || anOption == "-entities") |
| 5525 | { |
| 5526 | toPrintEntities = Standard_True; |
| 5527 | } |
| 5528 | else if (anOption == "-hasselected") |
| 5529 | { |
| 5530 | toCheckSelected = Standard_True; |
| 5531 | } |
| 5532 | } |
| 5533 | |
| 5534 | if (toCheckSelected) |
| 5535 | { |
| 5536 | aCtx->InitSelected(); |
| 5537 | TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape())); |
| 5538 | theDI << "Check if context has selected shape: " << hasSelected << "\n"; |
| 5539 | |
| 5540 | return 0; |
| 5541 | } |
| 5542 | |
| 5543 | if (toPrintEntities) |
| 5544 | { |
| 5545 | theDI << "Detected entities:\n"; |
| 5546 | Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector(); |
| 5547 | |
| 5548 | SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager(); |
| 5549 | for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter) |
| 5550 | { |
| 5551 | const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter); |
| 5552 | const Handle(Select3D_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter); |
| 5553 | const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->OwnerId(); |
| 5554 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); |
| 5555 | |
| 5556 | TCollection_AsciiString aName; |
| 5557 | GetMapOfAIS().Find1 (anObj, aName); |
| 5558 | aName.LeftJustify (20, ' '); |
| 5559 | char anInfoStr[512]; |
| 5560 | Sprintf (anInfoStr, |
| 5561 | " Depth: %g Distance: %g Point: %g %g %g", |
| 5562 | aPickData.Depth, |
| 5563 | aPickData.MinDist, |
| 5564 | aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z()); |
| 5565 | theDI << " " << aName |
| 5566 | << anInfoStr |
| 5567 | << " (" << anEntity->DynamicType()->Name() << ")" |
| 5568 | << "\n"; |
| 5569 | |
| 5570 | Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner); |
| 5571 | if (!aBRepOwner.IsNull()) |
| 5572 | { |
| 5573 | theDI << " Detected Shape: " |
| 5574 | << aBRepOwner->Shape().TShape()->DynamicType()->Name() |
| 5575 | << "\n"; |
| 5576 | } |
| 5577 | |
| 5578 | Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity); |
| 5579 | if (!aWire.IsNull()) |
| 5580 | { |
| 5581 | Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected(); |
| 5582 | theDI << " Detected Child: " |
| 5583 | << aSen->DynamicType()->Name() |
| 5584 | << "\n"; |
| 5585 | } |
| 5586 | |
| 5587 | Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity); |
| 5588 | if (!aPrimArr.IsNull()) |
| 5589 | { |
| 5590 | theDI << " Detected Element: " |
| 5591 | << aPrimArr->LastDetectedElement() |
| 5592 | << "\n"; |
| 5593 | } |
| 5594 | } |
| 5595 | return 0; |
| 5596 | } |
| 5597 | |
| 5598 | NCollection_Map<Handle(AIS_InteractiveObject)> aDetected; |
| 5599 | for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected()) |
| 5600 | { |
| 5601 | aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable())); |
| 5602 | } |
| 5603 | |
| 5604 | const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*'); |
| 5605 | if (theArgNb >= 2 |
| 5606 | && !toShowAll) |
| 5607 | { |
| 5608 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 5609 | { |
| 5610 | const TCollection_AsciiString anObjName = theArgVec[anArgIter]; |
| 5611 | Handle(AIS_InteractiveObject) anObj; |
| 5612 | if (!GetMapOfAIS().Find2 (anObjName, anObj)) |
| 5613 | { |
| 5614 | theDI << anObjName << " doesn't exist!\n"; |
| 5615 | continue; |
| 5616 | } |
| 5617 | |
| 5618 | TCollection_AsciiString aName = anObjName; |
| 5619 | aName.LeftJustify (20, ' '); |
| 5620 | theDI << " " << aName << " "; |
| 5621 | objInfo (aDetected, anObj, theDI); |
| 5622 | theDI << "\n"; |
| 5623 | } |
| 5624 | return 0; |
| 5625 | } |
| 5626 | |
| 5627 | if (aCtx->NbSelected() > 0 && !toShowAll) |
| 5628 | { |
| 5629 | NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap; |
| 5630 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
| 5631 | { |
| 5632 | const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner(); |
| 5633 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); |
| 5634 | // handle whole object selection |
| 5635 | if (anOwner == anObj->GlobalSelOwner()) |
| 5636 | { |
| 5637 | TCollection_AsciiString aName; |
| 5638 | GetMapOfAIS().Find1 (anObj, aName); |
| 5639 | aName.LeftJustify (20, ' '); |
| 5640 | theDI << aName << " "; |
| 5641 | objInfo (aDetected, anObj, theDI); |
| 5642 | theDI << "\n"; |
| 5643 | } |
| 5644 | } |
| 5645 | |
| 5646 | // process selected sub-shapes |
| 5647 | printLocalSelectionInfo (aCtx, theDI); |
| 5648 | |
| 5649 | return 0; |
| 5650 | } |
| 5651 | |
| 5652 | theDI << "Neutral-point state:\n"; |
| 5653 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); |
| 5654 | anObjIter.More(); anObjIter.Next()) |
| 5655 | { |
| 5656 | if (anObjIter.Key1().IsNull()) |
| 5657 | { |
| 5658 | continue; |
| 5659 | } |
| 5660 | |
| 5661 | TCollection_AsciiString aName = anObjIter.Key2(); |
| 5662 | aName.LeftJustify (20, ' '); |
| 5663 | theDI << " " << aName << " "; |
| 5664 | objInfo (aDetected, anObjIter.Key1(), theDI); |
| 5665 | theDI << "\n"; |
| 5666 | } |
| 5667 | printLocalSelectionInfo (aCtx, theDI); |
| 5668 | return 0; |
| 5669 | } |
| 5670 | |
| 5671 | //======================================================================= |
| 5672 | //function : PickShape |
| 5673 | //purpose : First Activate the rightmode + Put Filters to be able to |
| 5674 | // pick objets that are of type <TheType>... |
| 5675 | //======================================================================= |
| 5676 | |
| 5677 | TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType, |
| 5678 | const Standard_Integer theMaxPick) |
| 5679 | { |
| 5680 | Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1); |
| 5681 | PickShapes (theShapeType, aResArray, theMaxPick); |
| 5682 | return aResArray->First(); |
| 5683 | } |
| 5684 | |
| 5685 | //======================================================================= |
| 5686 | //function : PickShapes |
| 5687 | //purpose : |
| 5688 | //======================================================================= |
| 5689 | Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType, |
| 5690 | Handle(TopTools_HArray1OfShape)& theResArray, |
| 5691 | const Standard_Integer theMaxPick) |
| 5692 | { |
| 5693 | const Standard_Integer aNbToReach = theResArray->Length(); |
| 5694 | if (aNbToReach > 1) |
| 5695 | { |
| 5696 | std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n"; |
| 5697 | } |
| 5698 | |
| 5699 | // step 1: prepare the data |
| 5700 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 5701 | aCtx->RemoveFilters(); |
| 5702 | AIS_ListOfInteractive aDispObjects; |
| 5703 | aCtx->DisplayedObjects (aDispObjects); |
| 5704 | if (theShapeType == TopAbs_SHAPE) |
| 5705 | { |
| 5706 | aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape)); |
| 5707 | } |
| 5708 | else |
| 5709 | { |
| 5710 | aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType)); |
| 5711 | } |
| 5712 | |
| 5713 | const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType); |
| 5714 | for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next()) |
| 5715 | { |
| 5716 | if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value())) |
| 5717 | { |
| 5718 | aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single); |
| 5719 | } |
| 5720 | } |
| 5721 | |
| 5722 | // step 2 : wait for the selection... |
| 5723 | Standard_Integer aNbPickGood = 0, aNbPickFail = 0; |
| 5724 | Standard_Integer argccc = 5; |
| 5725 | const char *bufff[] = { "A", "B", "C", "D", "E" }; |
| 5726 | const char **argvvv = (const char** )bufff; |
| 5727 | for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; ) |
| 5728 | { |
| 5729 | while (ViewerMainLoop (argccc, argvvv)) {} |
| 5730 | Standard_Integer aNbStored = aCtx->NbSelected(); |
| 5731 | if (aNbStored != aNbPickGood) |
| 5732 | { |
| 5733 | aNbPickGood = aNbStored; |
| 5734 | } |
| 5735 | else |
| 5736 | { |
| 5737 | ++aNbPickFail; |
| 5738 | } |
| 5739 | std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n"; |
| 5740 | } |
| 5741 | |
| 5742 | // step3 get result. |
| 5743 | if (aNbPickFail >= aNbToReach) |
| 5744 | { |
| 5745 | return Standard_False; |
| 5746 | } |
| 5747 | |
| 5748 | Standard_Integer anIndex = theResArray->Lower(); |
| 5749 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex) |
| 5750 | { |
| 5751 | if (aCtx->HasSelectedShape()) |
| 5752 | { |
| 5753 | theResArray->SetValue (anIndex, aCtx->SelectedShape()); |
| 5754 | } |
| 5755 | else |
| 5756 | { |
| 5757 | Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive(); |
| 5758 | theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape()); |
| 5759 | } |
| 5760 | } |
| 5761 | |
| 5762 | aCtx->RemoveFilters(); |
| 5763 | if (theShapeType != TopAbs_SHAPE) |
| 5764 | { |
| 5765 | for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next()) |
| 5766 | { |
| 5767 | if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value())) |
| 5768 | { |
| 5769 | aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single); |
| 5770 | } |
| 5771 | } |
| 5772 | } |
| 5773 | return Standard_True; |
| 5774 | } |
| 5775 | |
| 5776 | //======================================================================= |
| 5777 | //function : VPickShape |
| 5778 | //purpose : |
| 5779 | //======================================================================= |
| 5780 | static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 5781 | { |
| 5782 | TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE; |
| 5783 | if (argc != 1) |
| 5784 | { |
| 5785 | TCollection_AsciiString aShapeArg (argv[1]); |
| 5786 | aShapeArg.LowerCase(); |
| 5787 | aShapeType = TopAbs_COMPOUND; |
| 5788 | if (aShapeArg == "v" |
| 5789 | || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX; |
| 5790 | else if (aShapeArg == "e" |
| 5791 | || aShapeArg == "edge") aShapeType = TopAbs_EDGE; |
| 5792 | else if (aShapeArg == "w" |
| 5793 | || aShapeArg == "wire") aShapeType = TopAbs_WIRE; |
| 5794 | else if (aShapeArg == "f" |
| 5795 | || aShapeArg == "face") aShapeType = TopAbs_FACE; |
| 5796 | else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE; |
| 5797 | else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL; |
| 5798 | else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID; |
| 5799 | else |
| 5800 | { |
| 5801 | std::cout << "Syntax error at '" << argv[1] << "'\n"; |
| 5802 | return 1; |
| 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 5807 | static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"}; |
| 5808 | |
| 5809 | const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1; |
| 5810 | if (aNbToPick == 1) |
| 5811 | { |
| 5812 | TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType); |
| 5813 | if (aPickedShape.IsNull()) |
| 5814 | { |
| 5815 | return 1; |
| 5816 | } |
| 5817 | |
| 5818 | TCollection_AsciiString aName; |
| 5819 | if (argc > 2) |
| 5820 | { |
| 5821 | aName = argv[2]; |
| 5822 | } |
| 5823 | else |
| 5824 | { |
| 5825 | const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)]; |
| 5826 | aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex; |
| 5827 | } |
| 5828 | |
| 5829 | DBRep::Set (aName.ToCString(), aPickedShape); |
| 5830 | Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape); |
| 5831 | ViewerTest::Display (aName, aShapePrs, false, true); |
| 5832 | di << "Name of picked shape: " << aName <<"\n"; |
| 5833 | } |
| 5834 | else |
| 5835 | { |
| 5836 | TCollection_AsciiString aName (argv[2]); |
| 5837 | aName.LowerCase(); |
| 5838 | const Standard_Boolean isAutoNaming = aName == "."; |
| 5839 | Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick); |
| 5840 | if (ViewerTest::PickShapes (aShapeType, aPickedArray)) |
| 5841 | { |
| 5842 | for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter) |
| 5843 | { |
| 5844 | TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter); |
| 5845 | aName.Clear(); |
| 5846 | if (!aPickedShape.IsNull() |
| 5847 | && isAutoNaming) |
| 5848 | { |
| 5849 | const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)]; |
| 5850 | aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex; |
| 5851 | } |
| 5852 | else |
| 5853 | { |
| 5854 | aName = argv[1 + aPickedIter]; |
| 5855 | } |
| 5856 | |
| 5857 | DBRep::Set (aName.ToCString(), aPickedShape); |
| 5858 | Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape); |
| 5859 | di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n"; |
| 5860 | ViewerTest::Display (aName, aShapePrs, false, true); |
| 5861 | } |
| 5862 | } |
| 5863 | } |
| 5864 | TheAISContext()->UpdateCurrentViewer(); |
| 5865 | return 0; |
| 5866 | } |
| 5867 | |
| 5868 | //======================================================================= |
| 5869 | //function : VSelFilter |
| 5870 | //purpose : |
| 5871 | //======================================================================= |
| 5872 | static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc, |
| 5873 | const char** theArgv) |
| 5874 | { |
| 5875 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
| 5876 | if (aContext.IsNull()) |
| 5877 | { |
| 5878 | std::cout << "Error: AIS context is not available.\n"; |
| 5879 | return 1; |
| 5880 | } |
| 5881 | |
| 5882 | for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter) |
| 5883 | { |
| 5884 | TCollection_AsciiString anArg (theArgv[anArgIter]); |
| 5885 | anArg.LowerCase(); |
| 5886 | if (anArg == "-clear") |
| 5887 | { |
| 5888 | aContext->RemoveFilters(); |
| 5889 | } |
| 5890 | else if (anArg == "-type" |
| 5891 | && anArgIter + 1 < theArgc) |
| 5892 | { |
| 5893 | TCollection_AsciiString aVal (theArgv[++anArgIter]); |
| 5894 | TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND; |
| 5895 | if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType)) |
| 5896 | { |
| 5897 | std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n"; |
| 5898 | return 1; |
| 5899 | } |
| 5900 | |
| 5901 | Handle(SelectMgr_Filter) aFilter; |
| 5902 | if (aShapeType == TopAbs_SHAPE) |
| 5903 | { |
| 5904 | aFilter = new AIS_TypeFilter (AIS_KOI_Shape); |
| 5905 | } |
| 5906 | else |
| 5907 | { |
| 5908 | aFilter = new StdSelect_ShapeTypeFilter (aShapeType); |
| 5909 | } |
| 5910 | aContext->AddFilter (aFilter); |
| 5911 | } |
| 5912 | else |
| 5913 | { |
| 5914 | std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n"; |
| 5915 | return 1; |
| 5916 | } |
| 5917 | } |
| 5918 | return 0; |
| 5919 | } |
| 5920 | |
| 5921 | //======================================================================= |
| 5922 | //function : VPickSelected |
| 5923 | //purpose : |
| 5924 | //======================================================================= |
| 5925 | static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs) |
| 5926 | { |
| 5927 | static Standard_Integer aCount = 0; |
| 5928 | TCollection_AsciiString aName = "PickedShape_"; |
| 5929 | |
| 5930 | if (theArgNb > 1) |
| 5931 | { |
| 5932 | aName = theArgs[1]; |
| 5933 | } |
| 5934 | else |
| 5935 | { |
| 5936 | aName = aName + aCount++ + "_"; |
| 5937 | } |
| 5938 | |
| 5939 | Standard_Integer anIdx = 0; |
| 5940 | for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx) |
| 5941 | { |
| 5942 | TopoDS_Shape aShape; |
| 5943 | if (TheAISContext()->HasSelectedShape()) |
| 5944 | { |
| 5945 | aShape = TheAISContext()->SelectedShape(); |
| 5946 | } |
| 5947 | else |
| 5948 | { |
| 5949 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); |
| 5950 | aShape = Handle(AIS_Shape)::DownCast (IO)->Shape(); |
| 5951 | } |
| 5952 | |
| 5953 | TCollection_AsciiString aCurrentName = aName; |
| 5954 | if (anIdx > 0) |
| 5955 | { |
| 5956 | aCurrentName += anIdx; |
| 5957 | } |
| 5958 | |
| 5959 | DBRep::Set ((aCurrentName).ToCString(), aShape); |
| 5960 | |
| 5961 | Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape); |
| 5962 | GetMapOfAIS().Bind (aNewShape, aCurrentName); |
| 5963 | TheAISContext()->Display (aNewShape, Standard_False); |
| 5964 | } |
| 5965 | |
| 5966 | TheAISContext()->UpdateCurrentViewer(); |
| 5967 | |
| 5968 | return 0; |
| 5969 | } |
| 5970 | |
| 5971 | //======================================================================= |
| 5972 | //function : list of known objects |
| 5973 | //purpose : |
| 5974 | //======================================================================= |
| 5975 | static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** ) |
| 5976 | { |
| 5977 | // 1234567890 12345678901234567 123456789 |
| 5978 | TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"}; |
| 5979 | TCollection_AsciiString BlankLine(64,'_'); |
| 5980 | Standard_Integer i ; |
| 5981 | |
| 5982 | di<<"/n"<<BlankLine.ToCString()<<"\n"; |
| 5983 | |
| 5984 | for( i =0;i<=2;i++) |
| 5985 | Colum[i].Center(20,' '); |
| 5986 | for(i=0;i<=2;i++) |
| 5987 | di<<"|"<<Colum[i].ToCString(); |
| 5988 | di<<"|\n"; |
| 5989 | |
| 5990 | di<<BlankLine.ToCString()<<"\n"; |
| 5991 | |
| 5992 | // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"}; |
| 5993 | const char ** names = GetTypeNames(); |
| 5994 | |
| 5995 | TCollection_AsciiString curstring; |
| 5996 | TCollection_AsciiString curcolum[3]; |
| 5997 | |
| 5998 | |
| 5999 | // les objets de type Datum.. |
| 6000 | curcolum[1]+="Datum"; |
| 6001 | for(i =0;i<=6;i++){ |
| 6002 | curcolum[0].Clear(); |
| 6003 | curcolum[0] += names[i]; |
| 6004 | |
| 6005 | curcolum[2].Clear(); |
| 6006 | curcolum[2]+=TCollection_AsciiString(i+1); |
| 6007 | |
| 6008 | for(Standard_Integer j =0;j<=2;j++){ |
| 6009 | curcolum[j].Center(20,' '); |
| 6010 | di<<"|"<<curcolum[j].ToCString(); |
| 6011 | } |
| 6012 | di<<"|\n"; |
| 6013 | } |
| 6014 | di<<BlankLine.ToCString()<<"\n"; |
| 6015 | |
| 6016 | // les objets de type shape |
| 6017 | curcolum[1].Clear(); |
| 6018 | curcolum[1]+="Shape"; |
| 6019 | curcolum[1].Center(20,' '); |
| 6020 | |
| 6021 | for(i=0;i<=2;i++){ |
| 6022 | curcolum[0].Clear(); |
| 6023 | curcolum[0] += names[7+i]; |
| 6024 | curcolum[2].Clear(); |
| 6025 | curcolum[2]+=TCollection_AsciiString(i); |
| 6026 | |
| 6027 | for(Standard_Integer j =0;j<=2;j++){ |
| 6028 | curcolum[j].Center(20,' '); |
| 6029 | di<<"|"<<curcolum[j].ToCString(); |
| 6030 | } |
| 6031 | di<<"|\n"; |
| 6032 | } |
| 6033 | di<<BlankLine.ToCString()<<"\n"; |
| 6034 | // les IO de type objet... |
| 6035 | curcolum[1].Clear(); |
| 6036 | curcolum[1]+="Object"; |
| 6037 | curcolum[1].Center(20,' '); |
| 6038 | for(i=0;i<=1;i++){ |
| 6039 | curcolum[0].Clear(); |
| 6040 | curcolum[0] += names[10+i]; |
| 6041 | curcolum[2].Clear(); |
| 6042 | curcolum[2]+=TCollection_AsciiString(i); |
| 6043 | |
| 6044 | for(Standard_Integer j =0;j<=2;j++){ |
| 6045 | curcolum[j].Center(20,' '); |
| 6046 | di<<"|"<<curcolum[j].ToCString(); |
| 6047 | } |
| 6048 | di<<"|\n"; |
| 6049 | } |
| 6050 | di<<BlankLine.ToCString()<<"\n"; |
| 6051 | // les contraintes et dimensions. |
| 6052 | // pour l'instant on separe juste contraintes et dimensions... |
| 6053 | // plus tard, on detaillera toutes les sortes... |
| 6054 | curcolum[1].Clear(); |
| 6055 | curcolum[1]+="Relation"; |
| 6056 | curcolum[1].Center(20,' '); |
| 6057 | for(i=0;i<=1;i++){ |
| 6058 | curcolum[0].Clear(); |
| 6059 | curcolum[0] += names[12+i]; |
| 6060 | curcolum[2].Clear(); |
| 6061 | curcolum[2]+=TCollection_AsciiString(i); |
| 6062 | |
| 6063 | for(Standard_Integer j =0;j<=2;j++){ |
| 6064 | curcolum[j].Center(20,' '); |
| 6065 | di<<"|"<<curcolum[j].ToCString(); |
| 6066 | } |
| 6067 | di<<"|\n"; |
| 6068 | } |
| 6069 | di<<BlankLine.ToCString()<<"\n"; |
| 6070 | |
| 6071 | |
| 6072 | return 0; |
| 6073 | } |
| 6074 | |
| 6075 | |
| 6076 | static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv) |
| 6077 | { |
| 6078 | if(argc!=2) return 1; |
| 6079 | |
| 6080 | AIS_KindOfInteractive TheType; |
| 6081 | Standard_Integer TheSign(-1); |
| 6082 | GetTypeAndSignfromString(argv[1],TheType,TheSign); |
| 6083 | |
| 6084 | |
| 6085 | AIS_ListOfInteractive LIO; |
| 6086 | |
| 6087 | // en attendant l'amelioration ais pour les dimensions... |
| 6088 | // |
| 6089 | Standard_Integer dimension_status(-1); |
| 6090 | if(TheType==AIS_KOI_Relation){ |
| 6091 | dimension_status = TheSign ==1 ? 1 : 0; |
| 6092 | TheSign=-1; |
| 6093 | } |
| 6094 | |
| 6095 | TheAISContext()->DisplayedObjects(TheType,TheSign,LIO); |
| 6096 | Handle(AIS_InteractiveObject) curio; |
| 6097 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ |
| 6098 | curio = it.Value(); |
| 6099 | |
| 6100 | if(dimension_status == -1) |
| 6101 | TheAISContext()->Erase(curio,Standard_False); |
| 6102 | else { |
| 6103 | AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension(); |
| 6104 | if ((dimension_status==0 && KOD == AIS_KOD_NONE)|| |
| 6105 | (dimension_status==1 && KOD != AIS_KOD_NONE)) |
| 6106 | TheAISContext()->Erase(curio,Standard_False); |
| 6107 | } |
| 6108 | } |
| 6109 | TheAISContext()->UpdateCurrentViewer(); |
| 6110 | return 0; |
| 6111 | } |
| 6112 | static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv) |
| 6113 | { |
| 6114 | if(argc!=2) return 1; |
| 6115 | |
| 6116 | AIS_KindOfInteractive TheType; |
| 6117 | Standard_Integer TheSign(-1); |
| 6118 | GetTypeAndSignfromString(argv[1],TheType,TheSign); |
| 6119 | |
| 6120 | // en attendant l'amelioration ais pour les dimensions... |
| 6121 | // |
| 6122 | Standard_Integer dimension_status(-1); |
| 6123 | if(TheType==AIS_KOI_Relation){ |
| 6124 | dimension_status = TheSign ==1 ? 1 : 0; |
| 6125 | TheSign=-1; |
| 6126 | } |
| 6127 | |
| 6128 | AIS_ListOfInteractive LIO; |
| 6129 | TheAISContext()->ObjectsInside(LIO,TheType,TheSign); |
| 6130 | Handle(AIS_InteractiveObject) curio; |
| 6131 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ |
| 6132 | curio = it.Value(); |
| 6133 | if(dimension_status == -1) |
| 6134 | TheAISContext()->Display(curio,Standard_False); |
| 6135 | else { |
| 6136 | AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension(); |
| 6137 | if ((dimension_status==0 && KOD == AIS_KOD_NONE)|| |
| 6138 | (dimension_status==1 && KOD != AIS_KOD_NONE)) |
| 6139 | TheAISContext()->Display(curio,Standard_False); |
| 6140 | } |
| 6141 | |
| 6142 | } |
| 6143 | |
| 6144 | TheAISContext()->UpdateCurrentViewer(); |
| 6145 | return 0; |
| 6146 | } |
| 6147 | |
| 6148 | static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a) |
| 6149 | { |
| 6150 | std::ifstream s(a[1]); |
| 6151 | BRep_Builder builder; |
| 6152 | TopoDS_Shape shape; |
| 6153 | BRepTools::Read(shape, s, builder); |
| 6154 | DBRep::Set(a[1], shape); |
| 6155 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
| 6156 | Handle(AIS_Shape) ais = new AIS_Shape(shape); |
| 6157 | Ctx->Display (ais, Standard_True); |
| 6158 | return 0; |
| 6159 | } |
| 6160 | |
| 6161 | //=============================================================================================== |
| 6162 | //function : VBsdf |
| 6163 | //purpose : |
| 6164 | //=============================================================================================== |
| 6165 | static int VBsdf (Draw_Interpretor& theDI, |
| 6166 | Standard_Integer theArgsNb, |
| 6167 | const char** theArgVec) |
| 6168 | { |
| 6169 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
| 6170 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
| 6171 | if (aView.IsNull() |
| 6172 | || aViewer.IsNull()) |
| 6173 | { |
| 6174 | std::cerr << "No active viewer!\n"; |
| 6175 | return 1; |
| 6176 | } |
| 6177 | |
| 6178 | ViewerTest_CmdParser aCmd; |
| 6179 | |
| 6180 | aCmd.SetDescription ("Adjusts parameters of material BSDF:"); |
| 6181 | |
| 6182 | aCmd.AddOption ("print|echo|p", "Prints BSDF"); |
| 6183 | |
| 6184 | aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call"); |
| 6185 | |
| 6186 | aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF"); |
| 6187 | aCmd.AddOption ("kd", "Weight of base diffuse BRDF"); |
| 6188 | aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF"); |
| 6189 | aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF"); |
| 6190 | aCmd.AddOption ("le", "Radiance emitted by surface"); |
| 6191 | |
| 6192 | aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K"); |
| 6193 | aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K"); |
| 6194 | |
| 6195 | aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF"); |
| 6196 | aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF"); |
| 6197 | |
| 6198 | aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF"); |
| 6199 | aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF"); |
| 6200 | |
| 6201 | aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation"); |
| 6202 | |
| 6203 | aCmd.Parse (theArgsNb, theArgVec); |
| 6204 | |
| 6205 | if (aCmd.HasOption ("help")) |
| 6206 | { |
| 6207 | theDI.PrintHelp (theArgVec[0]); |
| 6208 | return 0; |
| 6209 | } |
| 6210 | |
| 6211 | // check viewer update mode |
| 6212 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); |
| 6213 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
| 6214 | { |
| 6215 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) |
| 6216 | { |
| 6217 | break; |
| 6218 | } |
| 6219 | } |
| 6220 | |
| 6221 | // find object |
| 6222 | TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str()); |
| 6223 | Handle(AIS_InteractiveObject) anIObj; |
| 6224 | if (!GetMapOfAIS().Find2 (aName, anIObj)) |
| 6225 | { |
| 6226 | std::cerr << "Use 'vdisplay' before\n"; |
| 6227 | return 1; |
| 6228 | } |
| 6229 | |
| 6230 | Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material(); |
| 6231 | Graphic3d_BSDF aBSDF = aMaterial.BSDF(); |
| 6232 | |
| 6233 | if (aCmd.HasOption ("print")) |
| 6234 | { |
| 6235 | theDI << "\n" |
| 6236 | << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n" |
| 6237 | << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n" |
| 6238 | << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n" |
| 6239 | << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n" |
| 6240 | << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"; |
| 6241 | |
| 6242 | for (int aLayerID = 0; aLayerID < 2; ++aLayerID) |
| 6243 | { |
| 6244 | const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize() |
| 6245 | : aBSDF.FresnelBase.Serialize(); |
| 6246 | |
| 6247 | theDI << (aLayerID < 1 ? "Coat Fresnel: " |
| 6248 | : "Base Fresnel: "); |
| 6249 | |
| 6250 | if (aFresnel.x() >= 0.f) |
| 6251 | { |
| 6252 | theDI << "Schlick " << "R = " << aFresnel.r() << ", " |
| 6253 | << "G = " << aFresnel.g() << ", " |
| 6254 | << "B = " << aFresnel.b() << "\n"; |
| 6255 | } |
| 6256 | else if (aFresnel.x() >= -1.5f) |
| 6257 | { |
| 6258 | theDI << "Constant " << aFresnel.z() << "\n"; |
| 6259 | } |
| 6260 | else if (aFresnel.x() >= -2.5f) |
| 6261 | { |
| 6262 | theDI << "Conductor " << "N = " << aFresnel.y() << ", " |
| 6263 | << "K = " << aFresnel.z() << "\n"; |
| 6264 | } |
| 6265 | else |
| 6266 | { |
| 6267 | theDI << "Dielectric " << "N = " << aFresnel.y() << "\n"; |
| 6268 | } |
| 6269 | } |
| 6270 | |
| 6271 | theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n" |
| 6272 | << "Base roughness: " << aBSDF.Ks.w() << "\n" |
| 6273 | << "Absorption coeff: " << aBSDF.Absorption.w() << "\n" |
| 6274 | << "Absorption color: " << aBSDF.Absorption.r() << ", " |
| 6275 | << aBSDF.Absorption.g() << ", " |
| 6276 | << aBSDF.Absorption.b() << "\n"; |
| 6277 | |
| 6278 | return 0; |
| 6279 | } |
| 6280 | |
| 6281 | if (aCmd.HasOption ("coatRoughness", 1, Standard_True)) |
| 6282 | { |
| 6283 | aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness"); |
| 6284 | } |
| 6285 | |
| 6286 | if (aCmd.HasOption ("baseRoughness", 1, Standard_True)) |
| 6287 | { |
| 6288 | aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness"); |
| 6289 | } |
| 6290 | |
| 6291 | if (aCmd.HasOption ("absorpCoeff", 1, Standard_True)) |
| 6292 | { |
| 6293 | aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff"); |
| 6294 | } |
| 6295 | |
| 6296 | if (aCmd.HasOption ("absorpColor", 3, Standard_True)) |
| 6297 | { |
| 6298 | const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor"); |
| 6299 | |
| 6300 | aBSDF.Absorption.r() = aRGB.r(); |
| 6301 | aBSDF.Absorption.g() = aRGB.g(); |
| 6302 | aBSDF.Absorption.b() = aRGB.b(); |
| 6303 | } |
| 6304 | |
| 6305 | if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True)) |
| 6306 | { |
| 6307 | Graphic3d_Vec3 aKc; |
| 6308 | |
| 6309 | if (aCmd.HasOption ("kc", 3)) |
| 6310 | { |
| 6311 | aKc = aCmd.ArgVec3f ("kc"); |
| 6312 | } |
| 6313 | else |
| 6314 | { |
| 6315 | aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc")); |
| 6316 | } |
| 6317 | |
| 6318 | aBSDF.Kc.r() = aKc.r(); |
| 6319 | aBSDF.Kc.g() = aKc.g(); |
| 6320 | aBSDF.Kc.b() = aKc.b(); |
| 6321 | } |
| 6322 | |
| 6323 | if (aCmd.HasOption ("kd", 3)) |
| 6324 | { |
| 6325 | aBSDF.Kd = aCmd.ArgVec3f ("kd"); |
| 6326 | } |
| 6327 | else if (aCmd.HasOption ("kd", 1, Standard_True)) |
| 6328 | { |
| 6329 | aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd")); |
| 6330 | } |
| 6331 | |
| 6332 | if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True)) |
| 6333 | { |
| 6334 | Graphic3d_Vec3 aKs; |
| 6335 | |
| 6336 | if (aCmd.HasOption ("ks", 3)) |
| 6337 | { |
| 6338 | aKs = aCmd.ArgVec3f ("ks"); |
| 6339 | } |
| 6340 | else |
| 6341 | { |
| 6342 | aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks")); |
| 6343 | } |
| 6344 | |
| 6345 | aBSDF.Ks.r() = aKs.r(); |
| 6346 | aBSDF.Ks.g() = aKs.g(); |
| 6347 | aBSDF.Ks.b() = aKs.b(); |
| 6348 | } |
| 6349 | |
| 6350 | if (aCmd.HasOption ("kt", 3)) |
| 6351 | { |
| 6352 | aBSDF.Kt = aCmd.ArgVec3f ("kt"); |
| 6353 | } |
| 6354 | else if (aCmd.HasOption ("kt", 1, Standard_True)) |
| 6355 | { |
| 6356 | aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt")); |
| 6357 | } |
| 6358 | |
| 6359 | if (aCmd.HasOption ("le", 3)) |
| 6360 | { |
| 6361 | aBSDF.Le = aCmd.ArgVec3f ("le"); |
| 6362 | } |
| 6363 | else if (aCmd.HasOption ("le", 1, Standard_True)) |
| 6364 | { |
| 6365 | aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le")); |
| 6366 | } |
| 6367 | |
| 6368 | const std::string aFresnelErrorMessage = |
| 6369 | "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n"; |
| 6370 | |
| 6371 | for (int aLayerID = 0; aLayerID < 2; ++aLayerID) |
| 6372 | { |
| 6373 | const std::string aFresnel = aLayerID < 1 ? "baseFresnel" |
| 6374 | : "coatFresnel"; |
| 6375 | |
| 6376 | if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B |
| 6377 | { |
| 6378 | std::string aFresnelType = aCmd.Arg (aFresnel, 0); |
| 6379 | std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase); |
| 6380 | |
| 6381 | if (aFresnelType == "schlick") |
| 6382 | { |
| 6383 | Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())), |
| 6384 | static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())), |
| 6385 | static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str()))); |
| 6386 | |
| 6387 | aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f); |
| 6388 | aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f); |
| 6389 | aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f); |
| 6390 | |
| 6391 | (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB); |
| 6392 | } |
| 6393 | else |
| 6394 | { |
| 6395 | theDI << aFresnelErrorMessage.c_str() << "\n"; |
| 6396 | } |
| 6397 | } |
| 6398 | else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K |
| 6399 | { |
| 6400 | std::string aFresnelType = aCmd.Arg (aFresnel, 0); |
| 6401 | std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase); |
| 6402 | |
| 6403 | if (aFresnelType == "conductor") |
| 6404 | { |
| 6405 | const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())); |
| 6406 | const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())); |
| 6407 | |
| 6408 | (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK); |
| 6409 | } |
| 6410 | else |
| 6411 | { |
| 6412 | theDI << aFresnelErrorMessage.c_str() << "\n"; |
| 6413 | } |
| 6414 | } |
| 6415 | else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C |
| 6416 | { |
| 6417 | std::string aFresnelType = aCmd.Arg (aFresnel, 0); |
| 6418 | std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase); |
| 6419 | |
| 6420 | if (aFresnelType == "constant") |
| 6421 | { |
| 6422 | const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())); |
| 6423 | |
| 6424 | (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR); |
| 6425 | } |
| 6426 | else if (aFresnelType == "dielectric") |
| 6427 | { |
| 6428 | const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())); |
| 6429 | |
| 6430 | (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN); |
| 6431 | } |
| 6432 | else |
| 6433 | { |
| 6434 | theDI << aFresnelErrorMessage.c_str() << "\n"; |
| 6435 | } |
| 6436 | } |
| 6437 | } |
| 6438 | |
| 6439 | if (aCmd.HasOption ("normalize")) |
| 6440 | { |
| 6441 | aBSDF.Normalize(); |
| 6442 | } |
| 6443 | |
| 6444 | aMaterial.SetBSDF (aBSDF); |
| 6445 | anIObj->SetMaterial (aMaterial); |
| 6446 | |
| 6447 | return 0; |
| 6448 | } |
| 6449 | |
| 6450 | //============================================================================== |
| 6451 | //function : VLoadSelection |
| 6452 | //purpose : Adds given objects to map of AIS and loads selection primitives for them |
| 6453 | //============================================================================== |
| 6454 | static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/, |
| 6455 | Standard_Integer theArgNb, |
| 6456 | const char** theArgVec) |
| 6457 | { |
| 6458 | if (theArgNb < 2) |
| 6459 | { |
| 6460 | std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n"; |
| 6461 | return 1; |
| 6462 | } |
| 6463 | |
| 6464 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
| 6465 | if (aCtx.IsNull()) |
| 6466 | { |
| 6467 | ViewerTest::ViewerInit(); |
| 6468 | aCtx = ViewerTest::GetAISContext(); |
| 6469 | } |
| 6470 | |
| 6471 | // Parse input arguments |
| 6472 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
| 6473 | { |
| 6474 | const TCollection_AsciiString aName = theArgVec[anArgIter]; |
| 6475 | Handle(AIS_InteractiveObject) aShape; |
| 6476 | if (!GetMapOfAIS().Find2 (aName, aShape)) |
| 6477 | { |
| 6478 | TopoDS_Shape aDrawShape = DBRep::GetExisting (aName); |
| 6479 | if (!aDrawShape.IsNull()) |
| 6480 | { |
| 6481 | aShape = new AIS_Shape (aDrawShape); |
| 6482 | GetMapOfAIS().Bind (aShape, aName); |
| 6483 | } |
| 6484 | } |
| 6485 | if (aShape.IsNull()) |
| 6486 | { |
| 6487 | std::cout << "Syntax error: presentation '" << aName << "' not found\n"; |
| 6488 | return 1; |
| 6489 | } |
| 6490 | |
| 6491 | aCtx->Load (aShape, -1); |
| 6492 | aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True); |
| 6493 | } |
| 6494 | return 0; |
| 6495 | } |
| 6496 | |
| 6497 | //============================================================================== |
| 6498 | //function : ViewerTest::Commands |
| 6499 | //purpose : Add all the viewer command in the Draw_Interpretor |
| 6500 | //============================================================================== |
| 6501 | |
| 6502 | void ViewerTest::Commands(Draw_Interpretor& theCommands) |
| 6503 | { |
| 6504 | ViewerTest::ViewerCommands(theCommands); |
| 6505 | ViewerTest::RelationCommands(theCommands); |
| 6506 | ViewerTest::ObjectCommands(theCommands); |
| 6507 | ViewerTest::FilletCommands(theCommands); |
| 6508 | ViewerTest::OpenGlCommands(theCommands); |
| 6509 | |
| 6510 | const char *group = "AIS_Display"; |
| 6511 | |
| 6512 | // display |
| 6513 | theCommands.Add("visos", |
| 6514 | "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n" |
| 6515 | "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n", |
| 6516 | __FILE__, visos, group); |
| 6517 | |
| 6518 | theCommands.Add("vdisplay", |
| 6519 | "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]" |
| 6520 | "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]" |
| 6521 | "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]" |
| 6522 | "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft" |
| 6523 | "\n\t\t: |topRight|bottomLeft|bottomRight}" |
| 6524 | "\n\t\t: [offsetX offsetY]]]" |
| 6525 | "\n\t\t: [-dispMode mode] [-highMode mode]" |
| 6526 | "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]" |
| 6527 | "\n\t\t: [-redisplay] [-erased]" |
| 6528 | "\n\t\t: name1 [name2] ... [name n]" |
| 6529 | "\n\t\t: Displays named objects." |
| 6530 | "\n\t\t: Option -local enables displaying of objects in local" |
| 6531 | "\n\t\t: selection context. Local selection context will be opened" |
| 6532 | "\n\t\t: if there is not any." |
| 6533 | "\n\t\t: -noupdate Suppresses viewer redraw call." |
| 6534 | "\n\t\t: -mutable Enables optimizations for mutable objects." |
| 6535 | "\n\t\t: -neutral Draws objects in main viewer." |
| 6536 | "\n\t\t: -erased Loads the object into context, but does not display it." |
| 6537 | "\n\t\t: -layer Sets z-layer for objects." |
| 6538 | "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost" |
| 6539 | "\n\t\t: options can be used for the default z-layers." |
| 6540 | "\n\t\t: -top Draws object on top of main presentations" |
| 6541 | "\n\t\t: but below topmost." |
| 6542 | "\n\t\t: -topmost Draws in overlay for 3D presentations." |
| 6543 | "\n\t\t: with independent Depth." |
| 6544 | "\n\t\t: -overlay Draws objects in overlay for 2D presentations." |
| 6545 | "\n\t\t: (On-Screen-Display)" |
| 6546 | "\n\t\t: -underlay Draws objects in underlay for 2D presentations." |
| 6547 | "\n\t\t: (On-Screen-Display)" |
| 6548 | "\n\t\t: -selectable|-noselect Controls selection of objects." |
| 6549 | "\n\t\t: -trsfPers Sets a transform persistence flags." |
| 6550 | "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence." |
| 6551 | "\n\t\t: -2d Displays object in screen coordinates." |
| 6552 | "\n\t\t: (DY looks up)" |
| 6553 | "\n\t\t: -dispmode Sets display mode for objects." |
| 6554 | "\n\t\t: -highmode Sets hilight mode for objects." |
| 6555 | "\n\t\t: -redisplay Recomputes presentation of objects.", |
| 6556 | __FILE__, VDisplay2, group); |
| 6557 | |
| 6558 | theCommands.Add ("vnbdisplayed", |
| 6559 | "vnbdisplayed" |
| 6560 | "\n\t\t: Returns number of displayed objects", |
| 6561 | __FILE__, VNbDisplayed, group); |
| 6562 | |
| 6563 | theCommands.Add ("vupdate", |
| 6564 | "vupdate name1 [name2] ... [name n]" |
| 6565 | "\n\t\t: Updates named objects in interactive context", |
| 6566 | __FILE__, VUpdate, group); |
| 6567 | |
| 6568 | theCommands.Add("verase", |
| 6569 | "verase [-noupdate|-update] [-local] [name1] ... [name n] [-noerror]" |
| 6570 | "\n\t\t: Erases selected or named objects." |
| 6571 | "\n\t\t: If there are no selected or named objects the whole viewer is erased." |
| 6572 | "\n\t\t: Option -local enables erasing of selected or named objects without" |
| 6573 | "\n\t\t: closing local selection context." |
| 6574 | "\n\t\t: Option -noerror prevents exception on non-existing objects.", |
| 6575 | __FILE__, VErase, group); |
| 6576 | |
| 6577 | theCommands.Add("vremove", |
| 6578 | "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n] [-noerror]" |
| 6579 | "or vremove [-context] -all to remove all objects" |
| 6580 | "\n\t\t: Removes selected or named objects." |
| 6581 | "\n\t\t If -context is in arguments, the objects are not deleted" |
| 6582 | "\n\t\t from the map of objects and names." |
| 6583 | "\n\t\t: Option -local enables removing of selected or named objects without" |
| 6584 | "\n\t\t: closing local selection context. Empty local selection context will be" |
| 6585 | "\n\t\t: closed." |
| 6586 | "\n\t\t: Option -noupdate suppresses viewer redraw call." |
| 6587 | "\n\t\t: Option -noinfo suppresses displaying the list of removed objects." |
| 6588 | "\n\t\t: Option -noerror prevents exception on non-existing objects.", |
| 6589 | __FILE__, VRemove, group); |
| 6590 | |
| 6591 | theCommands.Add("vdonly", |
| 6592 | "vdonly [-noupdate|-update] [name1] ... [name n]" |
| 6593 | "\n\t\t: Displays only selected or named objects", |
| 6594 | __FILE__,VDonly2,group); |
| 6595 | |
| 6596 | theCommands.Add("vdisplayall", |
| 6597 | "vdisplayall" |
| 6598 | "\n\t\t: Displays all erased interactive objects (see vdir and vstate).", |
| 6599 | __FILE__, VDisplayAll, group); |
| 6600 | |
| 6601 | theCommands.Add("veraseall", |
| 6602 | "veraseall" |
| 6603 | "\n\t\t: Erases all objects displayed in the viewer.", |
| 6604 | __FILE__, VErase, group); |
| 6605 | |
| 6606 | theCommands.Add("verasetype", |
| 6607 | "verasetype <Type>" |
| 6608 | "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)", |
| 6609 | __FILE__, VEraseType, group); |
| 6610 | theCommands.Add("vbounding", |
| 6611 | "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]" |
| 6612 | "\n\t\t: [-print] [-hide]" |
| 6613 | "\n\t\t: Temporarily display bounding box of specified Interactive" |
| 6614 | "\n\t\t: Objects, or print it to console if -print is specified." |
| 6615 | "\n\t\t: Already displayed box might be hidden by -hide option.", |
| 6616 | __FILE__,VBounding,group); |
| 6617 | |
| 6618 | theCommands.Add("vdisplaytype", |
| 6619 | "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ", |
| 6620 | __FILE__,VDisplayType,group); |
| 6621 | |
| 6622 | theCommands.Add("vsetdispmode", |
| 6623 | "vsetdispmode [name] mode(1,2,..)" |
| 6624 | "\n\t\t: Sets display mode for all, selected or named objects.", |
| 6625 | __FILE__,VDispMode,group); |
| 6626 | |
| 6627 | theCommands.Add("vunsetdispmode", |
| 6628 | "vunsetdispmode [name]" |
| 6629 | "\n\t\t: Unsets custom display mode for selected or named objects.", |
| 6630 | __FILE__,VDispMode,group); |
| 6631 | |
| 6632 | theCommands.Add("vdir", |
| 6633 | "vdir [mask] [-list]" |
| 6634 | "\n\t\t: Lists all objects displayed in 3D viewer" |
| 6635 | "\n\t\t: mask - name filter like prefix*" |
| 6636 | "\n\t\t: -list - format list with new-line per name; OFF by default", |
| 6637 | __FILE__,VDir,group); |
| 6638 | |
| 6639 | #ifdef HAVE_FREEIMAGE |
| 6640 | #define DUMP_FORMATS "{png|bmp|jpg|gif}" |
| 6641 | #else |
| 6642 | #define DUMP_FORMATS "{ppm}" |
| 6643 | #endif |
| 6644 | theCommands.Add("vdump", |
| 6645 | "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]" |
| 6646 | "\n\t\t: [-buffer rgb|rgba|depth=rgb]" |
| 6647 | "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]" |
| 6648 | "\n\t\t: [-tileSize Size=0]" |
| 6649 | "\n\t\t: Dumps content of the active view into image file", |
| 6650 | __FILE__,VDump,group); |
| 6651 | |
| 6652 | theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects", |
| 6653 | __FILE__,VSubInt,group); |
| 6654 | |
| 6655 | theCommands.Add("vaspects", |
| 6656 | "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]" |
| 6657 | "\n\t\t: [-setVisibility 0|1]" |
| 6658 | "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]" |
| 6659 | "\n\t\t: [-setBackFaceColor Color]" |
| 6660 | "\n\t\t: [-setMaterial MatName] [-unsetMaterial]" |
| 6661 | "\n\t\t: [-setTransparency Transp] [-unsetTransparency]" |
| 6662 | "\n\t\t: [-setWidth LineWidth] [-unsetWidth]" |
| 6663 | "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]" |
| 6664 | "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]" |
| 6665 | "\n\t\t: [-unsetMarkerType]" |
| 6666 | "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]" |
| 6667 | "\n\t\t: [-freeBoundary {off/on | 0/1}]" |
| 6668 | "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]" |
| 6669 | "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]" |
| 6670 | "\n\t\t: [-subshapes subname1 [subname2 [...]]]" |
| 6671 | "\n\t\t: [-isoontriangulation 0|1]" |
| 6672 | "\n\t\t: [-setMaxParamValue {value}]" |
| 6673 | "\n\t\t: [-setSensitivity {selection_mode} {value}]" |
| 6674 | "\n\t\t: [-setShadingModel {unlit|flat|gouraud|phong}]" |
| 6675 | "\n\t\t: [-unsetShadingModel]" |
| 6676 | "\n\t\t: [-setInterior {solid|hatch|hidenline|point}]" |
| 6677 | "\n\t\t: [-unsetInterior] [-setHatch HatchStyle]" |
| 6678 | "\n\t\t: [-setFaceBoundaryDraw {0|1}] [-setMostContinuity {c0|c1|c2|c3|cn}" |
| 6679 | "\n\t\t: [-setFaceBoundaryWidth LineWidth] [-setFaceBoundaryColor R G B] [-setFaceBoundaryType LineType]" |
| 6680 | "\n\t\t: [-setDrawEdges {0|1}] [-setEdgeType LineType] [-setEdgeColor R G B] [-setQuadEdges {0|1}]" |
| 6681 | "\n\t\t: [-setDrawSilhouette {0|1}]" |
| 6682 | "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]" |
| 6683 | "\n\t\t: [-dumpJson]" |
| 6684 | "\n\t\t: [-dumpCompact {0|1}]" |
| 6685 | "\n\t\t: [-dumpDepth depth]" |
| 6686 | "\n\t\t: [-freeBoundary {off/on | 0/1}]" |
| 6687 | "\n\t\t: Manage presentation properties of all, selected or named objects." |
| 6688 | "\n\t\t: When -subshapes is specified than following properties will be" |
| 6689 | "\n\t\t: assigned to specified sub-shapes." |
| 6690 | "\n\t\t: When -defaults is specified than presentation properties will be" |
| 6691 | "\n\t\t: assigned to all objects that have not their own specified properties" |
| 6692 | "\n\t\t: and to all objects to be displayed in the future." |
| 6693 | "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier." |
| 6694 | "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials" |
| 6695 | "\n\t\t: accepted by arguments -setMaterial and -setColor", |
| 6696 | __FILE__,VAspects,group); |
| 6697 | |
| 6698 | theCommands.Add("vsetcolor", |
| 6699 | "vsetcolor [-noupdate|-update] [name] ColorName" |
| 6700 | "\n\t\t: Sets color for all, selected or named objects." |
| 6701 | "\n\t\t: Alias for vaspects -setcolor [name] ColorName.", |
| 6702 | __FILE__,VAspects,group); |
| 6703 | |
| 6704 | theCommands.Add("vunsetcolor", |
| 6705 | "vunsetcolor [-noupdate|-update] [name]" |
| 6706 | "\n\t\t: Resets color for all, selected or named objects." |
| 6707 | "\n\t\t: Alias for vaspects -unsetcolor [name].", |
| 6708 | __FILE__,VAspects,group); |
| 6709 | |
| 6710 | theCommands.Add("vsettransparency", |
| 6711 | "vsettransparency [-noupdate|-update] [name] Coefficient" |
| 6712 | "\n\t\t: Sets transparency for all, selected or named objects." |
| 6713 | "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)." |
| 6714 | "\n\t\t: Alias for vaspects -settransp [name] Coefficient.", |
| 6715 | __FILE__,VAspects,group); |
| 6716 | |
| 6717 | theCommands.Add("vunsettransparency", |
| 6718 | "vunsettransparency [-noupdate|-update] [name]" |
| 6719 | "\n\t\t: Resets transparency for all, selected or named objects." |
| 6720 | "\n\t\t: Alias for vaspects -unsettransp [name].", |
| 6721 | __FILE__,VAspects,group); |
| 6722 | |
| 6723 | theCommands.Add("vsetmaterial", |
| 6724 | "vsetmaterial [-noupdate|-update] [name] MaterialName" |
| 6725 | "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.", |
| 6726 | __FILE__,VAspects,group); |
| 6727 | |
| 6728 | theCommands.Add("vunsetmaterial", |
| 6729 | "vunsetmaterial [-noupdate|-update] [name]" |
| 6730 | "\n\t\t: Alias for vaspects -unsetmaterial [name].", |
| 6731 | __FILE__,VAspects,group); |
| 6732 | |
| 6733 | theCommands.Add("vsetwidth", |
| 6734 | "vsetwidth [-noupdate|-update] [name] width(0->10)" |
| 6735 | "\n\t\t: Alias for vaspects -setwidth [name] width.", |
| 6736 | __FILE__,VAspects,group); |
| 6737 | |
| 6738 | theCommands.Add("vunsetwidth", |
| 6739 | "vunsetwidth [-noupdate|-update] [name]" |
| 6740 | "\n\t\t: Alias for vaspects -unsetwidth [name].", |
| 6741 | __FILE__,VAspects,group); |
| 6742 | |
| 6743 | theCommands.Add("vsetinteriorstyle", |
| 6744 | "vsetinteriorstyle [-noupdate|-update] [name] Style" |
| 6745 | "\n\t\t: Alias for vaspects -setInterior [name] Style.", |
| 6746 | __FILE__,VAspects,group); |
| 6747 | |
| 6748 | theCommands.Add ("vsetedgetype", |
| 6749 | "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]" |
| 6750 | "\n\t\t: Alias for vaspects [name] -setEdgeType Type.", |
| 6751 | __FILE__, VAspects, group); |
| 6752 | |
| 6753 | theCommands.Add ("vunsetedgetype", |
| 6754 | "vunsetedgetype [name]" |
| 6755 | "\n\t\t: Alias for vaspects [name] -unsetEdgeType.", |
| 6756 | __FILE__, VAspects, group); |
| 6757 | |
| 6758 | theCommands.Add ("vshowfaceboundary", |
| 6759 | "vshowfaceboundary [name]" |
| 6760 | "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on", |
| 6761 | __FILE__, VAspects, group); |
| 6762 | |
| 6763 | theCommands.Add("vsensdis", |
| 6764 | "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)." |
| 6765 | "\n\t\t: Standard entity types are those defined in Select3D package:" |
| 6766 | "\n\t\t: - sensitive box" |
| 6767 | "\n\t\t: - sensitive face" |
| 6768 | "\n\t\t: - sensitive curve" |
| 6769 | "\n\t\t: - sensitive segment" |
| 6770 | "\n\t\t: - sensitive circle" |
| 6771 | "\n\t\t: - sensitive point" |
| 6772 | "\n\t\t: - sensitive triangulation" |
| 6773 | "\n\t\t: - sensitive triangle" |
| 6774 | "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.", |
| 6775 | __FILE__,VDispSensi,group); |
| 6776 | |
| 6777 | theCommands.Add("vsensera", |
| 6778 | "vsensera : erase active entities", |
| 6779 | __FILE__,VClearSensi,group); |
| 6780 | |
| 6781 | theCommands.Add("vsetshading", |
| 6782 | "vsetshading : vsetshading name Quality(default=0.0008) " |
| 6783 | "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.", |
| 6784 | __FILE__,VShading,group); |
| 6785 | |
| 6786 | theCommands.Add("vunsetshading", |
| 6787 | "vunsetshading :vunsetshading name " |
| 6788 | "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.", |
| 6789 | __FILE__,VShading,group); |
| 6790 | |
| 6791 | theCommands.Add ("vtexture", |
| 6792 | "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]" |
| 6793 | "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]" |
| 6794 | "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]" |
| 6795 | "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]" |
| 6796 | "\n\t\t: [-modulate {on|off}]" |
| 6797 | "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]" |
| 6798 | "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]" |
| 6799 | "\n\t\t: [-default]" |
| 6800 | "\n\t\t: The texture can be specified by filepath" |
| 6801 | "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures." |
| 6802 | "\n\t\t: The options are:" |
| 6803 | "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default" |
| 6804 | "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default" |
| 6805 | "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default" |
| 6806 | "\n\t\t: -modulate Enable or disable texture color modulation" |
| 6807 | "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle" |
| 6808 | "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector" |
| 6809 | "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector" |
| 6810 | "\n\t\t: -setFilter Setup texture filter" |
| 6811 | "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels" |
| 6812 | "\n\t\t: -default Sets texture mapping default parameters", |
| 6813 | __FILE__, VTexture, group); |
| 6814 | |
| 6815 | theCommands.Add("vtexscale", |
| 6816 | "vtexscale name ScaleU ScaleV" |
| 6817 | "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.", |
| 6818 | __FILE__,VTexture,group); |
| 6819 | |
| 6820 | theCommands.Add("vtexorigin", |
| 6821 | "vtexorigin name OriginU OriginV" |
| 6822 | "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.", |
| 6823 | __FILE__,VTexture,group); |
| 6824 | |
| 6825 | theCommands.Add("vtexrepeat", |
| 6826 | "vtexrepeat name RepeatU RepeatV" |
| 6827 | "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.", |
| 6828 | VTexture,group); |
| 6829 | |
| 6830 | theCommands.Add("vtexdefault", |
| 6831 | "vtexdefault name" |
| 6832 | "\n\t\t: Alias for vtexture name -default.", |
| 6833 | VTexture,group); |
| 6834 | |
| 6835 | theCommands.Add("vstate", |
| 6836 | "vstate [-entities] [-hasSelected] [name1] ... [nameN]" |
| 6837 | "\n\t\t: Reports show/hidden state for selected or named objects" |
| 6838 | "\n\t\t: -entities - print low-level information about detected entities" |
| 6839 | "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise", |
| 6840 | __FILE__,VState,group); |
| 6841 | |
| 6842 | theCommands.Add("vpickshapes", |
| 6843 | "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]" |
| 6844 | "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button." |
| 6845 | "\n\t\t: Hold also Shift for multiple selection.", |
| 6846 | __FILE__, VPickShape, group); |
| 6847 | |
| 6848 | theCommands.Add("vtypes", |
| 6849 | "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters", |
| 6850 | VIOTypes,group); |
| 6851 | |
| 6852 | theCommands.Add("vr", |
| 6853 | "vr filename" |
| 6854 | "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ", |
| 6855 | __FILE__,vr, group); |
| 6856 | |
| 6857 | theCommands.Add("vselfilter", |
| 6858 | "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]" |
| 6859 | "\nSets selection shape type filter in context or remove all filters." |
| 6860 | "\n : Option -type set type of selection filter. Filters are applyed with Or combination." |
| 6861 | "\n : Option -clear remove all filters in context", |
| 6862 | __FILE__,VSelFilter,group); |
| 6863 | |
| 6864 | theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.", |
| 6865 | __FILE__, VPickSelected, group); |
| 6866 | |
| 6867 | theCommands.Add ("vloadselection", |
| 6868 | "vloadselection [-context] [name1] ... [nameN] : allows to load selection" |
| 6869 | "\n\t\t: primitives for the shapes with names given without displaying them.", |
| 6870 | __FILE__, VLoadSelection, group); |
| 6871 | |
| 6872 | theCommands.Add("vbsdf", "vbsdf [name] [options]" |
| 6873 | "\nAdjusts parameters of material BSDF:" |
| 6874 | "\n -help : Shows this message" |
| 6875 | "\n -print : Print BSDF" |
| 6876 | "\n -kd : Weight of the Lambertian BRDF" |
| 6877 | "\n -kr : Weight of the reflection BRDF" |
| 6878 | "\n -kt : Weight of the transmission BTDF" |
| 6879 | "\n -ks : Weight of the glossy Blinn BRDF" |
| 6880 | "\n -le : Self-emitted radiance" |
| 6881 | "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x," |
| 6882 | "\n Schlick x y z, Dielectric x, Conductor x y" |
| 6883 | "\n -roughness : Roughness of material (Blinn's exponent)" |
| 6884 | "\n -absorpcoeff : Absorption coefficient (only for transparent material)" |
| 6885 | "\n -absorpcolor : Absorption color (only for transparent material)" |
| 6886 | "\n -normalize : Normalize BSDF coefficients", |
| 6887 | __FILE__, VBsdf, group); |
| 6888 | |
| 6889 | } |
| 6890 | |
| 6891 | //===================================================================== |
| 6892 | //========================= for testing Draft and Rib ================= |
| 6893 | //===================================================================== |
| 6894 | #include <BRepOffsetAPI_MakeThickSolid.hxx> |
| 6895 | #include <DBRep.hxx> |
| 6896 | #include <TopoDS_Face.hxx> |
| 6897 | #include <gp_Pln.hxx> |
| 6898 | #include <AIS_KindOfSurface.hxx> |
| 6899 | #include <BRepOffsetAPI_DraftAngle.hxx> |
| 6900 | #include <Precision.hxx> |
| 6901 | #include <BRepAlgo.hxx> |
| 6902 | #include <OSD_Environment.hxx> |
| 6903 | #include <DrawTrSurf.hxx> |
| 6904 | //#include <DbgTools.hxx> |
| 6905 | //#include <FeatAlgo_MakeLinearForm.hxx> |
| 6906 | |
| 6907 | |
| 6908 | |
| 6909 | |
| 6910 | //======================================================================= |
| 6911 | //function : IsValid |
| 6912 | //purpose : |
| 6913 | //======================================================================= |
| 6914 | static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs, |
| 6915 | const TopoDS_Shape& theResult, |
| 6916 | const Standard_Boolean closedSolid, |
| 6917 | const Standard_Boolean GeomCtrl) |
| 6918 | { |
| 6919 | OSD_Environment check ("DONT_SWITCH_IS_VALID") ; |
| 6920 | TCollection_AsciiString checkValid = check.Value(); |
| 6921 | Standard_Boolean ToCheck = Standard_True; |
| 6922 | if (!checkValid.IsEmpty()) { |
| 6923 | #ifdef OCCT_DEBUG |
| 6924 | std::cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n"; |
| 6925 | #endif |
| 6926 | if ( checkValid=="true" || checkValid=="TRUE" ) { |
| 6927 | ToCheck= Standard_False; |
| 6928 | } |
| 6929 | } else { |
| 6930 | #ifdef OCCT_DEBUG |
| 6931 | std::cout <<"DONT_SWITCH_IS_VALID non positionne\n"; |
| 6932 | #endif |
| 6933 | } |
| 6934 | Standard_Boolean IsValid = Standard_True; |
| 6935 | if (ToCheck) |
| 6936 | IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ; |
| 6937 | return IsValid; |
| 6938 | |
| 6939 | } |
| 6940 | |
| 6941 | //=============================================================================== |
| 6942 | // TDraft : test draft, uses AIS Viewer |
| 6943 | // Solid Face Plane Angle Reverse |
| 6944 | //=============================================================================== |
| 6945 | static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 6946 | { |
| 6947 | if (argc < 5) return 1; |
| 6948 | // argv[1] - TopoDS_Shape Solid |
| 6949 | // argv[2] - TopoDS_Shape Face |
| 6950 | // argv[3] - TopoDS_Shape Plane |
| 6951 | // argv[4] - Standard_Real Angle |
| 6952 | // argv[5] - Standard_Integer Reverse |
| 6953 | |
| 6954 | // Sprintf(prefix, argv[1]); |
| 6955 | Standard_Real anAngle = 0; |
| 6956 | Standard_Boolean Rev = Standard_False; |
| 6957 | Standard_Integer rev = 0; |
| 6958 | TopoDS_Shape Solid = DBRep::Get (argv[1]); |
| 6959 | TopoDS_Shape face = DBRep::Get (argv[2]); |
| 6960 | TopoDS_Face Face = TopoDS::Face(face); |
| 6961 | TopoDS_Shape Plane = DBRep::Get (argv[3]); |
| 6962 | if (Plane.IsNull ()) { |
| 6963 | di << "TEST : Plane is NULL\n"; |
| 6964 | return 1; |
| 6965 | } |
| 6966 | anAngle = Draw::Atof(argv[4]); |
| 6967 | anAngle = 2*M_PI * anAngle / 360.0; |
| 6968 | gp_Pln aPln; |
| 6969 | Handle( Geom_Surface )aSurf; |
| 6970 | AIS_KindOfSurface aSurfType; |
| 6971 | Standard_Real Offset; |
| 6972 | gp_Dir aDir; |
| 6973 | if(argc > 4) { // == 5 |
| 6974 | rev = Draw::Atoi(argv[5]); |
| 6975 | Rev = (rev)? Standard_True : Standard_False; |
| 6976 | } |
| 6977 | |
| 6978 | TopoDS_Face face2 = TopoDS::Face(Plane); |
| 6979 | if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset)) |
| 6980 | { |
| 6981 | di << "TEST : Can't find plane\n"; |
| 6982 | return 1; |
| 6983 | } |
| 6984 | |
| 6985 | aDir = aPln.Axis().Direction(); |
| 6986 | if (!aPln.Direct()) |
| 6987 | aDir.Reverse(); |
| 6988 | if (Plane.Orientation() == TopAbs_REVERSED) |
| 6989 | aDir.Reverse(); |
| 6990 | di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n"; |
| 6991 | |
| 6992 | BRepOffsetAPI_DraftAngle Draft (Solid); |
| 6993 | |
| 6994 | if(Abs(anAngle)< Precision::Angular()) { |
| 6995 | di << "TEST : NULL angle\n"; |
| 6996 | return 1;} |
| 6997 | |
| 6998 | if(Rev) anAngle = - anAngle; |
| 6999 | Draft.Add (Face, aDir, anAngle, aPln); |
| 7000 | Draft.Build (); |
| 7001 | if (!Draft.IsDone()) { |
| 7002 | di << "TEST : Draft Not DONE \n"; |
| 7003 | return 1; |
| 7004 | } |
| 7005 | TopTools_ListOfShape Larg; |
| 7006 | Larg.Append(Solid); |
| 7007 | if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) { |
| 7008 | di << "TEST : DesignAlgo returns Not valid\n"; |
| 7009 | return 1; |
| 7010 | } |
| 7011 | |
| 7012 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
| 7013 | Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape()); |
| 7014 | |
| 7015 | if ( !ais.IsNull() ) { |
| 7016 | ais->SetColor(DEFAULT_COLOR); |
| 7017 | ais->SetMaterial(DEFAULT_MATERIAL); |
| 7018 | // Display the AIS_Shape without redraw |
| 7019 | Ctx->Display(ais, Standard_False); |
| 7020 | |
| 7021 | const char *Name = "draft1"; |
| 7022 | Handle(AIS_InteractiveObject) an_object; |
| 7023 | if (GetMapOfAIS().Find2(Name, an_object)) |
| 7024 | { |
| 7025 | if (!an_object.IsNull()) |
| 7026 | { |
| 7027 | Ctx->Remove (an_object, Standard_True); |
| 7028 | } |
| 7029 | GetMapOfAIS().UnBind2 (Name); |
| 7030 | } |
| 7031 | GetMapOfAIS().Bind(ais, Name); |
| 7032 | // DBRep::Set("draft", ais->Shape()); |
| 7033 | } |
| 7034 | Ctx->Display(ais, Standard_True); |
| 7035 | return 0; |
| 7036 | } |
| 7037 | |
| 7038 | //============================================================================== |
| 7039 | //function : splitParameter |
| 7040 | //purpose : Split parameter string to parameter name and parameter value |
| 7041 | //============================================================================== |
| 7042 | Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString, |
| 7043 | TCollection_AsciiString& theName, |
| 7044 | TCollection_AsciiString& theValue) |
| 7045 | { |
| 7046 | Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length()); |
| 7047 | |
| 7048 | if (aParamNameEnd == 0) |
| 7049 | { |
| 7050 | return Standard_False; |
| 7051 | } |
| 7052 | |
| 7053 | TCollection_AsciiString aString (theString); |
| 7054 | if (aParamNameEnd != 0) |
| 7055 | { |
| 7056 | theValue = aString.Split (aParamNameEnd); |
| 7057 | aString.Split (aString.Length() - 1); |
| 7058 | theName = aString; |
| 7059 | } |
| 7060 | |
| 7061 | return Standard_True; |
| 7062 | } |
| 7063 | |
| 7064 | //============================================================================ |
| 7065 | // MyCommands |
| 7066 | //============================================================================ |
| 7067 | void ViewerTest::MyCommands( Draw_Interpretor& theCommands) |
| 7068 | { |
| 7069 | |
| 7070 | DrawTrSurf::BasicCommands(theCommands); |
| 7071 | const char* group = "Check Features Operations commands"; |
| 7072 | |
| 7073 | theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse", |
| 7074 | __FILE__, |
| 7075 | &TDraft,group); //Draft_Modification |
| 7076 | } |
| 7077 | |
| 7078 | //============================================================================== |
| 7079 | // ViewerTest::Factory |
| 7080 | //============================================================================== |
| 7081 | void ViewerTest::Factory(Draw_Interpretor& theDI) |
| 7082 | { |
| 7083 | // definition of Viewer Command |
| 7084 | ViewerTest::Commands(theDI); |
| 7085 | |
| 7086 | #ifdef OCCT_DEBUG |
| 7087 | theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n"; |
| 7088 | #endif |
| 7089 | } |
| 7090 | |
| 7091 | // Declare entry point PLUGINFACTORY |
| 7092 | DPLUGIN(ViewerTest) |