From: aba Date: Mon, 8 Feb 2016 11:47:57 +0000 (+0300) Subject: 0027142: Data Exchange - add possibility to set location in XCAFDoc_ShapeTool interface X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FCR27142;p=occt-copy.git 0027142: Data Exchange - add possibility to set location in XCAFDoc_ShapeTool interface --- diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx index 7949f6580c..f9e37bdf96 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -453,6 +453,41 @@ void XCAFDoc_ShapeTool::MakeReference (const TDF_Label &L, SetLabelNameByLink(L); } +TDF_Label XCAFDoc_ShapeTool::SetLocation( const TDF_Label &theLabel, + const TopLoc_Location &theLoc) +{ + if(theLoc.IsIdentity()) + { + return theLabel; + } + + TDF_Label aRefLabel = theLabel; + + if (!IsReference (theLabel)) + { + TDF_TagSource aTag; + aRefLabel = aTag.NewChild(Label()); + MakeReference( aRefLabel,theLabel, theLoc); + return aRefLabel; + + } + TDF_Label aShapeLabel; + TopLoc_Location anOldLoc; + GetReferredShape (aRefLabel, aShapeLabel); + anOldLoc = GetLocation(aRefLabel); + TopLoc_Location aNewLoc (theLoc.Transformation() * anOldLoc.Transformation()); + aRefLabel.ForgetAllAttributes (Standard_True); + MakeReference(aRefLabel, aShapeLabel, aNewLoc); + return aRefLabel; +} + + /* XCAFDoc_Location::Set (aRefLabel, aNewLoc); + + Handle(TDataStd_TreeNode) refNode, mainNode; + mainNode = TDataStd_TreeNode::Set ( aRefLabel, XCAFDoc::ShapeRefGUID() ); + refNode = TDataStd_TreeNode::Set ( aShapeLabel, XCAFDoc::ShapeRefGUID() ); + refNode->Remove(); + mainNode->Append(refNode);*/ //======================================================================= //function : addShape //purpose : private diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx index c1f7c9dc6b..da85de0940 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx @@ -411,6 +411,9 @@ public: //! from upper_usage componet to next_usage //! Returns null attribute if no SHUO found Standard_EXPORT static Standard_Boolean FindSHUO (const TDF_LabelSequence& Labels, Handle(XCAFDoc_GraphNode)& theSHUOAttr); + + Standard_EXPORT TDF_Label SetLocation( const TDF_Label &theLabel, + const TopLoc_Location &theLoc); //! Convert Shape (compound) to assembly Standard_EXPORT Standard_Boolean Expand (const TDF_Label& Shape) ; diff --git a/src/XDEDRAW/XDEDRAW_Shapes.cxx b/src/XDEDRAW/XDEDRAW_Shapes.cxx index 954be5fccc..8bb7b34fb7 100644 --- a/src/XDEDRAW/XDEDRAW_Shapes.cxx +++ b/src/XDEDRAW/XDEDRAW_Shapes.cxx @@ -816,6 +816,34 @@ static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integ return 0; } +static Standard_Integer setLocation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc < 3) + { + di << "Use: " << argv[0] << " result Doc label shape \n"; + return 1; + } + Handle(TDocStd_Document) Doc; + DDocStd::GetDocument(argv[2], Doc); + if ( Doc.IsNull() ) { di << argv[2] << " is not a document\n"; return 1; } + Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); + + TDF_Label aLabel; + TDF_Tool::Label(Doc->GetData(), argv[3], aLabel); + if (aLabel.IsNull()) {di<<"No such Label\n"; return 1;} + TopoDS_Shape aInitShape = DBRep::Get(argv[4]); + if (aInitShape.IsNull()) { + di << "Shape " << argv[2] << " is null\n"; + return 1; + } + TopLoc_Location aLoc = aInitShape.Location(); + TDF_Label aReflabel = myAssembly->SetLocation(aLabel, aLoc); + TopLoc_Location aNewLoc = myAssembly->GetLocation(aReflabel); + TopoDS_Shape aRes = myAssembly->GetShape(aReflabel); + DBRep::Set(argv[1], aRes); + return 0; +} + //======================================================================= //function : InitCommands //purpose : @@ -913,5 +941,7 @@ void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di) di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component", __FILE__, setStyledComponent, g); + + di.Add ("XSetLocation", "result Doc Label initshape", __FILE__, setLocation, g); }