0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BinMNaming / BinMNaming_NamingDriver.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 9484c8d..8411cfe
@@ -1,44 +1,42 @@
 // Created on: 2004-05-13
 // Created by: Sergey ZARITCHNY
-// Copyright (c) 2004-2012 OPEN CASCADE SAS
+// Copyright (c) 2004-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.
 
 
-
-
-#include <BinMNaming_NamingDriver.ixx>
-#include <TopAbs_ShapeEnum.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TColStd_Array1OfInteger.hxx>
-#include <CDM_MessageDriver.hxx>
-#include <TDF_Attribute.hxx>
-#include <TNaming_NameType.hxx>
-#include <TNaming_Naming.hxx>
-#include <TNaming_NamedShape.hxx>
-#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
 #include <BinMDF_ADriver.hxx>
+#include <BinMNaming.hxx>
+#include <BinMNaming_NamingDriver.hxx>
 #include <BinObjMgt_Persistent.hxx>
 #include <BinObjMgt_RRelocationTable.hxx>
 #include <BinObjMgt_SRelocationTable.hxx>
-#include <BinMNaming.hxx>
+#include <Message_Messenger.hxx>
+#include <Standard_Type.hxx>
 #include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TColStd_Array1OfInteger.hxx>
+#include <TDF_Attribute.hxx>
 #include <TDF_Tool.hxx>
+#include <TDocStd_FormatVersion.hxx>
+#include <TNaming_Iterator.hxx>
+#include <TNaming_Naming.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(BinMNaming_NamingDriver,BinMDF_ADriver)
+
 #define  NULL_ENTRY "0:0"
-#define  OBSOLETE_NUM sizeof(Standard_Integer)
+#define  OBSOLETE_NUM (int)sizeof(Standard_Integer)
+
 //=======================================================================
 // 'Z' - is reserved for: forfidden to use
 //=======================================================================
@@ -58,9 +56,8 @@ static Standard_Character NameTypeToChar(const TNaming_NameType theNameType)
     case TNaming_WIREIN       : return 'W';
     case TNaming_SHELLIN      : return 'H';
   default:
-    Standard_DomainError::Raise("TNaming_NameType:: Name Type Unknown");
+    throw Standard_DomainError("TNaming_NameType:: Name Type Unknown");
   }
-  return 'N'; // To avoid compilation error message.
 }
 
 //=======================================================================
@@ -80,9 +77,8 @@ static TNaming_NameType CharTypeToName(const Standard_Character theCharType)
     case 'W'  : return TNaming_WIREIN;
     case 'H'  : return TNaming_SHELLIN;
   default:
-    Standard_DomainError::Raise("TNaming_NameType:: Name Type Unknown");
+    throw Standard_DomainError("TNaming_NameType:: Name Type Unknown");
   }
-  return TNaming_UNKNOWN; // To avoid compilation error message.
 }
 
 //=======================================================================
@@ -125,7 +121,7 @@ static TopAbs_ShapeEnum CharToShapeType(const Standard_Character theCharType)
 //=======================================================================
 
 BinMNaming_NamingDriver::BinMNaming_NamingDriver
-                        (const Handle(CDM_MessageDriver)& theMsgDriver)
+                        (const Handle(Message_Messenger)& theMsgDriver)
      : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TNaming_Naming)->Name())
 {
 }
@@ -224,30 +220,27 @@ Standard_Boolean BinMNaming_NamingDriver::Paste
           else {
             aMsg = TCollection_ExtendedString("BinMNaming_NamingDriver: "
                                               "Cannot retrieve Index of Name");
-            WriteMessage (aMsg); 
+            myMessageDriver->Send (aMsg, Message_Warning); 
           }
         } else {
           aMsg = TCollection_ExtendedString("BinMNaming_NamingDriver: "
                                             "Cannot retrieve reference on "
                                             "StopNamedShape");
-          WriteMessage (aMsg); 
+          myMessageDriver->Send (aMsg, Message_Warning); 
         }
       } else {
         aMsg = TCollection_ExtendedString("BinMNaming_NamingDriver: "
                                           "Cannot retrieve reference on "
                                           "Arguments of Name");
-       WriteMessage (aMsg);
-      }
+       myMessageDriver->Send (aMsg, Message_Warning);
+         }
 
-#ifdef DEB
-      //cout << "CurDocVersion = " << BinMNaming::DocumentVersion() <<endl;
-#endif
-      if(BinMNaming::DocumentVersion() > 3) {
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_4) {
        TCollection_AsciiString entry;
        ok = theSource >> entry;
        if(ok) {
-#ifdef DEB
-         cout << "NamingDriver:: Retrieved Context Label = " << entry << " Ok = " << theSource.IsOK()  <<endl;
+#ifdef OCCT_DEBUG
+         std::cout << "NamingDriver:: Retrieved Context Label = " << entry << " Ok = " << theSource.IsOK()  <<std::endl;
 #endif
         
 //6. context label
@@ -259,14 +252,46 @@ Standard_Boolean BinMNaming_NamingDriver::Paste
                aName.ContextLabel(tLab);
            }
        }
-      }
-#ifdef DEB
-      else if(BinMNaming::DocumentVersion() == -1)
-       cout << "Current DocVersion field is not initialized. "  <<endl;
-      else 
-       cout << "Current DocVersion = " << BinMNaming::DocumentVersion() <<endl;
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_5 &&
+       theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() <= TDocStd_FormatVersion_VERSION_6) {
+          // Orientation processing - converting from old format
+      Handle(TNaming_NamedShape) aNShape;
+      if(anAtt->Label().FindAttribute(TNaming_NamedShape::GetID(), aNShape)) {
+            //const TDF_Label& aLab = aNS->Label();
+        TNaming_Iterator itL (aNShape);
+        for (; itL.More(); itL.Next()) {
+          const TopoDS_Shape& S = itL.NewShape();
+          if (S.IsNull()) continue;
+          if(aNShape->Evolution() == TNaming_SELECTED) {
+            if (itL.More() && itL.NewShape().ShapeType() != TopAbs_VERTEX &&
+                  !itL.OldShape().IsNull() && itL.OldShape().ShapeType() == TopAbs_VERTEX ) {//OR-N
+              TopAbs_Orientation OrientationToApply = itL.OldShape().Orientation();
+              aName.Orientation(OrientationToApply);
+                       }
+                 }
+               }
+         }
+       }
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_7) {
+      ok = theSource >> anIndx;
+      TopAbs_Orientation OrientationToApply(TopAbs_FORWARD);
+      if(ok) {
+        OrientationToApply = (TopAbs_Orientation)anIndx;
+               aName.Orientation(OrientationToApply);
+#ifdef OCCT_DEBUG
+           std::cout << "NamingDriver:: Retrieved Orientation = " << OrientationToApply << " Ok = " << theSource.IsOK()  <<std::endl;
 #endif
-    }
+         } else {
+          aMsg = TCollection_ExtendedString("BinMNaming_NamingDriver: "
+                                            "Cannot retrieve Name Orientation ");
+         myMessageDriver->Send (aMsg, Message_Warning);
+         }
+       }
+       }
+#ifdef OCCT_DEBUG
+             std::cout << "Current Document Format Version = " << theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() <<std::endl;      
+#endif
+       }
   }
   return ok;
 }
@@ -332,4 +357,8 @@ void BinMNaming_NamingDriver::Paste (const Handle(TDF_Attribute)&  theSource,
   if(!aName.ContextLabel().IsNull())
     TDF_Tool::Entry(aName.ContextLabel(), entry);
   theTarget << entry;
+
+//7. keep Orientation
+  theTarget << (Standard_Integer)aName.Orientation();
+
 }