1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

XCAFDoc/View fixes to store in the view: image, parts transparency, notes, notes positions

(cherry picked from commit b050e0a15c06403adfa545ad793555491a0b6b9f)
This commit is contained in:
nds
2018-09-27 17:38:43 +03:00
parent b079e6b053
commit 7099619e5d
7 changed files with 314 additions and 8 deletions

View File

@@ -263,13 +263,24 @@ Standard_GUID XCAFDoc::ViewRefPlaneGUID()
}
//=======================================================================
//function : ViewRefPlaneGUID
//function : ViewRefNoteGUID
//purpose :
//=======================================================================
Standard_GUID XCAFDoc::ViewRefNoteGUID()
{
static Standard_GUID ID("C814ACC6-43AC-4812-9B2A-4E9A2A549354");
static 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;
}

View File

@@ -123,8 +123,13 @@ public:
//! Return GUIDs for TreeNode representing specified types of View
Standard_EXPORT static Standard_GUID ViewRefPlaneGUID();
//! Return GUIDs for GraphNode representing specified types of View
//! Return GUIDs for TreeNode representing specified types of View
Standard_EXPORT static Standard_GUID ViewRefNoteGUID();
//! Return GUIDs for TreeNode representing specified types of View
Standard_EXPORT static Standard_GUID ViewRefEnabledShapesGUID();
//! Return GUIDs for GraphNode representing specified types of View
Standard_EXPORT static Standard_GUID ViewRefAnnotationGUID();
//! Returns GUID for UAttribute identifying lock flag

View File

@@ -20,6 +20,7 @@
#include <TDataStd_Integer.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_RealArray.hxx>
#include <TDataStd_ByteArray.hxx>
#include <TDataXtd_Axis.hxx>
#include <TDataXtd_Geometry.hxx>
#include <TDataXtd_Plane.hxx>
@@ -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));
}
}
}
//=======================================================================
@@ -259,7 +289,37 @@ Handle(XCAFView_Object) XCAFDoc_View::GetObject() const
anObj->SetGDTPoint(i, aPoint);
}
}
//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;
}

View File

@@ -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 :

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -26,6 +26,8 @@
#include <TColgp_HArray1OfPnt.hxx>
#include <TCollection_HAsciiString.hxx>
#include <XCAFView_ProjectionType.hxx>
#include <TColStd_HArray1OfByte.hxx>
#include <TColStd_HArray1OfBoolean.hxx>
class XCAFView_Object;
DEFINE_STANDARD_HANDLE(XCAFView_Object, Standard_Transient)
@@ -218,6 +220,92 @@ public:
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