From aee5a1b3f62360f6eedeb5213df57603e33b92ca Mon Sep 17 00:00:00 2001 From: ema Date: Tue, 4 Apr 2017 13:39:39 +0300 Subject: [PATCH] Storage the parts transparency in the view --- src/XCAFDoc/XCAFDoc.cxx | 10 ++++ src/XCAFDoc/XCAFDoc.hxx | 3 ++ src/XCAFDoc/XCAFDoc_View.cxx | 25 +++++++++- src/XCAFDoc/XCAFDoc_ViewTool.cxx | 83 ++++++++++++++++++++++++++++++++ src/XCAFDoc/XCAFDoc_ViewTool.hxx | 11 ++++- src/XCAFView/XCAFView_Object.cxx | 2 + src/XCAFView/XCAFView_Object.hxx | 39 +++++++++++++++ 7 files changed, 170 insertions(+), 3 deletions(-) diff --git a/src/XCAFDoc/XCAFDoc.cxx b/src/XCAFDoc/XCAFDoc.cxx index 37490006d5..7e0e91614e 100644 --- a/src/XCAFDoc/XCAFDoc.cxx +++ b/src/XCAFDoc/XCAFDoc.cxx @@ -250,6 +250,16 @@ Standard_GUID XCAFDoc::ViewRefPlaneGUID() return ID; } +//======================================================================= +//function : ViewRefPlaneGUID +//purpose : +//======================================================================= + +Standard_GUID XCAFDoc::ViewRefEnabledShapesGUID() +{ + static Standard_GUID ID("efd213e4-6dfd-11d4-b9c8-0060b0ee281b"); + return ID; +} //======================================================================= //function : LockGUID //purpose : diff --git a/src/XCAFDoc/XCAFDoc.hxx b/src/XCAFDoc/XCAFDoc.hxx index 9532983eb1..3eb79afe3c 100644 --- a/src/XCAFDoc/XCAFDoc.hxx +++ b/src/XCAFDoc/XCAFDoc.hxx @@ -120,6 +120,9 @@ public: //! Return GUIDs for TreeNode representing specified types of View Standard_EXPORT static Standard_GUID ViewRefPlaneGUID(); + + //! Return GUIDs for TreeNode representing specified types of View + Standard_EXPORT static Standard_GUID ViewRefEnabledShapesGUID(); //! Returns GUID for UAttribute identifying lock flag Standard_EXPORT static Standard_GUID LockGUID(); diff --git a/src/XCAFDoc/XCAFDoc_View.cxx b/src/XCAFDoc/XCAFDoc_View.cxx index 714376ab00..5531cf132c 100644 --- a/src/XCAFDoc/XCAFDoc_View.cxx +++ b/src/XCAFDoc/XCAFDoc_View.cxx @@ -46,7 +46,8 @@ enum ChildLab ChildLab_BackPlaneDistance, ChildLab_ViewVolumeSidesClipping, ChildLab_GDTPoints, - ChildLab_Image + ChildLab_Image, + ChildLab_EnabledShapes }; //======================================================================= @@ -155,6 +156,15 @@ void XCAFDoc_View::SetObject (const Handle(XCAFView_Object)& theObject) arr->SetValue(i, image->Value(i)); } } + //shapes transparency + if (theObject->HasEnabledShapes()) + { + TDF_Label aShapeTranspLabel = Label().FindChild(ChildLab_EnabledShapes); + for (Standard_Integer i = 1; i <= theObject->NbEnabledShapes(); i++) { + Standard_Integer aValue = theObject->EnabledShape(i) ? 1 : 0; + TDataStd_Integer::Set(aShapeTranspLabel.FindChild(i), aValue); + } + } } //======================================================================= @@ -263,6 +273,19 @@ Handle(XCAFView_Object) XCAFDoc_View::GetObject() const if (Label().FindChild(ChildLab_Image).FindAttribute(TDataStd_ByteArray::GetID(), anArr)) { anObj->SetImage(anArr->InternalArray()); } + + // Shapes transparency + if (!Label().FindChild(ChildLab_EnabledShapes, Standard_False).IsNull()) { + TDF_Label aShapesTranspLabel = Label().FindChild(ChildLab_EnabledShapes); + anObj->CreateEnabledShapes(aShapesTranspLabel.NbChildren()); + for (Standard_Integer i = 1; i <= aShapesTranspLabel.NbChildren(); i++) { + gp_Pnt aPoint; + Handle(TDataStd_Integer) aTranspAttr; + aShapesTranspLabel.FindChild(i).FindAttribute(TDataStd_Integer::GetID(), aTranspAttr); + Standard_Boolean aValue = (aTranspAttr->Get() == 1); + anObj->SetEnabledShape(i, aValue); + } + } return anObj; } diff --git a/src/XCAFDoc/XCAFDoc_ViewTool.cxx b/src/XCAFDoc/XCAFDoc_ViewTool.cxx index 583292f714..9a5741f936 100644 --- a/src/XCAFDoc/XCAFDoc_ViewTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ViewTool.cxx @@ -318,6 +318,46 @@ void XCAFDoc_ViewTool::SetClippingPlanes(const TDF_LabelSequence& theClippingPla aChGNode->SetFather(aPlaneGNode); } } +//======================================================================= +//function : SetEnabledShapes +//purpose : +//======================================================================= +void XCAFDoc_ViewTool::SetEnabledShapes(const TDF_LabelSequence& theShapesTransparencyLabels, + const TDF_Label& theViewL) const +{ + if (!IsView(theViewL)) + return; + + Handle(XCAFDoc_GraphNode) aChGNode; + Handle(XCAFDoc_GraphNode) aPlaneGNode; + + if (theViewL.FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aChGNode)) { + while (aChGNode->NbFathers() > 0) { + aPlaneGNode = aChGNode->GetFather(1); + aPlaneGNode->UnSetChild(aChGNode); + if (aPlaneGNode->NbChildren() == 0) + aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefEnabledShapesGUID()); + } + theViewL.ForgetAttribute(XCAFDoc::ViewRefEnabledShapesGUID()); + } + + + if (!theViewL.FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aChGNode) && theShapesTransparencyLabels.Length() > 0) { + aChGNode = new XCAFDoc_GraphNode; + aChGNode = XCAFDoc_GraphNode::Set(theViewL); + aChGNode->SetGraphID(XCAFDoc::ViewRefEnabledShapesGUID()); + } + for (Standard_Integer i = theShapesTransparencyLabels.Lower(); i <= theShapesTransparencyLabels.Upper(); i++) + { + if (!theShapesTransparencyLabels.Value(i).FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aPlaneGNode)) { + aPlaneGNode = new XCAFDoc_GraphNode; + aPlaneGNode = XCAFDoc_GraphNode::Set(theShapesTransparencyLabels.Value(i)); + } + aPlaneGNode->SetGraphID(XCAFDoc::ViewRefEnabledShapesGUID()); + aPlaneGNode->SetChild(aChGNode); + aChGNode->SetFather(aPlaneGNode); + } +} //======================================================================= //function : GetRefShapeLabel @@ -391,6 +431,30 @@ Standard_Boolean XCAFDoc_ViewTool::GetRefClippingPlaneLabel(const TDF_Label& the return Standard_True; } +//======================================================================= +//function : GetRefEnabledShapesLabel +//purpose : +//======================================================================= +Standard_Boolean XCAFDoc_ViewTool::GetRefEnabledShapesLabel(const TDF_Label& theViewL, + TDF_LabelSequence& theShapesTranspanencyLabels) const +{ + theShapesTranspanencyLabels.Clear(); + Handle(TDataStd_TreeNode) aNode; + if (!theViewL.FindAttribute(XCAFDoc::ViewRefGUID(), aNode) || !aNode->HasFather()) { + Handle(XCAFDoc_GraphNode) aGNode; + if (theViewL.FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aGNode) && aGNode->NbFathers() > 0) { + for (Standard_Integer i = 1; i <= aGNode->NbFathers(); i++) + theShapesTranspanencyLabels.Append(aGNode->GetFather(i)->Label()); + return Standard_True; + } + else + return Standard_False; + } + + theShapesTranspanencyLabels.Append(aNode->Father()->Label()); + return Standard_True; +} + //======================================================================= //function : GetViewLabelsForShape //purpose : @@ -448,6 +512,25 @@ Standard_Boolean XCAFDoc_ViewTool::GetViewLabelsForClippingPlane(const TDF_Label return aResult; } +//======================================================================= +//function :GetViewLabelsForEnabledShapesLabel +//purpose : +//======================================================================= +Standard_Boolean XCAFDoc_ViewTool::GetViewLabelsForEnabledShapesLabel(const TDF_Label& theShapesTransparencyL, + TDF_LabelSequence& theViews) const +{ + Handle(XCAFDoc_GraphNode) aGNode; + Standard_Boolean aResult = Standard_False; + if (theShapesTransparencyL.FindAttribute(XCAFDoc::ViewRefPlaneGUID(), aGNode) && aGNode->NbChildren() > 0) { + for (Standard_Integer i = 1; i <= aGNode->NbChildren(); i++) + { + theViews.Append(aGNode->GetChild(i)->Label()); + } + aResult = Standard_True; + } + return aResult; +} + //======================================================================= //function : IsLocked //purpose : diff --git a/src/XCAFDoc/XCAFDoc_ViewTool.hxx b/src/XCAFDoc/XCAFDoc_ViewTool.hxx index df8b3efa5b..8e04874dda 100644 --- a/src/XCAFDoc/XCAFDoc_ViewTool.hxx +++ b/src/XCAFDoc/XCAFDoc_ViewTool.hxx @@ -78,9 +78,10 @@ public: //! Set Clipping planes to given View Standard_EXPORT void SetClippingPlanes(const TDF_LabelSequence& theClippingPlaneLabels, const TDF_Label& theViewL) const; - + Standard_EXPORT void SetEnabledShapes(const TDF_LabelSequence& theShapesTransparencyLabels, + const TDF_Label& theViewL) const; //! Returns all View labels defined for label ShapeL - Standard_EXPORT Standard_Boolean GetViewLabelsForShape (const TDF_Label& theShapeL, TDF_LabelSequence& theViews) const; + Standard_EXPORT Standard_Boolean GetViewLabelsForShape(const TDF_Label& theShapeL, TDF_LabelSequence& theViews) const; //! Returns all View labels defined for label GDTL Standard_EXPORT Standard_Boolean GetViewLabelsForGDT (const TDF_Label& theGDTL, TDF_LabelSequence& theViews) const; @@ -88,6 +89,9 @@ public: //! Returns all View labels defined for label ClippingPlaneL Standard_EXPORT Standard_Boolean GetViewLabelsForClippingPlane(const TDF_Label& theClippingPlaneL, TDF_LabelSequence& theViews) const; + //! Returns all View labels defined for label Shapes transparency + Standard_EXPORT Standard_Boolean GetViewLabelsForEnabledShapesLabel(const TDF_Label& theShapesTransparencyL, TDF_LabelSequence& theViews) const; + //! Adds a view definition to a View table and returns its label Standard_EXPORT TDF_Label AddView() ; @@ -103,6 +107,9 @@ public: //! Returns False if the theViewL is not in View table Standard_EXPORT Standard_Boolean GetRefClippingPlaneLabel(const TDF_Label& theViewL, TDF_LabelSequence& theClippingPlaneLabels) const; + //! Returns shapes transparency labels defined for label theViewL + //! Returns False if the theViewL is not in View table + Standard_EXPORT Standard_Boolean GetRefEnabledShapesLabel(const TDF_Label& theViewL, TDF_LabelSequence& theShapesTranspanencyLabels) const; //! Returns true if the given View is marked as locked Standard_EXPORT Standard_Boolean IsLocked(const TDF_Label& theViewL) const; diff --git a/src/XCAFView/XCAFView_Object.cxx b/src/XCAFView/XCAFView_Object.cxx index 3b7ea48f44..9421d1ace2 100644 --- a/src/XCAFView/XCAFView_Object.cxx +++ b/src/XCAFView/XCAFView_Object.cxx @@ -29,6 +29,7 @@ XCAFView_Object::XCAFView_Object() myViewVolumeSidesClipping = Standard_False; myGDTPoints = NULL; myImage = NULL; + myEnabledShapes = NULL; } //======================================================================= @@ -52,5 +53,6 @@ XCAFView_Object::XCAFView_Object(const Handle(XCAFView_Object)& theObj) myViewVolumeSidesClipping = theObj->myViewVolumeSidesClipping; myGDTPoints = NULL; myImage = theObj->myImage; + myEnabledShapes = NULL; } diff --git a/src/XCAFView/XCAFView_Object.hxx b/src/XCAFView/XCAFView_Object.hxx index a41f6df732..c02713dafb 100644 --- a/src/XCAFView/XCAFView_Object.hxx +++ b/src/XCAFView/XCAFView_Object.hxx @@ -27,6 +27,7 @@ #include #include #include +#include class XCAFView_Object; DEFINE_STANDARD_HANDLE(XCAFView_Object, Standard_Transient) @@ -233,6 +234,43 @@ public: { return (!myImage.IsNull()); } + + Standard_EXPORT void CreateEnabledShapes(const Standard_Integer theLenght) + { + if (theLenght > 0) + myEnabledShapes = new TColStd_HArray1OfBoolean(1, theLenght); + } + + Standard_EXPORT Standard_Boolean HasEnabledShapes() + { + return (!myEnabledShapes.IsNull()); + } + + Standard_EXPORT Standard_Integer NbEnabledShapes() + { + if (myEnabledShapes.IsNull()) + return 0; + return myEnabledShapes->Length(); + } + + Standard_EXPORT void SetEnabledShape(const Standard_Integer theIndex, const bool theVal) + { + if (myEnabledShapes.IsNull()) + return; + if (theIndex > 0 && theIndex <= myEnabledShapes->Length()) + myEnabledShapes->SetValue(theIndex, theVal); + } + + Standard_EXPORT bool EnabledShape(const Standard_Integer theIndex) + { + if (myEnabledShapes.IsNull()) + return Standard_False; + if (theIndex > 0 && theIndex <= myEnabledShapes->Length()) + return myEnabledShapes->Value(theIndex); + else + return Standard_False; + } + DEFINE_STANDARD_RTTIEXT(XCAFView_Object,Standard_Transient) private: @@ -253,6 +291,7 @@ private: Standard_Boolean myViewVolumeSidesClipping; Handle(TColgp_HArray1OfPnt) myGDTPoints; // Point for each GDT to describe position of GDT frame in View. Handle(TColStd_HArray1OfByte) myImage; + Handle(TColStd_HArray1OfBoolean) myEnabledShapes; }; #endif // _XCAFView_Object_HeaderFile