]> OCCT Git - occt-copy.git/commitdiff
0027142: Data Exchange - add possibility to set location in XCAFDoc_ShapeTool interface CR27142
authoraba <aba@opencascade.com>
Mon, 8 Feb 2016 11:47:57 +0000 (14:47 +0300)
committeraba <aba@opencascade.com>
Mon, 8 Feb 2016 11:47:57 +0000 (14:47 +0300)
src/XCAFDoc/XCAFDoc_ShapeTool.cxx
src/XCAFDoc/XCAFDoc_ShapeTool.hxx
src/XDEDRAW/XDEDRAW_Shapes.cxx

index 7949f6580cead67d59c2acd8bd1ed7d7ae86c705..f9e37bdf96a8a45a37052b3a9bf3d89f35ca0f2c 100644 (file)
@@ -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
index c1f7c9dc6b9f8d91d6716c2a84094451bed728d5..da85de09403ec0f3c35c6a500ce82493dcf0a71b 100644 (file)
@@ -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) ;
index 954be5fccce4796f927ddf0c33b2e2b8c813f1b3..8bb7b34fb7a33416d1c420bdd185eaa7ce9f142c 100644 (file)
@@ -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);
   
 }