0023950: Names and visibility of points not saved when writing XCAF Document into...
[occt.git] / src / STEPControl / STEPControl_ActorWrite.cxx
old mode 100755 (executable)
new mode 100644 (file)
index d713de5..efc1b61
@@ -1,19 +1,15 @@
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// 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.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 //:k8 abv 6 Jan 99: unique names for PRODUCTs
 //:k9 abv 6 Jan 99: TR10: eliminating duplicated APPLICATION_CONTEXT entities
@@ -528,17 +524,19 @@ Standard_Boolean STEPControl_ActorWrite::IsAssembly (TopoDS_Shape &S) const
 {
   if ( ! GroupMode() || S.ShapeType() != TopAbs_COMPOUND ) return Standard_False;
   // PTV 16.09.2002  OCC725 for storing compound of vertices
-  if (S.ShapeType() == TopAbs_COMPOUND ) {
-    Standard_Boolean IsOnlyVertices = Standard_True;
-    TopoDS_Iterator anItr( S );
-    for ( ; anItr.More(); anItr.Next() ) {
-      if ( anItr.Value().ShapeType() != TopAbs_VERTEX ) {
-        IsOnlyVertices = Standard_False;
-        break;
+  if (Interface_Static::IVal("write.step.vertex.mode") == 0) {//bug 23950
+    if (S.ShapeType() == TopAbs_COMPOUND ) {
+      Standard_Boolean IsOnlyVertices = Standard_True;
+      TopoDS_Iterator anItr( S );
+      for ( ; anItr.More(); anItr.Next() ) {
+        if ( anItr.Value().ShapeType() != TopAbs_VERTEX ) {
+          IsOnlyVertices = Standard_False;
+          break;
+        }
       }
+      if ( IsOnlyVertices )
+        return Standard_False;
     }
-    if ( IsOnlyVertices )
-      return Standard_False;
   }
   if ( GroupMode() ==1 ) return Standard_True;
   TopoDS_Iterator it ( S );
@@ -760,6 +758,8 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferShape (const Handle(Tran
   // create a list of items to translate
   Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
   
+  Standard_Boolean isSeparateVertices = 
+    Interface_Static::IVal("write.step.vertex.mode") == 0;//bug 23950
   // PTV 16.09.2002 OCC725 separate shape from solo vertices.
   Standard_Boolean isOnlyVertices = Standard_False;
   if (theShape.ShapeType() == TopAbs_COMPOUND) {
@@ -770,24 +770,26 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferShape (const Handle(Tran
     aB.MakeCompound(aNewShape);
     aB.MakeCompound(aCompOfVrtx);
     TopoDS_Iterator anCompIt(theShape);
-    for (; anCompIt.More(); anCompIt.Next()) {
-      TopoDS_Shape aCurSh = anCompIt.Value();
-      if (aCurSh.ShapeType() != TopAbs_VERTEX) {
-        aB.Add(aNewShape, aCurSh);
-        countSh++;
-      }
-      else {
-        aB.Add(aCompOfVrtx, aCurSh);
-        countVrtx++;
+    if (isSeparateVertices) {
+      for (; anCompIt.More(); anCompIt.Next()) {
+        TopoDS_Shape aCurSh = anCompIt.Value();
+        if (aCurSh.ShapeType() != TopAbs_VERTEX) {
+          aB.Add(aNewShape, aCurSh);
+          countSh++;
+        }
+        else {
+          aB.Add(aCompOfVrtx, aCurSh);
+          countVrtx++;
+        }
       }
+      // replace the shapes
+      if (countSh)
+        theShape = aNewShape;
+      if (countVrtx)
+        RepItemSeq->Append(aCompOfVrtx);
+      if (countSh == 0) 
+        isOnlyVertices = Standard_True;
     }
-    // replace the shapes
-    if (countSh)
-      theShape = aNewShape;
-    if (countVrtx)
-      RepItemSeq->Append(aCompOfVrtx);
-    if (countSh == 0) 
-      isOnlyVertices = Standard_True;
   } 
   
   if (theShape.ShapeType() == TopAbs_COMPOUND) {
@@ -831,6 +833,19 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferShape (const Handle(Tran
   else if (theShape.ShapeType() == TopAbs_FACE) {
     RepItemSeq->Append(TopoDS::Face(theShape));
   }
+  else if (theShape.ShapeType() == TopAbs_COMPSOLID) {
+    FP->AddWarning(start,"NonManifold COMPSOLID was translated like a set of SOLIDs");
+    if ( GroupMode() > 0)
+      return TransferCompound(start, SDR0, FP);
+    else {
+      TopExp_Explorer SolidExp;
+      for (SolidExp.Init(theShape, TopAbs_SOLID);
+           SolidExp.More();SolidExp.Next()) {
+        RepItemSeq->Append(TopoDS::Solid(SolidExp.Current()));
+      }
+    }
+  }
+
   else if (mymode != STEPControl_GeometricCurveSet && mymode != STEPControl_AsIs) {
     FP->AddFail(start,"The Shape is not a SOLID, nor a SHELL, nor a FACE");
     return binder;
@@ -1271,6 +1286,8 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferCompound (const Handle(T
   Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
   // Prepare a collection for non-manifold group of shapes
   Handle(TopTools_HSequenceOfShape) NonManifoldGroup = new TopTools_HSequenceOfShape();
+  Standard_Boolean isSeparateVertices = 
+    (Interface_Static::IVal("write.step.vertex.mode") == 0);//bug 23950
   // PTV OCC725 17.09.2002 -- begin --
   Standard_Integer nbFreeVrtx = 0;
   TopoDS_Compound aCompOfVrtx;
@@ -1284,7 +1301,7 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferCompound (const Handle(T
 
   for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
     TopoDS_Shape aSubShape = iter.Value();
-    if (aSubShape.ShapeType() != TopAbs_VERTEX) {
+    if (aSubShape.ShapeType() != TopAbs_VERTEX || !isSeparateVertices) {
 
       // Store non-manifold topology as shells (ssv; 10.11.2010)
       if (!isManifold && aSubShape.ShapeType() == TopAbs_SOLID) {
@@ -1339,12 +1356,13 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferCompound (const Handle(T
     while ( !bnd.IsNull() ) {
       Handle(Transfer_SimpleBinderOfTransient) bx = 
         Handle(Transfer_SimpleBinderOfTransient)::DownCast(bnd);
-      if ( !bx.IsNull() )
+      if ( !bx.IsNull() ) {
         // Single SDR is created for a non-manifold group (ssv: 12.11.2010)
         if (!isManifold && i > 1)
           break;
         else
           binder->AddResult( TransientResult( bx->Result() ) );
+      }
       bnd = bnd->NextResult();
     }
   }
@@ -1427,6 +1445,8 @@ Handle(Transfer_Binder)  STEPControl_ActorWrite::TransferSubShape (const Handle(
     FP->Bind (mapper,resbind);
     resprod=resbind; //KA - OCC7141(skl 10.11.2004)
   }
+  if (resprod.IsNull())
+    return resprod;
 
   // A new resbind may have been produced
 //  DeclareAndCast(Transfer_SimpleBinderOfTransient,restrans,resbind);