From 9b6b45a2a0788a02f245d2771bc92f6638c5a1af Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 27 Sep 2018 17:38:43 +0300 Subject: [PATCH] XCAFDoc/View fixes to store in the view: image, parts transparency, notes, notes positions (cherry picked from commit b050e0a15c06403adfa545ad793555491a0b6b9f) (cherry picked from commit 7099619e5d4f0c04e2c6827247a7c1050fd2711b) (cherry picked from commit ccd4b101f5ab18ab3518b9779e88d687e2db6ff1) # Conflicts: # src/XCAFDoc/XCAFDoc.cxx # src/XCAFDoc/XCAFDoc.hxx (cherry picked from commit a22653eb867815de9036e487a33a741dfb465d0b) (cherry picked from commit 9f130570964d5c0d38a0e3af23c0b83656210bed) (cherry picked from commit c00bcd15f1dd1c5f7ed28f948b5b172e6068871d) --- src/XCAFDoc/XCAFDoc.cxx | 15 +++- src/XCAFDoc/XCAFDoc.hxx | 4 + src/XCAFDoc/XCAFDoc_View.cxx | 62 ++++++++++++++- src/XCAFDoc/XCAFDoc_ViewTool.cxx | 127 ++++++++++++++++++++++++++++++- src/XCAFDoc/XCAFDoc_ViewTool.hxx | 12 +++ src/XCAFView/XCAFView_Object.cxx | 6 ++ src/XCAFView/XCAFView_Object.hxx | 93 +++++++++++++++++++++- 7 files changed, 312 insertions(+), 7 deletions(-) diff --git a/src/XCAFDoc/XCAFDoc.cxx b/src/XCAFDoc/XCAFDoc.cxx index d00a8d281a..719d675f77 100644 --- a/src/XCAFDoc/XCAFDoc.cxx +++ b/src/XCAFDoc/XCAFDoc.cxx @@ -272,13 +272,24 @@ const Standard_GUID& XCAFDoc::ViewRefPlaneGUID() } //======================================================================= -//function : ViewRefPlaneGUID +//function : ViewRefNoteGUID //purpose : //======================================================================= const Standard_GUID& XCAFDoc::ViewRefNoteGUID() { - static const Standard_GUID ID("C814ACC6-43AC-4812-9B2A-4E9A2A549354"); + static const Standard_GUID ID("efd213e2-6dfd-11d4-b9c8-0060b0ee281b"); + return ID; +} + +//======================================================================= +//function : ViewRefEnabledShapesGUID +//purpose : +//======================================================================= + +Standard_GUID XCAFDoc::ViewRefEnabledShapesGUID() +{ + static Standard_GUID ID("efd213e4-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } diff --git a/src/XCAFDoc/XCAFDoc.hxx b/src/XCAFDoc/XCAFDoc.hxx index c4bc8f2996..42d43db452 100644 --- a/src/XCAFDoc/XCAFDoc.hxx +++ b/src/XCAFDoc/XCAFDoc.hxx @@ -128,6 +128,10 @@ public: //! Return GUIDs for GraphNode representing specified types of View Standard_EXPORT static const Standard_GUID& ViewRefNoteGUID(); + + //! Return GUIDs for TreeNode representing specified types of View + Standard_EXPORT static Standard_GUID ViewRefEnabledShapesGUID(); + Standard_EXPORT static const Standard_GUID& ViewRefAnnotationGUID(); //! Returns GUID for UAttribute identifying lock flag diff --git a/src/XCAFDoc/XCAFDoc_View.cxx b/src/XCAFDoc/XCAFDoc_View.cxx index 9e96db27a6..2eda98d9ee 100644 --- a/src/XCAFDoc/XCAFDoc_View.cxx +++ b/src/XCAFDoc/XCAFDoc_View.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,10 @@ enum ChildLab ChildLab_BackPlaneDistance, ChildLab_ViewVolumeSidesClipping, ChildLab_ClippingExpression, - ChildLab_GDTPoints + ChildLab_GDTPoints, + ChildLab_Image, + ChildLab_EnabledShapes, + ChildLab_NotePoints }; //======================================================================= @@ -149,6 +153,32 @@ void XCAFDoc_View::SetObject (const Handle(XCAFView_Object)& theObject) TDataXtd_Point::Set(aPointsLabel.FindChild(i), theObject->GDTPoint(i)); } } + //Image + if (theObject->HasImage()) + { + Handle(TColStd_HArray1OfByte) image = theObject->Image(); + Handle(TDataStd_ByteArray) arr = TDataStd_ByteArray::Set(Label().FindChild(ChildLab_Image), image->Lower(), image->Upper()); + for (Standard_Integer i = image->Lower(); i <= image->Upper(); i++) { + 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); + } + } + //note points + if (theObject->HasNotePoints()) + { + TDF_Label aPointsLabel = Label().FindChild(ChildLab_NotePoints); + for (Standard_Integer i = 1; i <= theObject->NbNotePoints(); i++) { + TDataXtd_Point::Set(aPointsLabel.FindChild(i), theObject->NotePoint(i)); + } + } } //======================================================================= @@ -273,7 +303,37 @@ Handle(XCAFView_Object) XCAFDoc_View::GetObject() const } } } + //Image + Handle(TDataStd_ByteArray) anArr; + 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); + } + } + + // Note Points + if (!Label().FindChild(ChildLab_NotePoints, Standard_False).IsNull()) { + TDF_Label aPointsLabel = Label().FindChild(ChildLab_NotePoints); + anObj->CreateNotePoints(aPointsLabel.NbChildren()); + for (Standard_Integer i = 1; i <= aPointsLabel.NbChildren(); i++) { + gp_Pnt aPoint; + Handle(TDataXtd_Point) aPointAttr; + aPointsLabel.FindChild(i).FindAttribute(TDataXtd_Point::GetID(), aPointAttr); + TDataXtd_Geometry::Point(aPointAttr->Label(), aPoint); + anObj->SetNotePoint(i, aPoint); + } + } return anObj; } diff --git a/src/XCAFDoc/XCAFDoc_ViewTool.cxx b/src/XCAFDoc/XCAFDoc_ViewTool.cxx index 8a6269a6f2..059bd59577 100644 --- a/src/XCAFDoc/XCAFDoc_ViewTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ViewTool.cxx @@ -305,11 +305,10 @@ void XCAFDoc_ViewTool::SetView(const TDF_LabelSequence& theShapeLabels, aPlaneGNode = aChGNode->GetFather(1); aPlaneGNode->UnSetChild(aChGNode); if (aPlaneGNode->NbChildren() == 0) - aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefGDTGUID()); + aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefPlaneGUID()); } theViewL.ForgetAttribute(XCAFDoc::ViewRefPlaneGUID()); } - if (!theViewL.FindAttribute(XCAFDoc::ViewRefShapeGUID(), aChGNode) && theShapeLabels.Length() > 0) { aChGNode = new XCAFDoc_GraphNode; aChGNode = XCAFDoc_GraphNode::Set(theViewL); @@ -444,7 +443,7 @@ void XCAFDoc_ViewTool::SetClippingPlanes(const TDF_LabelSequence& theClippingPla aPlaneGNode = aChGNode->GetFather(1); aPlaneGNode->UnSetChild(aChGNode); if (aPlaneGNode->NbChildren() == 0) - aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefGDTGUID()); + aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefPlaneGUID()); } theViewL.ForgetAttribute(XCAFDoc::ViewRefPlaneGUID()); } @@ -465,7 +464,86 @@ 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) aShapeGNode; + + if (theViewL.FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aChGNode)) { + while (aChGNode->NbFathers() > 0) { + aShapeGNode = aChGNode->GetFather(1); + aShapeGNode->UnSetChild(aChGNode); + if (aShapeGNode->NbChildren() == 0) + aShapeGNode->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(), aShapeGNode)) { + aShapeGNode = new XCAFDoc_GraphNode; + aShapeGNode = XCAFDoc_GraphNode::Set(theShapesTransparencyLabels.Value(i)); + } + aShapeGNode->SetGraphID(XCAFDoc::ViewRefEnabledShapesGUID()); + aShapeGNode->SetChild(aChGNode); + aChGNode->SetFather(aShapeGNode); + } +} +//======================================================================= +//function : SetNotes +//purpose : +//======================================================================= +void XCAFDoc_ViewTool::SetNotes(const TDF_LabelSequence& theNoteLabels, + const TDF_Label& theViewL) const +{ + if (!IsView(theViewL)) + return; + + Handle(XCAFDoc_GraphNode) aChGNode; + Handle(XCAFDoc_GraphNode) aNoteGNode; + + if (theViewL.FindAttribute(XCAFDoc::ViewRefNoteGUID(), aChGNode)) { + while (aChGNode->NbFathers() > 0) { + aNoteGNode = aChGNode->GetFather(1); + aNoteGNode->UnSetChild(aChGNode); + if (aNoteGNode->NbChildren() == 0) + aNoteGNode->ForgetAttribute(XCAFDoc::ViewRefNoteGUID()); + } + theViewL.ForgetAttribute(XCAFDoc::ViewRefNoteGUID()); + } + + if (!theViewL.FindAttribute(XCAFDoc::ViewRefNoteGUID(), aChGNode) && theNoteLabels.Length() > 0) { + aChGNode = new XCAFDoc_GraphNode; + aChGNode = XCAFDoc_GraphNode::Set(theViewL); + aChGNode->SetGraphID(XCAFDoc::ViewRefNoteGUID()); + } + for (Standard_Integer i = theNoteLabels.Lower(); i <= theNoteLabels.Upper(); i++) + { + if (!theNoteLabels.Value(i).FindAttribute(XCAFDoc::ViewRefNoteGUID(), aNoteGNode)) { + aNoteGNode = new XCAFDoc_GraphNode; + aNoteGNode = XCAFDoc_GraphNode::Set(theNoteLabels.Value(i)); + } + aNoteGNode->SetGraphID(XCAFDoc::ViewRefNoteGUID()); + aNoteGNode->SetChild(aChGNode); + aChGNode->SetFather(aNoteGNode); + } +} //======================================================================= //function : RemoveView //purpose : @@ -579,6 +657,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 : GetRefNoteLabel //purpose : @@ -684,6 +786,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 : GetViewLabelsForNote //purpose : diff --git a/src/XCAFDoc/XCAFDoc_ViewTool.hxx b/src/XCAFDoc/XCAFDoc_ViewTool.hxx index ea1a3b0468..d24d4f9eb7 100644 --- a/src/XCAFDoc/XCAFDoc_ViewTool.hxx +++ b/src/XCAFDoc/XCAFDoc_ViewTool.hxx @@ -86,6 +86,12 @@ 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; + + //! Set Notes to given View + Standard_EXPORT void SetNotes(const TDF_LabelSequence& theNoteLabels, + const TDF_Label& theViewL) const; //! Remove View Standard_EXPORT void RemoveView(const TDF_Label& theViewL); @@ -105,6 +111,9 @@ public: //! Returns all View labels defined for label AnnotationL Standard_EXPORT Standard_Boolean GetViewLabelsForAnnotation(const TDF_Label& theAnnotationL, 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() ; @@ -120,6 +129,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 Notes labels defined for label theViewL //! Returns False if the theViewL is not in View table Standard_EXPORT Standard_Boolean GetRefNoteLabel(const TDF_Label& theViewL, TDF_LabelSequence& theNoteLabels) const; diff --git a/src/XCAFView/XCAFView_Object.cxx b/src/XCAFView/XCAFView_Object.cxx index bc1e06f1de..bf86ecbb03 100644 --- a/src/XCAFView/XCAFView_Object.cxx +++ b/src/XCAFView/XCAFView_Object.cxx @@ -28,6 +28,9 @@ XCAFView_Object::XCAFView_Object() myBackPlaneClipping = Standard_False; myViewVolumeSidesClipping = Standard_False; myGDTPoints = NULL; + myImage = NULL; + myEnabledShapes = NULL; + myNotePoints = NULL; } //======================================================================= @@ -50,5 +53,8 @@ XCAFView_Object::XCAFView_Object(const Handle(XCAFView_Object)& theObj) myBackPlaneDistance = theObj->myBackPlaneDistance; myViewVolumeSidesClipping = theObj->myViewVolumeSidesClipping; myGDTPoints = NULL; + myImage = theObj->myImage; + myEnabledShapes = NULL; + myGDTPoints = NULL; } diff --git a/src/XCAFView/XCAFView_Object.hxx b/src/XCAFView/XCAFView_Object.hxx index 5085da4f87..9baf129f2a 100644 --- a/src/XCAFView/XCAFView_Object.hxx +++ b/src/XCAFView/XCAFView_Object.hxx @@ -26,6 +26,8 @@ #include #include #include +#include +#include class XCAFView_Object; DEFINE_STANDARD_HANDLE(XCAFView_Object, Standard_Transient) @@ -217,7 +219,93 @@ public: else return gp_Pnt(); } - + + Standard_EXPORT void SetImage(Handle(TColStd_HArray1OfByte) theImage) + { + myImage = theImage; + } + + Standard_EXPORT Handle(TColStd_HArray1OfByte) Image() + { + return myImage; + } + + Standard_EXPORT Standard_Boolean HasImage() + { + 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; + } + Standard_EXPORT void CreateNotePoints(const Standard_Integer theLenght) + { + if (theLenght > 0) + myNotePoints = new TColgp_HArray1OfPnt(1, theLenght); + } + + Standard_EXPORT Standard_Boolean HasNotePoints() + { + return (!myNotePoints.IsNull()); + } + + Standard_EXPORT Standard_Integer NbNotePoints() + { + if (myNotePoints.IsNull()) + return 0; + return myNotePoints->Length(); + } + + Standard_EXPORT void SetNotePoint(const Standard_Integer theIndex, const gp_Pnt thePoint) + { + if (myNotePoints.IsNull()) + return; + if (theIndex > 0 && theIndex <= myNotePoints->Length()) + myNotePoints->SetValue(theIndex, thePoint); + } + + Standard_EXPORT gp_Pnt NotePoint(const Standard_Integer theIndex) + { + if (myNotePoints.IsNull()) + return gp_Pnt(); + if (theIndex > 0 && theIndex <= myNotePoints->Length()) + return myNotePoints->Value(theIndex); + else + return gp_Pnt(); + } + DEFINE_STANDARD_RTTIEXT(XCAFView_Object,Standard_Transient) private: @@ -237,6 +325,9 @@ private: Standard_Real myBackPlaneDistance; 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; + Handle(TColgp_HArray1OfPnt) myNotePoints; }; #endif // _XCAFView_Object_HeaderFile -- 2.39.5