From ad3217cd8d15085afdbcd437280b07c3a4f66475 Mon Sep 17 00:00:00 2001 From: kgv Date: Thu, 3 Apr 2014 16:29:23 +0400 Subject: [PATCH] 0024762: Visualization - new interactive object AIS_ColoredShape with customized subshapes presentations AIS_Shape, ::SetColor(), ::SetMaterial(), ::SetTransparency(), ::SetWidth() - improve consistency. Setup color for marker aspect as well. vaspects - new command superseeds vsetcolor, vsetmaterial, vsettransparancy, vsetwidth and their unset analogs. Improve syntax and arguments validation. OpenGl_AspectMarker::SetAspect() - do not reset myMarkerSize when sprite is unchanged. Extend NCollection_IndexedDataMap - Iterator::Key() and FindFromKey() with value copying. Add test case bugs vis bug24762_coloredshape. --- src/AIS/AIS.cdl | 1 + src/AIS/AIS_ColoredShape.cxx | 460 +++++++ src/AIS/AIS_ColoredShape.hxx | 145 ++ src/AIS/AIS_Drawer.lxx | 150 +- src/AIS/AIS_Shape.cdl | 17 +- src/AIS/AIS_Shape.cxx | 516 ++++--- src/AIS/FILES | 2 + src/Graphic3d/Graphic3d_MaterialAspect.cdl | 6 + src/Graphic3d/Graphic3d_MaterialAspect.cxx | 42 + .../NCollection_IndexedDataMap.hxx | 106 +- src/OpenGl/OpenGl_AspectMarker.cxx | 22 +- src/StdPrs/StdPrs_ShadedShape.cdl | 5 + src/StdPrs/StdPrs_ShadedShape.cxx | 42 +- src/ViewerTest/ViewerTest.cxx | 1201 ++++++++++------- tests/bugs/vis/bug24762_coloredshape | 48 + 15 files changed, 1975 insertions(+), 788 deletions(-) create mode 100644 src/AIS/AIS_ColoredShape.cxx create mode 100644 src/AIS/AIS_ColoredShape.hxx create mode 100644 tests/bugs/vis/bug24762_coloredshape diff --git a/src/AIS/AIS.cdl b/src/AIS/AIS.cdl index f772d4e8ab..75098fd7d4 100644 --- a/src/AIS/AIS.cdl +++ b/src/AIS/AIS.cdl @@ -325,6 +325,7 @@ is class Triangulation; + imported ColoredShape; imported TexturedShape; class Drawer; diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx new file mode 100644 index 0000000000..d6784a74b6 --- /dev/null +++ b/src/AIS/AIS_ColoredShape.cxx @@ -0,0 +1,460 @@ +// Created on: 2014-04-24 +// Created by: Kirill Gavrilov +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE (AIS_ColoredDrawer, AIS_Drawer) +IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredDrawer, AIS_Drawer) + +IMPLEMENT_STANDARD_HANDLE (AIS_ColoredShape, AIS_Shape) +IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredShape, AIS_Shape) + +//======================================================================= +//function : AIS_ColoredShape +//purpose : +//======================================================================= +AIS_ColoredShape::AIS_ColoredShape (const TopoDS_Shape& theShape) +: AIS_Shape (theShape) +{ + // disable dedicated line aspects + myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect()); + myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect()); + myDrawer->SetSeenLineAspect (myDrawer->LineAspect()); +} + +//======================================================================= +//function : AIS_ColoredShape +//purpose : +//======================================================================= +AIS_ColoredShape::AIS_ColoredShape (const Handle(AIS_Shape)& theShape) +: AIS_Shape (theShape->Shape()) +{ + // disable dedicated line aspects + myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect()); + myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect()); + myDrawer->SetSeenLineAspect (myDrawer->LineAspect()); + if (theShape->HasMaterial()) + { + SetMaterial (theShape->Material()); + } + if (theShape->HasColor()) + { + SetColor (theShape->Color()); + } + if (theShape->HasWidth()) + { + SetWidth (theShape->Width()); + } + if (theShape->IsTransparent()) + { + SetTransparency (theShape->Transparency()); + } +} + +//======================================================================= +//function : CustomAspects +//purpose : +//======================================================================= +Handle(AIS_ColoredDrawer) AIS_ColoredShape::CustomAspects (const TopoDS_Shape& theShape) +{ + Handle(AIS_ColoredDrawer) aDrawer; + myShapeColors.Find (theShape, aDrawer); + if (aDrawer.IsNull()) + { + aDrawer = new AIS_ColoredDrawer (myDrawer); + myShapeColors.Bind (theShape, aDrawer); + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); + } + return aDrawer; +} + +//======================================================================= +//function : ClearCustomAspects +//purpose : +//======================================================================= +void AIS_ColoredShape::ClearCustomAspects() +{ + if (myShapeColors.IsEmpty()) + { + return; + } + myShapeColors.Clear(); + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); +} + +//======================================================================= +//function : UnsetCustomAspects +//purpose : +//======================================================================= +void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape& theShape, + const Standard_Boolean theToUnregister) +{ + if (!myShapeColors.IsBound (theShape)) + { + return; + } + + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); + if (theToUnregister) + { + myShapeColors.UnBind (theShape); + return; + } + + myShapeColors.ChangeFind (theShape) = new AIS_ColoredDrawer (myDrawer); +} + +//======================================================================= +//function : SetCustomColor +//purpose : +//======================================================================= +void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape, + const Quantity_Color& theColor) +{ + if (theShape.IsNull()) + { + return; + } + + const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape); + setColor (aDrawer, theColor); + aDrawer->SetOwnColor (theColor); + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); +} + +//======================================================================= +//function : SetCustomWidth +//purpose : +//======================================================================= +void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape, + const Standard_Real theLineWidth) +{ + if (theShape.IsNull()) + { + return; + } + + const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape); + setWidth (CustomAspects (theShape), theLineWidth); + aDrawer->SetOwnWidth (theLineWidth); + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); +} + +//======================================================================= +//function : SetColor +//purpose : +//======================================================================= + +void AIS_ColoredShape::SetColor (const Quantity_Color& theColor) +{ + setColor (myDrawer, theColor); + myOwnColor = theColor; + hasOwnColor = Standard_True; + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); + for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) + { + const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value(); + if (aDrawer->HasOwnColor()) + { + continue; + } + + if (aDrawer->HasShadingAspect()) + { + aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel); + } + if (aDrawer->HasLineAspect()) + { + aDrawer->LineAspect()->SetColor (theColor); + } + if (aDrawer->HasWireAspect()) + { + aDrawer->WireAspect()->SetColor (theColor); + } + } +} + +//======================================================================= +//function : SetWidth +//purpose : +//======================================================================= + +void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth) +{ + setWidth (myDrawer, theLineWidth); + myOwnWidth = theLineWidth; + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); + for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) + { + const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value(); + if (aDrawer->HasOwnWidth()) + { + continue; + } + + if (aDrawer->HasLineAspect()) + { + aDrawer->LineAspect()->SetWidth (theLineWidth); + } + if (aDrawer->HasWireAspect()) + { + aDrawer->WireAspect()->SetWidth (theLineWidth); + } + } +} + +//======================================================================= +//function : SetTransparency +//purpose : +//======================================================================= + +void AIS_ColoredShape::SetTransparency (const Standard_Real theValue) +{ + setTransparency (myDrawer, theValue); + myTransparency = theValue; + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (AIS_Shaded); + for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) + { + const Handle(AIS_Drawer)& aDrawer = anIter.Value(); + if (aDrawer->HasShadingAspect()) + { + aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel); + } + } +} + +//======================================================================= +//function : Compute +//purpose : +//======================================================================= +void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& , + const Handle(Prs3d_Presentation)& thePrs, + const Standard_Integer theMode) +{ + thePrs->Clear(); + if (IsInfinite()) + { + thePrs->SetInfiniteState (Standard_True); + } + + const Standard_Boolean isClosed = StdPrs_ToolShadedShape::IsClosed (myshape); + if (theMode == AIS_Shaded) + { + // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization) + Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew; + Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev); + Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev); + if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular()) + || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion())) + { + BRepTools::Clean (myshape); + } + StdPrs_ShadedShape::Tessellate (myshape, myDrawer); + } + + // 1) myShapeColors + myshape --> array[TopAbs_ShapeEnum] of map of color-to-compound + DataMapOfShapeCompd aTypeKeyshapeDrawshapeArray[(size_t )TopAbs_SHAPE]; + dispatchColors (myshape, myShapeColors, aTypeKeyshapeDrawshapeArray); + + // 2) finally add appropriate presentations (1 color -- 1 compound) according to theMode + Handle(AIS_ColoredDrawer) aCustomDrawer; + for (size_t aShType = 0; aShType < (size_t )TopAbs_SHAPE; ++aShType) + { + DataMapOfShapeCompd& aKeyshapeDrawshapeMap = aTypeKeyshapeDrawshapeArray[aShType]; + for (DataMapOfShapeCompd::Iterator aMapIter (aKeyshapeDrawshapeMap); + aMapIter.More(); aMapIter.Next()) + { + const TopoDS_Shape& aShapeKey = aMapIter.Key(); // key shape with detailed color or a base shape + const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with type + Handle(AIS_Drawer) aDrawer = !myShapeColors.Find (aShapeKey, aCustomDrawer) ? myDrawer : aCustomDrawer; + + // Draw each kind of subshapes and personal-colored shapes in a separate group + // since it's necessary to set transparency/material for all subshapes + // without affecting their unique colors + Handle(Graphic3d_Group) aCurrGroup = Prs3d_Root::NewGroup (thePrs); + switch (theMode) + { + default: + case AIS_Shaded: + { + if ((Standard_Integer )aShapeDraw.ShapeType() <= TopAbs_FACE + && !IsInfinite()) + { + StdPrs_ShadedShape::Add (thePrs, aShapeDraw, aDrawer); + + aDrawer->SetShadingAspectGlobal (Standard_False); + Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect(); + isClosed ? anAsp->SuppressBackFace() : anAsp->AllowBackFace(); + aCurrGroup->SetGroupPrimitivesAspect (anAsp); + break; + } + // compute wire-frame otherwise + } + case AIS_WireFrame: + { + StdPrs_WFDeflectionShape::Add (thePrs, aShapeDraw, aDrawer); + break; + } + } + } + } +} + +//======================================================================= +//function : dispatchColors +//purpose : +//======================================================================= +Standard_Boolean AIS_ColoredShape::dispatchColors (const TopoDS_Shape& theBaseKey, + const TopoDS_Shape& theSubshapeToParse, + const DataMapOfShapeShape& theSubshapeKeyshapeMap, + const TopAbs_ShapeEnum theParentType, + DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray) +{ + TopAbs_ShapeEnum aShType = theSubshapeToParse.ShapeType(); + if (aShType == TopAbs_SHAPE) + { + return Standard_False; + } + + // check own setting of current shape + TopoDS_Shape aKeyShape = theBaseKey; + Standard_Boolean isOverriden = theSubshapeKeyshapeMap.Find (theSubshapeToParse, aKeyShape); + + // iterate on sub-shapes + BRep_Builder aBBuilder; + TopoDS_Shape aShapeCopy = theSubshapeToParse.EmptyCopied(); + Standard_Boolean isSubOverride = Standard_False; + Standard_Integer nbDef = 0; + for (TopoDS_Iterator it (theSubshapeToParse); it.More(); it.Next()) + { + if (dispatchColors (theBaseKey, it.Value(), + theSubshapeKeyshapeMap, aShType, + theTypeKeyshapeDrawshapeArray)) + { + isSubOverride = Standard_True; + } + else + { + aBBuilder.Add (aShapeCopy, it.Value()); + ++nbDef; + } + } + if (aShType == TopAbs_FACE || !isSubOverride) + { + aShapeCopy = theSubshapeToParse; + } + else if (nbDef == 0) + { + return isOverriden || isSubOverride; // empty compound + } + + // if any of styles is overridden regarding to default one, add rest to map + if (isOverriden + || (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden + && theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face + || (theParentType == TopAbs_SHAPE && !(isOverriden || isSubOverride))) // bind original shape to default color + { + TopoDS_Compound aCompound; + DataMapOfShapeCompd& aKeyshapeDrawshapeMap = theTypeKeyshapeDrawshapeArray[(size_t )aShType]; + if (!aKeyshapeDrawshapeMap.FindFromKey (aKeyShape, aCompound)) + { + aBBuilder.MakeCompound (aCompound); + aKeyshapeDrawshapeMap.Add (aKeyShape, aCompound); + } + aBBuilder.Add (aCompound, aShapeCopy); + } + return isOverriden || isSubOverride; +} + +//======================================================================= +//function : dispatchColors +//purpose : +//======================================================================= +void AIS_ColoredShape::dispatchColors (const TopoDS_Shape& theBaseShape, + const DataMapOfShapeColor& theKeyshapeColorMap, + DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray) +{ + // Extract map (KeyshapeColored -> Color) + // to subshapes map (Subshape -> KeyshapeColored). + // This needed when colored shape is not part of + // (but subshapes are) and actually container for subshapes. + DataMapOfShapeShape aSubshapeKeyshapeMap; + for (DataMapOfShapeColor::Iterator anIt (theKeyshapeColorMap); + anIt.More(); anIt.Next()) + { + const TopoDS_Shape& aSh = anIt.Key(); + TopAbs_ShapeEnum aType = aSh.ShapeType(); + TopAbs_ShapeEnum aSubType = (aType == TopAbs_SOLID || aType == TopAbs_SHELL) + ? TopAbs_FACE + : (aType == TopAbs_WIRE ? TopAbs_EDGE : TopAbs_SHAPE); + switch (aSubType) + { + case TopAbs_SHAPE: + { + aSubshapeKeyshapeMap.Bind (aSh, aSh); + break; + } + default: + { + for (TopExp_Explorer anExp (aSh, aSubType); anExp.More(); anExp.Next()) + { + if (!aSubshapeKeyshapeMap.IsBound (anExp.Current())) + { + aSubshapeKeyshapeMap.Bind (anExp.Current(), aSh); + } + } + } + } + } + + // Fill the array of maps per shape type + dispatchColors (theBaseShape, theBaseShape, + aSubshapeKeyshapeMap, TopAbs_SHAPE, + theTypeKeyshapeDrawshapeArray); +} diff --git a/src/AIS/AIS_ColoredShape.hxx b/src/AIS/AIS_ColoredShape.hxx new file mode 100644 index 0000000000..0fedcf8d20 --- /dev/null +++ b/src/AIS/AIS_ColoredShape.hxx @@ -0,0 +1,145 @@ +// Created on: 2014-04-24 +// Created by: Kirill Gavrilov +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _AIS_ColoredShape_HeaderFile +#define _AIS_ColoredShape_HeaderFile + +#include +#include + +#include +#include +#include +#include + +//! Customizable properties. +class AIS_ColoredDrawer : public AIS_Drawer +{ +public: + + AIS_ColoredDrawer (const Handle(AIS_Drawer)& theLink) + : myHasOwnColor (Standard_False), + myHasOwnWidth (Standard_False) + { + Link (theLink); + } + + Standard_Boolean HasOwnColor() const { return myHasOwnColor; } + void UnsetOwnColor() { myHasOwnColor = Standard_False; } + void SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = Standard_True; } + Standard_Boolean HasOwnWidth() const { return myHasOwnWidth; } + void UnsetOwnWidth() { myHasOwnWidth = Standard_False; } + void SetOwnWidth (const Standard_Real /*theWidth*/) { myHasOwnWidth = Standard_True; } + +public: //! @name list of overridden properties + + Standard_Boolean myHasOwnColor; + Standard_Boolean myHasOwnWidth; + +public: + DEFINE_STANDARD_RTTI(AIS_ColoredDrawer); + +}; + +DEFINE_STANDARD_HANDLE(AIS_ColoredDrawer, AIS_Drawer) + +//! Presentation of the shape with customizable sub-shapes properties. +class AIS_ColoredShape : public AIS_Shape +{ +public: + + //! Default constructor + Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape); + + //! Copy constructor + Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape); + +public: //! @name sub-shape aspects + + //! Customize properties of specified sub-shape. + //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape! + //! This method can be used to mark sub-shapes with customizable properties. + Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape); + + //! Reset the map of custom sub-shape aspects. + Standard_EXPORT void ClearCustomAspects(); + + //! Reset custom properties of specified sub-shape. + //! @param theToUnregister unregister or not sub-shape from the map + Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape& theShape, + const Standard_Boolean theToUnregister = Standard_False); + + //! Customize color of specified sub-shape + Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape, + const Quantity_Color& theColor); + + //! Customize line width of specified sub-shape + Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape, + const Standard_Real theLineWidth); + +public: //! @name global aspects + + //! Setup color of entire shape. + Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor); + + //! Setup line width of entire shape. + Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth); + + //! Sets transparency value. + Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue); + +protected: //! @name override presentation computation + + Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, + const Handle(Prs3d_Presentation)& thePrs, + const Standard_Integer theMode); + +protected: + + typedef NCollection_DataMap DataMapOfShapeColor; + typedef NCollection_DataMap DataMapOfShapeShape; + typedef NCollection_IndexedDataMap DataMapOfShapeCompd; + +protected: + + //! Recursive function to map shapes. + //! @param theBaseKey the key to be used for undetailed shapes (default colors) + //! @param theSubshapeToParse the subshape to be parsed + //! @param theSubshapeKeyshapeMap shapes map Subshape (in the base shape) -> Keyshape (detailed shape) + //! @param theParentType the parent subshape type + //! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill + Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape& theBaseKey, + const TopoDS_Shape& theSubshapeToParse, + const DataMapOfShapeShape& theSubshapeKeyshapeMap, + const TopAbs_ShapeEnum theParentType, + DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray); + + Standard_EXPORT static void dispatchColors (const TopoDS_Shape& theBaseShape, + const DataMapOfShapeColor& theKeyshapeColorMap, + DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray); + +protected: + + DataMapOfShapeColor myShapeColors; + +public: + + DEFINE_STANDARD_RTTI(AIS_ColoredShape); + +}; + +DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape) + +#endif // _AIS_ColoredShape_HeaderFile diff --git a/src/AIS/AIS_Drawer.lxx b/src/AIS/AIS_Drawer.lxx index 1b4a63515d..fab6a2f019 100644 --- a/src/AIS/AIS_Drawer.lxx +++ b/src/AIS/AIS_Drawer.lxx @@ -15,86 +15,136 @@ // commercial license or contractual agreement. inline Standard_Boolean AIS_Drawer::WasLastLocal() const -{return Standard_False;} +{ + return Standard_False; +} -inline Standard_Boolean AIS_Drawer::HasLocalAttributes() const -{return hasLocalAttributes;} +inline Standard_Boolean AIS_Drawer::HasLocalAttributes() const +{ + return hasLocalAttributes; +} -inline Standard_Real AIS_Drawer::PreviousDeviationCoefficient () const -{return (myhasOwnDeviationCoefficient) ? myPreviousDeviationCoefficient : 0.0;} +inline Standard_Real AIS_Drawer::PreviousDeviationCoefficient() const +{ + return myhasOwnDeviationCoefficient ? myPreviousDeviationCoefficient : 0.0; +} -inline Standard_Real AIS_Drawer::PreviousHLRDeviationCoefficient () const -{return (myhasOwnHLRDeviationCoefficient) ? myPreviousHLRDeviationCoefficient : 0.0;} +inline Standard_Real AIS_Drawer::PreviousHLRDeviationCoefficient() const +{ + return myhasOwnHLRDeviationCoefficient ? myPreviousHLRDeviationCoefficient : 0.0; +} -inline Standard_Real AIS_Drawer::PreviousDeviationAngle () const -{return (myhasOwnDeviationAngle) ? myPreviousDeviationAngle : 0.0;} +inline Standard_Real AIS_Drawer::PreviousDeviationAngle() const +{ + return myhasOwnDeviationAngle ? myPreviousDeviationAngle : 0.0; +} -inline Standard_Real AIS_Drawer::PreviousHLRDeviationAngle () const -{return (myhasOwnHLRDeviationAngle) ? myPreviousHLRDeviationAngle : 0.0;} +inline Standard_Real AIS_Drawer::PreviousHLRDeviationAngle() const +{ + return myhasOwnHLRDeviationAngle ? myPreviousHLRDeviationAngle : 0.0; +} -inline void AIS_Drawer::Link ( const Handle(Prs3d_Drawer)& aDrawer) -{ myLink = aDrawer;} +inline void AIS_Drawer::Link (const Handle(Prs3d_Drawer)& theDrawer) +{ + myLink = theDrawer; +} inline Standard_Boolean AIS_Drawer::HasLink() const -{ return ! myLink.IsNull();} +{ + return !myLink.IsNull(); +} -inline void AIS_Drawer::SetDeviationCoefficient () -{ myhasOwnDeviationCoefficient = Standard_False; } +inline void AIS_Drawer::SetDeviationCoefficient() +{ + myhasOwnDeviationCoefficient = Standard_False; +} -inline void AIS_Drawer::SetHLRDeviationCoefficient () -{ myhasOwnHLRDeviationCoefficient = Standard_False; } +inline void AIS_Drawer::SetHLRDeviationCoefficient() +{ + myhasOwnHLRDeviationCoefficient = Standard_False; +} -inline void AIS_Drawer::SetDeviationAngle () -{ myhasOwnDeviationAngle = Standard_False;} +inline void AIS_Drawer::SetDeviationAngle() +{ + myhasOwnDeviationAngle = Standard_False; +} -inline void AIS_Drawer::SetHLRAngle () -{ myhasOwnHLRDeviationAngle = Standard_False;} +inline void AIS_Drawer::SetHLRAngle() +{ + myhasOwnHLRDeviationAngle = Standard_False; +} -inline Standard_Boolean AIS_Drawer::IsOwnDeviationCoefficient () const -{ return myhasOwnDeviationCoefficient;} +inline Standard_Boolean AIS_Drawer::IsOwnDeviationCoefficient() const +{ + return myhasOwnDeviationCoefficient; +} -inline Standard_Boolean AIS_Drawer::IsOwnDeviationAngle () const -{ return myhasOwnDeviationAngle;} +inline Standard_Boolean AIS_Drawer::IsOwnDeviationAngle() const +{ + return myhasOwnDeviationAngle; +} -inline Standard_Boolean AIS_Drawer::IsOwnHLRDeviationCoefficient () const -{ return myhasOwnHLRDeviationCoefficient;} +inline Standard_Boolean AIS_Drawer::IsOwnHLRDeviationCoefficient() const +{ + return myhasOwnHLRDeviationCoefficient; +} -inline Standard_Boolean AIS_Drawer::IsOwnHLRDeviationAngle () const -{ return myhasOwnHLRDeviationAngle;} +inline Standard_Boolean AIS_Drawer::IsOwnHLRDeviationAngle() const +{ + return myhasOwnHLRDeviationAngle; +} -inline Standard_Boolean AIS_Drawer::HasTextAspect () const -{ return (!myTextAspect.IsNull());} +inline Standard_Boolean AIS_Drawer::HasTextAspect() const +{ + return !myTextAspect.IsNull(); +} -inline Standard_Boolean AIS_Drawer::HasWireAspect () const -{ return (!myWireAspect.IsNull());} +inline Standard_Boolean AIS_Drawer::HasWireAspect() const +{ + return !myWireAspect.IsNull(); +} -inline Standard_Boolean AIS_Drawer::HasLineAspect () const -{return !myLineAspect.IsNull(); } +inline Standard_Boolean AIS_Drawer::HasLineAspect() const +{ + return !myLineAspect.IsNull(); +} -inline Standard_Boolean AIS_Drawer::HasShadingAspect () const -{ return !myShadingAspect.IsNull();} +inline Standard_Boolean AIS_Drawer::HasShadingAspect() const +{ + return !myShadingAspect.IsNull(); +} -inline Standard_Boolean AIS_Drawer::HasPointAspect () const -{ return !myPointAspect.IsNull();} +inline Standard_Boolean AIS_Drawer::HasPointAspect() const +{ + return !myPointAspect.IsNull(); +} -inline Standard_Boolean AIS_Drawer::HasDatumAspect () const -{ return !myDatumAspect.IsNull();} +inline Standard_Boolean AIS_Drawer::HasDatumAspect() const +{ + return !myDatumAspect.IsNull(); +} -inline Standard_Boolean AIS_Drawer::HasPlaneAspect () const -{ return !myPlaneAspect.IsNull();} +inline Standard_Boolean AIS_Drawer::HasPlaneAspect() const +{ + return !myPlaneAspect.IsNull(); +} -inline Standard_Boolean AIS_Drawer::IsOwnFaceBoundaryDraw () const -{ return myHasOwnFaceBoundaryDraw; } +inline Standard_Boolean AIS_Drawer::IsOwnFaceBoundaryDraw() const +{ + return myHasOwnFaceBoundaryDraw; +} -inline Standard_Boolean AIS_Drawer::IsOwnFaceBoundaryAspect () const -{ return !myFaceBoundaryAspect.IsNull (); } +inline Standard_Boolean AIS_Drawer::IsOwnFaceBoundaryAspect() const +{ + return !myFaceBoundaryAspect.IsNull(); +} -inline void AIS_Drawer::SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR) +inline void AIS_Drawer::SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR) { myTypeOfHLR = theTypeOfHLR; } -inline Prs3d_TypeOfHLR AIS_Drawer::TypeOfHLR ( ) const +inline Prs3d_TypeOfHLR AIS_Drawer::TypeOfHLR() const { return (myTypeOfHLR == Prs3d_TOH_NotSet) ? myLink->TypeOfHLR() : myTypeOfHLR; } diff --git a/src/AIS/AIS_Shape.cdl b/src/AIS/AIS_Shape.cdl index a0932562d6..a7990c9e9e 100644 --- a/src/AIS/AIS_Shape.cdl +++ b/src/AIS/AIS_Shape.cdl @@ -61,6 +61,7 @@ uses Projector from Prs3d, PresentationManager3d from PrsMgr, Selection from SelectMgr, + Drawer from AIS, KindOfInteractive from AIS, Transformation from Geom, Drawer from Prs3d, @@ -298,7 +299,21 @@ uses aBox : Box from Bnd; aDrawer : Drawer from Prs3d) is protected; - + setColor (me; + theDrawer : Drawer from AIS; + theColor : Color from Quantity) + is protected; + + setWidth (me; + theDrawer : Drawer from AIS; + theWidth : Real from Standard) + is protected; + + setTransparency (me; + theDrawer : Drawer from AIS; + theValue : Real from Standard) + is protected; + fields myshape : Shape from TopoDS is protected; myBB : Box from Bnd is protected; diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index a569bfe116..1114378bf9 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -215,23 +215,15 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat } case 1: { - Standard_Real prevangle ; - Standard_Real newangle ; - Standard_Real prevcoeff ; - Standard_Real newcoeff ; - - Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle(newangle,prevangle); - Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(newcoeff,prevcoeff); - if (((Abs (newangle - prevangle) > Precision::Angular()) && isOwnDeviationAngle) || - ((Abs (newcoeff - prevcoeff) > Precision::Confusion()) && isOwnDeviationCoefficient)) { -#ifdef DEB - cout << "AIS_Shape : compute"< Precision::Angular()) + || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion())) + { + BRepTools::Clean (myshape); } - + //shading only on face... if ((Standard_Integer) myshape.ShapeType()>4) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); @@ -496,197 +488,260 @@ void AIS_Shape::SetColor(const Quantity_NameOfColor aCol) } //======================================================================= -//function : SetColor -//purpose : +//function : setColor +//purpose : //======================================================================= -void AIS_Shape::SetColor(const Quantity_Color &aCol) +void AIS_Shape::setColor (const Handle(AIS_Drawer)& theDrawer, + const Quantity_Color& theColor) const { - if( !HasColor() && !IsTransparent() && !HasMaterial() ) { - myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); + if (!theDrawer->HasShadingAspect()) + { + theDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); + *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect(); } - hasOwnColor = Standard_True; - - myDrawer->ShadingAspect()->SetColor(aCol,myCurrentFacingModel); - myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel); - myDrawer->SetShadingAspectGlobal(Standard_False); - + if (!theDrawer->HasLineAspect()) + { + theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); + *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect(); + } + if (!theDrawer->HasWireAspect()) + { + theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); + *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect(); + } + if (!theDrawer->HasPointAspect()) + { + theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0)); + *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect(); + } + // disable dedicated line aspects + theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect()); + theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect()); + theDrawer->SetSeenLineAspect (theDrawer->LineAspect()); + + // override color + theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel); + theDrawer->SetShadingAspectGlobal (Standard_False); + theDrawer->LineAspect()->SetColor (theColor); + theDrawer->WireAspect()->SetColor (theColor); + theDrawer->PointAspect()->SetColor (theColor); +} - const Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line); +//======================================================================= +//function : SetColor +//purpose : +//======================================================================= - myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); - myDrawer->SetWireAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); - myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); - myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); - myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); +void AIS_Shape::SetColor (const Quantity_Color& theColor) +{ + setColor (myDrawer, theColor); + myOwnColor = theColor; + hasOwnColor = Standard_True; // fast shading modification... - if(!GetContext().IsNull()){ - if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){ - Handle(Prs3d_Presentation) aPresentation = GetContext()->MainPrsMgr()->Presentation (this, 1)->Presentation(); - Handle(Graphic3d_Group) aCurGroup = Prs3d_Root::CurrentGroup(aPresentation); + if (!GetContext().IsNull()) + { + if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + { + Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); + Handle(Graphic3d_Group) aCurGroup = Prs3d_Root::CurrentGroup (aPrs); Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect(); - Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect(); + Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect(); + Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect(); // Set aspects for presentation and for group - aPresentation->SetPrimitivesAspect(anAreaAspect); - aPresentation->SetPrimitivesAspect(aLineAspect); + aPrs->SetPrimitivesAspect (anAreaAspect); + aPrs->SetPrimitivesAspect (aLineAspect); + aPrs->SetPrimitivesAspect (aPointAspect); // Check if aspect of given type is set for the group, // because setting aspect for group with no already set aspect // can lead to loss of presentation data - if (aCurGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) - aCurGroup->SetGroupPrimitivesAspect(anAreaAspect); - if (aCurGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_LINE)) - aCurGroup->SetGroupPrimitivesAspect(aLineAspect); + if (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) + { + aCurGroup->SetGroupPrimitivesAspect (anAreaAspect); + } + if (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE)) + { + aCurGroup->SetGroupPrimitivesAspect (aLineAspect); + } + if (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER)) + { + aCurGroup->SetGroupPrimitivesAspect (aPointAspect); + } } } - LoadRecomputable(0); - LoadRecomputable(2); + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (2); } //======================================================================= //function : UnsetColor -//purpose : +//purpose : //======================================================================= void AIS_Shape::UnsetColor() { - if ( !HasColor() ) + if (!HasColor()) { myToRecomputeModes.Clear(); return; } hasOwnColor = Standard_False; - Handle(Prs3d_LineAspect) NullAsp; - Handle(Prs3d_ShadingAspect) NullShA; - - if(!HasWidth()) { - myDrawer->SetLineAspect(NullAsp); - myDrawer->SetWireAspect(NullAsp); - myDrawer->SetFreeBoundaryAspect(NullAsp); - myDrawer->SetUnFreeBoundaryAspect(NullAsp); - myDrawer->SetSeenLineAspect(NullAsp); + if (!HasWidth()) + { + Handle(Prs3d_LineAspect) anEmptyAsp; + myDrawer->SetLineAspect (anEmptyAsp); + myDrawer->SetWireAspect (anEmptyAsp); + myDrawer->SetFreeBoundaryAspect (anEmptyAsp); + myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp); + myDrawer->SetSeenLineAspect (anEmptyAsp); } - else { - Quantity_Color CC; - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); - myDrawer->LineAspect()->SetColor(CC); - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC); - myDrawer->WireAspect()->SetColor(CC); - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC); - myDrawer->FreeBoundaryAspect()->SetColor(CC); - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC); - myDrawer->UnFreeBoundaryAspect()->SetColor(CC); - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC); - myDrawer->SeenLineAspect()->SetColor(CC); + else + { + Quantity_Color aColor; + AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor); + myDrawer->LineAspect()->SetColor (aColor); + AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor); + myDrawer->WireAspect()->SetColor (aColor); + AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor); + myDrawer->FreeBoundaryAspect()->SetColor (aColor); + AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor); + myDrawer->UnFreeBoundaryAspect()->SetColor (aColor); + AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor); + myDrawer->SeenLineAspect()->SetColor (aColor); } - if( HasMaterial() || IsTransparent()) { + if (HasMaterial() + || IsTransparent()) + { Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link()); - if( HasMaterial() ) { - Quantity_Color color = myDrawer->Link()->ShadingAspect()->Color(myCurrentFacingModel); - mat.SetColor(color); + if (HasMaterial()) + { + Quantity_Color aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel); + mat.SetColor (aColor); } - if( IsTransparent() ) { - Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel); - mat.SetTransparency(trans); + if (IsTransparent()) + { + Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel); + mat.SetTransparency (aTransp); } - myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel); + myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel); } - else { - myDrawer->SetShadingAspect(NullShA); + else + { + myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); } + myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)()); - if(!GetContext().IsNull()){ - if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ - Handle(Prs3d_Presentation) aPresentation = GetContext()->MainPrsMgr()->Presentation (this, 1)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); + if (!GetContext().IsNull()) + { + if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + { + Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect(); - Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect(); - Quantity_Color CC; - AIS_GraphicTool::GetInteriorColor(myDrawer->Link(),CC); - anAreaAsp->SetInteriorColor(CC); - aPresentation->SetPrimitivesAspect(anAreaAsp); - aPresentation->SetPrimitivesAspect(aLineAsp); + Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect(); + Quantity_Color aColor; + AIS_GraphicTool::GetInteriorColor (myDrawer->Link(), aColor); + anAreaAsp->SetInteriorColor (aColor); + aPrs->SetPrimitivesAspect (anAreaAsp); + aPrs->SetPrimitivesAspect (aLineAsp); // Check if aspect of given type is set for the group, // because setting aspect for group with no already set aspect // can lead to loss of presentation data - if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) - aGroup->SetGroupPrimitivesAspect(anAreaAsp); - if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_LINE)) - aGroup->SetGroupPrimitivesAspect(aLineAsp); + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) + { + aGroup->SetGroupPrimitivesAspect (anAreaAsp); + } + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE)) + { + aGroup->SetGroupPrimitivesAspect (aLineAsp); + } } } - LoadRecomputable(0); - LoadRecomputable(2); + LoadRecomputable (AIS_WireFrame); + LoadRecomputable (2); } //======================================================================= -//function : SetWidth -//purpose : +//function : setWidth +//purpose : //======================================================================= -void AIS_Shape::SetWidth(const Standard_Real W) +void AIS_Shape::setWidth (const Handle(AIS_Drawer)& theDrawer, + const Standard_Real theLineWidth) const { - if(HasColor() || HasWidth()){ - myDrawer->LineAspect()->SetWidth(W); - myDrawer->WireAspect()->SetWidth(W); - myDrawer->FreeBoundaryAspect()->SetWidth(W); - myDrawer->UnFreeBoundaryAspect()->SetWidth(W); - myDrawer->SeenLineAspect()->SetWidth(W); + if (!theDrawer->HasLineAspect()) + { + theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); + *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect(); } - else{ - Quantity_Color CC; - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); - myDrawer->SetLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W)); - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC); - myDrawer->SetWireAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W)); - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC); - myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W)); - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC); - myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W)); - AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC); - myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W)); + if (!theDrawer->HasWireAspect()) + { + theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0)); + *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect(); } - myOwnWidth = W; - LoadRecomputable(0); // means that it is necessary to recompute only the wireframe.... - LoadRecomputable(2); // and the bounding box... + // disable dedicated line aspects + theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect()); + theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect()); + theDrawer->SetSeenLineAspect (theDrawer->LineAspect()); + + // override width + theDrawer->LineAspect()->SetWidth (theLineWidth); + theDrawer->WireAspect()->SetWidth (theLineWidth); } //======================================================================= -//function : UnsetWidth +//function : SetWidth //purpose : //======================================================================= +void AIS_Shape::SetWidth (const Standard_Real theLineWidth) +{ + setWidth (myDrawer, theLineWidth); + myOwnWidth = theLineWidth; + LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe.... + LoadRecomputable (2); // and the bounding box... +} + +//======================================================================= +//function : UnsetWidth +//purpose : +//======================================================================= + void AIS_Shape::UnsetWidth() { - if(myOwnWidth == 0.0) + if (myOwnWidth == 0.0) { myToRecomputeModes.Clear(); return; } - myOwnWidth=0.0; - Handle(Prs3d_LineAspect) NullAsp; + myOwnWidth = 0.0; - if(!HasColor()){ - myDrawer->SetLineAspect(NullAsp); - myDrawer->SetWireAspect(NullAsp); - myDrawer->SetFreeBoundaryAspect(NullAsp); - myDrawer->SetUnFreeBoundaryAspect(NullAsp); - myDrawer->SetSeenLineAspect(NullAsp); + Handle(Prs3d_LineAspect) anEmptyAsp; + + if (!HasColor()) + { + myDrawer->SetLineAspect (anEmptyAsp); + myDrawer->SetWireAspect (anEmptyAsp); + myDrawer->SetFreeBoundaryAspect (anEmptyAsp); + myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp); + myDrawer->SetSeenLineAspect (anEmptyAsp); } - else{ - myDrawer->LineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line)); - myDrawer->WireAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Wire)); - myDrawer->FreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Free)); - myDrawer->UnFreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_UnFree)); - myDrawer->SeenLineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Seen)); + else + { + myDrawer->LineAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line)); + myDrawer->WireAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire)); + myDrawer->FreeBoundaryAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free)); + myDrawer->UnFreeBoundaryAspect()->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree)); + myDrawer->SeenLineAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen)); } - LoadRecomputable(0); + LoadRecomputable (AIS_WireFrame); } //======================================================================= @@ -701,143 +756,188 @@ void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat) //======================================================================= //function : SetMaterial -//purpose : +//purpose : //======================================================================= -void AIS_Shape::SetMaterial(const Graphic3d_MaterialAspect& aMat) +void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat) { - if( !HasColor() && !IsTransparent() && !HasMaterial() ) { - myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); + if (!myDrawer->HasShadingAspect()) + { + myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); + *myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect(); } hasOwnMaterial = Standard_True; - myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel); - myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel); + myDrawer->ShadingAspect()->SetMaterial (theMat, myCurrentFacingModel); + if (HasColor()) + { + myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel); + } + myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel); - if(!GetContext().IsNull()){ - if(GetContext()->MainPrsMgr()->HasPresentation(this,1)) + if (!GetContext().IsNull()) + { + if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) { - Handle(Prs3d_Presentation) aPresentation = GetContext()->MainPrsMgr()->Presentation (this, 1)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); + Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - aPresentation->SetPrimitivesAspect(anAreaAsp); + aPrs->SetPrimitivesAspect (anAreaAsp); // Check if aspect of given type is set for the group, // because setting aspect for group with no already set aspect // can lead to loss of presentation data - if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) - aGroup->SetGroupPrimitivesAspect(anAreaAsp); + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) + { + aGroup->SetGroupPrimitivesAspect (anAreaAsp); + } } - myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update + myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update myToRecomputeModes.Clear(); } } + //======================================================================= //function : UnsetMaterial -//purpose : +//purpose : //======================================================================= void AIS_Shape::UnsetMaterial() { - if( !HasMaterial() ) return; + if (!HasMaterial()) + { + return; + } - if( HasColor() || IsTransparent()) { - Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(myDrawer->Link()); - if( HasColor() ) { - Quantity_Color color = myDrawer->ShadingAspect()->Color(myCurrentFacingModel); - mat.SetColor(color); - } - if( IsTransparent() ) { - Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel); - mat.SetTransparency(trans); + if (HasColor() + || IsTransparent()) + { + myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel), + myCurrentFacingModel); + if (HasColor()) + { + myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel); + myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel); } - myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel); - } else { - Handle(Prs3d_ShadingAspect) SA; - myDrawer->SetShadingAspect(SA); + } + else + { + myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); } hasOwnMaterial = Standard_False; - if(!GetContext().IsNull()){ - if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ - Handle(Prs3d_Presentation) aPresentation = GetContext()->MainPrsMgr()->Presentation (this, 1)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); + + if (!GetContext().IsNull()) + { + if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + { + Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - aPresentation->SetPrimitivesAspect(anAreaAsp); + aPrs->SetPrimitivesAspect (anAreaAsp); // Check if aspect of given type is set for the group, // because setting aspect for group with no already set aspect // can lead to loss of presentation data - if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) - aGroup->SetGroupPrimitivesAspect(anAreaAsp); + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) + { + aGroup->SetGroupPrimitivesAspect (anAreaAsp); + } } } - myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update + myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update myToRecomputeModes.Clear(); } //======================================================================= -//function : SetTransparency -//purpose : +//function : setTransparency +//purpose : //======================================================================= -void AIS_Shape::SetTransparency(const Standard_Real AValue) +void AIS_Shape::setTransparency (const Handle(AIS_Drawer)& theDrawer, + const Standard_Real theValue) const { - if ( !HasColor() && !HasMaterial() ) { - myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); + if (!theDrawer->HasShadingAspect()) + { + theDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); + *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect(); } - myDrawer->ShadingAspect()->SetTransparency(AValue,myCurrentFacingModel); - myTransparency = AValue; - if(!GetContext().IsNull()){ - if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ - Handle(Prs3d_Presentation) aPresentation = GetContext()->MainPrsMgr()->Presentation (this, 1)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); + // override transparency + theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel); +} + +//======================================================================= +//function : SetTransparency +//purpose : +//======================================================================= + +void AIS_Shape::SetTransparency (const Standard_Real theValue) +{ + setTransparency (myDrawer, theValue); + myTransparency = theValue; + + if (!GetContext().IsNull()) + { + if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + { + Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - aPresentation->SetPrimitivesAspect(anAreaAsp); - //force highest priority for transparent objects - aPresentation->SetDisplayPriority(10); + aPrs->SetPrimitivesAspect (anAreaAsp); + // force highest priority for transparent objects + aPrs->SetDisplayPriority (10); // Check if aspect of given type is set for the group, // because setting aspect for group with no already set aspect // can lead to loss of presentation data - if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) - aGroup->SetGroupPrimitivesAspect(anAreaAsp); + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) + { + aGroup->SetGroupPrimitivesAspect (anAreaAsp); + } } } - myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update + myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update myToRecomputeModes.Clear(); } //======================================================================= //function : UnsetTransparency -//purpose : +//purpose : //======================================================================= void AIS_Shape::UnsetTransparency() { - if( HasColor() || HasMaterial() ) { - myDrawer->ShadingAspect()->SetTransparency(0.0,myCurrentFacingModel); - } else { - Handle(Prs3d_ShadingAspect) SA; - myDrawer->SetShadingAspect(SA); - } - myTransparency = 0.0; + if (!myDrawer->HasShadingAspect()) + { + return; + } + else if (HasColor() || HasMaterial()) + { + myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel); + } + else + { + myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); + } - if(!GetContext().IsNull()){ - if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ - Handle(Prs3d_Presentation) aPresentation = GetContext()->MainPrsMgr()->Presentation (this, 1)->Presentation(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); + if (!GetContext().IsNull()) + { + if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded)) + { + Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->Presentation (this, AIS_Shaded)->Presentation(); + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); - aPresentation->SetPrimitivesAspect(anAreaAsp); + aPrs->SetPrimitivesAspect (anAreaAsp); // Check if aspect of given type is set for the group, // because setting aspect for group with no already set aspect // can lead to loss of presentation data - if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) - aGroup->SetGroupPrimitivesAspect(anAreaAsp); - - aPresentation->ResetDisplayPriority(); + if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA)) + { + aGroup->SetGroupPrimitivesAspect (anAreaAsp); + } + aPrs->ResetDisplayPriority(); } } - myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update + myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update myToRecomputeModes.Clear(); } diff --git a/src/AIS/FILES b/src/AIS/FILES index f19a8a5a14..9b7b40d1f5 100755 --- a/src/AIS/FILES +++ b/src/AIS/FILES @@ -5,6 +5,8 @@ AIS_LocalContext_1.cxx AIS_NListTransient.hxx AIS_NListIteratorOfListTransient.hxx AIS_NDataMapOfTransientIteratorOfListTransient.hxx +AIS_ColoredShape.hxx +AIS_ColoredShape.cxx AIS_TexturedShape.hxx AIS_TexturedShape.cxx AIS_Triangulation.cdl diff --git a/src/Graphic3d/Graphic3d_MaterialAspect.cdl b/src/Graphic3d/Graphic3d_MaterialAspect.cdl index 7b67e83986..a917a3d6f8 100644 --- a/src/Graphic3d/Graphic3d_MaterialAspect.cdl +++ b/src/Graphic3d/Graphic3d_MaterialAspect.cdl @@ -397,6 +397,12 @@ is -- Trigger: when is < 1 or > NumberOfMaterials. ---Level: Public + MaterialFromName (myclass; + theName : CString from Standard) + returns NameOfMaterial from Graphic3d; + ---Purpose: + -- Returns the material for specified name or Graphic3d_NOM_DEFAULT if name is unknown. + ---------------------------- -- Category: Private methods ---------------------------- diff --git a/src/Graphic3d/Graphic3d_MaterialAspect.cxx b/src/Graphic3d/Graphic3d_MaterialAspect.cxx index fc4f275e7d..c7891ca8d4 100644 --- a/src/Graphic3d/Graphic3d_MaterialAspect.cxx +++ b/src/Graphic3d/Graphic3d_MaterialAspect.cxx @@ -897,6 +897,48 @@ Standard_CString Graphic3d_MaterialAspect::MaterialName(const Standard_Integer a return theMaterials[aRank-1].name; } +Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::MaterialFromName (const Standard_CString theName) +{ + TCollection_AsciiString aName (theName); + aName.LowerCase(); + aName.Capitalize(); + const Standard_Integer aNbMaterials = Graphic3d_MaterialAspect::NumberOfMaterials(); + for (Standard_Integer aMatIter = 1; aMatIter <= aNbMaterials; ++aMatIter) + { + if (aName == Graphic3d_MaterialAspect::MaterialName (aMatIter)) + { + return Graphic3d_NameOfMaterial(aMatIter - 1); + } + } + + // parse aliases + if (aName == "Plastic") // Plastified + { + return Graphic3d_NOM_PLASTIC; + } + else if (aName == "Shiny_plastic") // Shiny_plastified + { + return Graphic3d_NOM_SHINY_PLASTIC; + } + else if (aName == "Plaster") // Plastered + { + return Graphic3d_NOM_PLASTER; + } + else if (aName == "Satin") // Satined + { + return Graphic3d_NOM_SATIN; + } + else if (aName == "Neon_gnc") // Ionized + { + return Graphic3d_NOM_NEON_GNC; + } + else if (aName == "Neon_phc") // Neon + { + return Graphic3d_NOM_NEON_PHC; + } + return Graphic3d_NOM_DEFAULT; +} + Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType(const Standard_Integer aRank) { if( aRank < 1 || aRank > NumberOfMaterials() ) diff --git a/src/NCollection/NCollection_IndexedDataMap.hxx b/src/NCollection/NCollection_IndexedDataMap.hxx index de26082814..806d810528 100644 --- a/src/NCollection/NCollection_IndexedDataMap.hxx +++ b/src/NCollection/NCollection_IndexedDataMap.hxx @@ -104,15 +104,18 @@ template < class TheKeyType, myMap(NULL), myIndex(0) {} //! Constructor - Iterator (const NCollection_IndexedDataMap& theMap) : - myMap((NCollection_IndexedDataMap *) &theMap), - myIndex(1) {} + Iterator (const NCollection_IndexedDataMap& theMap) + : myMap ((NCollection_IndexedDataMap* )&theMap), + myNode (myMap->nodeFromIndex (1)), + myIndex (1) {} //! Query if the end of collection is reached by iterator virtual Standard_Boolean More(void) const { return (myIndex <= myMap->Extent()); } //! Make a step along the collection virtual void Next(void) - { myIndex++; } + { + myNode = myMap->nodeFromIndex (++myIndex); + } //! Value access virtual const TheItemType& Value(void) const { @@ -120,7 +123,7 @@ template < class TheKeyType, if (!More()) Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::Iterator::Value"); #endif - return myMap->FindFromIndex(myIndex); + return myNode->Value(); } //! ChangeValue access virtual TheItemType& ChangeValue(void) const @@ -129,12 +132,21 @@ template < class TheKeyType, if (!More()) Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::Iterator::ChangeValue"); #endif - return myMap->ChangeFromIndex(myIndex); + return myNode->ChangeValue(); + } + //! Key + const TheKeyType& Key() const + { +#if !defined No_Exception && !defined No_Standard_NoSuchObject + if (!More()) + Standard_NoSuchObject::Raise("NCollection_DataMap::Iterator::Key"); +#endif + return myNode->Key1(); } - private: - NCollection_IndexedDataMap * myMap; //!< Pointer to the map being iterated - Standard_Integer myIndex; //!< Current index + NCollection_IndexedDataMap* myMap; //!< Pointer to the map being iterated + IndexedDataMapNode* myNode; //!< Current node + Standard_Integer myIndex; //!< Current index }; public: @@ -365,16 +377,12 @@ template < class TheKeyType, if (theKey2 < 1 || theKey2 > Extent()) Standard_OutOfRange::Raise ("NCollection_IndexedDataMap::FindKey"); #endif - IndexedDataMapNode * pNode2 = - (IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; - while (pNode2) + IndexedDataMapNode* aNode = nodeFromIndex (theKey2); + if (aNode == NULL) { - if (pNode2->Key2() == theKey2) - return pNode2->Key1(); - pNode2 = (IndexedDataMapNode*) pNode2->Next2(); + Standard_NoSuchObject::Raise ("NCollection_IndexedDataMap::FindKey"); } - Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::FindKey"); - return pNode2->Key1(); // This for compiler + return aNode->Key1(); } //! FindFromIndex @@ -384,16 +392,12 @@ template < class TheKeyType, if (theKey2 < 1 || theKey2 > Extent()) Standard_OutOfRange::Raise ("NCollection_IndexedDataMap::FindFromIndex"); #endif - IndexedDataMapNode * pNode2 = - (IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; - while (pNode2) + IndexedDataMapNode* aNode = nodeFromIndex (theKey2); + if (aNode == NULL) { - if (pNode2->Key2() == theKey2) - return pNode2->Value(); - pNode2 = (IndexedDataMapNode*) pNode2->Next2(); + Standard_NoSuchObject::Raise ("NCollection_IndexedDataMap::FindFromIndex"); } - Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::FindFromIndex"); - return pNode2->Value(); // This for compiler + return aNode->Value(); } //! operator () @@ -407,16 +411,12 @@ template < class TheKeyType, if (theKey2 < 1 || theKey2 > Extent()) Standard_OutOfRange::Raise("NCollection_IndexedDataMap::ChangeFromIndex"); #endif - IndexedDataMapNode * pNode2 = - (IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; - while (pNode2) + IndexedDataMapNode* aNode = nodeFromIndex (theKey2); + if (aNode == NULL) { - if (pNode2->Key2() == theKey2) - return pNode2->ChangeValue(); - pNode2 = (IndexedDataMapNode*) pNode2->Next2(); + Standard_NoSuchObject::Raise ("NCollection_IndexedDataMap::ChangeFromIndex"); } - Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::FindFromIndex"); - return pNode2->ChangeValue(); // This for compiler + return aNode->ChangeValue(); } //! operator () @@ -476,6 +476,27 @@ template < class TheKeyType, return pNode1->ChangeValue(); } + //! Find value for key with copying. + //! @return true if key was found + Standard_Boolean FindFromKey (const TheKeyType& theKey1, + TheItemType& theValue) const + { + if (IsEmpty()) + { + return Standard_False; + } + for (IndexedDataMapNode* aNode = (IndexedDataMapNode* )myData1[Hasher::HashCode (theKey1, NbBuckets())]; + aNode != NULL; aNode = (IndexedDataMapNode* )aNode->Next()) + { + if (Hasher::IsEqual (aNode->Key1(), theKey1)) + { + theValue = aNode->Value(); + return Standard_True; + } + } + return Standard_False; + } + //! Clear data. If doReleaseMemory is false then the table of //! buckets is not released and will be reused. void Clear(const Standard_Boolean doReleaseMemory = Standard_True) @@ -505,6 +526,25 @@ template < class TheKeyType, CreateIterator(void) const { return *(new (this->IterAllocator()) Iterator(*this)); } + //! Find map node associated with specified index. + //! Return NULL if not found (exception-free internal implementation). + IndexedDataMapNode* nodeFromIndex (const Standard_Integer theKey2) const + { + if (Extent() == 0) + { + return NULL; + } + for (IndexedDataMapNode* aNode = (IndexedDataMapNode* )myData2[::HashCode (theKey2, NbBuckets())]; + aNode != NULL; aNode = (IndexedDataMapNode* )aNode->Next2()) + { + if (aNode->Key2() == theKey2) + { + return aNode; + } + } + return NULL; + } + }; #endif diff --git a/src/OpenGl/OpenGl_AspectMarker.cxx b/src/OpenGl/OpenGl_AspectMarker.cxx index 65d234251f..b294421971 100644 --- a/src/OpenGl/OpenGl_AspectMarker.cxx +++ b/src/OpenGl/OpenGl_AspectMarker.cxx @@ -1462,13 +1462,13 @@ OpenGl_AspectMarker::OpenGl_AspectMarker() // ======================================================================= void OpenGl_AspectMarker::SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect) { - myColor.rgb[0] = (float )theAspect.Color.r; - myColor.rgb[1] = (float )theAspect.Color.g; - myColor.rgb[2] = (float )theAspect.Color.b; - myColor.rgb[3] = 1.0f; - myMarkerImage = theAspect.MarkerImage; - myType = theAspect.MarkerType; - myScale = myMarkerSize = theAspect.Scale; + myColor.rgb[0] = (float )theAspect.Color.r; + myColor.rgb[1] = (float )theAspect.Color.g; + myColor.rgb[2] = (float )theAspect.Color.b; + myColor.rgb[3] = 1.0f; + myMarkerImage = theAspect.MarkerImage; + myType = theAspect.MarkerType; + myScale = theAspect.Scale; myShaderProgram = theAspect.ShaderProgram; // update sprite resource bindings @@ -1476,13 +1476,11 @@ void OpenGl_AspectMarker::SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect) TCollection_AsciiString aSpriteAKey = THE_EMPTY_KEY; myResources.SpriteKeys (myMarkerImage, myType, myScale, myColor, aSpriteKey, aSpriteAKey); - if (aSpriteKey.IsEmpty() || myResources.SpriteKey != aSpriteKey) - { - myResources.ResetSpriteReadiness(); - } - if (aSpriteAKey.IsEmpty() || myResources.SpriteAKey != aSpriteAKey) + if (aSpriteKey.IsEmpty() || myResources.SpriteKey != aSpriteKey + || aSpriteAKey.IsEmpty() || myResources.SpriteAKey != aSpriteAKey) { myResources.ResetSpriteReadiness(); + myMarkerSize = theAspect.Scale; } // update shader program resource bindings diff --git a/src/StdPrs/StdPrs_ShadedShape.cdl b/src/StdPrs/StdPrs_ShadedShape.cdl index 747904a526..c36c2cde5e 100755 --- a/src/StdPrs/StdPrs_ShadedShape.cdl +++ b/src/StdPrs/StdPrs_ShadedShape.cdl @@ -44,4 +44,9 @@ is theUVScale : Pnt2d from gp); ---Purpose: Shades with texture coordinates. + Tessellate (myclass; + theShape : Shape from TopoDS; + theDrawer : Drawer from Prs3d); + ---Purpose: Validates triangulation within the shape and performs tessellation if necessary. + end ShadedShape; diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index 6360df85a4..4c8adf498c 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -361,6 +361,32 @@ void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePresentation, Standard_False, aDummy, aDummy, aDummy); } +// ======================================================================= +// function : Tessellate +// purpose : +// ======================================================================= +void StdPrs_ShadedShape::Tessellate (const TopoDS_Shape& theShape, + const Handle (Prs3d_Drawer)& theDrawer) +{ + // Check if it is possible to avoid unnecessary recomputation + // of shape triangulation + Standard_Real aDeflection = GetDeflection (theShape, theDrawer); + if (BRepTools::Triangulation (theShape, aDeflection)) + { + return; + } + + // retrieve meshing tool from Factory + BRepTools::Clean (theShape); + Handle(BRepMesh_DiscretRoot) aMeshAlgo = BRepMesh_DiscretFactory::Get().Discret (theShape, + aDeflection, + theDrawer->HLRAngle()); + if (!aMeshAlgo.IsNull()) + { + aMeshAlgo->Perform(); + } +} + // ======================================================================= // function : Add // purpose : @@ -411,22 +437,8 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePresentation StdPrs_WFShape::Add (thePresentation, theShape, theDrawer); } } - Standard_Real aDeflection = GetDeflection (theShape, theDrawer); - - // Check if it is possible to avoid unnecessary recomputation - // of shape triangulation - if (!BRepTools::Triangulation (theShape, aDeflection)) - { - BRepTools::Clean (theShape); - - // retrieve meshing tool from Factory - Handle(BRepMesh_DiscretRoot) aMeshAlgo = BRepMesh_DiscretFactory::Get().Discret (theShape, - aDeflection, - theDrawer->HLRAngle()); - if (!aMeshAlgo.IsNull()) - aMeshAlgo->Perform(); - } + Tessellate (theShape, theDrawer); ShadeFromShape (theShape, thePresentation, theDrawer, theHasTexels, theUVOrigin, theUVRepeat, theUVScale); diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index df43089f30..b3a44da149 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -136,38 +137,6 @@ Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theNam return DEFAULT_COLOR; } -//======================================================================= -//function : GetMaterialFromName -//purpose : get the Graphic3d_NameOfMaterial from a string -//======================================================================= - -static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name ) -{ - Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL; - - if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS; - else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE; - else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER; - else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD; - else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER; - else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER; - else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL; - else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED; - else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE; - else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME; - else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM; - else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC; - else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC; - else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER; - else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC; - else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN; - else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC; - else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN; - else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE; - - return mat; -} - //======================================================================= //function : GetTypeNames //purpose : @@ -1169,493 +1138,766 @@ static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** arg else return 1; } return 0; - } -//============================================================================== -//function : VColor2 -//Author : ege -//purpose : change the color of a selected or named or displayed shape -//Draw arg : vcolor2 [name] color -//============================================================================== -static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv) -{ - Standard_Boolean ThereIsCurrent; - Standard_Boolean ThereIsArgument; - Standard_Boolean IsBound = Standard_False ; +//! Auxiliary class to iterate presentations from different collections. +class ViewTest_PrsIter +{ +public: - const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0); - if (HaveToSet) { - if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; } - ThereIsArgument = (argc != 2); + //! Create and initialize iterator object. + ViewTest_PrsIter (const TCollection_AsciiString& theName) + : mySource (IterSource_All) + { + NCollection_Sequence aNames; + if (!theName.IsEmpty()) + aNames.Append (theName); + Init (aNames); } - else { - if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; } - ThereIsArgument = (argc == 2); + + //! Create and initialize iterator object. + ViewTest_PrsIter (const NCollection_Sequence& theNames) + : mySource (IterSource_All) + { + Init (theNames); } - if ( !a3DView().IsNull() ) { - TCollection_AsciiString name; - if (ThereIsArgument) { - name = argv[1]; - IsBound= GetMapOfAIS().IsBound2(name); + //! Initialize the iterator. + void Init (const NCollection_Sequence& theNames) + { + Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); + mySeq = theNames; + mySelIter.Nullify(); + myCurrent.Nullify(); + myCurrentTrs.Nullify(); + if (!mySeq.IsEmpty()) + { + mySource = IterSource_List; + mySeqIter = NCollection_Sequence::Iterator (mySeq); } - if (TheAISContext()->HasOpenedContext()) - TheAISContext()->CloseLocalContext(); + else if (aCtx->NbCurrents() > 0) + { + mySource = IterSource_Selected; + mySelIter = aCtx; + mySelIter->InitCurrent(); + } + else + { + mySource = IterSource_All; + myMapIter.Initialize (GetMapOfAIS()); + } + initCurrent(); + } - // On set le Booleen There is current - if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; } - else ThereIsCurrent =Standard_False; + const TCollection_AsciiString& CurrentName() const + { + return myCurrentName; + } - //======================================================================= - // Il y a un argument - //======================================================================= - if ( ThereIsArgument && IsBound ) { - const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); - if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { - Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast (anObj); -#ifdef DEB - if (HaveToSet) - di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n"; - else - di << "HaveToSet 0\n"; -#endif + const Handle(AIS_InteractiveObject)& Current() const + { + return myCurrent; + } - if(HaveToSet) - TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) ); - else - TheAISContext()->UnsetColor(ashape); - } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { - Handle(NIS_Triangulated) ashape = - Handle(NIS_Triangulated)::DownCast (anObj); - if (!ashape.IsNull()) - ashape->SetColor (ViewerTest::GetColorFromName(argv[2])); + const Handle(Standard_Transient)& CurrentTrs() const + { + return myCurrentTrs; + } + + //! @return true if iterator points to valid object within collection + Standard_Boolean More() const + { + switch (mySource) + { + case IterSource_All: return myMapIter.More(); + case IterSource_List: return mySeqIter.More(); + case IterSource_Selected: return mySelIter->MoreCurrent(); + } + return Standard_False; + } + + //! Go to the next item. + void Next() + { + myCurrentName.Clear(); + myCurrentTrs.Nullify(); + myCurrent.Nullify(); + switch (mySource) + { + case IterSource_All: + { + myMapIter.Next(); + break; + } + case IterSource_List: + { + mySeqIter.Next(); + break; + } + case IterSource_Selected: + { + mySelIter->NextCurrent(); + break; } } + initCurrent(); + } +private: - //======================================================================= - // Il n'y a pas d'arguments - // Mais un ou plusieurs objets on des current representation - //======================================================================= - if (ThereIsCurrent && !ThereIsArgument) { - for (TheAISContext() -> InitCurrent() ; - TheAISContext() -> MoreCurrent() ; - TheAISContext() ->NextCurrent() ) + void initCurrent() + { + switch (mySource) + { + case IterSource_All: { - const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current(); - if (ashape.IsNull()) - continue; -#ifdef DEB - if (HaveToSet) - di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n"; - else - di << "HaveToSet 0\n"; -#endif - if(HaveToSet) - TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False); - else - TheAISContext()->UnsetColor(ashape,Standard_False); + if (myMapIter.More()) + { + myCurrentName = myMapIter.Key2(); + myCurrentTrs = myMapIter.Key1(); + myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs); + } + break; } - - TheAISContext()->UpdateCurrentViewer(); - } - - //======================================================================= - // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant - // on impose a tous les objets du viewer la couleur passee - //======================================================================= - else if (!ThereIsCurrent && !ThereIsArgument){ - ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS()); - while ( it.More() ) { - const Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast(it.Key1()); - if (!ashape.IsNull()) { - if(HaveToSet) - TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False); - else - TheAISContext()->UnsetColor(ashape,Standard_False); + case IterSource_List: + { + if (mySeqIter.More()) + { + if (!GetMapOfAIS().IsBound2 (mySeqIter.Value())) + { + std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n"; + return; + } + myCurrentName = mySeqIter.Value(); + myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value()); + myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs); + } + break; + } + case IterSource_Selected: + { + if (mySelIter->MoreCurrent()) + { + myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current()); + myCurrent = mySelIter->Current(); } - it.Next(); + break; } - TheAISContext()->UpdateCurrentViewer(); } } - return 0; -} + +private: + + enum IterSource + { + IterSource_All, + IterSource_List, + IterSource_Selected + }; + +private: + + Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected) + ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All) + NCollection_Sequence mySeq; + NCollection_Sequence::Iterator mySeqIter; + + TCollection_AsciiString myCurrentName;//!< current item name + Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object) + Handle(AIS_InteractiveObject) myCurrent; //!< current item + + IterSource mySource; //!< iterated collection + +}; //============================================================================== -//function : VTransparency -//Author : ege -//purpose : change the transparency of a selected or named or displayed shape -//Draw arg : vtransparency [name] TransparencyCoeficient +//function : VInteriorStyle +//purpose : sets interior style of the a selected or named or displayed shape //============================================================================== - -static int VTransparency (Draw_Interpretor& di, Standard_Integer argc, - const char** argv) +static int VSetInteriorStyle (Draw_Interpretor& theDI, + Standard_Integer theArgNb, + const char** theArgVec) { - Standard_Boolean ThereIsCurrent; - Standard_Boolean ThereIsArgument; - Standard_Boolean IsBound = Standard_False ; - - const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0); - if (HaveToSet) { - if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } - ThereIsArgument = (argc != 2); - } - else{ - if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; } - ThereIsArgument = (argc == 2); + const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); + if (aCtx.IsNull()) + { + std::cerr << "Error: no active view!\n"; + return 1; } - if ( !a3DView().IsNull() ) { - TCollection_AsciiString name; - if (ThereIsArgument) { - name = argv[1]; - IsBound= GetMapOfAIS().IsBound2(name); + ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto; + Standard_Integer anArgIter = 1; + for (; anArgIter < theArgNb; ++anArgIter) + { + if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate)) + { + break; } - if (TheAISContext()->HasOpenedContext()) - TheAISContext()->CloseLocalContext(); + } + TCollection_AsciiString aName; + if (theArgNb - anArgIter == 2) + { + aName = theArgVec[anArgIter++]; + } + else if (theArgNb - anArgIter != 1) + { + std::cout << "Error: wrong number of arguments! See usage:\n"; + theDI.PrintHelp (theArgVec[0]); + return 1; + } + Standard_Integer anInterStyle = Aspect_IS_SOLID; + TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]); + aStyleArg.LowerCase(); + if (aStyleArg == "empty") + { + anInterStyle = 0; + } + else if (aStyleArg == "hollow") + { + anInterStyle = 1; + } + else if (aStyleArg == "hatch") + { + anInterStyle = 2; + } + else if (aStyleArg == "solid") + { + anInterStyle = 3; + } + else if (aStyleArg == "hiddenline") + { + anInterStyle = 4; + } + else + { + anInterStyle = aStyleArg.IntegerValue(); + } + if (anInterStyle < Aspect_IS_EMPTY + || anInterStyle > Aspect_IS_HIDDENLINE) + { + std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), " + << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n"; + return 1; + } - if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; } - else ThereIsCurrent = Standard_False; + if (!aName.IsEmpty() + && !GetMapOfAIS().IsBound2 (aName)) + { + std::cout << "Error: object " << aName << " is not displayed!\n"; + return 1; + } - //======================================================================= - // Il y a des arguments: un nom et une couleur - //======================================================================= - if ( ThereIsArgument && IsBound ) { - const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); - if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { - const Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast(anObj); - if(HaveToSet) - TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) ); - else - TheAISContext()->UnsetTransparency(ashape); - } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { - const Handle(NIS_InteractiveObject) ashape = - Handle(NIS_InteractiveObject)::DownCast(anObj); - if(HaveToSet) - ashape->SetTransparency(Draw::Atof(argv[2]) ); - else - ashape->UnsetTransparency(); - } + if (aCtx->HasOpenedContext()) + { + aCtx->CloseLocalContext(); + } + for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anIO = anIter.Current(); + if (!anIO.IsNull()) + { + const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes(); + Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect(); + Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect(); + aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle); + aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True); } - //======================================================================= - // Il n'y a pas d'arguments - // Mais un ou plusieurs objets on des current representation - //======================================================================= - if (ThereIsCurrent && !ThereIsArgument) { - for (TheAISContext() -> InitCurrent() ; - TheAISContext() -> MoreCurrent() ; - TheAISContext() ->NextCurrent() ) - { - Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current(); - if(HaveToSet) - TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False); - else - TheAISContext()->UnsetTransparency(ashape,Standard_False); - } + } - TheAISContext()->UpdateCurrentViewer(); - } - //======================================================================= - // Il n'y a pas d'arguments ET aucun objet courrant - //======================================================================= - else if ( !ThereIsCurrent && !ThereIsArgument ) { - ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName - it(GetMapOfAIS()); - while ( it.More() ) { - Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast(it.Key1()); - if (!ashape.IsNull()) { - if(HaveToSet) - TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False); - else - TheAISContext()->UnsetTransparency(ashape,Standard_False); - } - it.Next(); - } - TheAISContext()->UpdateCurrentViewer(); - } + // update the screen and redraw the view + const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False); + a3DView()->SetImmediateUpdate (isAutoUpdate); + if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress) + || aToUpdate == ViewerTest_RM_RedrawForce) + { + TheAISContext()->UpdateCurrentViewer(); } return 0; } - -//============================================================================== -//function : VMaterial -//Author : ege -//purpose : change the Material of a selected or named or displayed shape -//Draw arg : vmaterial [Name] Material -//============================================================================== -static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +//! Auxiliary structure for VAspects +struct ViewerTest_AspectsChangeSet { - - Standard_Boolean ThereIsCurrent; - Standard_Boolean ThereIsName; - Standard_Boolean IsBound = Standard_False ; - - const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0); - if (HaveToSet) { - if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } - ThereIsName = (argc != 2); - } - else { - if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; } - ThereIsName = (argc == 2); + Standard_Integer ToSetColor; + Quantity_Color Color; + + Standard_Integer ToSetLineWidth; + Standard_Real LineWidth; + + Standard_Integer ToSetTransparency; + Standard_Real Transparency; + + Standard_Integer ToSetMaterial; + Graphic3d_NameOfMaterial Material; + TCollection_AsciiString MatName; + + NCollection_Sequence SubShapes; + + //! Empty constructor + ViewerTest_AspectsChangeSet() + : ToSetColor (0), + Color (DEFAULT_COLOR), + ToSetLineWidth (0), + LineWidth (1.0), + ToSetTransparency (0), + Transparency (0.0), + ToSetMaterial (0), + Material (Graphic3d_NOM_DEFAULT) {} + + //! @return true if no changes have been requested + Standard_Boolean IsEmpty() const + { + return ToSetLineWidth == 0 + && ToSetTransparency == 0 + && ToSetColor == 0 + && ToSetMaterial == 0; } - if ( !a3DView().IsNull() ) { - TCollection_AsciiString name; - if (ThereIsName) { - name = argv[1]; - IsBound= GetMapOfAIS().IsBound2(name); + //! @return true if properties are valid + Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const + { + Standard_Boolean isOk = Standard_True; + if (LineWidth <= 0.0 + || LineWidth > 10.0) + { + std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n"; + isOk = Standard_False; } - if (TheAISContext()->HasOpenedContext()) - TheAISContext()->CloseLocalContext(); - if (TheAISContext() -> NbCurrents() > 0 ) - ThereIsCurrent =Standard_True; - else - ThereIsCurrent =Standard_False; - - //======================================================================= - // Ther is a name of shape and a material name - //======================================================================= - if ( ThereIsName && IsBound ) { - Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name)); - if (!ashape.IsNull()) { - if (HaveToSet) - TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2])); - else - TheAISContext()->UnsetMaterial(ashape); - } + if (Transparency < 0.0 + || Transparency > 1.0) + { + std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n"; + isOk = Standard_False; } - //======================================================================= - // Il n'y a pas de nom de shape - // Mais un ou plusieurs objets on des current representation - //======================================================================= - if (ThereIsCurrent && !ThereIsName) { - for (TheAISContext() -> InitCurrent() ; - TheAISContext() -> MoreCurrent() ; - TheAISContext() ->NextCurrent() ) - { - Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current(); - if (HaveToSet) - TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False); - else - TheAISContext()->UnsetMaterial(ashape,Standard_False); - } - TheAISContext()->UpdateCurrentViewer(); - } - - //======================================================================= - // Il n'y a pas de noms de shape ET aucun objet courrant - // On impose a tous les objets du viewer le material passe en argument - //======================================================================= - else if (!ThereIsCurrent && !ThereIsName){ - ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName - it(GetMapOfAIS()); - while ( it.More() ) { - Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast (it.Key1()); - if (!ashape.IsNull()) { - if (HaveToSet) - TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False); - else - TheAISContext()->UnsetMaterial(ashape,Standard_False); - } - it.Next(); - } - TheAISContext()->UpdateCurrentViewer(); + if (theIsSubPart + && ToSetTransparency) + { + std::cout << "Error: the transparency can not be defined for sub-part of object!\n"; + isOk = Standard_False; } + if (ToSetMaterial == 1 + && Material == Graphic3d_NOM_DEFAULT) + { + std::cout << "Error: unknown material " << MatName << ".\n"; + isOk = Standard_False; + } + return isOk; } - return 0; -} - +}; //============================================================================== -//function : VWidth -//Author : ege -//purpose : change the width of the edges of a selected or named or displayed shape -//Draw arg : vwidth [Name] WidthValue(1->10) +//function : VAspects +//purpose : //============================================================================== -static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, + Standard_Integer theArgNb, + const char** theArgVec) { + TCollection_AsciiString aCmdName (theArgVec[0]); + const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); + if (aCtx.IsNull()) + { + std::cerr << "Error: no active view!\n"; + return 1; + } + + ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto; + Standard_Integer anArgIter = 1; + NCollection_Sequence aNames; + for (; anArgIter < theArgNb; ++anArgIter) + { + TCollection_AsciiString anArg = theArgVec[anArgIter]; + if (parseRedrawMode (anArg, aToUpdate)) + { + continue; + } + else if (!anArg.IsEmpty() + && anArg.Value (1) != '-') + { + aNames.Append (anArg); + } + else + { + break; + } + } - Standard_Boolean ThereIsCurrent; - Standard_Boolean ThereIsArgument; - Standard_Boolean IsBound = Standard_False ; + NCollection_Sequence aChanges; + aChanges.Append (ViewerTest_AspectsChangeSet()); + ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast(); - const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0); - if (HaveToSet) { - if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } - ThereIsArgument = (argc != 2); + // parse syntax of legacy commands + if (aCmdName == "vsetwidth") + { + if (aNames.IsEmpty() + || !aNames.Last().IsRealValue()) + { + std::cout << "Error: not enough arguments!\n"; + return 1; + } + aChangeSet->ToSetLineWidth = 1; + aChangeSet->LineWidth = aNames.Last().RealValue(); + aNames.Remove (aNames.Length()); } - else { - if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; } - ThereIsArgument = (argc == 2); + else if (aCmdName == "vunsetwidth") + { + aChangeSet->ToSetLineWidth = -1; } - if ( !a3DView().IsNull() ) { - TCollection_AsciiString name; - if (ThereIsArgument) { - name = argv[1]; - IsBound= GetMapOfAIS().IsBound2(name); + else if (aCmdName == "vsetcolor") + { + if (aNames.IsEmpty()) + { + std::cout << "Error: not enough arguments!\n"; + return 1; } - if (TheAISContext()->HasOpenedContext()) - TheAISContext()->CloseLocalContext(); - - if (TheAISContext() -> NbCurrents() > 0 ) - ThereIsCurrent =Standard_True; - else - ThereIsCurrent =Standard_False; + aChangeSet->ToSetColor = 1; + aChangeSet->Color = ViewerTest::GetColorFromName (aNames.Last().ToCString()); + aNames.Remove (aNames.Length()); + } + else if (aCmdName == "vunsetcolor") + { + aChangeSet->ToSetColor = -1; + } + else if (aCmdName == "vsettransparency") + { + if (aNames.IsEmpty() + || !aNames.Last().IsRealValue()) + { + std::cout << "Error: not enough arguments!\n"; + return 1; + } + aChangeSet->ToSetTransparency = 1; + aChangeSet->Transparency = aNames.Last().RealValue(); + aNames.Remove (aNames.Length()); + } + else if (aCmdName == "vunsettransparency") + { + aChangeSet->ToSetTransparency = -1; + } + else if (aCmdName == "vsetmaterial") + { + if (aNames.IsEmpty()) + { + std::cout << "Error: not enough arguments!\n"; + return 1; + } + aChangeSet->ToSetMaterial = 1; + aChangeSet->MatName = aNames.Last(); + aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString()); + aNames.Remove (aNames.Length()); + } + else if (aCmdName == "vunsetmaterial") + { + aChangeSet->ToSetMaterial = -1; + } + else if (anArgIter >= theArgNb) + { + std::cout << "Error: not enough arguments!\n"; + return 1; + } - if ( ThereIsArgument && IsBound ) { - const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); - if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { - const Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); - if (HaveToSet) - TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) ); - else - TheAISContext()->UnsetWidth (ashape); - } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { - const Handle(NIS_Triangulated) ashape = - Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name)); - if (HaveToSet && !ashape.IsNull()) - ashape->SetLineWidth ( Draw::Atof (argv[2]) ); + if (!aChangeSet->IsEmpty()) + { + anArgIter = theArgNb; + } + for (; anArgIter < theArgNb; ++anArgIter) + { + TCollection_AsciiString anArg = theArgVec[anArgIter]; + anArg.LowerCase(); + if (anArg == "-setwidth" + || anArg == "-setlinewidth") + { + if (++anArgIter >= theArgNb) + { + std::cout << "Error: wrong syntax at " << anArg << "\n"; + return 1; } + aChangeSet->ToSetLineWidth = 1; + aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]); } - - //======================================================================= - // Il n'y a pas d'arguments - // Mais un ou plusieurs objets on des current representation - //======================================================================= - if (ThereIsCurrent && !ThereIsArgument) { - for (TheAISContext() -> InitCurrent() ; - TheAISContext() -> MoreCurrent() ; - TheAISContext() ->NextCurrent() ) + else if (anArg == "-unsetwidth" + || anArg == "-unsetlinewidth") + { + aChangeSet->ToSetLineWidth = -1; + aChangeSet->LineWidth = 1.0; + } + else if (anArg == "-settransp" + || anArg == "-settransparancy") + { + if (++anArgIter >= theArgNb) { - Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current(); - if (HaveToSet) - TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False); - else - TheAISContext()->UnsetWidth(ashape,Standard_False); + std::cout << "Error: wrong syntax at " << anArg << "\n"; + return 1; } - TheAISContext()->UpdateCurrentViewer(); - } - //======================================================================= - // Il n'y a pas d'arguments ET aucun objet courrant - //======================================================================= - else if (!ThereIsCurrent && !ThereIsArgument){ - ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName - it(GetMapOfAIS()); - while ( it.More() ) { - Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast (it.Key1()); - if (!ashape.IsNull()) { - if (HaveToSet) - TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False); - else - TheAISContext()->UnsetWidth(ashape,Standard_False); + aChangeSet->ToSetTransparency = 1; + aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]); + if (aChangeSet->Transparency >= 0.0 + && aChangeSet->Transparency <= Precision::Confusion()) + { + aChangeSet->ToSetTransparency = -1; + aChangeSet->Transparency = 0.0; + } + } + else if (anArg == "-setalpha") + { + if (++anArgIter >= theArgNb) + { + std::cout << "Error: wrong syntax at " << anArg << "\n"; + return 1; + } + aChangeSet->ToSetTransparency = 1; + aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]); + if (aChangeSet->Transparency < 0.0 + || aChangeSet->Transparency > 1.0) + { + std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n"; + return 1; + } + aChangeSet->Transparency = 1.0 - aChangeSet->Transparency; + if (aChangeSet->Transparency >= 0.0 + && aChangeSet->Transparency <= Precision::Confusion()) + { + aChangeSet->ToSetTransparency = -1; + aChangeSet->Transparency = 0.0; + } + } + else if (anArg == "-unsettransp" + || anArg == "-unsettransparancy" + || anArg == "-unsetalpha" + || anArg == "-opaque") + { + aChangeSet->ToSetTransparency = -1; + aChangeSet->Transparency = 0.0; + } + else if (anArg == "-setcolor") + { + if (++anArgIter >= theArgNb) + { + std::cout << "Error: wrong syntax at " << anArg << "\n"; + return 1; + } + aChangeSet->ToSetColor = 1; + aChangeSet->Color = ViewerTest::GetColorFromName (theArgVec[anArgIter]); + } + else if (anArg == "-unsetcolor") + { + aChangeSet->ToSetColor = -1; + aChangeSet->Color = DEFAULT_COLOR; + } + else if (anArg == "-setmat" + || anArg == "-setmaterial") + { + if (++anArgIter >= theArgNb) + { + std::cout << "Error: wrong syntax at " << anArg << "\n"; + return 1; + } + aChangeSet->ToSetMaterial = 1; + aChangeSet->MatName = theArgVec[anArgIter]; + aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString()); + } + else if (anArg == "-unsetmat" + || anArg == "-unsetmaterial") + { + aChangeSet->ToSetMaterial = -1; + aChangeSet->Material = Graphic3d_NOM_DEFAULT; + } + else if (anArg == "-subshape" + || anArg == "-subshapes") + { + if (aNames.IsEmpty()) + { + std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n"; + return 1; + } + + aChanges.Append (ViewerTest_AspectsChangeSet()); + aChangeSet = &aChanges.ChangeLast(); + + for (++anArgIter; anArgIter < theArgNb; ++anArgIter) + { + Standard_CString aSubShapeName = theArgVec[anArgIter]; + if (*aSubShapeName == '-') + { + --anArgIter; + break; } - it.Next(); - } - TheAISContext()->UpdateCurrentViewer(); - } - } - return 0; -} -//============================================================================== -//function : VInteriorStyle -//purpose : sets interior style of the a selected or named or displayed shape -//Draw arg : vsetinteriorstyle [shape] style -//============================================================================== -static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO, - const Standard_Integer theStyle, - Draw_Interpretor& di) -{ - if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) { - di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE << - " (Aspect_IS_HIDDENLINE)]\n"; - return; - } - const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes(); - Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect(); - Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect(); - Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle); - aFillAspect->SetInteriorStyle (aStyle); - TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/); -} + TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName); + if (aSubShape.IsNull()) + { + std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n"; + return 1; + } + aChangeSet->SubShapes.Append (aSubShape); + } -static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv) -{ - if (argc < 2 || argc > 3) { - di << argv[0] << " requires 2 or 3 arguments\n"; - di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n"; - di << "Style must match Aspect_InteriorStyle and be one of:\n"; - di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n"; - return 1; + if (aChangeSet->SubShapes.IsEmpty()) + { + std::cerr << "Error: empty list is specified after -subshapes!\n"; + return 1; + } + } + else if (anArg == "-unset") + { + aChangeSet->ToSetLineWidth = -1; + aChangeSet->LineWidth = 1.0; + aChangeSet->ToSetTransparency = -1; + aChangeSet->Transparency = 0.0; + aChangeSet->ToSetColor = -1; + aChangeSet->Color = DEFAULT_COLOR; + aChangeSet->ToSetMaterial = -1; + aChangeSet->Material = Graphic3d_NOM_DEFAULT; + } + else + { + std::cout << "Error: wrong syntax at " << anArg << "\n"; + return 1; + } } - Standard_Boolean ThereIsCurrent; - Standard_Boolean ThereIsArgument; - Standard_Boolean IsBound = Standard_False ; + Standard_Boolean isFirst = Standard_True; + for (NCollection_Sequence::Iterator aChangesIter (aChanges); + aChangesIter.More(); aChangesIter.Next()) + { + if (!aChangesIter.Value().Validate (!isFirst)) + { + return 1; + } + isFirst = Standard_False; + } - ThereIsArgument = (argc > 2); - if ( !a3DView().IsNull() ) { - TCollection_AsciiString name; - if (ThereIsArgument) { - name = argv[1]; - IsBound= GetMapOfAIS().IsBound2(name); + if (aCtx->HasOpenedContext()) + { + aCtx->CloseLocalContext(); + } + for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next()) + { + const TCollection_AsciiString& aName = aPrsIter.CurrentName(); + Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current(); + Handle(AIS_ColoredShape) aColoredPrs; + Standard_Boolean toDisplay = Standard_False; + if (aChanges.Length() > 1) + { + Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs); + if (aShapePrs.IsNull()) + { + std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n"; + return 1; + } + aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs); + if (aColoredPrs.IsNull()) + { + aColoredPrs = new AIS_ColoredShape (aShapePrs); + aCtx->Remove (aShapePrs, Standard_False); + GetMapOfAIS().UnBind2 (aName); + GetMapOfAIS().Bind (aColoredPrs, aName); + toDisplay = Standard_True; + aShapePrs = aColoredPrs; + aPrs = aColoredPrs; + } } - if (TheAISContext()->HasOpenedContext()) - TheAISContext()->CloseLocalContext(); - if (TheAISContext() -> NbCurrents() > 0 ) - ThereIsCurrent =Standard_True; - else - ThereIsCurrent =Standard_False; + if (!aPrs.IsNull()) + { + NCollection_Sequence::Iterator aChangesIter (aChanges); + aChangeSet = &aChangesIter.ChangeValue(); + if (aChangeSet->ToSetMaterial == 1) + { + aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False); + } + else if (aChangeSet->ToSetMaterial == -1) + { + aCtx->UnsetMaterial (aPrs, Standard_False); + } + if (aChangeSet->ToSetColor == 1) + { + aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False); + } + else if (aChangeSet->ToSetColor == -1) + { + aCtx->UnsetColor (aPrs, Standard_False); + } + if (aChangeSet->ToSetTransparency == 1) + { + aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False); + } + else if (aChangeSet->ToSetTransparency == -1) + { + aCtx->UnsetTransparency (aPrs, Standard_False); + } + if (aChangeSet->ToSetLineWidth == 1) + { + aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False); + } + else if (aChangeSet->ToSetLineWidth == -1) + { + aCtx->UnsetWidth (aPrs, Standard_False); + } - if ( ThereIsArgument && IsBound ) { - const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); - if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { - const Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); - SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di); + for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next()) + { + aChangeSet = &aChangesIter.ChangeValue(); + for (NCollection_Sequence::Iterator aSubShapeIter (aChangeSet->SubShapes); + aSubShapeIter.More(); aSubShapeIter.Next()) + { + const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); + if (aChangeSet->ToSetColor == 1) + { + aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color); + } + if (aChangeSet->ToSetLineWidth == 1) + { + aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth); + } + if (aChangeSet->ToSetColor == -1 + || aChangeSet->ToSetLineWidth == -1) + { + aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True); + } + } } - } - //======================================================================= - // No arguments specified - // But there are one or more selected objects - //======================================================================= - if (ThereIsCurrent && !ThereIsArgument) { - for (TheAISContext() -> InitCurrent() ; - TheAISContext() -> MoreCurrent() ; - TheAISContext() ->NextCurrent() ) + if (toDisplay) + { + aCtx->Display (aPrs, Standard_False); + } + else if (!aColoredPrs.IsNull()) { - Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current(); - SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di); + aColoredPrs->Redisplay(); } } - //======================================================================= - // No arguments specified and there are no selected objects - //======================================================================= - else if (!ThereIsCurrent && !ThereIsArgument){ - ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName - it(GetMapOfAIS()); - while ( it.More() ) { - Handle(AIS_InteractiveObject) ashape = - Handle(AIS_InteractiveObject)::DownCast (it.Key1()); - if (!ashape.IsNull()) - SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di); - it.Next(); + else + { + Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs()); + Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj); + if (!aNisObj.IsNull()) + { + if (aChangeSet->ToSetTransparency != 0) + { + aNisObj->SetTransparency (aChangeSet->Transparency); + } + } + if (!aNisTri.IsNull()) + { + if (aChangeSet->ToSetColor != 0) + { + aNisTri->SetColor (aChangeSet->Color); + } + if (aChangeSet->ToSetLineWidth != 0) + { + aNisTri->SetLineWidth (aChangeSet->LineWidth); + } } } + } + + // update the screen and redraw the view + const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False); + a3DView()->SetImmediateUpdate (isAutoUpdate); + if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress) + || aToUpdate == ViewerTest_RM_RedrawForce) + { TheAISContext()->UpdateCurrentViewer(); } return 0; @@ -3878,46 +4120,67 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects", __FILE__,VSubInt,group); + theCommands.Add("vaspects", + "vaspects [-noupdate|-update] [name1 [name2 [...]]]" + "\n\t\t: [-setcolor ColorName] [-unsetcolor]" + "\n\t\t: [-setmaterial MatName] [-unsetmaterial]" + "\n\t\t: [-settransparency Transp] [-unsettransparancy]" + "\n\t\t: [-setwidth LineWidth] [-unsetwidth]" + "\n\t\t: [-subshapes subname1 [subname2 [...]]]" + "\n\t\t: Manage presentation properties of all, selected or named objects." + "\n\t\t: When -subshapes is specified than following properties will be" + "\n\t\t: assigned to specified sub-shapes.", + __FILE__,VAspects,group); + theCommands.Add("vsetcolor", - "vsetcolor [name] ColorName" - "\n\t\t: Sets color for all, selected or named objects.", - __FILE__,VColor2,group); + "vsetcolor [-noupdate|-update] [name] ColorName" + "\n\t\t: Sets color for all, selected or named objects." + "\n\t\t: Alias for vaspects -setcolor [name] ColorName.", + __FILE__,VAspects,group); theCommands.Add("vunsetcolor", - "vunsetcolor [name]" - "\n\t\t: Resets color for all, selected or named objects.", - __FILE__,VColor2,group); + "vunsetcolor [-noupdate|-update] [name]" + "\n\t\t: Resets color for all, selected or named objects." + "\n\t\t: Alias for vaspects -unsetcolor [name].", + __FILE__,VAspects,group); theCommands.Add("vsettransparency", - "vsettransparency [name] Coefficient" + "vsettransparency [-noupdate|-update] [name] Coefficient" "\n\t\t: Sets transparency for all, selected or named objects." - "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).", - __FILE__,VTransparency,group); + "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)." + "\n\t\t: Alias for vaspects -settransp [name] Coefficient.", + __FILE__,VAspects,group); theCommands.Add("vunsettransparency", - "vunsettransparency [name]" - "\n\t\t: Resets transparency for all, selected or named objects.", - __FILE__,VTransparency,group); + "vunsettransparency [-noupdate|-update] [name]" + "\n\t\t: Resets transparency for all, selected or named objects." + "\n\t\t: Alias for vaspects -unsettransp [name].", + __FILE__,VAspects,group); theCommands.Add("vsetmaterial", - "vmaterial : vmaterial [name of shape] MaterialName", - __FILE__,VMaterial,group); + "vsetmaterial [-noupdate|-update] [name] MaterialName" + "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.", + __FILE__,VAspects,group); theCommands.Add("vunsetmaterial", - "vmaterial : vmaterial [name of shape]", - __FILE__,VMaterial,group); + "vunsetmaterial [-noupdate|-update] [name]" + "\n\t\t: Alias for vaspects -unsetmaterial [name].", + __FILE__,VAspects,group); theCommands.Add("vsetwidth", - "vsetwidth : vwidth [name of shape] width(0->10)", - __FILE__,VWidth,group); + "vsetwidth [-noupdate|-update] [name] width(0->10)" + "\n\t\t: Alias for vaspects -setwidth [name] width.", + __FILE__,VAspects,group); theCommands.Add("vunsetwidth", - "vunsetwidth : vwidth [name of shape]", - __FILE__,VWidth,group); + "vunsetwidth [-noupdate|-update] [name]" + "\n\t\t: Alias for vaspects -unsetwidth [name] width.", + __FILE__,VAspects,group); theCommands.Add("vsetinteriorstyle", - "vsetinteriorstyle : vsetinteriorstyle [name of shape] style", - __FILE__,VInteriorStyle,group); + "vsetinteriorstyle [-noupdate|-update] [name] style" + "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.", + __FILE__,VSetInteriorStyle,group); theCommands.Add("vardis", "vardis : display activeareas", diff --git a/tests/bugs/vis/bug24762_coloredshape b/tests/bugs/vis/bug24762_coloredshape new file mode 100644 index 0000000000..c126609666 --- /dev/null +++ b/tests/bugs/vis/bug24762_coloredshape @@ -0,0 +1,48 @@ +puts "========" +puts "OCC24762 new interactive object AIS_ColoredShape with customized subshapes presentations" +puts "========" + +# draw box in advance which should fit all our markers +box b 0 0 0 1 2 3 +box bb 3 0 0 2 3 1 + +# prepare view +vinit View1 +vclear +vglinfo +vsetdispmode 1 +vaxo +vdisplay b bb +vfit + +# customize box 1 +explode b V +vaspects b -subshapes b_1 -setcolor GREEN +explode b E +vaspects b -subshapes b_6 b_12 -setcolor RED -setwidth 6 +explode b W +vaspects b -subshapes b_2 -setcolor HOTPINK -setwidth 4 +explode b F +vaspects b -subshapes b_3 -setcolor GRAY + +# customize box 2 +explode bb F +vaspects bb -setcolor GREEN -subshapes bb_6 -setcolor RED +vsetdispmode bb 0 + +# take snapshot +vdump $imagedir/${casename}.png + +# check colors on box 1 +set aWireColor [vreadpixel 54 150 rgb name] +set anEdgeColor [vreadpixel 100 90 rgb name] +set aFaceColor [vreadpixel 30 200 rgb name] +if {"$aWireColor" != "HOTPINK"} { + puts "Error: wrong Wire color" +} +if {"$anEdgeColor" != "RED"} { + puts "Error: wrong Edge color" +} +if {"$aFaceColor" != "LEMONCHIFFON1"} { + puts "Error: wrong Face color" +} -- 2.20.1