]> OCCT Git - occt-copy.git/commitdiff
0032260: Draw Harness, IVtkDraw - add command ivtkwritevtp dumping actor into VTP...
authorkgv <kgv@opencascade.com>
Mon, 29 Mar 2021 11:48:53 +0000 (14:48 +0300)
committerkgv <kgv@opencascade.com>
Thu, 1 Apr 2021 07:43:09 +0000 (10:43 +0300)
src/IVtkDraw/IVtkDraw.cxx

index e71826b5ef2d5614d3f5cb0b453b9f4061b3b42b..c03641234a709ffe8f69af5d538e7cae857b915b 100644 (file)
@@ -74,6 +74,7 @@
 #include <vtkSmartPointer.h>
 #include <vtkTIFFWriter.h>
 #include <vtkWindowToImageFilter.h>
+#include <vtkXMLPolyDataWriter.h>
 #ifndef _WIN32
   #include <X11/X.h>
   #include <X11/Shell.h>
@@ -91,6 +92,8 @@
   #define HAVE_VTK_SRGB
 #endif
 
+#pragma comment(lib, "vtkIOXML-8.2.lib") ///
+
 //================================================================
 // TYPE DEFINITIONS
 //================================================================
@@ -1256,6 +1259,78 @@ static Standard_Integer VtkSetTransparency (Draw_Interpretor& ,
   return 0;
 }
 
+//================================================================
+// Function  : VtkWriteVtp
+// Purpose   :
+//================================================================
+static Standard_Integer VtkWriteVtp (Draw_Interpretor& theDI,
+                                     Standard_Integer theArgNb,
+                                     const char** theArgVec)
+{
+  if (!GetInteractor()
+   || !GetInteractor()->IsEnabled())
+  {
+    Message::SendFail() << "Error: call ivtkinit before\n";
+    return 1;
+  }
+
+  vtkSmartPointer<vtkActor> anActor;
+  TCollection_AsciiString aFileName;
+  vtkSmartPointer<vtkXMLPolyDataWriter> aWriter = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    TCollection_AsciiString anArgCase (anArg);
+    anArgCase.LowerCase();
+    if (anArgCase == "-binary")
+    {
+      const bool isBinary = Draw::ParseOnOffIterator (theArgNb, theArgVec, anArgIter);
+      if (isBinary)
+      {
+        aWriter->SetDataModeToBinary();
+      }
+      else
+      {
+        aWriter->SetDataModeToAscii();
+      }
+    }
+    else if (anActor.GetPointer() == NULL
+          && GetMapOfActors().Find2 (anArg, anActor))
+    {
+      vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc = IVtkTools_ShapeObject::GetShapeSource (anActor);
+      if (aSrc.GetPointer() == NULL
+       || aSrc->GetShape().IsNull())
+      {
+        theDI << "Syntax error: invalid actor '" << anArg << "'";
+        return 1;
+      }
+
+      aWriter->SetInputConnection (aSrc->GetOutputPort());
+    }
+    else if (aFileName.IsEmpty())
+    {
+      aFileName = anArg;
+      aWriter->SetFileName (aFileName.ToCString());
+    }
+    else
+    {
+      theDI << "Syntax error: unknown argument '" << anArg << "'";
+      return 1;
+    }
+  }
+  if (aFileName.IsEmpty() || anActor.GetPointer() == NULL)
+  {
+    Message::SendFail() << "Syntax error: wrong number of arguments";
+    return 1;
+  }
+
+  if (aWriter->Write() == 0)
+  {
+    theDI << "Error: unable to write file '" << aFileName << "'";
+  }
+  return 0;
+}
+
 //================================================================
 // Function  : VtkMoveTo
 // Purpose   : 
@@ -1733,6 +1808,11 @@ void IVtkDraw::Commands (Draw_Interpretor& theCommands)
               "ivtksettransparency name 0..1"
       "\n\t\t: Sets transparency to the object with name 'name'.",
     __FILE__, VtkSetTransparency, group);
+
+  theCommands.Add("ivtkwritevtp",
+              "ivtkwritevtp name1 fileName"
+      "\n\t\t: Export IVtk actor into VTP format.",
+    __FILE__, VtkWriteVtp, group);
 }
 
 //================================================================