0023594: XCAFDoc_LayerTool extended to work with layer defined by its label, not...
authorRoman Lygin <roman.lygin@gmail.com>
Wed, 28 Nov 2012 09:19:04 +0000 (13:19 +0400)
committerRoman Lygin <roman.lygin@gmail.com>
Fri, 7 Dec 2012 08:14:14 +0000 (12:14 +0400)
src/XCAFDoc/XCAFDoc_LayerTool.cdl
src/XCAFDoc/XCAFDoc_LayerTool.cxx

index 41944a0..4cac6ec 100755 (executable)
@@ -118,16 +118,31 @@ is
        ---Purpose: Remove link from label <L> and Layer <aLayer>.
        --          returns FALSE if no such layer.
 
+    UnSetOneLayer (me; L: Label from TDF;
+                    aLayerL: Label from TDF) returns Boolean;
+       ---Purpose: Remove link from label <L> and Layer <aLayerL>.
+       --          returns FALSE if <aLayerL> is not a layer label.
+
     IsSet (me; L: Label from TDF;
               aLayer : ExtendedString from TCollection) returns Boolean;
        ---Purpose: Returns True if label <L> has a Layer assosiated 
        --          with the <aLayer>.
     
+    IsSet (me; L: Label from TDF;
+              aLayerL: Label from TDF) returns Boolean;
+       ---Purpose: Returns True if label <L> has a Layer assosiated 
+       --          with the <aLayerL> label.
+    
     GetLayers (me: mutable; L: Label from TDF; 
                           aLayerS : out HSequenceOfExtendedString from TColStd)
      returns Boolean;
        ---Purpose: Return sequence of strings <aLayerS> that assosiated with label <L>.
     
+    GetLayers (me: mutable; L: Label from TDF; 
+                          aLayerLS : out LabelSequence from TDF)
+     returns Boolean;
+       ---Purpose: Return sequence of labels <aLayerSL> that assosiated with label <L>.
+    
     GetLayers (me: mutable; L: Label from TDF) returns HSequenceOfExtendedString from TColStd;
        ---Purpose: Return sequence of strings that assosiated with label <L>.
     
@@ -174,15 +189,29 @@ is
        ---Purpose: Remove link between shape <Sh> and layer <aLayer>.
        --          returns FALSE if no such layer <aLayer> or shape <Sh>.
 
+    UnSetOneLayer (me: mutable; Sh: Shape from TopoDS;
+                          aLayerL: Label from TDF) returns Boolean;
+       ---Purpose: Remove link between shape <Sh> and layer <aLayerL>.
+       --          returns FALSE if no such layer <aLayerL> or shape <Sh>.
+
     IsSet (me: mutable; Sh: Shape from TopoDS;
                        aLayer : ExtendedString from TCollection) returns Boolean;
        ---Purpose: Returns True if shape <Sh> has a Layer assosiated 
        --          with the <aLayer>.
     
+    IsSet (me: mutable; Sh: Shape from TopoDS;
+                       aLayerL : Label from TDF) returns Boolean;
+       ---Purpose: Returns True if shape <Sh> has a Layer assosiated 
+       --          with the <aLayerL>.
+    
     GetLayers (me: mutable; Sh: Shape from TopoDS;
                           aLayerS : out HSequenceOfExtendedString from TColStd) returns Boolean;
        ---Purpose: Return sequence of strings <aLayerS> that assosiated with shape <Sh>.
     
+    GetLayers (me: mutable; Sh: Shape from TopoDS;
+                          aLayerLS : out LabelSequence from TDF) returns Boolean;
+       ---Purpose: Return sequence of labels <aLayerLS> that assosiated with shape <Sh>.
+    
     GetLayers (me: mutable; Sh: Shape from TopoDS) returns HSequenceOfExtendedString from TColStd;
        ---Purpose: Return sequence of strings that assosiated with shape <Sh>.
 
index c2e1cb0..e558911 100755 (executable)
@@ -273,13 +273,24 @@ Standard_Boolean XCAFDoc_LayerTool::UnSetOneLayer(const TDF_Label& L,
 {
   TDF_Label alab;
   if ( !FindLayer(aLayer, alab) ) return Standard_False;
-  
+  return UnSetOneLayer (L, alab);
+}
+
+//=======================================================================
+//function : UnSetOneLayer
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean XCAFDoc_LayerTool::UnSetOneLayer(const TDF_Label& L,
+                                                 const TDF_Label& aLayerL) const
+{
   Handle(XCAFDoc_GraphNode) FGNode, ChGNode;
   if ( !L.FindAttribute (XCAFDoc::LayerRefGUID(), ChGNode) ) return Standard_False;
-  if ( !alab.FindAttribute (XCAFDoc::LayerRefGUID(), FGNode) ) return Standard_False;
+  if ( !aLayerL.FindAttribute (XCAFDoc::LayerRefGUID(), FGNode) ) return Standard_False;
   ChGNode->UnSetFather(FGNode);
   return Standard_True;
 }
+
 //=======================================================================
 //function : IsSet
 //purpose  : 
@@ -303,6 +314,28 @@ Standard_Boolean XCAFDoc_LayerTool::IsSet(const TDF_Label& L,
 }
 
 
+//=======================================================================
+//function : IsSet
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean XCAFDoc_LayerTool::IsSet(const TDF_Label& L,
+                                         const TDF_Label& aLayerL) const
+{
+  Handle(XCAFDoc_GraphNode) Node;
+  Handle(TDataStd_Name) aName;
+  TDF_Label lab;
+  if (L.FindAttribute(XCAFDoc::LayerRefGUID(), Node) && (Node->NbFathers() != 0 ) ) {
+    Standard_Integer i = 1;
+    for (; i <= Node->NbFathers(); i++) {
+      lab = Node->GetFather(i)->Label();
+      if (lab == aLayerL)
+       return Standard_True;
+    }
+  }
+  return Standard_False;
+}
+
 //=======================================================================
 //function : GetLayers
 //purpose  : 
@@ -312,32 +345,42 @@ Standard_Boolean XCAFDoc_LayerTool::GetLayers(const TDF_Label& L,
                                              Handle(TColStd_HSequenceOfExtendedString)& aLayerS) 
 {
   aLayerS = GetLayers(L);
-  if (aLayerS->Length() != 0) return Standard_True;
-  return Standard_False;
+  return (aLayerS->Length() != 0);
 }
 
-
 //=======================================================================
 //function : GetLayers
 //purpose  : 
 //=======================================================================
 
-Handle(TColStd_HSequenceOfExtendedString) XCAFDoc_LayerTool::GetLayers(const TDF_Label& L) 
+Standard_Boolean XCAFDoc_LayerTool::GetLayers(const TDF_Label& L,
+                                             TDF_LabelSequence& aLayerLS) 
 {
-  Handle(TColStd_HSequenceOfExtendedString) aLayerS = new TColStd_HSequenceOfExtendedString;
+  aLayerLS.Clear();
   Handle(XCAFDoc_GraphNode) aGNode;
   if ( L.FindAttribute( XCAFDoc::LayerRefGUID(), aGNode) ) {
-    if ( aGNode->NbFathers() == 0 ) {
-      return aLayerS;
+    for (Standard_Integer i = 1; i <= aGNode->NbFathers(); i++) {
+      aLayerLS.Append (aGNode->GetFather(i)->Label());
     }
-    Standard_Integer i = 1;
-    TDF_Label aLab;
-    Handle(TDataStd_Name) aName;
-    for (; i <= aGNode->NbFathers(); i++) {
-      aLab = aGNode->GetFather(i)->Label();
-      if ( aLab.FindAttribute(TDataStd_Name::GetID(), aName) ) {
-       aLayerS->Append( aName->Get() );
-//     cout << aName->Get() <<endl;
+  }
+  return aLayerLS.Length() > 0;
+}
+
+//=======================================================================
+//function : GetLayers
+//purpose  : 
+//=======================================================================
+
+Handle(TColStd_HSequenceOfExtendedString) XCAFDoc_LayerTool::GetLayers(const TDF_Label& L) 
+{
+  Handle(TColStd_HSequenceOfExtendedString) aLayerS = new TColStd_HSequenceOfExtendedString;
+  TDF_LabelSequence aLayerLS;
+  if ( GetLayers( L, aLayerLS ) ) {
+    for (Standard_Integer i = 1; i <= aLayerLS.Length(); ++i) {
+      const TDF_Label& aLab = aLayerLS(i);
+      Handle(TDataStd_Name) aName;
+      if ( aLab.FindAttribute( TDataStd_Name::GetID(), aName ) ) {
+        aLayerS->Append( aName->Get() );
       }
     }
   }
@@ -451,6 +494,19 @@ Standard_Boolean XCAFDoc_LayerTool::UnSetOneLayer(const TopoDS_Shape& Sh,
   return UnSetOneLayer(aLab, aLayer);
 }
 
+//=======================================================================
+//function : UnSetOneLayer
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean XCAFDoc_LayerTool::UnSetOneLayer(const TopoDS_Shape& Sh,
+                                                 const TDF_Label& aLayerL)
+{
+  TDF_Label aLab;
+  if (! myShapeTool->FindShape(Sh, aLab) ) return Standard_False;
+  return UnSetOneLayer(aLab, aLayerL);
+}
+
 //=======================================================================
 //function : IsSet
 //purpose  : 
@@ -465,6 +521,19 @@ Standard_Boolean XCAFDoc_LayerTool::IsSet(const TopoDS_Shape& Sh,
 }
 
 
+//=======================================================================
+//function : IsSet
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean XCAFDoc_LayerTool::IsSet(const TopoDS_Shape& Sh,
+                                         const TDF_Label& aLayerL) 
+{
+  TDF_Label aLab;
+  if (! myShapeTool->FindShape(Sh, aLab) ) return Standard_False;
+  return IsSet(aLab, aLayerL);
+}
+
 //=======================================================================
 //function : GetLayers
 //purpose  : 
@@ -478,6 +547,19 @@ Standard_Boolean XCAFDoc_LayerTool::GetLayers(const TopoDS_Shape& Sh,
   return GetLayers(aLab, aLayerS);
 }
 
+//=======================================================================
+//function : GetLayers
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean XCAFDoc_LayerTool::GetLayers(const TopoDS_Shape& Sh,
+                                             TDF_LabelSequence& aLayerLS) 
+{
+  TDF_Label aLab;
+  if (! myShapeTool->FindShape(Sh, aLab) ) return Standard_False;
+  return GetLayers(aLab, aLayerLS);
+}
+
 
 //=======================================================================
 //function : GetLayers