From: nds Date: Tue, 3 Sep 2019 21:49:54 +0000 (+0300) Subject: 0030791: Visualization - possibility to display materials by different hatching style... X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=9ef696f23ed074e6bb62fc3adeec8c104a2ff889;p=occt-copy.git 0030791: Visualization - possibility to display materials by different hatching style for clipping # move capping style from presentation into drawer # crash in capping by setting projection as # several hatch templates (cherry picked from commit 3a8ba84200bb4402ef38e1889ed7072b24dce42f) (cherry picked from commit 280e1f1b27270fe3aeea29c6c858937f0fa371e0) # Conflicts: # src/AIS/AIS_InteractiveObject.cxx # src/ViewerTest/ViewerTest_ViewerCommands.cxx --- diff --git a/data/images/hatch_1_.png b/data/images/hatch_1_.png new file mode 100644 index 0000000000..4f7fc204be Binary files /dev/null and b/data/images/hatch_1_.png differ diff --git a/data/images/hatch_2.png b/data/images/hatch_2.png new file mode 100644 index 0000000000..0bf87b2f73 Binary files /dev/null and b/data/images/hatch_2.png differ diff --git a/data/images/hatch_3.png b/data/images/hatch_3.png new file mode 100644 index 0000000000..c89101b323 Binary files /dev/null and b/data/images/hatch_3.png differ diff --git a/data/images/hatch_4.png b/data/images/hatch_4.png new file mode 100644 index 0000000000..5e5839ac92 Binary files /dev/null and b/data/images/hatch_4.png differ diff --git a/data/images/hatch_5.png b/data/images/hatch_5.png new file mode 100644 index 0000000000..bf468b6ab0 Binary files /dev/null and b/data/images/hatch_5.png differ diff --git a/data/images/hatch_6.png b/data/images/hatch_6.png new file mode 100644 index 0000000000..7624d86e9f Binary files /dev/null and b/data/images/hatch_6.png differ diff --git a/data/images/hatch_7.png b/data/images/hatch_7.png new file mode 100644 index 0000000000..5f395a201b Binary files /dev/null and b/data/images/hatch_7.png differ diff --git a/data/images/hatch_8.png b/data/images/hatch_8.png new file mode 100644 index 0000000000..f580b76a6c Binary files /dev/null and b/data/images/hatch_8.png differ diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx index 7eca254336..6a04383fa8 100644 --- a/src/AIS/AIS_ColoredShape.cxx +++ b/src/AIS/AIS_ColoredShape.cxx @@ -633,9 +633,11 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation { aShadedGroup = thePrs->NewGroup(); aShadedGroup->SetClosed (isClosed); - if (isClosed - && !myCappingStyle.IsNull()) - aShadedGroup->SetGroupPrimitivesAspect (myCappingStyle); + if (isClosed) + { + if (aDrawer->HasOwnFillCappingAspect()) + aShadedGroup->SetGroupPrimitivesAspect (aDrawer->FillCappingAspect()); + } } aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect()); aShadedGroup->AddPrimitiveArray (aTriangles); diff --git a/src/AIS/AIS_InteractiveObject.cxx b/src/AIS/AIS_InteractiveObject.cxx index d307a5b77b..8ec7f1d38c 100644 --- a/src/AIS/AIS_InteractiveObject.cxx +++ b/src/AIS/AIS_InteractiveObject.cxx @@ -84,37 +84,6 @@ void AIS_InteractiveObject::SetContext (const Handle(AIS_InteractiveContext)& th } } -//======================================================================= -//function : SetCappingStyle -//purpose : -//======================================================================= -void AIS_InteractiveObject::SetCappingStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle) -{ - myCappingStyle = theStyle; - - // Modify existing presentations - for (Standard_Integer aPrsIter = 1, n = myPresentations.Length(); aPrsIter <= n; ++aPrsIter) - { - const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter); - if (!aPrs3d.IsNull()) - { - const Handle(Graphic3d_Structure)& aStruct = aPrs3d->Presentation(); - if (!aStruct.IsNull()) - { - const Graphic3d_SequenceOfGroup& aGroups = aStruct->Groups(); - for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next()) - { - Handle(Graphic3d_Group)& aGrp = aGroupIter.ChangeValue(); - if (aGrp.IsNull()) - continue; - - aGrp->SetGroupPrimitivesAspect (theStyle); - } - } - } - } -} - //======================================================================= //function : HasPresentation //purpose : diff --git a/src/AIS/AIS_InteractiveObject.hxx b/src/AIS/AIS_InteractiveObject.hxx index bd6877e196..ec9b48de08 100644 --- a/src/AIS/AIS_InteractiveObject.hxx +++ b/src/AIS/AIS_InteractiveObject.hxx @@ -104,12 +104,6 @@ public: void ClearOwner() { myOwner.Nullify(); } public: - //! Set style of filling capping section created by clipping planes. - Standard_EXPORT virtual void SetCappingStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle); - - //! Returns style for filling capping section created by clipping planes. - const Handle(Graphic3d_AspectFillCapping)& CappingStyle() const { return myCappingStyle; } - //! Returns the context pointer to the interactive context. Standard_EXPORT Handle(AIS_InteractiveContext) GetContext() const; @@ -136,7 +130,6 @@ protected: AIS_InteractiveContext* myCTXPtr; //!< pointer to Interactive Context, where object is currently displayed; @sa SetContext() Handle(Standard_Transient) myOwner; //!< application-specific owner object - Handle(Graphic3d_AspectFillCapping) myCappingStyle; }; diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index 57509b973d..82d8a9907d 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -180,7 +180,7 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat try { OCC_CATCH_SIGNALS - StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer, myCappingStyle); + StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer, myDrawer->FillCappingAspect()); } catch (Standard_Failure const& anException) { diff --git a/src/OpenGl/OpenGl_CappingAlgo.cxx b/src/OpenGl/OpenGl_CappingAlgo.cxx index 3154878cb3..1d77c45ca5 100755 --- a/src/OpenGl/OpenGl_CappingAlgo.cxx +++ b/src/OpenGl/OpenGl_CappingAlgo.cxx @@ -293,8 +293,11 @@ namespace const gp_Dir aPlaneUp (aPlaneMat.GetValue (0, 2), aPlaneMat.GetValue (1, 2), aPlaneMat.GetValue (2, 2)); const gp_Dir& aCameraUp = aCamera->Up(); const gp_Vec aCameraPln = aPlaneSide.Dot (aCameraUp) * aPlaneSide + aPlaneUp.Dot (aCameraUp) * aPlaneUp; - const gp_Dir& aCameraDir = aCamera->Direction(); - aRotateAngle = static_cast (aCameraPln.AngleWithRef (aPlaneUp, aCameraDir) / M_PI * 180.0); + if (aCameraPln.Magnitude() > Precision::Confusion()) + { + const gp_Dir& aCameraDir = aCamera->Direction(); + aRotateAngle = static_cast (aCameraPln.AngleWithRef (aPlaneUp, aCameraDir) / M_PI * 180.0); + } } aHatchAngle = aRotateAngle; diff --git a/src/Prs3d/Prs3d_Drawer.cxx b/src/Prs3d/Prs3d_Drawer.cxx index 92858a2198..a03fa3d36f 100644 --- a/src/Prs3d/Prs3d_Drawer.cxx +++ b/src/Prs3d/Prs3d_Drawer.cxx @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -109,7 +110,9 @@ Prs3d_Drawer::Prs3d_Drawer() myHasOwnDimLengthModelUnits (Standard_False), myHasOwnDimAngleModelUnits (Standard_False), myHasOwnDimLengthDisplayUnits (Standard_False), - myHasOwnDimAngleDisplayUnits (Standard_False) + myHasOwnDimAngleDisplayUnits (Standard_False), + + myHasOwnFillCappingAspect (Standard_False) { myDimensionModelUnits.SetLengthUnits ("m"); myDimensionModelUnits.SetAngleUnits ("rad"); @@ -431,6 +434,27 @@ void Prs3d_Drawer::SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theA myHasOwnDimensionAspect = !myDimensionAspect.IsNull(); } +// ======================================================================= +// function : FillCappingAspect +// purpose : +// ======================================================================= + +const Handle(Graphic3d_AspectFillCapping)& Prs3d_Drawer::FillCappingAspect() +{ + return myFillCappingAspect; +} + +// ======================================================================= +// function : SetFillCappingAspect +// purpose : +// ======================================================================= + +void Prs3d_Drawer::SetFillCappingAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect) +{ + myFillCappingAspect = theAspect; + myHasOwnFillCappingAspect = !myFillCappingAspect.IsNull(); +} + // ======================================================================= // function : SetDimLengthModelUnits // purpose : diff --git a/src/Prs3d/Prs3d_Drawer.hxx b/src/Prs3d/Prs3d_Drawer.hxx index 967b11834b..50a74ffe37 100644 --- a/src/Prs3d/Prs3d_Drawer.hxx +++ b/src/Prs3d/Prs3d_Drawer.hxx @@ -31,6 +31,7 @@ #include #include +class Graphic3d_AspectFillCapping; class Prs3d_IsoAspect; class Prs3d_LineAspect; class Prs3d_TextAspect; @@ -792,6 +793,16 @@ public: //! the appearance of dimensions that overrides the one in the link. Standard_Boolean HasOwnDimensionAspect() const { return myHasOwnDimensionAspect; } + //! Returns style for filling capping section created by clipping planes. + Standard_EXPORT const Handle(Graphic3d_AspectFillCapping)& FillCappingAspect(); + + //! Set style of filling capping section created by clipping planes. + Standard_EXPORT void SetFillCappingAspect (const Handle(Graphic3d_AspectFillCapping)& theStyle); + + //! Returns true if the drawer has its own attribute for + //! the appearance of dimensions that overrides the one in the link. + Standard_Boolean HasOwnFillCappingAspect() const { return myHasOwnFillCappingAspect; } + //! Sets dimension length model units for computing of dimension presentation. //! The method sets value owned by the drawer that will be used during //! visualization instead of the one set in link. @@ -984,6 +995,10 @@ protected: Prs3d_DimensionUnits myDimensionDisplayUnits; Standard_Boolean myHasOwnDimLengthDisplayUnits; Standard_Boolean myHasOwnDimAngleDisplayUnits; + + Handle(Graphic3d_AspectFillCapping) myFillCappingAspect; + Standard_Boolean myHasOwnFillCappingAspect; + }; Standard_DEPRECATED("Class name is deprecated - use Prs3d_Drawer instead") diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index edae95fac9..d2a7b1de5a 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -9224,6 +9224,371 @@ namespace } } +//=============================================================================================== +//function : setCappingParams +//purpose : +//=============================================================================================== +static Standard_Boolean setCappingParams (const TCollection_AsciiString& theChangeArg, + const Handle(Graphic3d_AspectFillCapping)& theCappingStyle, + const char** theChangeArgs, + Standard_Integer aNbChangeArgs, + Standard_Integer& anArgIter) +{ + if (theCappingStyle.IsNull()) + return Standard_False; + + Standard_Boolean toEnable = Standard_True; + if (theChangeArg == "-useobjectmaterial" + || theChangeArg == "-useobjectmat" + || theChangeArg == "-useobjmat" + || theChangeArg == "-useobjmaterial") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + if (ViewerTest::ParseOnOff (theChangeArgs[1], toEnable)) + { + theCappingStyle->SetUseObjectMaterial (toEnable == Standard_True); + anArgIter += 1; + } + } + else if (theChangeArg == "-useobjecttexture" + || theChangeArg == "-useobjecttex" + || theChangeArg == "-useobjtexture" + || theChangeArg == "-useobjtex") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + if (ViewerTest::ParseOnOff (theChangeArgs[1], toEnable)) + { + theCappingStyle->SetUseObjectTexture (toEnable == Standard_True); + anArgIter += 1; + } + } + else if (theChangeArg == "-useobjectshader" + || theChangeArg == "-useobjshader") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + if (ViewerTest::ParseOnOff (theChangeArgs[1], toEnable)) + { + theCappingStyle->SetUseObjectShader (toEnable == Standard_True); + anArgIter += 1; + } + } + else if (theChangeArg == "-color" + || theChangeArg == "color") + { + Quantity_Color aColor; + Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, + theChangeArgs + 1, + aColor); + if (aNbParsed == 0) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + Graphic3d_MaterialAspect aMat = theCappingStyle->Material(); + aMat.SetAmbientColor (aColor); + aMat.SetDiffuseColor (aColor); + theCappingStyle->SetMaterial (aMat); + anArgIter += aNbParsed; + } + else if ((theChangeArg == "-transparency" + || theChangeArg == "-transp") + && aNbChangeArgs >= 2) + { + TCollection_AsciiString aValStr (theChangeArgs[1]); + if (aValStr.IsRealValue()) + { + Graphic3d_MaterialAspect aMat = theCappingStyle->Material(); + aMat.SetTransparency ((float )aValStr.RealValue()); + theCappingStyle->SetMaterial (aMat); + } + else + { + std::cout << "Syntax error at '" << aValStr << "'\n"; + return Standard_False; + } + anArgIter += 1; + } + else if (theChangeArg == "-texname" + || theChangeArg == "texname") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + TCollection_AsciiString aTextureName (theChangeArgs[1]); + Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); + if (!aTexture->IsDone()) + { + theCappingStyle->SetTexture (Handle(Graphic3d_TextureMap)()); + } + else + { + aTexture->EnableModulate(); + aTexture->EnableRepeat(); + theCappingStyle->SetTexture (aTexture.get()); + } + anArgIter += 1; + } + else if (theChangeArg == "-texscale" + || theChangeArg == "texscale") + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = theCappingStyle->Texture(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return Standard_False; + } + + if (aNbChangeArgs < 3) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (theChangeArgs[1]); + Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (theChangeArgs[2]); + aHatchTexture->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); + anArgIter += 2; + } + else if (theChangeArg == "-texorigin" + || theChangeArg == "texorigin") // texture origin + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = theCappingStyle->Texture(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return Standard_False; + } + + if (aNbChangeArgs < 3) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (theChangeArgs[1]); + Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (theChangeArgs[2]); + + aHatchTexture->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); + anArgIter += 2; + } + else if (theChangeArg == "-texrotate" + || theChangeArg == "texrotate") // texture rotation + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = theCappingStyle->Texture(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return Standard_False; + } + + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (theChangeArgs[1]); + aHatchTexture->GetParams()->SetRotation (aRot); + anArgIter += 1; + } + else if (theChangeArg == "-hatch" + || theChangeArg == "hatch") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + if (ViewerTest::ParseOnOff (theChangeArgs[1], toEnable)) + { + theCappingStyle->SetToDrawHatch (toEnable == Standard_True); + anArgIter += 1; + } + } + else if (theChangeArg == "-hatchtexture" + || theChangeArg == "hatchtexture") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + TCollection_AsciiString aTextureName (theChangeArgs[1]); + Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); + if (!aTexture->IsDone()) + { + theCappingStyle->SetHatchStyle (Handle(Graphic3d_TextureMap)()); + } + else + { + aTexture->EnableModulate(); + aTexture->EnableRepeat(); + theCappingStyle->SetHatchStyle (aTexture.get()); + theCappingStyle->SetToDrawHatch (true); + } + anArgIter += 1; + } + else if (theChangeArg == "-hatchstipple" + || theChangeArg == "hatchstipple") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + theCappingStyle->SetHatchStyle ((Aspect_HatchStyle)Draw::Atoi (theChangeArgs[1])); + theCappingStyle->SetToDrawHatch (true); + anArgIter += 1; + } + else if (theChangeArg == "-hatchcolor" + || theChangeArg == "hatchcolor") + { + Quantity_Color aColor; + Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, + theChangeArgs + 1, + aColor); + if (aNbParsed == 0) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + Graphic3d_MaterialAspect aMat = theCappingStyle->HatchMaterial(); + aMat.SetAmbientColor (aColor); + aMat.SetDiffuseColor (aColor); + theCappingStyle->SetHatchMaterial (aMat); + anArgIter += aNbParsed; + } + + else if (theChangeArg == "-hatchscale" + || theChangeArg == "hatchscale") + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = theCappingStyle->TextureHatch(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return Standard_False; + } + + if (aNbChangeArgs < 3) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (theChangeArgs[1]); + Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (theChangeArgs[2]); + aHatchTexture->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); + anArgIter += 2; + } + else if (theChangeArg == "-hatchorigin" + || theChangeArg == "hatchorigin") // texture origin + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = theCappingStyle->TextureHatch(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return Standard_False; + } + + if (aNbChangeArgs < 3) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (theChangeArgs[1]); + Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (theChangeArgs[2]); + + aHatchTexture->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); + anArgIter += 2; + } + else if (theChangeArg == "-hatchrotate" + || theChangeArg == "hatchrotate") // texture rotation + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = theCappingStyle->TextureHatch(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return Standard_False; + } + + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (theChangeArgs[1]); + aHatchTexture->GetParams()->SetRotation (aRot); + anArgIter += 1; + } + else if (theChangeArg == "-hatchzoompers" + || theChangeArg == "hatchzoompers") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + if (ViewerTest::ParseOnOff (theChangeArgs[1], toEnable)) + { + theCappingStyle->SetHatchZoomPeristent (toEnable == Standard_True); + anArgIter += 1; + } + } + else if (theChangeArg == "-hatchrotatepers" + || theChangeArg == "hatchrotatepers") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return Standard_False; + } + + if (ViewerTest::ParseOnOff (theChangeArgs[1], toEnable)) + { + theCappingStyle->SetHatchRotationPeristent (toEnable == Standard_True); + anArgIter += 1; + } + } + else + { + return Standard_False; + } + + return Standard_True; +} + //=============================================================================================== //function : VClipPlane //purpose : @@ -9520,72 +9885,6 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons // just skip otherwise (old syntax) } } - else if (aChangeArg == "-useobjectmaterial" - || aChangeArg == "-useobjectmat" - || aChangeArg == "-useobjmat" - || aChangeArg == "-useobjmaterial") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) - { - aClipPlane->CappingSectionStyle()->SetUseObjectMaterial (toEnable == Standard_True); - anArgIter += 1; - } - } - else if (aChangeArg == "-useobjecttexture" - || aChangeArg == "-useobjecttex" - || aChangeArg == "-useobjtexture" - || aChangeArg == "-useobjtex") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) - { - aClipPlane->CappingSectionStyle()->SetUseObjectTexture (toEnable == Standard_True); - anArgIter += 1; - } - } - else if (aChangeArg == "-useobjectshader" - || aChangeArg == "-useobjshader") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) - { - aClipPlane->CappingSectionStyle()->SetUseObjectShader (toEnable == Standard_True); - anArgIter += 1; - } - } - else if (aChangeArg == "-color" - || aChangeArg == "color") - { - Quantity_Color aColor; - Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, - aChangeArgs + 1, - aColor); - if (aNbParsed == 0) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - aClipPlane->SetCappingColor (aColor); - Graphic3d_MaterialAspect aMat = aClipPlane->CappingSectionStyle()->Material(); - aClipPlane->CappingSectionStyle()->SetMaterial (aMat); - anArgIter += aNbParsed; - } else if (aNbChangeArgs >= 1 && (aChangeArg == "-material" || aChangeArg == "material")) @@ -9599,24 +9898,6 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons } aClipPlane->SetCappingMaterial (aMatName); } - else if ((aChangeArg == "-transparency" - || aChangeArg == "-transp") - && aNbChangeArgs >= 2) - { - TCollection_AsciiString aValStr (aChangeArgs[1]); - if (aValStr.IsRealValue()) - { - Graphic3d_MaterialAspect aMat = aClipPlane->CappingSectionStyle()->Material(); - aMat.SetTransparency ((float )aValStr.RealValue()); - aClipPlane->CappingSectionStyle()->SetMaterial (aMat); - } - else - { - std::cout << "Syntax error at '" << aValStr << "'\n"; - return 1; - } - anArgIter += 1; - } else if (aChangeArg == "-overrideaspect" || aChangeArg == "overrideaspect") { @@ -9632,263 +9913,6 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons anArgIter += 1; } } - else if (aChangeArg == "-texname" - || aChangeArg == "texname") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - TCollection_AsciiString aTextureName (aChangeArgs[1]); - Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); - if (!aTexture->IsDone()) - { - aClipPlane->CappingSectionStyle()->SetTexture (Handle(Graphic3d_TextureMap)()); - } - else - { - aTexture->EnableModulate(); - aTexture->EnableRepeat(); - aClipPlane->CappingSectionStyle()->SetTexture (aTexture.get()); - } - anArgIter += 1; - } - else if (aChangeArg == "-texscale" - || aChangeArg == "texscale") - { - const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture(); - - if (aHatchTexture.IsNull()) - { - std::cout << "Error: no texture is set.\n"; - return 1; - } - - if (aNbChangeArgs < 3) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); - Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); - aHatchTexture->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); - anArgIter += 2; - } - else if (aChangeArg == "-texorigin" - || aChangeArg == "texorigin") // texture origin - { - const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture(); - - if (aHatchTexture.IsNull()) - { - std::cout << "Error: no texture is set.\n"; - return 1; - } - - if (aNbChangeArgs < 3) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); - Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); - - aHatchTexture->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); - anArgIter += 2; - } - else if (aChangeArg == "-texrotate" - || aChangeArg == "texrotate") // texture rotation - { - const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture(); - - if (aHatchTexture.IsNull()) - { - std::cout << "Error: no texture is set.\n"; - return 1; - } - - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); - aHatchTexture->GetParams()->SetRotation (aRot); - anArgIter += 1; - } - else if (aChangeArg == "-hatch" - || aChangeArg == "hatch") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) - { - aClipPlane->CappingSectionStyle()->SetToDrawHatch (toEnable == Standard_True); - anArgIter += 1; - } - } - else if (aChangeArg == "-hatchtexture" - || aChangeArg == "hatchtexture") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - TCollection_AsciiString aTextureName (aChangeArgs[1]); - Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); - if (!aTexture->IsDone()) - { - aClipPlane->CappingSectionStyle()->SetHatchStyle (Handle(Graphic3d_TextureMap)()); - } - else - { - aTexture->EnableModulate(); - aTexture->EnableRepeat(); - aClipPlane->CappingSectionStyle()->SetHatchStyle (aTexture.get()); - aClipPlane->CappingSectionStyle()->SetToDrawHatch (true); - } - anArgIter += 1; - } - else if (aChangeArg == "-hatchstipple" - || aChangeArg == "hatchstipple") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - aClipPlane->CappingSectionStyle()->SetHatchStyle ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1])); - aClipPlane->CappingSectionStyle()->SetToDrawHatch (true); - anArgIter += 1; - } - else if (aChangeArg == "-hatchcolor" - || aChangeArg == "hatchcolor") - { - Quantity_Color aColor; - Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, - aChangeArgs + 1, - aColor); - if (aNbParsed == 0) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - Graphic3d_MaterialAspect aMat = aClipPlane->CappingSectionStyle()->HatchMaterial(); - aMat.SetAmbientColor (aColor); - aMat.SetDiffuseColor (aColor); - aClipPlane->CappingSectionStyle()->SetHatchMaterial (aMat); - anArgIter += aNbParsed; - } - - else if (aChangeArg == "-hatchscale" - || aChangeArg == "hatchscale") - { - const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch(); - - if (aHatchTexture.IsNull()) - { - std::cout << "Error: no texture is set.\n"; - return 1; - } - - if (aNbChangeArgs < 3) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); - Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); - aHatchTexture->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); - anArgIter += 2; - } - else if (aChangeArg == "-hatchorigin" - || aChangeArg == "hatchorigin") // texture origin - { - const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch(); - - if (aHatchTexture.IsNull()) - { - std::cout << "Error: no texture is set.\n"; - return 1; - } - - if (aNbChangeArgs < 3) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); - Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); - - aHatchTexture->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); - anArgIter += 2; - } - else if (aChangeArg == "-hatchrotate" - || aChangeArg == "hatchrotate") // texture rotation - { - const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch(); - - if (aHatchTexture.IsNull()) - { - std::cout << "Error: no texture is set.\n"; - return 1; - } - - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); - aHatchTexture->GetParams()->SetRotation (aRot); - anArgIter += 1; - } - else if (aChangeArg == "-hatchzoompers" - || aChangeArg == "hatchzoompers") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) - { - aClipPlane->CappingSectionStyle()->SetHatchZoomPeristent (toEnable == Standard_True); - anArgIter += 1; - } - } - else if (aChangeArg == "-hatchrotatepers" - || aChangeArg == "hatchrotatepers") - { - if (aNbChangeArgs < 2) - { - std::cout << "Syntax error: need more arguments.\n"; - return 1; - } - - if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) - { - aClipPlane->CappingSectionStyle()->SetHatchRotationPeristent (toEnable == Standard_True); - anArgIter += 1; - } - } else if (aChangeArg == "-delete" || aChangeArg == "delete") { @@ -9965,7 +9989,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons anArgIter = anArgIter + anIt - 1; } } - else + else if (!setCappingParams (aChangeArg, aClipPlane->CappingSectionStyle(), aChangeArgs, aNbChangeArgs, anArgIter)) { std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n"; return 1; @@ -9976,6 +10000,69 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons return 0; } +//=============================================================================================== +//function : VSetCapping +//purpose : +//=============================================================================================== +static int VSetCapping (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) +{ + if (theArgsNb < 2) + { + std::cout << "Syntax error: the wrong number of input parameters.\n"; + return 1; + } + + TCollection_AsciiString aName (theArgVec[1]); + gp_Pln aWorkingPlane; + Standard_Boolean toUpdate = Standard_True; + + NCollection_DataMap aRealParams; + NCollection_DataMap aStringParams; + + Handle(AIS_InteractiveObject) anObject; + if (GetMapOfAIS().Find2 (aName, anObject)) + { + if (anObject.IsNull()) + { + std::cout << "Syntax error: no presentation with this name.\n"; + return 1; + } + } + + Handle(Graphic3d_AspectFillCapping) aFillCapping = anObject->Attributes()->FillCappingAspect(); + for (Standard_Integer anArgIter = 2; anArgIter < theArgsNb; ++anArgIter) + { + const char** aChangeArgs = theArgVec + anArgIter; + Standard_Integer aNbChangeArgs = theArgsNb - anArgIter; + TCollection_AsciiString aChangeArg (aChangeArgs[0]); + aChangeArg.LowerCase(); + + Standard_Boolean toEnable = Standard_True; + if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable)) + { + if (!toEnable) + anObject->Attributes()->SetFillCappingAspect (NULL); + else + { + if (aFillCapping.IsNull()) + { + aFillCapping = new Graphic3d_AspectFillCapping(); + anObject->Attributes()->SetFillCappingAspect (aFillCapping); + } + } + } + else if (!setCappingParams (aChangeArg, aFillCapping, aChangeArgs, aNbChangeArgs, anArgIter)) + { + std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n"; + return 1; + } + } + ViewerTest::GetAISContext()->Redisplay (anObject, Standard_False); + + return 0; +} + + //=============================================================================================== //function : VZRange //purpose : @@ -14311,6 +14398,33 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object" "\n\t\t: -useObjShader {off|on|0|1} use shader program of object", __FILE__, VClipPlane, group); + + theCommands.Add("vsetcapping", + "vsetcapping name [{0|1}]" + "\n\t\t: Sets capping parameters for all, selected or named objects." + "\n\t\t: Capping options:" + "\n\t\t: -capping {off|on|0|1} turn capping on/off" + "\n\t\t: -overrideAspect override presentation aspect (if defined)" + "\n\t\t: -color R G B set capping color" + "\n\t\t: -transparency Value set capping transparency 0..1" + "\n\t\t: -texName Texture set capping texture" + "\n\t\t: -texScale SX SY set capping tex scale" + "\n\t\t: -texOrigin TX TY set capping tex origin" + "\n\t\t: -texRotate Angle set capping tex rotation" + "\n\t\t: -hatch {on|off} turn on/off hatch style on capping" + "\n\t\t: -hatchStipple ID set stipple mask for drawing hatch" + "\n\t\t: -hatchColor R G B set color for hatch material" + "\n\t\t: -hatchTexture Texture set texture (semi-opaque) for drawing hatch" + "\n\t\t: -hatchScale SX SY set hatch texture scale" + "\n\t\t: -hatchOrigin TX TY set hatch texture origin" + "\n\t\t: -hatchRotate Angle set hatch texture rotation" + "\n\t\t: -hatchZoomPers allow hatch tetxure mapping to be constant when zooming" + "\n\t\t: -hatchRotatePers allow hatch tetxure mapping to be constant when rotating" + "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object" + "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object" + "\n\t\t: -useObjShader {off|on|0|1} use shader program of object", + __FILE__, VSetCapping, group); + theCommands.Add("vdefaults", "vdefaults [-absDefl value]" "\n\t\t: [-devCoeff value]"