mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0030692: Data Exchange - introduce base framework RWMesh for importing mesh data formats into XDE document
RWMesh_CafReader - added new interface class for common workflow for reading mesh data files into XDE document. OSD_Path - added auxiliary methods splitting path into folder+file pair and checking relative/absolute path semantically: OSD_Path::FolderAndFileFromPath(), ::IsRelativePath(), ::IsAbsolutePath(). V3d_TypeOfOrientation enumeration has been extended with aliases (like front/left) for Z-up and Y-up conventions. V3d_View::SetProj() now accepts argument for asking Y-up instead of Z-up. Added command vviewproj defining standard camera direction. Commands vaxo, vleft, vright, vtop, vbottom, vfront, vbottom now redirect to vviewproj. TCollection_AsciiString::SubString() now uses Standard_OutOfRange_Always_Raise_if() to suppress GCC warning. Eliminated gcc 4.4 compilation errors within Standard_OutOfRange_Raise_if,Standard_RangeError_Raise_if.
This commit is contained in:
@@ -8,6 +8,10 @@ XCAFPrs_DataMapIteratorOfDataMapOfStyleTransient.hxx
|
||||
XCAFPrs_IndexedDataMapOfShapeStyle.hxx
|
||||
XCAFPrs_DataMapOfStyleShape.hxx
|
||||
XCAFPrs_DataMapOfStyleTransient.hxx
|
||||
XCAFPrs_DocumentExplorer.cxx
|
||||
XCAFPrs_DocumentExplorer.hxx
|
||||
XCAFPrs_DocumentIdIterator.hxx
|
||||
XCAFPrs_DocumentNode.hxx
|
||||
XCAFPrs_Driver.cxx
|
||||
XCAFPrs_Driver.hxx
|
||||
XCAFPrs_Style.cxx
|
||||
|
441
src/XCAFPrs/XCAFPrs_DocumentExplorer.cxx
Normal file
441
src/XCAFPrs/XCAFPrs_DocumentExplorer.cxx
Normal file
@@ -0,0 +1,441 @@
|
||||
// Author: Kirill Gavrilov
|
||||
// Copyright (c) 2017-2019 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 <XCAFPrs_DocumentExplorer.hxx>
|
||||
|
||||
#include <TDF_Tool.hxx>
|
||||
#include <TDocStd_Document.hxx>
|
||||
#include <XCAFDoc_ColorTool.hxx>
|
||||
#include <XCAFDoc_DocumentTool.hxx>
|
||||
#include <XCAFDoc_ShapeTool.hxx>
|
||||
#include <XCAFPrs_DocumentIdIterator.hxx>
|
||||
|
||||
namespace
|
||||
{
|
||||
//! Return merged style for the child node.
|
||||
static XCAFPrs_Style mergedStyle (const Handle(XCAFDoc_ColorTool)& theColorTool,
|
||||
const XCAFPrs_Style& theParenStyle,
|
||||
const TDF_Label& theLabel,
|
||||
const TDF_Label& theRefLabel)
|
||||
{
|
||||
if (theColorTool.IsNull())
|
||||
{
|
||||
return theParenStyle;
|
||||
}
|
||||
|
||||
XCAFPrs_Style aStyle = theParenStyle;
|
||||
Quantity_ColorRGBA aColor;
|
||||
if (theColorTool->GetColor (theRefLabel, XCAFDoc_ColorGen, aColor))
|
||||
{
|
||||
aStyle.SetColorCurv (aColor.GetRGB());
|
||||
aStyle.SetColorSurf (aColor);
|
||||
}
|
||||
if (theColorTool->GetColor (theRefLabel, XCAFDoc_ColorSurf, aColor))
|
||||
{
|
||||
aStyle.SetColorSurf (aColor);
|
||||
}
|
||||
if (theColorTool->GetColor (theRefLabel, XCAFDoc_ColorCurv, aColor))
|
||||
{
|
||||
aStyle.SetColorCurv (aColor.GetRGB());
|
||||
}
|
||||
|
||||
if (theLabel != theRefLabel)
|
||||
{
|
||||
// override Reference style with Instance style when defined (bad model?)
|
||||
if (theColorTool->GetColor (theLabel, XCAFDoc_ColorGen, aColor))
|
||||
{
|
||||
aStyle.SetColorCurv (aColor.GetRGB());
|
||||
aStyle.SetColorSurf (aColor);
|
||||
}
|
||||
if (theColorTool->GetColor (theLabel, XCAFDoc_ColorSurf, aColor))
|
||||
{
|
||||
aStyle.SetColorSurf (aColor);
|
||||
}
|
||||
if (theColorTool->GetColor (theLabel, XCAFDoc_ColorCurv, aColor))
|
||||
{
|
||||
aStyle.SetColorCurv (aColor.GetRGB());
|
||||
}
|
||||
}
|
||||
|
||||
return aStyle;
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : DefineChildId
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TCollection_AsciiString XCAFPrs_DocumentExplorer::DefineChildId (const TDF_Label& theLabel,
|
||||
const TCollection_AsciiString& theParentId)
|
||||
{
|
||||
TCollection_AsciiString anEntryId;
|
||||
TDF_Tool::Entry (theLabel, anEntryId);
|
||||
return !theParentId.IsEmpty()
|
||||
? theParentId + "/" + anEntryId + "."
|
||||
: anEntryId + ".";
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : FindLabelFromPathId
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TDF_Label XCAFPrs_DocumentExplorer::FindLabelFromPathId (const Handle(TDocStd_Document)& theDocument,
|
||||
const TCollection_AsciiString& theId,
|
||||
TopLoc_Location& theParentLocation,
|
||||
TopLoc_Location& theLocation)
|
||||
{
|
||||
theParentLocation = TopLoc_Location();
|
||||
theLocation = TopLoc_Location();
|
||||
TDF_Label anInstanceLabel;
|
||||
for (XCAFPrs_DocumentIdIterator anPathIter (theId); anPathIter.More();)
|
||||
{
|
||||
TDF_Label aSubLabel;
|
||||
{
|
||||
const TCollection_AsciiString& anOcafId = anPathIter.Value();
|
||||
TDF_Tool::Label (theDocument->Main().Data(), anOcafId, aSubLabel);
|
||||
if (aSubLabel.IsNull())
|
||||
{
|
||||
return TDF_Label();
|
||||
}
|
||||
}
|
||||
|
||||
anPathIter.Next();
|
||||
if (!anPathIter.More())
|
||||
{
|
||||
theParentLocation = theLocation;
|
||||
}
|
||||
|
||||
TopLoc_Location aLocTrsf = XCAFDoc_ShapeTool::GetLocation (aSubLabel);
|
||||
theLocation = theLocation * aLocTrsf;
|
||||
anInstanceLabel = aSubLabel;
|
||||
}
|
||||
return anInstanceLabel;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : FindShapeFromPathId
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TopoDS_Shape XCAFPrs_DocumentExplorer::FindShapeFromPathId (const Handle(TDocStd_Document)& theDocument,
|
||||
const TCollection_AsciiString& theId)
|
||||
{
|
||||
TopLoc_Location aLocation;
|
||||
TDF_Label anInstanceLabel = FindLabelFromPathId (theDocument, theId, aLocation);
|
||||
if (anInstanceLabel.IsNull())
|
||||
{
|
||||
return TopoDS_Shape();
|
||||
}
|
||||
|
||||
TDF_Label aRefLabel = anInstanceLabel;
|
||||
XCAFDoc_ShapeTool::GetReferredShape (anInstanceLabel, aRefLabel);
|
||||
if (aRefLabel.IsNull())
|
||||
{
|
||||
return TopoDS_Shape();
|
||||
}
|
||||
|
||||
TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape (aRefLabel);
|
||||
if (aShape.IsNull())
|
||||
{
|
||||
return TopoDS_Shape();
|
||||
}
|
||||
|
||||
aShape.Location (aLocation);
|
||||
return aShape;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : XCAFPrs_DocumentExplorer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
XCAFPrs_DocumentExplorer::XCAFPrs_DocumentExplorer()
|
||||
: myTop (-1),
|
||||
myHasMore (Standard_False),
|
||||
myFlags (XCAFPrs_DocumentExplorerFlags_None)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : XCAFPrs_DocumentExplorer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
XCAFPrs_DocumentExplorer::XCAFPrs_DocumentExplorer (const Handle(TDocStd_Document)& theDocument,
|
||||
const XCAFPrs_DocumentExplorerFlags theFlags,
|
||||
const XCAFPrs_Style& theDefStyle)
|
||||
: myTop (-1),
|
||||
myHasMore (Standard_False),
|
||||
myFlags (XCAFPrs_DocumentExplorerFlags_None)
|
||||
{
|
||||
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (theDocument->Main());
|
||||
TDF_LabelSequence aRootLabels;
|
||||
aShapeTool->GetFreeShapes (aRootLabels);
|
||||
Init (theDocument, aRootLabels, theFlags, theDefStyle);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : XCAFPrs_DocumentExplorer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
XCAFPrs_DocumentExplorer::XCAFPrs_DocumentExplorer (const Handle(TDocStd_Document)& theDocument,
|
||||
const TDF_LabelSequence& theRoots,
|
||||
const XCAFPrs_DocumentExplorerFlags theFlags,
|
||||
const XCAFPrs_Style& theDefStyle)
|
||||
: myTop (-1),
|
||||
myHasMore (Standard_False),
|
||||
myFlags (XCAFPrs_DocumentExplorerFlags_None)
|
||||
{
|
||||
Init (theDocument, theRoots, theFlags, theDefStyle);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Init
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void XCAFPrs_DocumentExplorer::Init (const Handle(TDocStd_Document)& theDocument,
|
||||
const TDF_Label& theRoot,
|
||||
const XCAFPrs_DocumentExplorerFlags theFlags,
|
||||
const XCAFPrs_Style& theDefStyle)
|
||||
{
|
||||
TDF_LabelSequence aSeq;
|
||||
aSeq.Append (theRoot);
|
||||
Init (theDocument, aSeq, theFlags, theDefStyle);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Init
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void XCAFPrs_DocumentExplorer::Init (const Handle(TDocStd_Document)& theDocument,
|
||||
const TDF_LabelSequence& theRoots,
|
||||
const XCAFPrs_DocumentExplorerFlags theFlags,
|
||||
const XCAFPrs_Style& theDefStyle)
|
||||
{
|
||||
if ((theFlags & XCAFPrs_DocumentExplorerFlags_NoStyle) != 0)
|
||||
{
|
||||
myColorTool = XCAFDoc_DocumentTool::ColorTool (theDocument->Main());
|
||||
}
|
||||
else
|
||||
{
|
||||
myColorTool.Nullify();
|
||||
}
|
||||
|
||||
///myColorTool = theColorTool;
|
||||
myDefStyle = theDefStyle;
|
||||
myRoots = theRoots;
|
||||
myRootIter = TDF_LabelSequence::Iterator (myRoots);
|
||||
myFlags = theFlags;
|
||||
initRoot();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : initRoot
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void XCAFPrs_DocumentExplorer::initRoot()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
// reset the stack
|
||||
for (Standard_Integer aStackIter = 0; aStackIter <= myTop; ++aStackIter)
|
||||
{
|
||||
myNodeStack.SetValue (aStackIter, XCAFPrs_DocumentNode());
|
||||
}
|
||||
myTop = -1;
|
||||
if (!myRootIter.More())
|
||||
{
|
||||
myHasMore = Standard_False;
|
||||
initCurrent (Standard_False);
|
||||
return;
|
||||
}
|
||||
|
||||
const TDF_Label& aRootLab = myRootIter.Value();
|
||||
if (aRootLab.IsNull())
|
||||
{
|
||||
// assert - invalid input
|
||||
//Standard_ProgramError::Raise ("CadDocumentExplorer - NULL label in the input");
|
||||
myRootIter.Next();
|
||||
continue;
|
||||
}
|
||||
|
||||
myHasMore = Standard_True;
|
||||
TDF_Label aRefLabel = aRootLab;
|
||||
XCAFDoc_ShapeTool::GetReferredShape (aRootLab, aRefLabel);
|
||||
if (XCAFDoc_ShapeTool::IsAssembly (aRefLabel))
|
||||
{
|
||||
Next();
|
||||
}
|
||||
else
|
||||
{
|
||||
initCurrent (Standard_False);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : initCurrent
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void XCAFPrs_DocumentExplorer::initCurrent (Standard_Boolean theIsAssmebly)
|
||||
{
|
||||
myCurrent = XCAFPrs_DocumentNode();
|
||||
if (theIsAssmebly)
|
||||
{
|
||||
if (myTop < 0)
|
||||
{
|
||||
Standard_ProgramError::Raise ("CadDocumentExplorer - internal error");
|
||||
}
|
||||
myCurrent = myNodeStack.Value (myTop);
|
||||
}
|
||||
else if (myTop < 0)
|
||||
{
|
||||
if (!myRootIter.More())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
myCurrent.Label = myRootIter.Value();
|
||||
myCurrent.RefLabel = myCurrent.Label;
|
||||
XCAFDoc_ShapeTool::GetReferredShape (myCurrent.Label, myCurrent.RefLabel);
|
||||
myCurrent.LocalTrsf= XCAFDoc_ShapeTool::GetLocation (myCurrent.Label);
|
||||
myCurrent.Location = myCurrent.LocalTrsf;
|
||||
myCurrent.Style = mergedStyle (myColorTool, myDefStyle, myCurrent.Label, myCurrent.RefLabel);
|
||||
myCurrent.Id = DefineChildId (myCurrent.Label, TCollection_AsciiString());
|
||||
}
|
||||
else
|
||||
{
|
||||
const XCAFPrs_DocumentNode& aTopNodeInStack = myNodeStack.Value (myTop);
|
||||
myCurrent.Label = aTopNodeInStack.ChildIter.Value();
|
||||
myCurrent.RefLabel = myCurrent.Label;
|
||||
XCAFDoc_ShapeTool::GetReferredShape (myCurrent.Label, myCurrent.RefLabel);
|
||||
myCurrent.LocalTrsf= XCAFDoc_ShapeTool::GetLocation (myCurrent.Label);
|
||||
myCurrent.Location = aTopNodeInStack.Location * myCurrent.LocalTrsf;
|
||||
myCurrent.Style = mergedStyle (myColorTool, aTopNodeInStack.Style, myCurrent.Label, myCurrent.RefLabel);
|
||||
myCurrent.Id = DefineChildId (myCurrent.Label, aTopNodeInStack.Id);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Next
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void XCAFPrs_DocumentExplorer::Next()
|
||||
{
|
||||
if (!myHasMore)
|
||||
{
|
||||
Standard_ProgramError::Raise ("CadDocumentExplorer::Next() - out of range");
|
||||
return; // assert
|
||||
}
|
||||
|
||||
if (myTop < 0)
|
||||
{
|
||||
const TDF_Label& aRootLab = myRootIter.Value();
|
||||
TDF_Label aRefLabel = aRootLab;
|
||||
XCAFDoc_ShapeTool::GetReferredShape (aRootLab, aRefLabel);
|
||||
if (!XCAFDoc_ShapeTool::IsAssembly (aRefLabel))
|
||||
{
|
||||
// already visited once
|
||||
myRootIter.Next();
|
||||
initRoot();
|
||||
return;
|
||||
}
|
||||
|
||||
// push and try to find
|
||||
myTop = 0;
|
||||
XCAFPrs_DocumentNode aNodeInStack;
|
||||
aNodeInStack.IsAssembly = Standard_True;
|
||||
aNodeInStack.Label = aRootLab;
|
||||
aNodeInStack.RefLabel = aRefLabel;
|
||||
aNodeInStack.ChildIter = TDF_ChildIterator (aNodeInStack.RefLabel);
|
||||
aNodeInStack.LocalTrsf = XCAFDoc_ShapeTool::GetLocation (aNodeInStack.Label);
|
||||
aNodeInStack.Location = aNodeInStack.LocalTrsf;
|
||||
aNodeInStack.Style = mergedStyle (myColorTool, myDefStyle, aNodeInStack.Label, aNodeInStack.RefLabel);
|
||||
aNodeInStack.Id = DefineChildId (aNodeInStack.Label, TCollection_AsciiString());
|
||||
myNodeStack.SetValue (0, aNodeInStack);
|
||||
if ((myFlags & XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes) == 0)
|
||||
{
|
||||
initCurrent (Standard_True);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!myCurrent.IsAssembly)
|
||||
{
|
||||
myNodeStack.ChangeValue (myTop).ChildIter.Next();
|
||||
}
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (myNodeStack.Value (myTop).ChildIter.More())
|
||||
{
|
||||
const TDF_Label& aNodeTop = myNodeStack.Value (myTop).ChildIter.Value();
|
||||
if (aNodeTop.IsNull()
|
||||
|| (!aNodeTop.HasChild() && !aNodeTop.HasAttribute()))
|
||||
{
|
||||
myNodeStack.ChangeValue (myTop).ChildIter.Next();
|
||||
continue;
|
||||
}
|
||||
|
||||
TDF_Label aRefLabel = aNodeTop;
|
||||
XCAFDoc_ShapeTool::GetReferredShape (aNodeTop, aRefLabel);
|
||||
if (!XCAFDoc_ShapeTool::IsAssembly (aRefLabel))
|
||||
{
|
||||
myHasMore = Standard_True;
|
||||
initCurrent (Standard_False);
|
||||
return;
|
||||
}
|
||||
else if (aRefLabel.HasAttribute()
|
||||
|| aRefLabel.HasChild())
|
||||
{
|
||||
const XCAFPrs_DocumentNode& aParent = myNodeStack.Value (myTop);
|
||||
++myTop;
|
||||
|
||||
XCAFPrs_DocumentNode aNodeInStack;
|
||||
aNodeInStack.IsAssembly = Standard_True;
|
||||
aNodeInStack.Label = aNodeTop;
|
||||
aNodeInStack.RefLabel = aRefLabel;
|
||||
aNodeInStack.LocalTrsf = XCAFDoc_ShapeTool::GetLocation (aNodeInStack.Label);
|
||||
aNodeInStack.Location = aParent.Location * aNodeInStack.LocalTrsf;
|
||||
aNodeInStack.Style = mergedStyle (myColorTool, aParent.Style, aNodeInStack.Label, aNodeInStack.RefLabel);
|
||||
aNodeInStack.Id = DefineChildId (aNodeInStack.Label, aParent.Id);
|
||||
aNodeInStack.ChildIter = TDF_ChildIterator (aNodeInStack.RefLabel);
|
||||
myNodeStack.SetValue (myTop, aNodeInStack);
|
||||
if ((myFlags & XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes) == 0)
|
||||
{
|
||||
initCurrent (Standard_True);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
myNodeStack.ChangeValue (myTop).ChildIter.Next();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
myNodeStack.SetValue (myTop, XCAFPrs_DocumentNode());
|
||||
--myTop;
|
||||
if (myTop < 0)
|
||||
{
|
||||
myRootIter.Next();
|
||||
initRoot();
|
||||
return;
|
||||
}
|
||||
|
||||
myNodeStack.ChangeValue (myTop).ChildIter.Next();
|
||||
}
|
||||
}
|
||||
}
|
174
src/XCAFPrs/XCAFPrs_DocumentExplorer.hxx
Normal file
174
src/XCAFPrs/XCAFPrs_DocumentExplorer.hxx
Normal file
@@ -0,0 +1,174 @@
|
||||
// Author: Kirill Gavrilov
|
||||
// Copyright (c) 2017-2019 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 _XCAFPrs_DocumentExplorer_HeaderFile
|
||||
#define _XCAFPrs_DocumentExplorer_HeaderFile
|
||||
|
||||
#include <NCollection_Vector.hxx>
|
||||
#include <NCollection_Sequence.hxx>
|
||||
#include <XCAFPrs_DocumentNode.hxx>
|
||||
#include <TDF_LabelSequence.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
|
||||
class TDocStd_Document;
|
||||
class XCAFDoc_ShapeTool;
|
||||
class XCAFDoc_ColorTool;
|
||||
|
||||
typedef Standard_Integer XCAFPrs_DocumentExplorerFlags;
|
||||
|
||||
//! Document explorer flags.
|
||||
enum
|
||||
{
|
||||
XCAFPrs_DocumentExplorerFlags_None = 0x00, //!< no flags
|
||||
XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes = 0x01, //!< explore only leaf nodes (skip assembly nodes)
|
||||
XCAFPrs_DocumentExplorerFlags_NoStyle = 0x02, //!< do not fetch styles
|
||||
};
|
||||
|
||||
//! Document iterator through shape nodes.
|
||||
class XCAFPrs_DocumentExplorer
|
||||
{
|
||||
public: //! @name string identification tools
|
||||
|
||||
//! Construct a unique string identifier for the given label.
|
||||
//! The identifier is a concatenation of label entries (TDF_Tool::Entry() with tailing '.') of hierarchy from parent to child
|
||||
//! joined via '/' and looking like this:
|
||||
//! @code
|
||||
//! 0:1:1:1./0:1:1:1:9./0:1:1:5:7.
|
||||
//! @endcode
|
||||
//! This generation scheme also allows finding originating labels using TDF_Tool::Label().
|
||||
//! The tailing dot simplifies parent equality check.
|
||||
//! @param theLabel child label to define id
|
||||
//! @param theParentId parent string identifier defined by this method
|
||||
Standard_EXPORT static TCollection_AsciiString DefineChildId (const TDF_Label& theLabel,
|
||||
const TCollection_AsciiString& theParentId);
|
||||
|
||||
//! Find a shape entity based on a text identifier constructed from OCAF labels defining full path.
|
||||
//! @sa DefineChildId()
|
||||
Standard_EXPORT static TDF_Label FindLabelFromPathId (const Handle(TDocStd_Document)& theDocument,
|
||||
const TCollection_AsciiString& theId,
|
||||
TopLoc_Location& theParentLocation,
|
||||
TopLoc_Location& theLocation);
|
||||
|
||||
//! Find a shape entity based on a text identifier constructed from OCAF labels defining full path.
|
||||
//! @sa DefineChildId()
|
||||
static TDF_Label FindLabelFromPathId (const Handle(TDocStd_Document)& theDocument,
|
||||
const TCollection_AsciiString& theId,
|
||||
TopLoc_Location& theLocation)
|
||||
{
|
||||
TopLoc_Location aDummy;
|
||||
return FindLabelFromPathId (theDocument, theId, aDummy, theLocation);
|
||||
}
|
||||
|
||||
//! Find a shape entity based on a text identifier constructed from OCAF labels defining full path.
|
||||
//! @sa DefineChildId()
|
||||
Standard_EXPORT static TopoDS_Shape FindShapeFromPathId (const Handle(TDocStd_Document)& theDocument,
|
||||
const TCollection_AsciiString& theId);
|
||||
|
||||
public:
|
||||
|
||||
//! Empty constructor.
|
||||
Standard_EXPORT XCAFPrs_DocumentExplorer();
|
||||
|
||||
//! Constructor for exploring the whole document.
|
||||
//! @param theDocument document to explore
|
||||
//! @param theFlags iteration flags
|
||||
//! @param theDefStyle default style for nodes with undefined style
|
||||
Standard_EXPORT XCAFPrs_DocumentExplorer (const Handle(TDocStd_Document)& theDocument,
|
||||
const XCAFPrs_DocumentExplorerFlags theFlags,
|
||||
const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
|
||||
|
||||
//! Constructor for exploring specified list of root shapes in the document.
|
||||
//! @param theDocument document to explore
|
||||
//! @param theRoots root labels to explore within specified document
|
||||
//! @param theFlags iteration flags
|
||||
//! @param theDefStyle default style for nodes with undefined style
|
||||
Standard_EXPORT XCAFPrs_DocumentExplorer (const Handle(TDocStd_Document)& theDocument,
|
||||
const TDF_LabelSequence& theRoots,
|
||||
const XCAFPrs_DocumentExplorerFlags theFlags,
|
||||
const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
|
||||
|
||||
//! Initialize the iterator from a single root shape in the document.
|
||||
//! @param theDocument document to explore
|
||||
//! @param theRoot single root label to explore within specified document
|
||||
//! @param theFlags iteration flags
|
||||
//! @param theDefStyle default style for nodes with undefined style
|
||||
Standard_EXPORT void Init (const Handle(TDocStd_Document)& theDocument,
|
||||
const TDF_Label& theRoot,
|
||||
const XCAFPrs_DocumentExplorerFlags theFlags,
|
||||
const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
|
||||
|
||||
//! Initialize the iterator from the list of root shapes in the document.
|
||||
//! @param theDocument document to explore
|
||||
//! @param theRoots root labels to explore within specified document
|
||||
//! @param theFlags iteration flags
|
||||
//! @param theDefStyle default style for nodes with undefined style
|
||||
Standard_EXPORT void Init (const Handle(TDocStd_Document)& theDocument,
|
||||
const TDF_LabelSequence& theRoots,
|
||||
const XCAFPrs_DocumentExplorerFlags theFlags,
|
||||
const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
|
||||
|
||||
//! Return TRUE if iterator points to the valid node.
|
||||
Standard_Boolean More() const { return myHasMore; }
|
||||
|
||||
//! Return current position.
|
||||
const XCAFPrs_DocumentNode& Current() const { return myCurrent; }
|
||||
|
||||
//! Return current position.
|
||||
XCAFPrs_DocumentNode& ChangeCurrent() { return myCurrent; }
|
||||
|
||||
//! Return current position within specified assembly depth.
|
||||
const XCAFPrs_DocumentNode& Current (Standard_Integer theDepth) const
|
||||
{
|
||||
const Standard_Integer aCurrDepth = CurrentDepth();
|
||||
if (theDepth == aCurrDepth)
|
||||
{
|
||||
return myCurrent;
|
||||
}
|
||||
|
||||
Standard_OutOfRange_Raise_if (theDepth < 0 || theDepth > myTop,
|
||||
"XCAFPrs_DocumentExplorer::Current() out of range");
|
||||
return myNodeStack.Value (theDepth);
|
||||
}
|
||||
|
||||
//! Return depth of the current node in hierarchy, starting from 0.
|
||||
//! Zero means Root label.
|
||||
Standard_Integer CurrentDepth() const { return myCurrent.IsAssembly ? myTop : myTop + 1; }
|
||||
|
||||
//! Go to the next node.
|
||||
Standard_EXPORT void Next();
|
||||
|
||||
protected:
|
||||
|
||||
//! Initialize root label.
|
||||
Standard_EXPORT void initRoot();
|
||||
|
||||
//! Initialize properties for a current label.
|
||||
Standard_EXPORT void initCurrent (Standard_Boolean theIsAssmebly);
|
||||
|
||||
protected:
|
||||
|
||||
Handle(XCAFDoc_ColorTool) myColorTool; //!< color tool
|
||||
TDF_LabelSequence myRoots; //!< sequence of root labels
|
||||
TDF_LabelSequence::Iterator myRootIter; //!< current root label
|
||||
NCollection_Vector<XCAFPrs_DocumentNode>
|
||||
myNodeStack; //!< node stack
|
||||
Standard_Integer myTop; //!< top position in the node stack
|
||||
Standard_Boolean myHasMore; //!< global flag indicating that iterator points to the label
|
||||
XCAFPrs_Style myDefStyle; //!< default style
|
||||
XCAFPrs_DocumentNode myCurrent; //!< current label info
|
||||
XCAFPrs_DocumentExplorerFlags myFlags; //!< iteration flags
|
||||
|
||||
};
|
||||
|
||||
#endif // _XCAFPrs_DocumentExplorer_HeaderFile
|
90
src/XCAFPrs/XCAFPrs_DocumentIdIterator.hxx
Normal file
90
src/XCAFPrs/XCAFPrs_DocumentIdIterator.hxx
Normal file
@@ -0,0 +1,90 @@
|
||||
// Author: Kirill Gavrilov
|
||||
// Copyright (c) 2017-2019 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 _XCAFPrs_DocumentIdIterator_HeaderFile
|
||||
#define _XCAFPrs_DocumentIdIterator_HeaderFile
|
||||
|
||||
#include <XCAFPrs_Style.hxx>
|
||||
|
||||
#include <TDF_ChildIterator.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TopLoc_Location.hxx>
|
||||
|
||||
//! Auxiliary tool for iterating through Path identification string.
|
||||
class XCAFPrs_DocumentIdIterator
|
||||
{
|
||||
public:
|
||||
//! Main constructor.
|
||||
XCAFPrs_DocumentIdIterator (const TCollection_AsciiString& thePath)
|
||||
: myPath (thePath), myPosition (0)
|
||||
{
|
||||
Next();
|
||||
}
|
||||
|
||||
//! Return TRUE if iterator points to a value.
|
||||
bool More() const { return !mySubId.IsEmpty(); }
|
||||
|
||||
//! Return current value.
|
||||
const TCollection_AsciiString& Value() const { return mySubId; }
|
||||
|
||||
//! Find the next value.
|
||||
void Next();
|
||||
|
||||
private:
|
||||
|
||||
// Disable assignment operator.
|
||||
XCAFPrs_DocumentIdIterator& operator= (const XCAFPrs_DocumentIdIterator& );
|
||||
|
||||
private:
|
||||
const TCollection_AsciiString& myPath; //!< full path
|
||||
TCollection_AsciiString mySubId; //!< current value
|
||||
Standard_Integer myPosition; //!< last processed new-line symbol
|
||||
};
|
||||
|
||||
// =======================================================================
|
||||
// function : Next
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
inline void XCAFPrs_DocumentIdIterator::Next()
|
||||
{
|
||||
for (Standard_Integer aCharIndex = myPosition + 1; aCharIndex <= myPath.Length(); ++aCharIndex)
|
||||
{
|
||||
if (myPath.Value (aCharIndex) == '/')
|
||||
{
|
||||
// intermediate items have trailing dot and separator before the next item
|
||||
const Standard_Integer aLen = aCharIndex - myPosition - 2;
|
||||
if (aLen < 1)
|
||||
{
|
||||
return; // assert - should never happen for valid IDs!
|
||||
}
|
||||
|
||||
mySubId = myPath.SubString (myPosition + 1, aCharIndex - 2);
|
||||
myPosition = aCharIndex;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (myPosition < myPath.Length())
|
||||
{
|
||||
// last item has only trailing dot
|
||||
mySubId = myPath.SubString (myPosition + 1, myPath.Length() - 1);
|
||||
myPosition = myPath.Length();
|
||||
}
|
||||
else
|
||||
{
|
||||
mySubId.Clear();
|
||||
myPosition = myPath.Length();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _XCAFPrs_DocumentIdIterator_HeaderFile
|
39
src/XCAFPrs/XCAFPrs_DocumentNode.hxx
Normal file
39
src/XCAFPrs/XCAFPrs_DocumentNode.hxx
Normal file
@@ -0,0 +1,39 @@
|
||||
// Author: Kirill Gavrilov
|
||||
// Copyright (c) 2017-2019 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 _XCAFPrs_DocumentNode_HeaderFile
|
||||
#define _XCAFPrs_DocumentNode_HeaderFile
|
||||
|
||||
#include <XCAFPrs_Style.hxx>
|
||||
|
||||
#include <TDF_ChildIterator.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TopLoc_Location.hxx>
|
||||
|
||||
//! Structure defining document node.
|
||||
struct XCAFPrs_DocumentNode
|
||||
{
|
||||
TCollection_AsciiString Id; //!< string identifier
|
||||
TDF_Label Label; //!< label in the document
|
||||
TDF_Label RefLabel; //!< reference label in the document
|
||||
XCAFPrs_Style Style; //!< node style
|
||||
TopLoc_Location Location; //!< node global transformation
|
||||
TopLoc_Location LocalTrsf; //!< node transformation relative to parent
|
||||
TDF_ChildIterator ChildIter; //!< child iterator
|
||||
Standard_Boolean IsAssembly; //!< flag indicating that this label is assembly
|
||||
|
||||
XCAFPrs_DocumentNode() : IsAssembly (Standard_False) {}
|
||||
};
|
||||
|
||||
#endif // _XCAFPrs_DocumentNode_HeaderFile
|
Reference in New Issue
Block a user