From 12a38ea06606335ef87f1cf388b6cdf7f3d91088 Mon Sep 17 00:00:00 2001 From: kgv Date: Mon, 29 Mar 2021 14:48:53 +0300 Subject: [PATCH] 0032260: Draw Harness, IVtkDraw - add command ivtkwritevtp dumping actor into VTP file --- src/IVtkDraw/IVtkDraw.cxx | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/IVtkDraw/IVtkDraw.cxx b/src/IVtkDraw/IVtkDraw.cxx index e71826b5ef..c03641234a 100644 --- a/src/IVtkDraw/IVtkDraw.cxx +++ b/src/IVtkDraw/IVtkDraw.cxx @@ -74,6 +74,7 @@ #include #include #include +#include #ifndef _WIN32 #include #include @@ -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 anActor; + TCollection_AsciiString aFileName; + vtkSmartPointer aWriter = vtkSmartPointer::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 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); } //================================================================ -- 2.39.5