0025748: Parallel version of progress indicator
[occt.git] / src / XmlMNaming / XmlMNaming_NamedShapeDriver.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 9200ebe..813bf7b
@@ -1,41 +1,41 @@
 // Created on: 2001-07-11
 // Created by: Julia DOROVSKIKH
-// Copyright (c) 2001-2012 OPEN CASCADE SAS
+// Copyright (c) 2001-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.
 
 //AGV 150202: Changed prototype LDOM_Node::getOwnerDocument()
 
-#include <XmlMNaming_NamedShapeDriver.ixx>
-
-#include <XmlObjMgt.hxx>
-#include <XmlMNaming_Array1OfShape1.hxx>
-#include <XmlMNaming_Shape1.hxx>
-
+#include <BRepTools.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_ProgressScope.hxx>
+#include <LDOM_OSStream.hxx>
+#include <LDOM_Text.hxx>
+#include <Standard_SStream.hxx>
+#include <Standard_Type.hxx>
+#include <TDF_Attribute.hxx>
 #include <TDF_Label.hxx>
 #include <TNaming_Builder.hxx>
-#include <TNaming_NamedShape.hxx>
 #include <TNaming_Iterator.hxx>
-
+#include <TNaming_NamedShape.hxx>
 #include <TopoDS_Shape.hxx>
-#include <BRepTools.hxx>
-#include <LDOM_Text.hxx>
-#include <LDOM_OSStream.hxx>
+#include <TopTools_LocationSet.hxx>
+#include <XmlMNaming_NamedShapeDriver.hxx>
+#include <XmlMNaming_Shape1.hxx>
+#include <XmlObjMgt.hxx>
+#include <XmlObjMgt_Array1.hxx>
+#include <XmlObjMgt_Persistent.hxx>
 
-#include <Standard_SStream.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(XmlMNaming_NamedShapeDriver,XmlMDF_ADriver)
 
 static TNaming_Evolution          EvolutionEnum   (const XmlObjMgt_DOMString&);
 static const XmlObjMgt_DOMString& EvolutionString (const TNaming_Evolution);
@@ -65,7 +65,7 @@ IMPLEMENT_DOMSTRING (EvolReplaceString,   "replace")
 //=======================================================================
 
 XmlMNaming_NamedShapeDriver::XmlMNaming_NamedShapeDriver
-                        (const Handle(CDM_MessageDriver&) theMessageDriver)
+                        (const Handle(Message_Messenger)& theMessageDriver)
      : XmlMDF_ADriver (theMessageDriver, NULL),
   myShapeSet (Standard_False) // triangles mode
 {}
@@ -107,8 +107,8 @@ Standard_Boolean XmlMNaming_NamedShapeDriver::Paste
   // apres creation Builder qui a mis la version a 1 :
   aTarget -> SetVersion (aVersion);
 
-  const XmlMNaming_Array1OfShape1 OldPShapes (anElement, ::OldsString());
-  const XmlMNaming_Array1OfShape1 NewPShapes (anElement, ::NewsString());
+  const XmlObjMgt_Array1 OldPShapes (anElement, ::OldsString());
+  const XmlObjMgt_Array1 NewPShapes (anElement, ::NewsString());
   if (NewPShapes.Length() == 0 && OldPShapes.Length() == 0)
     return Standard_True;
 
@@ -122,7 +122,7 @@ Standard_Boolean XmlMNaming_NamedShapeDriver::Paste
   Standard_Integer upper = NewPShapes.Upper();
   if (OldPShapes.Upper() > upper) upper = OldPShapes.Upper();
 
-  for (Standard_Integer i = lower; i <= upper; i++)
+  for (Standard_Integer i = upper; i >= lower; --i)
   {
     const XmlMNaming_Shape1 aNewPShape  = NewPShapes.Value(i);
     const XmlMNaming_Shape1 anOldPShape = OldPShapes.Value(i);
@@ -130,7 +130,7 @@ Standard_Boolean XmlMNaming_NamedShapeDriver::Paste
     if ( evol != TNaming_PRIMITIVE && anOldPShape.Element() != NULL )
     {
       if (::doTranslate (anOldPShape, anOldShape, aShapeSet)) {
-        WriteMessage ("NamedShapeDriver: Error reading a shape from array");
+        myMessageDriver->Send ("NamedShapeDriver: Error reading a shape from array", Message_Fail);
         return Standard_False;
       }
     }
@@ -138,7 +138,7 @@ Standard_Boolean XmlMNaming_NamedShapeDriver::Paste
     if (evol != TNaming_DELETE && aNewPShape.Element() != NULL )
     {
       if (::doTranslate (aNewPShape, aNewShape, aShapeSet)) {
-        WriteMessage ("NamedShapeDriver: Error reading a shape from array");
+        myMessageDriver->Send ("NamedShapeDriver: Error reading a shape from array", Message_Fail);
         return Standard_False;
       }
     }
@@ -161,10 +161,13 @@ Standard_Boolean XmlMNaming_NamedShapeDriver::Paste
       aBld.Select(aNewShape, anOldShape);
       break;
     case TNaming_REPLACE:
-      aBld.Replace(anOldShape,aNewShape);
-      break;
+      aBld.Modify(anOldShape,aNewShape);
+      break; // for compatibility
+      //    case TNaming_REPLACE:
+      //      aBld.Replace(anOldShape,aNewShape);
+      //      break;
     default:
-      Standard_DomainError::Raise("TNaming_Evolution; enum term unknown");
+      throw Standard_DomainError("TNaming_Evolution; enum term unknown");
     }
     anOldShape.Nullify();
     aNewShape.Nullify();
@@ -199,7 +202,7 @@ void XmlMNaming_NamedShapeDriver::Paste (const Handle(TDF_Attribute)& theSource,
   }
 
   BRepTools_ShapeSet& aShapeSet = (BRepTools_ShapeSet&) myShapeSet;
-  XmlMNaming_Array1OfShape1 OldPShapes (1,NbShapes), NewPShapes (1,NbShapes);
+  XmlObjMgt_Array1 OldPShapes (1,NbShapes), NewPShapes (1,NbShapes);
 
   OldPShapes.CreateArrayElement (theTarget, ::OldsString());
   NewPShapes.CreateArrayElement (theTarget, ::NewsString());
@@ -248,12 +251,10 @@ static const XmlObjMgt_DOMString& EvolutionString(const TNaming_Evolution i)
     case TNaming_MODIFY       : return ::EvolModifyString();
     case TNaming_DELETE       : return ::EvolDeleteString();
     case TNaming_SELECTED     : return ::EvolSelectedString();
-    case TNaming_REPLACE      : return ::EvolReplaceString();
+    case TNaming_REPLACE      : return ::EvolModifyString();  //    case TNaming_REPLACE      : return ::EvolReplaceString(); for compatibility
   default:
-    Standard_DomainError::Raise("TNaming_Evolution; enum term unknown");
+    throw Standard_DomainError("TNaming_Evolution; enum term unknown");
   }
-  static XmlObjMgt_DOMString aNullString;
-  return aNullString; // To avoid compilation error message.
 }
 
 //=======================================================================
@@ -274,10 +275,9 @@ static TNaming_Evolution EvolutionEnum (const XmlObjMgt_DOMString& theString)
     else if (theString.equals (::EvolSelectedString()))
       aResult = TNaming_SELECTED;
     else if (theString.equals (::EvolReplaceString()))
-      aResult = TNaming_REPLACE;
+      aResult = TNaming_MODIFY; // for compatibility //TNaming_REPLACE;
     else
-      Standard_DomainError::Raise
-        ("TNaming_Evolution; string value without enum term equivalence");
+      throw Standard_DomainError("TNaming_Evolution; string value without enum term equivalence");
   }
   return aResult;
 }
@@ -334,8 +334,8 @@ static int doTranslate  (const XmlMNaming_Shape1&       thePShape,
 //purpose  : 
 //=======================================================================
 
-void XmlMNaming_NamedShapeDriver::ReadShapeSection
-                                        (const XmlObjMgt_Element& theElement)
+void XmlMNaming_NamedShapeDriver::ReadShapeSection (const XmlObjMgt_Element& theElement, 
+                                                    const Message_ProgressRange& theRange)
 {
   XmlObjMgt_Element anElement =
     XmlObjMgt::FindChildByName (theElement, ::ShapesString());
@@ -345,15 +345,10 @@ void XmlMNaming_NamedShapeDriver::ReadShapeSection
          aNode = anElement.getNextSibling())
     {
       if (aNode.getNodeType() == LDOM_Node::TEXT_NODE) {
-        LDOM_Text aText = (LDOM_Text&) aNode;
-        LDOMString aData = aText.getData();
-       #ifdef USE_STL_STREAM
+        LDOMString aData = aNode.getNodeValue();
         std::stringstream aStream (std::string(aData.GetString()));
-       #else
-        istrstream aStream (Standard_CString(aData.GetString()));
-       #endif
         myShapeSet.Clear();
-        myShapeSet.Read (aStream);
+        myShapeSet.Read (aStream, theRange);
         break;
       }
     }
@@ -365,8 +360,8 @@ void XmlMNaming_NamedShapeDriver::ReadShapeSection
 //purpose  : 
 //=======================================================================
 
-void XmlMNaming_NamedShapeDriver::WriteShapeSection
-                                        (XmlObjMgt_Element& theElement)
+void XmlMNaming_NamedShapeDriver::WriteShapeSection (XmlObjMgt_Element& theElement,
+                                                     const Message_ProgressRange& theRange)
 {
   //  Create "shapes" element and append it as child
   XmlObjMgt_Document aDoc     = theElement.getOwnerDocument();
@@ -376,11 +371,15 @@ void XmlMNaming_NamedShapeDriver::WriteShapeSection
   //  Add text to the "shapes" element
   if (myShapeSet.NbShapes() > 0) {
     myShapeSet.SetFormatNb(2);
-    LDOM_OSStream aStream (1024);
+    LDOM_OSStream aStream (16 * 1024);
 //    ostrstream aStream;
 //    aStream.rdbuf() -> setbuf (0, 16380);
-    myShapeSet.Write (aStream);
-    aStream << ends;
+    Message_ProgressScope aPS(theRange, "Writing shape section", 2);
+    myShapeSet.Write (aStream, aPS.Next());
+    if (!aPS.More())
+      return;
+
+    aStream << std::ends;
     char * aStr = (char *)aStream.str();
     LDOM_Text aText = aDoc.createTextNode (aStr);
     delete [] aStr;
@@ -390,6 +389,9 @@ void XmlMNaming_NamedShapeDriver::WriteShapeSection
   // Clear the shape set to avoid appending to it on the next write
     BRepTools_ShapeSet& aShapeSet = (BRepTools_ShapeSet&) myShapeSet;
     aShapeSet.Clear();
+    if (!aPS.More())
+      return;
+    aPS.Next();
   }
 }