1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-03 14:10:33 +03:00

// new iteration of updating

This commit is contained in:
dpasukhi
2023-01-08 13:54:53 +00:00
parent 63b4a36425
commit 6b4fa7a257
82 changed files with 9428 additions and 7199 deletions

View File

@@ -4,4 +4,4 @@ ModelingAlgorithms TKGeomAlgo TKTopAlgo TKPrim TKBO TKBool TKHLR TKFillet TKOffs
Visualization TKService TKV3d TKOpenGl TKOpenGles TKMeshVS TKIVtk TKD3DHost
ApplicationFramework TKCDF TKLCAF TKCAF TKBinL TKXmlL TKBin TKXml TKStdL TKStd TKTObj TKBinTObj TKXmlTObj TKVCAF
DataExchange TKXDE TKXSBase TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP TKIGES TKXCAF TKXDEIGES TKXDESTEP TKSTL TKVRML TKXmlXCAF TKBinXCAF TKRWMesh TKXDECascade TKExpress ExpToCasExe
Draw TKDraw TKTopTest TKOpenGlTest TKOpenGlesTest TKD3DHostTest TKViewerTest TKXSDRAW TKDCAF TKXDEDRAW TKTObjDRAW TKQADraw TKIVtkDraw DRAWEXE
Draw TKDraw TKTopTest TKOpenGlTest TKOpenGlesTest TKD3DHostTest TKViewerTest TKXSDRAW TKDCAF TKXDEDRAW TKTObjDRAW TKQADraw TKIVtkDraw DRAWEXE TKXSDRAWBase TKXSDRAWDEWrapper TKXSDRAWGLTF TKXSDRAWIGES TKXSDRAWOBJ TKXSDRAWPLY TKXSDRAWSTEP TKXSDRAWSTL TKXSDRAWVRML

View File

@@ -33,8 +33,6 @@ IFSelect_Editor.cxx
IFSelect_Editor.hxx
IFSelect_EditValue.hxx
IFSelect_FileModifier.gxx
IFSelect_Functions.cxx
IFSelect_Functions.hxx
IFSelect_GeneralModifier.cxx
IFSelect_GeneralModifier.hxx
IFSelect_GraphCounter.cxx

File diff suppressed because it is too large Load Diff

View File

@@ -1,78 +0,0 @@
// Created on: 1993-07-28
// Created by: Christian CAILLET
// Copyright (c) 1993-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _IFSelect_Functions_HeaderFile
#define _IFSelect_Functions_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_CString.hxx>
#include <Standard_Integer.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
class Standard_Transient;
class IFSelect_WorkSession;
class IFSelect_Dispatch;
//! Functions gives access to all the actions which can be
//! commanded with the resources provided by IFSelect : especially
//! WorkSession and various types of Selections and Dispatches
//!
//! It works by adding functions by method Init
class IFSelect_Functions
{
public:
DEFINE_STANDARD_ALLOC
//! Takes the name of an entity, either as argument,
//! or (if <name> is empty) on keyboard, and returns the entity
//! name can be a label or a number (in alphanumeric),
//! it is searched by NumberFromLabel from WorkSession.
//! If <name> doesn't match en entity, a Null Handle is returned
Standard_EXPORT static Handle(Standard_Transient) GiveEntity (const Handle(IFSelect_WorkSession)& WS, const Standard_CString name = "");
//! Same as GetEntity, but returns the number in the model of the
//! entity. Returns 0 for null handle
Standard_EXPORT static Standard_Integer GiveEntityNumber (const Handle(IFSelect_WorkSession)& WS, const Standard_CString name = "");
//! Computes a List of entities from a WorkSession and two idents,
//! first and second, as follows :
//! if <first> is a Number or Label of an entity : this entity
//! if <first> is the name of a Selection in <WS>, and <second>
//! not defined, the standard result of this Selection
//! if <first> is for a Selection and <second> is defined, the
//! standard result of this selection from the list computed
//! with <second> (an entity or a selection)
//! If <second> is erroneous, it is ignored
Standard_EXPORT static Handle(TColStd_HSequenceOfTransient) GiveList (const Handle(IFSelect_WorkSession)& WS, const Standard_CString first = "", const Standard_CString second = "");
//! Evaluates and returns a Dispatch, from data of a WorkSession
//! if <mode> is False, searches for exact name of Dispatch in WS
//! Else (D), allows a parameter between brackets :
//! ex.: dispatch_name(parameter)
//! The parameter can be: an integer for DispPerCount or DispPerFiles
//! or the name of a Signature for DispPerSignature
//! Returns Null Handle if not found not well evaluated
Standard_EXPORT static Handle(IFSelect_Dispatch) GiveDispatch (const Handle(IFSelect_WorkSession)& WS, const Standard_CString name, const Standard_Boolean mode = Standard_True);
//! Defines and loads all basic functions (as ActFunc)
Standard_EXPORT static void Init();
};
#endif // _IFSelect_Functions_HeaderFile

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWBase)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

2
src/TKXSDRAWBase/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

View File

@@ -0,0 +1 @@
XSDRAWBase

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWDEWrapper)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

View File

@@ -0,0 +1 @@
XSDRAWDEWrapper

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWGLTF)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

2
src/TKXSDRAWGLTF/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

View File

@@ -0,0 +1 @@
XSDRAWGLTF

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWIGES)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

2
src/TKXSDRAWIGES/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

View File

@@ -0,0 +1 @@
XSDRAWIGES

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWOBJ)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

24
src/TKXSDRAWOBJ/EXTERNLIB Normal file
View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

2
src/TKXSDRAWOBJ/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

1
src/TKXSDRAWOBJ/PACKAGES Normal file
View File

@@ -0,0 +1 @@
XSDRAWOBJ

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWPLY)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

24
src/TKXSDRAWPLY/EXTERNLIB Normal file
View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

2
src/TKXSDRAWPLY/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

1
src/TKXSDRAWPLY/PACKAGES Normal file
View File

@@ -0,0 +1 @@
XSDRAWPLY

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWSTEP)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

2
src/TKXSDRAWSTEP/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

View File

@@ -0,0 +1 @@
XSDRAWSTEP

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWSTL)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

24
src/TKXSDRAWSTL/EXTERNLIB Normal file
View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

2
src/TKXSDRAWSTL/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

1
src/TKXSDRAWSTL/PACKAGES Normal file
View File

@@ -0,0 +1 @@
XSDRAWSTL

View File

@@ -0,0 +1,3 @@
project(TKXSDRAWVRML)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@@ -0,0 +1,24 @@
TKBRep
TKV3d
TKMath
TKernel
TKService
TKXSBase
TKMeshVS
TKG3d
TKViewerTest
TKG2d
TKSTEPBase
TKTopAlgo
TKGeomBase
TKGeomAlgo
TKMesh
TKDraw
TKSTEP
TKIGES
TKSTL
TKVRML
TKLCAF
TKDCAF
TKXCAF
TKRWMesh

2
src/TKXSDRAWVRML/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

View File

@@ -0,0 +1 @@
XSDRAWVRML

View File

@@ -223,348 +223,6 @@ static Standard_Integer FromShape(Draw_Interpretor& theDI,
return 0;
}
//=======================================================================
//function : ReadIges
//purpose : Read IGES to DECAF document
//=======================================================================
static Standard_Integer ReadIges(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI << "Use: " << theArgVec[0] << " Doc filename [mode]: read IGES file to a document\n";
return 0;
}
Handle(IGESCAFControl_ConfigurationNode) aNode =
new IGESCAFControl_ConfigurationNode();
Standard_Integer onlyvisible = Interface_Static::IVal("read.iges.onlyvisible");
aNode->InternalParameters.ReadOnlyVisible = onlyvisible == 1;
if (theNbArgs == 4)
{
Standard_Boolean aMode = Standard_True;
for (Standard_Integer i = 0; theArgVec[3][i]; i++)
switch (theArgVec[3][i])
{
case '-': aMode = Standard_False; break;
case '+': aMode = Standard_True; break;
case 'c': aNode->InternalParameters.ReadColor = aMode; break;
case 'n': aNode->InternalParameters.ReadName = aMode; break;
case 'l': aNode->InternalParameters.ReadLayer = aMode; break;
}
}
Handle(TDocStd_Document) aDoc;
if (!DDocStd::GetDocument(theArgVec[1], aDoc, Standard_False))
{
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
anApp->NewDocument("BinXCAF", aDoc);
TDataStd_Name::Set(aDoc->GetData()->Root(), theArgVec[1]);
Handle(DDocStd_DrawDocument) aDrawD = new DDocStd_DrawDocument(aDoc);
Draw::Set(theArgVec[1], aDrawD);
}
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
Handle(IGESCAFControl_Provider) aProvider =
new IGESCAFControl_Provider(aNode);
aProvider->SetToUpdateStaticParameters(false);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Read(theArgVec[2], aDoc, aWS, aProgress->Start()))
{
theDI << "Error: Can't read IGES file\n";
return 1;
}
CollectActiveWorkSessions(aWS, theArgVec[2], THE_PREVIOUS_WORK_SESSIONS);
Message::SendInfo() << "Document saved with name " << theArgVec[1];
return 0;
}
//=======================================================================
//function : WriteIges
//purpose : Write DECAF document to IGES
//=======================================================================
//=======================================================================
static Standard_Integer WriteIges(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI << "Use: " << theArgVec[0] << " Doc filename [mode]: write document to IGES file\n";
return 0;
}
Handle(IGESCAFControl_ConfigurationNode) aNode =
new IGESCAFControl_ConfigurationNode();
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(theArgVec[1], aDoc);
if (aDoc.IsNull())
{
theDI << theArgVec[1] << " is not a document\n";
return 1;
}
if (theNbArgs == 4)
{
Standard_Boolean aMode = Standard_True;
for (Standard_Integer i = 0; theArgVec[3][i]; i++)
switch (theArgVec[3][i])
{
case '-': aMode = Standard_False; break;
case '+': aMode = Standard_True; break;
case 'c': aNode->InternalParameters.WriteColor = aMode; break;
case 'n': aNode->InternalParameters.WriteName = aMode; break;
case 'l': aNode->InternalParameters.WriteLayer = aMode; break;
}
}
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
Handle(IGESCAFControl_Provider) aProvider =
new IGESCAFControl_Provider(aNode);
aProvider->SetToUpdateStaticParameters(false);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
const TCollection_AsciiString aPath = theArgVec[2];
if (!aProvider->Write(aPath, aDoc, aWS, aProgress->Start()))
{
theDI << "Error: Can't write IGES file\n";
return 1;
}
CollectActiveWorkSessions(aWS, aPath, THE_PREVIOUS_WORK_SESSIONS);
return 0;
}
//=======================================================================
//function : ReadStep
//purpose : Read STEP file to DECAF document
//=======================================================================
static Standard_Integer ReadStep(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
Standard_CString aDocName = NULL;
TCollection_AsciiString aFilePath, aModeStr;
bool aToTestStream = false;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgCase == "-stream")
{
aToTestStream = true;
}
else if (aDocName == NULL)
{
aDocName = theArgVec[anArgIter];
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIter];
}
else if (aModeStr.IsEmpty())
{
aModeStr = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
Handle(STEPCAFControl_ConfigurationNode) aNode =
new STEPCAFControl_ConfigurationNode();
if (!aModeStr.IsEmpty())
{
Standard_Boolean aMode = Standard_True;
for (Standard_Integer i = 1; aModeStr.Value(i); ++i)
{
switch (aModeStr.Value(i))
{
case '-': aMode = Standard_False; break;
case '+': aMode = Standard_True; break;
case 'c': aNode->InternalParameters.WriteColor = aMode; break;
case 'n': aNode->InternalParameters.WriteName = aMode; break;
case 'l': aNode->InternalParameters.WriteLayer = aMode; break;
case 'v': aNode->InternalParameters.WriteProps = aMode; break;
default:
{
theDI << "Syntax error at '" << aModeStr << "'\n";
return 1;
}
}
}
}
Handle(TDocStd_Document) aDoc;
if (!DDocStd::GetDocument(aDocName, aDoc, Standard_False))
{
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
anApp->NewDocument("BinXCAF", aDoc);
TDataStd_Name::Set(aDoc->GetData()->Root(), aDocName);
Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
Draw::Set(aDocName, aDrawDoc);
}
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
Handle(STEPCAFControl_Provider) aProvider =
new STEPCAFControl_Provider(aNode);
aProvider->SetToUpdateStaticParameters(false);
Standard_Boolean aReadStat = Standard_False;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (aToTestStream)
{
std::ifstream aStream;
OSD_OpenStream(aStream, aFilePath.ToCString(), std::ios::in | std::ios::binary);
TCollection_AsciiString aFolder, aFileNameShort;
OSD_Path::FolderAndFileFromPath(aFilePath, aFolder, aFileNameShort);
aReadStat =
aProvider->Read(aStream, aDoc, aFilePath, aWS, aProgress->Start());
}
else
{
aReadStat =
aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start());
}
if (!aReadStat)
{
theDI << "Cannot read any relevant data from the STEP file\n";
return 1;
}
Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
Draw::Set(aDocName, aDrawDoc);
CollectActiveWorkSessions(aWS, aFilePath, THE_PREVIOUS_WORK_SESSIONS);
Message::SendInfo() << "Document saved with name " << aDocName;
return 0;
}
//=======================================================================
//function : WriteStep
//purpose : Write DECAF document to STEP
//=======================================================================
static Standard_Integer WriteStep(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
Handle(TDocStd_Document) aDoc;
TCollection_AsciiString aDocName, aFilePath;
Handle(STEPCAFControl_ConfigurationNode) aNode =
new STEPCAFControl_ConfigurationNode();
bool aHasModeArg = false, aToTestStream = false;
TDF_Label aLabel;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgCase == "-stream")
{
aToTestStream = true;
}
else if (aDocName.IsEmpty())
{
Standard_CString aDocNameStr = theArgVec[anArgIter];
DDocStd::GetDocument(aDocNameStr, aDoc);
if (aDoc.IsNull())
{
theDI << "Syntax error: '" << theArgVec[anArgIter] << "' is not a document\n";
return 1;
}
aDocName = aDocNameStr;
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIter];
}
else if (!aHasModeArg)
{
aHasModeArg = true;
Standard_Boolean aIsWriteType = Standard_True;
switch (anArgCase.Value(1))
{
case 'a':
case '0': aNode->InternalParameters.WriteModelType = STEPControl_AsIs; break;
case 'f':
case '1': aNode->InternalParameters.WriteModelType = STEPControl_FacetedBrep; break;
case 's':
case '2': aNode->InternalParameters.WriteModelType = STEPControl_ShellBasedSurfaceModel; break;
case 'm':
case '3': aNode->InternalParameters.WriteModelType = STEPControl_ManifoldSolidBrep; break;
case 'w':
case '4': aNode->InternalParameters.WriteModelType = STEPControl_GeometricCurveSet; break;
default:
{
aIsWriteType = Standard_False;
}
}
Standard_Boolean aWrMode = Standard_True;
Standard_Boolean aIsAttrType = Standard_True;
for (Standard_Integer i = 1; i <= anArgCase.Length(); ++i)
{
switch (anArgCase.Value(i))
{
case '-': aWrMode = Standard_False; break;
case '+': aWrMode = Standard_True; break;
case 'c': aNode->InternalParameters.WriteColor = aWrMode; break;
case 'n': aNode->InternalParameters.WriteName = aWrMode; break;
case 'l': aNode->InternalParameters.WriteLayer = aWrMode; break;
case 'v': aNode->InternalParameters.WriteProps = aWrMode; break;
default:
{
aIsAttrType = Standard_False;
}
}
}
if (!aIsAttrType && !aIsWriteType)
{
theDI << "Syntax error: mode '" << anArgCase << "' is incorrect mode\n";
return 1;
}
}
else if (aNode->InternalParameters.WriteMultiPrefix.IsEmpty()
&& anArgCase.Search(":") == -1)
{
aNode->InternalParameters.WriteMultiPrefix = theArgVec[anArgIter];
}
else if (aLabel.IsNull())
{
aNode->InternalParameters.WriteLabels.Append(theArgVec[anArgIter]);
}
else
{
theDI << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
Handle(STEPCAFControl_Provider) aProvider =
new STEPCAFControl_Provider(aNode);
aProvider->SetToUpdateStaticParameters(false);
Standard_Boolean aReadStat = Standard_False;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (aToTestStream)
{
std::ofstream aStream;
OSD_OpenStream(aStream, aFilePath, std::ios::out | std::ios::binary);
TCollection_AsciiString aFolder, aFileNameShort;
OSD_Path::FolderAndFileFromPath(aFilePath, aFolder, aFileNameShort);
aReadStat =
aProvider->Write(aStream, aDoc, aWS, aProgress->Start());
}
else
{
aReadStat =
aProvider->Write(aFilePath, aDoc, aWS, aProgress->Start());
}
if (!aReadStat)
{
theDI << "Cannot write any relevant data to the STEP file\n";
return 1;
}
CollectActiveWorkSessions(aWS, aFilePath, THE_PREVIOUS_WORK_SESSIONS);
return 0;
}
//=======================================================================
//function : Expand
//purpose :
@@ -692,504 +350,6 @@ static Standard_Integer Extract(Draw_Interpretor& theDI,
return 0;
}
//=======================================================================
//function : ReadVrml
//purpose :
//=======================================================================
static Standard_Integer ReadVrml(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
Handle(Vrml_ConfigurationNode) aNode =
new Vrml_ConfigurationNode();
Handle(TDocStd_Document) aDoc;
Standard_Boolean toUseExistingDoc = Standard_False;
Standard_CString aDocName = NULL;
TCollection_AsciiString aFilePath;
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
for (Standard_Integer anArgIt = 1; anArgIt < theNbArgs; anArgIt++)
{
TCollection_AsciiString anArg(theArgVec[anArgIt]);
anArg.LowerCase();
if (anArgIt + 1 < theNbArgs && anArg == "-fileunit")
{
const TCollection_AsciiString aUnitStr(theArgVec[++anArgIt]);
aNode->InternalParameters.ReadFileUnit = UnitsAPI::AnyToSI(1.0, aUnitStr.ToCString());
if (aNode->InternalParameters.ReadFileUnit <= 0.0)
{
theDI << "Error: wrong length unit '" << aUnitStr << "'\n";
return 1;
}
}
else if (anArgIt + 1 < theNbArgs && anArg == "-filecoordsys")
{
if (!parseCoordinateSystem(theArgVec[++anArgIt], aNode->InternalParameters.ReadFileCoordinateSys))
{
theDI << "Error: unknown coordinate system '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
else if (anArgIt + 1 < theNbArgs && anArg == "-systemcoordsys")
{
if (!parseCoordinateSystem(theArgVec[++anArgIt], aNode->InternalParameters.ReadSystemCoordinateSys))
{
theDI << "Error: unknown coordinate system '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
else if (anArg == "-fillincomplete")
{
aNode->InternalParameters.ReadFillIncomplete = true;
if (anArgIt + 1 < theNbArgs &&
Draw::ParseOnOff(theArgVec[anArgIt + 1], aNode->InternalParameters.ReadFillIncomplete))
{
++anArgIt;
}
}
else if (anArg == "-nocreatedoc")
{
toUseExistingDoc = true;
}
else if (aDocName == nullptr)
{
aDocName = theArgVec[anArgIt];
DDocStd::GetDocument(aDocName, aDoc, Standard_False);
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIt];
}
else
{
theDI << "Syntax error at '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty() || aDocName == nullptr)
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
if (aDoc.IsNull())
{
if (toUseExistingDoc)
{
theDI << "Error: document with name " << aDocName << " does not exist\n";
return 1;
}
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
anApp->NewDocument("BinXCAF", aDoc);
}
else if (!toUseExistingDoc)
{
theDI << "Error: document with name " << aDocName << " already exists\n";
return 1;
}
Handle(Vrml_Provider) aProvider =
new Vrml_Provider(aNode);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start()))
{
theDI << "Error: file reading failed '" << aFilePath << "'\n";
return 1;
}
TDataStd_Name::Set(aDoc->GetData()->Root(), aDocName);
Handle(DDocStd_DrawDocument) aDD = new DDocStd_DrawDocument(aDoc);
Draw::Set(aDocName, aDD);
CollectActiveWorkSessions(aWS, aFilePath, THE_PREVIOUS_WORK_SESSIONS);
return 0;
}
//=======================================================================
//function : WriteVrml
//purpose : Write DECAF document to Vrml
//=======================================================================
static Standard_Integer WriteVrml(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI << "Use: " << theArgVec[0] << " Doc filename: write document to Vrml file\n";
return 0;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(theArgVec[1], aDoc);
if (aDoc.IsNull())
{
theDI << theArgVec[1] << " is not a document\n";
return 1;
}
if (theNbArgs < 3 || theNbArgs > 5)
{
theDI << "wrong number of parameters\n";
return 0;
}
Handle(Vrml_ConfigurationNode) aNode =
new Vrml_ConfigurationNode();
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
Handle(Vrml_Provider) aProvider =
new Vrml_Provider(aNode);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Write(theArgVec[2], aDoc, aWS, aProgress->Start()))
{
theDI << "Error: file writing failed '" << theArgVec[2] << "'\n";
return 1;
}
CollectActiveWorkSessions(aWS, theArgVec[2], THE_PREVIOUS_WORK_SESSIONS);
return 0;
}
//=======================================================================
//function : DumpConfiguration
//purpose :
//=======================================================================
static Standard_Integer DumpConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper();
TCollection_AsciiString aPath;
Standard_Boolean aIsRecursive = Standard_True;
Standard_Boolean isHandleFormat = Standard_False;
Standard_Boolean isHandleVendors = Standard_False;
TColStd_ListOfAsciiString aFormats;
TColStd_ListOfAsciiString aVendors;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArg(theArgVec[anArgIter]);
anArg.LowerCase();
if ((anArg == "-path") &&
(anArgIter + 1 < theNbArgs))
{
++anArgIter;
aPath = theArgVec[anArgIter];
}
else if ((anArg == "-recursive") &&
(anArgIter + 1 < theNbArgs) &&
Draw::ParseOnOff(theArgVec[anArgIter + 1], aIsRecursive))
{
++anArgIter;
}
else if (anArg == "-format")
{
isHandleFormat = Standard_True;
isHandleVendors = Standard_False;
}
else if (anArg == "-vendor")
{
isHandleFormat = Standard_False;
isHandleVendors = Standard_True;
}
else if (isHandleFormat)
{
aFormats.Append(theArgVec[anArgIter]);
}
else if (isHandleVendors)
{
aVendors.Append(theArgVec[anArgIter]);
}
else if (!isHandleFormat && !isHandleVendors)
{
theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
Standard_Boolean aStat = Standard_True;
if (!aPath.IsEmpty())
{
aStat = aConf->Save(aPath, aIsRecursive, aFormats, aVendors);
}
else
{
theDI << aConf->Save(aIsRecursive, aFormats, aVendors) << "\n";
}
if (!aStat)
{
return 1;
}
return 0;
}
//=======================================================================
//function : CompareConfiguration
//purpose :
//=======================================================================
static Standard_Integer CompareConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs > 5)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
Handle(DE_ConfigurationContext) aResourceFirst = new DE_ConfigurationContext();
if (!aResourceFirst->Load(theArgVec[1]))
{
theDI << "Error: Can't load first configuration\n";
return 1;
}
Handle(DE_ConfigurationContext) aResourceSecond = new DE_ConfigurationContext();
if (!aResourceSecond->Load(theArgVec[2]))
{
theDI << "Error: Can't load second configuration\n";
return 1;
}
const DE_ResourceMap& aResourceMapFirst = aResourceFirst->GetInternalMap();
const DE_ResourceMap& aResourceMapSecond = aResourceSecond->GetInternalMap();
Standard_Integer anDiffers = 0;
for (DE_ResourceMap::Iterator anOrigIt(aResourceMapFirst);
anOrigIt.More(); anOrigIt.Next())
{
const TCollection_AsciiString& anOrigValue = anOrigIt.Value();
const TCollection_AsciiString& anOrigKey = anOrigIt.Key();
TCollection_AsciiString aCompValue;
if (!aResourceMapSecond.Find(anOrigKey, aCompValue))
{
Message::SendWarning() << "Second configuration don't have the next scope : " << anOrigKey;
anDiffers++;
}
if (!aCompValue.IsEqual(anOrigValue))
{
Message::SendWarning() << "Configurations have differs value with the next scope :" << anOrigKey
<< " First value : " << anOrigValue << " Second value : " << aCompValue;
anDiffers++;
}
}
TCollection_AsciiString aMessage;
if (aResourceMapFirst.Extent() != aResourceMapSecond.Extent() || anDiffers > 0)
{
theDI << "Error: Configurations are not same : " << " Differs count : "
<< anDiffers << " Count of first's scopes : " << aResourceMapFirst.Extent()
<< " Count of second's scopes : " << aResourceMapSecond.Extent() << "\n";
return 1;
}
return 0;
}
//=======================================================================
//function : LoadConfiguration
//purpose :
//=======================================================================
static Standard_Integer LoadConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs > 4)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper();
TCollection_AsciiString aString = theArgVec[1];
Standard_Boolean aIsRecursive = Standard_True;
if (theNbArgs == 4)
{
TCollection_AsciiString anArg = theArgVec[2];
anArg.LowerCase();
if (!(anArg == "-recursive") ||
!Draw::ParseOnOff(theArgVec[3], aIsRecursive))
{
theDI << "Syntax error at argument '" << theArgVec[3] << "'\n";
return 1;
}
}
if (!aConf->Load(aString, aIsRecursive))
{
theDI << "Error: configuration is incorrect\n";
return 1;
}
return 0;
}
//=======================================================================
//function : ReadFile
//purpose :
//=======================================================================
static Standard_Integer ReadFile(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs > 6)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
TCollection_AsciiString aDocShapeName;
TCollection_AsciiString aFilePath;
Handle(TDocStd_Document) aDoc;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
TCollection_AsciiString aConfString;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readfile");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArg(theArgVec[anArgIter]);
anArg.LowerCase();
if ((anArg == "-conf") &&
(anArgIter + 1 < theNbArgs))
{
++anArgIter;
aConfString = theArgVec[anArgIter];
}
else if (aDocShapeName.IsEmpty())
{
aDocShapeName = theArgVec[anArgIter];
Standard_CString aNameVar = aDocShapeName.ToCString();
if (!isNoDoc)
{
DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
}
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aDocShapeName.IsEmpty() || aFilePath.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
if (aDoc.IsNull() && !isNoDoc)
{
anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
TDataStd_Name::Set(aDoc->GetData()->Root(), theArgVec[1]);
Draw::Set(theArgVec[1], aDrawDoc);
}
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy();
Standard_Boolean aStat = Standard_True;
if (!aConfString.IsEmpty())
{
aStat = aConf->Load(aConfString);
}
if (aStat)
{
TopoDS_Shape aShape;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
aStat = isNoDoc ? aConf->Read(aFilePath, aShape, aWS) : aConf->Read(aFilePath, aDoc, aWS);
if (isNoDoc && aStat)
{
DBRep::Set(aDocShapeName.ToCString(), aShape);
}
CollectActiveWorkSessions(aWS, aFilePath, THE_PREVIOUS_WORK_SESSIONS);
}
if (!aStat)
{
return 1;
}
return 0;
}
//=======================================================================
//function : WriteFile
//purpose :
//=======================================================================
static Standard_Integer WriteFile(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs > 6)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
TCollection_AsciiString aDocShapeName;
TCollection_AsciiString aFilePath;
Handle(TDocStd_Document) aDoc;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
TCollection_AsciiString aConfString;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "writefile");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArg(theArgVec[anArgIter]);
anArg.LowerCase();
if ((anArg == "-conf") &&
(anArgIter + 1 < theNbArgs))
{
++anArgIter;
aConfString = theArgVec[anArgIter];
}
else if (aDocShapeName.IsEmpty())
{
aDocShapeName = theArgVec[anArgIter];
Standard_CString aNameVar = aDocShapeName.ToCString();
if (!isNoDoc)
{
DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
}
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aDocShapeName.IsEmpty() || aFilePath.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
if (aDoc.IsNull() && !isNoDoc)
{
theDI << "Error: incorrect document\n";
return 1;
}
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy();
Standard_Boolean aStat = Standard_True;
if (!aConfString.IsEmpty())
{
aStat = aConf->Load(aConfString);
}
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (aStat)
{
if (isNoDoc)
{
TopoDS_Shape aShape = DBRep::Get(aDocShapeName);
if (aShape.IsNull())
{
theDI << "Error: incorrect shape " << aDocShapeName << "\n";
return 1;
}
aStat = aConf->Write(aFilePath, aShape, aWS);
}
else
{
aStat = aConf->Write(aFilePath, aDoc, aWS);
}
}
if (!aStat)
{
return 1;
}
CollectActiveWorkSessions(aWS, aFilePath, THE_PREVIOUS_WORK_SESSIONS);
return 0;
}
void XDEDRAW_Common::InitCommands(Draw_Interpretor& theDI)
{
static Standard_Boolean initactor = Standard_False;
@@ -1201,25 +361,6 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& theDI)
Standard_CString g = "XDE translation commands";
theDI.Add("ReadIges", "Doc filename: Read IGES file to DECAF document", __FILE__, ReadIges, g);
theDI.Add("WriteIges", "Doc filename: Write DECAF document to IGES file", __FILE__, WriteIges, g);
theDI.Add("ReadStep",
"Doc filename [mode] [-stream]"
"\n\t\t: Read STEP file to a document."
"\n\t\t: -stream read using istream reading interface (testing)",
__FILE__, ReadStep, g);
theDI.Add("WriteStep",
"Doc filename [mode=a [multifile_prefix] [label]] [-stream]"
"\n\t\t: Write DECAF document to STEP file"
"\n\t\t: mode can be: a or 0 : AsIs (default)"
"\n\t\t: f or 1 : FacettedBRep s or 2 : ShellBasedSurfaceModel"
"\n\t\t: m or 3 : ManifoldSolidBrep w or 4 : GeometricCurveSet/WireFrame"
"\n\t\t: multifile_prefix: triggers writing assembly components as separate files,"
"\n\t\t: and defines common prefix for their names"
"\n\t\t: label tag of the sub-assembly label to save only that sub-assembly"
"\n\t\t: -stream read using ostream writing interface (testing)",
__FILE__, WriteStep, g);
theDI.Add("XFileList", "Print list of files that was transferred by the last transfer", __FILE__, GetDicWSList, g);
theDI.Add("XFileCur", ": returns name of file which is set as current", __FILE__, GetCurWS, g);
theDI.Add("XFileSet", "filename: Set the specified file to be the current one", __FILE__, SetCurWS, g);
@@ -1230,56 +371,4 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& theDI)
theDI.Add("XExtract", "XExtract dstDoc [dstAssmblSh] srcDoc srcLabel1 srcLabel2 ...\t"
"Extracts given srcLabel1 srcLabel2 ... from srcDoc into given Doc or assembly shape",
__FILE__, Extract, g);
theDI.Add("ReadVrml",
"ReadVrml docName filePath [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
"\n\t\t: [-systemCoordSys {Zup|Yup}] [-noCreateDoc] [-fillIncomplete {ON|OFF}]"
"\n\t\t: Read Vrml file into XDE document."
"\n\t\t: -fileCoordSys coordinate system defined by Vrml file; Yup when not specified."
"\n\t\t: -fileUnit length unit of Vrml file content."
"\n\t\t: -systemCoordSys result coordinate system; Zup when not specified."
"\n\t\t: -noCreateDoc read into existing XDE document."
"\n\t\t: -fillIncomplete fill the document with partially retrieved data even if reader has failed with "
"error; true when not specified",
__FILE__, ReadVrml, g);
theDI.Add("WriteVrml",
"WriteVrml Doc filename [version VRML#1.0/VRML#2.0 (1/2): 2 by default] [representation shaded/wireframe/both (0/1/2): 0 by default]",
__FILE__, WriteVrml, g);
theDI.Add("DumpConfiguration",
"DumpConfiguration [-path <path>] [-recursive {on|off}] [-format fmt1 fmt2 ...] [-vendor vend1 vend2 ...]\n"
"\n\t\t: Dump special resource generated from global configuration."
"\n\t\t: '-path' - save resource configuration to the file"
"\n\t\t: '-recursive' - flag to generate a resource from providers. Default is On. Off disables other options"
"\n\t\t: '-format' - flag to generate a resource for choosen formats. If list is empty, generate it for all"
"\n\t\t: '-vendor' - flag to generate a resource for choosen vendors. If list is empty, generate it for all",
__FILE__, DumpConfiguration, g);
theDI.Add("LoadConfiguration",
"LoadConfiguration conf [-recursive {on|off}]\n"
"\n\t\t: 'conf' - path to the resouce file or string value in the special format"
"\n\t\t: '-recursive' - flag to generate a resource for all providers. Default is true"
"\n\t\t: Configure global configuration according special resource",
__FILE__, LoadConfiguration, g);
theDI.Add("CompareConfiguration",
"CompareConfiguration conf1 conf2\n"
"\n\t\t: 'conf1' - path to the first resouce file or string value in the special format"
"\n\t\t: 'conf2' - path to the second resouce file or string value in the special format"
"\n\t\t: Compare two configurations",
__FILE__, CompareConfiguration, g);
theDI.Add("ReadFile",
"ReadFile docName filePath [-conf <value|path>]\n"
"\n\t\t: Read CAD file to document with registered format's providers. Use global configuration by default.",
__FILE__, ReadFile, g);
theDI.Add("readfile",
"readfile shapeName filePath [-conf <value|path>]\n"
"\n\t\t: Read CAD file to shape with registered format's providers. Use global configuration by default.",
__FILE__, ReadFile, g);
theDI.Add("WriteFile",
"WriteFile docName filePath [-conf <value|path>]\n"
"\n\t\t: Write CAD file to document with registered format's providers. Use global configuration by default.",
__FILE__, WriteFile, g);
theDI.Add("writefile",
"writefile shapeName filePath [-conf <value|path>]\n"
"\n\t\t: Write CAD file to shape with registered format's providers. Use global configuration by default.",
__FILE__, WriteFile, g);
}

View File

@@ -21,8 +21,6 @@
#include <Draw_Interpretor.hxx>
class XDEDRAW_Common
{
public:

View File

@@ -4,10 +4,6 @@ XSControl_ConnectedShapes.cxx
XSControl_ConnectedShapes.hxx
XSControl_Controller.cxx
XSControl_Controller.hxx
XSControl_FuncShape.cxx
XSControl_FuncShape.hxx
XSControl_Functions.cxx
XSControl_Functions.hxx
XSControl_Reader.cxx
XSControl_Reader.hxx
XSControl_SelectForTransfer.cxx

View File

@@ -1,834 +0,0 @@
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <Geom_Geometry.hxx>
#include <IFSelect_Act.hxx>
#include <IFSelect_Functions.hxx>
#include <IFSelect_SessionPilot.hxx>
#include <Interface_Macros.hxx>
#include <Interface_InterfaceModel.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <ShapeExtend_Explorer.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <Transfer_SimpleBinderOfTransient.hxx>
#include <Transfer_FinderProcess.hxx>
#include <Transfer_TransientListBinder.hxx>
#include <Transfer_TransientProcess.hxx>
#include <TransferBRep.hxx>
#include <TransferBRep_ShapeListBinder.hxx>
#include <TransferBRep_ShapeMapper.hxx>
#include <XSControl.hxx>
#include <XSControl_ConnectedShapes.hxx>
#include <XSControl_Controller.hxx>
#include <XSControl_FuncShape.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_TransferWriter.hxx>
#include <XSControl_Vars.hxx>
#include <XSControl_WorkSession.hxx>
#include <stdio.h>
//#include <TransferBRep_Analyzer.hxx>
// ######################################################################
// #### ####
// #### COMMANDS ####
// #### ####
// ######################################################################
//=======================================================================
//function : XSControl_tpdraw
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpdraw
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Standard_CString arg2 = pilot->Arg(2);
const Standard_CString arg3 = pilot->Arg(3);
const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout<<"No Transfer Read"<<std::endl; return IFSelect_RetError;}
// **** tpdraw ****
if (argc < 2) {
sout<<"Donner [mode facultatif : item ou root] , NUMERO , nom DRAW facultatif"<<std::endl;
sout<<" mode si present : item ou root, sinon n0 d entite modele"<<std::endl;
sout<<" NUMERO entier : d entite, d item transfert ou de root transfert\n"
<< " ou * pour dire tous"<<std::endl;
return IFSelect_RetError;
}
Standard_Integer mode = 0, num=0;
if (arg1[0] == 'i') mode = 1;
else if (arg1[0] == 'r') mode = 2;
Standard_Boolean tout = Standard_False;
if (mode == 0) {
if (argc < 2) { sout<<"Donner au moins un NUMERO ou *"<<std::endl; return IFSelect_RetError; }
if (arg1[0] == '*') tout = Standard_True;
else num = IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot),arg1);
} else {
if (arg2[0] == '*') tout = Standard_True;
else num = IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot),arg2);
}
Standard_Integer nbvar = 0;
Handle(Transfer_Binder) binder;
Handle(Standard_Transient) ent;
TopoDS_Shape sh; char nomvar[40];
// Standard_Boolean moderoot = (pilot->Word(0).Value(3) == 'r');
Standard_Integer n1, n2, i, max=0, index=0;
Handle(Interface_InterfaceModel) model = TP->Model();
if (model.IsNull()) {
if (mode == 0) {
sout<<"Pas de modele, preciser n0 d item de transfert"<<std::endl;
return IFSelect_RetError;
}
}
if (mode == 0) { sout<<"Entite de modele"; max = model->NbEntities(); }
if (mode == 1) { sout<<"Item de transfert"; max = TP->NbMapped(); }
if (mode == 2) { sout<<"Racine de transfert"; max = TP->NbRoots(); }
if (tout) {
n1 = 1; n2 = max;
sout<<", listage de 1 a "<<max<<std::endl;
}
else if (num <= 0 || num > max) {
sout<<" - Num="<<num<<" hors limite (de 1 a "<<max<<")"<<std::endl;
return IFSelect_RetError;
} else {
n1 = n2 = num; nbvar = -1; // nbvar : 1ere shape simple = pas de n0
sout<<", n0 "<<num<<std::endl;
}
for (i = n1; i <= n2; i ++) {
if (mode == 0) {
ent = model->Value(i);
num = i;
index = TP->MapIndex(ent);
} else if (mode == 1) {
ent = TP->Mapped(i);
if (model.IsNull()) num = 0;
else num = model->Number(ent);
index = i;
} else if (mode == 2) {
ent = TP->Root(i);
if (model.IsNull()) num = 0;
else num = model->Number(ent);
index = TP->MapIndex(ent);
}
if (index > 0) binder = TP->MapItem (index);
if (binder.IsNull()) index = 0;
if (index == 0) {
if (!tout) sout<<"Entite n0 "<<num<<" : non repertoriee"<<std::endl;
continue;
}
if (!binder->HasResult()) {
if (!tout) sout<<"Entite n0 "<<num<<" : pas de resultat"<<std::endl;
continue;
}
sh = TransferBRep::ShapeResult (binder);
//DeclareAndCast(TransferBRep_ShapeBinder,shb,binder);
if (!sh.IsNull()) {
//sh = shb->Result();
nbvar ++;
if (sh.IsNull()) { sout<<" (no Shape recorded)"<<std::endl; continue; }
if (tout) sout<<"[ "<<i<<" ]:";
if (num == 0) sout<<" pas dans le modele";
else sout<<" ent.n0 "<<num;
sout<<", item transfert n0 "<<index;
if (nbvar == 0) {
if (argc > 3 && mode > 0) sprintf (nomvar,"%s",arg3);
else if (argc > 2 && mode == 0) sprintf (nomvar,"%s",arg2);
else sprintf (nomvar,"tp_%d",i);
} else {
if (argc > 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar);
else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar);
else sprintf (nomvar,"tp_%d",i);
}
sout<<" -> 1 DRAW Shape: "<<nomvar<<std::endl;
XSControl::Vars(pilot)->SetShape(nomvar,sh);
continue;
}
DeclareAndCast(TransferBRep_ShapeListBinder,slb,binder);
if (!slb.IsNull()) {
Standard_Integer nbs = slb->NbShapes();
if (tout) sout<<"[ "<<i<<" ]:";
if (num == 0) sout<<" pas dans le modele";
else sout<<" ent.n0 "<<num;
sout<<", item transfert n0 "<<index;
sout<<" -> "<<nbs<<" DRAW Shapes :";
for (Standard_Integer j = 1; j <= nbs; j ++) {
sh = slb->Shape(j); if (nbvar < 0) nbvar = 0; nbvar ++;
if (sh.IsNull()) { sout<<" (no Shape recorded)"<<std::endl; continue; }
if (argc > 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar);
else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar);
else sprintf (nomvar,"tp_%d_%d",i,nbvar);
sout<<" "<<nomvar;
XSControl::Vars(pilot)->SetShape(nomvar,sh);
}
sout<<std::endl;
continue;
}
DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder);
if (!trb.IsNull()) {
Handle(Standard_Transient) resu = trb->Result();
if (resu.IsNull()) {
sout<<"Entite n0 "<<num<<" : pas de resultat"<<std::endl;
continue;
}
DeclareAndCast(Geom_Geometry,geom,resu);
sout<<"Entite n0 "<<num<<" : resultat "<<resu->DynamicType()->Name();
if (geom.IsNull()) { sout<<std::endl; continue; }
nbvar ++;
if (nbvar == 0) {
if (argc > 3 && mode > 0) sprintf (nomvar,"%s",arg3);
else if (argc > 2 && mode == 0) sprintf (nomvar,"%s",arg2);
else sprintf (nomvar,"tp_%d",i);
} else {
if (argc > 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar);
else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar);
else sprintf (nomvar,"tp_%d",i);
}
char* nomv = nomvar;
XSControl::Vars(pilot)->Set (nomv,geom);
sout<<" -> DRAW Geom : "<<nomvar<<std::endl;
continue;
}
if (sh.IsNull() && trb.IsNull())
if (!tout) sout<<"Entite n0 "<<num<<" : resultat pas une Shape mais "<<binder->ResultTypeName()<<std::endl;
}
if (sh.IsNull()) sout<<" (No Shape)"<<std::endl;
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_tpcompound
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpcompound
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout<<"No Transfer Read"<<std::endl; return IFSelect_RetError;}
// **** tpcompound ****
if (argc < 2) { sout<<"Give a NAME for the Compound + optional givelist, else roots are taken"<<std::endl; return IFSelect_RetError; }
Handle(TopTools_HSequenceOfShape) list;
if (argc == 2) list = TransferBRep::Shapes(TP);
else {
Handle(TColStd_HSequenceOfTransient) lise = IFSelect_Functions::GiveList(pilot->Session(),pilot->CommandPart(2));
if (lise.IsNull()) { sout<<"Not a valid entity list : "<<pilot->CommandPart(2)<<std::endl; return IFSelect_RetError; }
list = TransferBRep::Shapes (TP,lise);
sout<<lise->Length()<<" Entities, ";
}
if (list.IsNull()) { sout<<"No Shape listed"<<std::endl; return IFSelect_RetError; }
Standard_Integer nb = list->Length();
sout<<nb<<" Shape(s) listed"<<std::endl;
TopoDS_Compound C;
BRep_Builder B;
B.MakeCompound(C);
for (Standard_Integer i = 1; i <= nb; i ++) B.Add (C,list->Value(i));
XSControl::Vars(pilot)->SetShape (arg1,C);
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_traccess
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_traccess
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Standard_CString arg2 = pilot->Arg(2);
// **** trdraw : TransferReader **** 26
// **** trsave : TransferReader **** 27
// **** trcomp (comp -> DRAW) **** 28
// **** trscomp (comp -> save) **** 29
Standard_Boolean cascomp = (pilot->Word(0).Location(1,'o',1,5) > 0);
Standard_Boolean cassave = (pilot->Word(0).Location(1,'s',1,5) > 0);
TCollection_AsciiString nomsh, noms;
const Handle(XSControl_TransferReader) &TR = XSControl::Session(pilot)->TransferReader();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TR.IsNull()) { sout<<" manque init"<<std::endl; return IFSelect_RetError; }
const Handle(Interface_InterfaceModel) &mdl = TR->Model();
if (mdl.IsNull()) { sout<<" modele absent"<<std::endl; return IFSelect_RetError; }
Standard_Integer num = (argc > 1 ? IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot),arg1) : 0);
if (argc > 1) nomsh = arg1;
else nomsh = cascomp ? "TREAD_COMP" : "TREAD_LIST";
if (cassave) sout<<" save shapes -> current directory"<<std::endl;
if (num == 0 || cascomp) {
TopoDS_Compound C; // pour cas compound
BRep_Builder B;
B.MakeCompound(C);
const Handle(TopTools_HSequenceOfShape) &list = TR->ShapeResultList(Standard_True);
sout<<" TOUS RESULTATS par ShapeResultList, soit "<<list->Length()<<std::endl;
for (Standard_Integer i = 1, nb = list->Length(); i <= nb; ++i)
{
noms = nomsh + "_" + i;
if ( (i%1000) == 0) sout<<"("<<i<<")"<<std::endl;
else if ( (i%100) == 0) sout<<"*";
else if ( (i%10) == 0) sout<<"0";
else sout<<".";
if (list->Value(i).IsNull()) continue;
if (!cascomp && !cassave) XSControl::Vars(pilot)->SetShape (noms.ToCString(), list->Value(i));
else if (!cascomp && cassave) BRepTools::Write (list->Value(i), noms.ToCString());
else if (cascomp) B.Add (C,list->Value(i));
}
sout<<std::endl;
if (cascomp && !cassave) XSControl::Vars(pilot)->SetShape (nomsh.ToCString(), C);
else if (cascomp && cassave) BRepTools::Write (C, nomsh.ToCString());
} else {
if (num < 1 || num > mdl->NbEntities()) { sout<<" incorrect:"<<arg1<<std::endl; return IFSelect_RetError; }
TopoDS_Shape sh = TR->ShapeResult(mdl->Value(num));
if (sh.IsNull()) { sout<<" Pas de resultat pour "<<arg1<<std::endl; return IFSelect_RetError; }
if (argc > 2) nomsh = arg2;
else nomsh = TCollection_AsciiString ("TREAD_") + num;
if (!cascomp && !cassave) XSControl::Vars(pilot)->SetShape (nomsh.ToCString(), sh);
else if (!cascomp && cassave) BRepTools::Write (sh, nomsh.ToCString());
else sout<<"Option non comprise"<<std::endl;
}
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_IsEqualSubShape
//purpose :
//=======================================================================
// PTV 23.08.2000 Added for checking where are an entity from.
static Standard_Boolean XSControl_IsEqualSubShape (const TopoDS_Shape& Shape,
TopoDS_Shape& sh, Standard_Integer aLevel)
{
if ( sh.IsSame(Shape) ) return Standard_True;
if (aLevel > 0) {
TopoDS_Shape varShape;
aLevel--;
TopoDS_Iterator it(sh);
for (; it.More(); it.Next() ) {
varShape = it.Value();
if ( XSControl_IsEqualSubShape(Shape, varShape, aLevel) ) return Standard_True;
}
}
return Standard_False;
}
//=======================================================================
//function : XSControl_fromshape
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_fromshape
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** fromshape (tread) ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (argc < 2) {
sout<<"Give name of a DRAW Shape"<<std::endl;
return IFSelect_RetError;
}
const char* a1 = (char *)arg1;
TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(a1);
if (Shape.IsNull()) {
sout<<"Not a DRAW Shape:"<<arg1<<std::endl;
return IFSelect_RetError;
}
Standard_Boolean yena = Standard_False;
Standard_Integer aLevel = 1;
if (argc >=3 )
aLevel = atoi(pilot->Arg(2));
Standard_Boolean silent = Standard_False;
if (aLevel <0 ) {
silent = Standard_True;
aLevel = -aLevel;
}
// IMPORT
const Handle(XSControl_TransferReader) &TR = XSControl::Session(pilot)->TransferReader();
if (TR.IsNull()) { } // sout<<"No read transfer (import) recorded"<<std::endl;
else {
yena = Standard_True;
if ( ! silent ) sout<<"Shape "<<arg1<<" : ";
Standard_Integer modrec = 1;
Handle(Standard_Transient) ent = TR->EntityFromShapeResult (Shape,modrec);
if (ent.IsNull()) {
modrec = -1;
ent = TR->EntityFromShapeResult (Shape,modrec);
}
if (ent.IsNull()) {
modrec = 2;
Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
if (TP.IsNull()) {
if ( silent )
sout << "Shape "<<arg1<<" : ";
sout<<"no map"<<std::endl;
}
else {
TopoDS_Shape S0 = Shape;
TopLoc_Location L;
S0.Location ( L );
Standard_Integer i, nb = TP->NbMapped();
if ( ! silent ) sout<<"searching in map among "<<nb<<" ...";
for (i = 1; i <= nb; i ++) {
ent = TP->Mapped(i);
TopoDS_Shape sh = TransferBRep::ShapeResult(TP,ent);
if (sh.IsNull()) {
ent.Nullify();
continue;
}
if (XSControl_IsEqualSubShape(Shape, sh, aLevel)) break;
modrec = -2;
sh.Location ( L );
if (XSControl_IsEqualSubShape(S0, sh, aLevel)) break;
ent.Nullify();
modrec = 2;
}
}
}
if ( ! ent.IsNull() ) {
if ( silent ) sout << "Shape " << arg1 << ": ";
if (modrec <0) sout<<"(moved from origin) ";
//else sout<<"(origin) ";
}
// on affiche
if (ent.IsNull()) {
if ( ! silent ) sout<<" unknown as imported";
// skl 11.05.2004
// if Shape is a compound try to make "fromshape" for its subshapes
if(Shape.ShapeType()==TopAbs_COMPOUND) {
sout<<std::endl<<"Subshapes imported from entities:";
TopoDS_Iterator Iter(Shape);
for (; Iter.More(); Iter.Next()) {
TopoDS_Shape subsh = Iter.Value();
Standard_Integer submodrec = 1;
Handle(Standard_Transient) subent = TR->EntityFromShapeResult(subsh,submodrec);
if (subent.IsNull()) {
submodrec = -1;
subent = TR->EntityFromShapeResult(subsh,submodrec);
}
if (!subent.IsNull()) {
sout<<" "<<XSControl::Session(pilot)->Model()->Number(subent);
}
}
}
}
else {
sout<<"imported from entity ";
XSControl::Session(pilot)->Model()->Print (ent, sout);
if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile() << std::endl;
}
if ( ! silent ) sout<<std::endl;
}
// ET EN EXPORT ?
const Handle(Transfer_FinderProcess) &FP = XSControl::Session(pilot)->TransferWriter()->FinderProcess();
if (FP.IsNull()) { }
else {
yena = Standard_True;
Handle(Transfer_Finder) fnd = TransferBRep::ShapeMapper (FP,Shape);
Handle(Standard_Transient) ent;
if (!fnd.IsNull()) ent = FP->FindTransient (fnd);
if (!ent.IsNull()) {
sout<<"Shape "<<arg1<<": exported to entity ";
XSControl::Session(pilot)->Model()->Print (ent, sout);
if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile();
sout<<std::endl;
}
// abv 31.08.00: treat case of split shape (several results)
// it is supposed that results are of the same type and lie in one-level comp
else {
Handle(Transfer_Binder) bnd = FP->Find ( fnd );
if ( ! bnd.IsNull() ) {
Handle(Transfer_TransientListBinder) TransientListBinder =
//Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) ); //skl
Handle(Transfer_TransientListBinder)::DownCast( bnd ); //skl
if (! TransientListBinder.IsNull() ) {
Standard_Integer i = 1, nb = TransientListBinder->NbTransients();
if (nb > 0) sout<<"Shape "<<arg1<<": exported to entities ";
for (; i<=nb; i++) {
XSControl::Session(pilot)->Model()->Print( TransientListBinder->Transient(i), sout);
if (i < nb) sout<<", ";
}
if (nb > 0) {
if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile();
sout<<std::endl;
}
}
/* else {
TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
if ( ! comp.IsNull() && comp.ShapeType() < Shape.ShapeType() ) {
Standard_Boolean start = Standard_True;
for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
Handle(Transfer_Finder) cfnd = TransferBRep::ShapeMapper (FP,it.Value());
if ( cfnd.IsNull() ) continue;
Handle(Standard_Transient) cent = FP->FindTransient (cfnd);
if ( cent.IsNull() ) continue;
if ( start )
sout<<"Shape "<<arg1<<" : exported to entities ";
else sout << ", ";
start = Standard_False;
XSControl::Session(pilot)->Model()->Print(cent,sout);
}
if ( ! start ) sout<<std::endl;
}
} */
}
}
}
if (!yena) sout<<"No transfer (either import or export) recorded"<<std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : XSControl_trconnexentities
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_trconnexentities
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** connected entities (last transfer) ****
const Handle(XSControl_TransferReader) &TR = XSControl::Session(pilot)->TransferReader();
Handle(Transfer_TransientProcess) TP;
if (!TR.IsNull()) TP = TR->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout<<"no transfer map"<<std::endl; return IFSelect_RetVoid; }
if (argc < 2) {
sout<<"Give name of a DRAW Shape + optional shape type v-e-w-f(D)-s"<<std::endl;
return IFSelect_RetError;
}
const char* a1 = (const char *)arg1;
TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(a1);
if (Shape.IsNull()) { sout<<"Not a DRAW Shape:"<<arg1<<std::endl; return IFSelect_RetError; }
sout<<"Shape "<<arg1<<" : ";
Handle(TColStd_HSequenceOfTransient) list =
XSControl_ConnectedShapes::AdjacentEntities (Shape,TP,TopAbs_FACE);
Standard_Integer i, nb = list->Length();
sout<<nb<<" Entities produced Connected Shapes :"<<std::endl;
const Handle(Interface_InterfaceModel) &model = XSControl::Session(pilot)->Model();
sout<<"(";
for (i = 1; i <= nb; i ++) {
if (i > 1) sout<<",";
sout<<model->Number(list->Value(i));
}
sout<<")"<<std::endl;
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_trimport
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_trimport
(const Handle(IFSelect_SessionPilot)& pilot)
{
// FileName ou . (pour courant) VarName GiveList (obligatoire)
// GiveList : * pour xst-transferrable-roots
Handle(XSControl_WorkSession) WS = XSControl::Session(pilot);
Standard_Integer argc = pilot->NbWords();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (argc < 4) {
sout<<"Give : filename or . for current model; varname or . to take fileroot\n GiveList, * for all transferrable roots"<<std::endl;
return IFSelect_RetError;
}
const Standard_CString arg1 = pilot->Arg(1);
const Standard_CString arg2 = pilot->Arg(2);
const Standard_CString arg3 = pilot->Arg(3);
// File Name and Variable (root) Name
TCollection_AsciiString fnom,rnom;
Standard_Boolean modfic = XSControl_FuncShape::FileAndVar
(WS,arg1,arg2,"IMPORT",fnom,rnom);
if (modfic) sout<<" File to read : "<<fnom<<std::endl;
else sout<<" Model taken from the session : "<<fnom<<std::endl;
sout<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom<<std::endl;
// keep the current command, because sub-commands will be called
TCollection_AsciiString compart = pilot->CommandPart (3);
// Reading file if required
if (modfic) {
TCollection_AsciiString comload ("xload ");
comload.AssignCat(arg1);
IFSelect_ReturnStatus status = pilot->Execute(comload);
if (status != IFSelect_RetDone)
{ sout<<"Abandon import"<<std::endl; return status; }
} else {
sout<<"Currently Loaded Model"<<std::endl;
}
// Selecting Entities
Handle(TColStd_HSequenceOfTransient) list;
if (arg3[0] == '*' && arg3[1] == '\0') {
list = WS->GiveList ("xst-transferrable-roots");
sout<<"All Transferrable Roots : ";
} else {
sout<<"List given by "<<compart.ToCString()<<" : ";
list = WS->GiveList (compart.ToCString());
}
if (list.IsNull()) { sout<<"No list defined. Abandon"<<std::endl; return IFSelect_RetError; }
Standard_Integer nbl = list->Length();
sout<<"Nb entities selected : "<<nbl<<std::endl;
// Starting Transfer
WS->InitTransferReader (0);
const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
if (TR.IsNull()) { sout<<" init not done or failed"<<std::endl; return IFSelect_RetError; }
TR->BeginTransfer();
// Transferring
Standard_Integer nbt = TR->TransferList(list);
sout<<"Nb Entities Selected : "<<nbl<<" have given "<<nbt<<" results"<<std::endl;
// Filling VARS. one compound (trimpcomp) or one shape per ent (trimport)
Standard_Boolean iscomp = (pilot->Arg(0)[5] == 'c');
Standard_Integer nbs = 0;
TopoDS_Shape sh;
TopoDS_Compound C;
BRep_Builder B;
B.MakeCompound (C);
Handle(Interface_InterfaceModel) mdl = TR->Model();
if (mdl.IsNull()) { sout<<" modele absent"<<std::endl; return IFSelect_RetError; }
for (Standard_Integer il= 1; il <= nbl; il ++) {
Handle(Standard_Transient) ent = list->Value(il);
sh = TR->ShapeResult(ent);
if (sh.IsNull()) continue;
nbs ++;
if (iscomp) B.Add (C,sh);
else {
char nomsh[50];
sprintf (nomsh,"%s_%d",rnom.ToCString(),nbs);
XSControl::Vars(pilot)->SetShape(nomsh,sh);
}
}
if (nbs == 0) sout<<"No Shape produced"<<std::endl;
else if (nbs == 1) {
sout<<"One Shape produced, named "<<rnom.ToCString()<<std::endl;
XSControl::Vars(pilot)->SetShape(rnom.ToCString(),sh);
} else if (iscomp) {
sout<<"One compound made of "<<nbs<<" Shapes, named "<<rnom.ToCString()<<std::endl;
XSControl::Vars(pilot)->SetShape(rnom.ToCString(),C);
} else { // several individual shapes
sout<<nbs<<" Shapes, named "<<rnom.ToCString()<<"_1 to "<<rnom.ToCString()<<"_"<<nbs<<std::endl;
}
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_twrite
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_twrite
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** twrite ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
Handle(XSControl_TransferWriter) TW = XSControl::Session(pilot)->TransferWriter();
if (argc < 2) { sout<<" donner nom de shape draw"<<std::endl; return IFSelect_RetError; }
sout<<"Attention, on alimente le modele courant ..."<<std::endl;
// Shape
for (Standard_Integer i = 1; i < argc; i ++) {
const char* ai = (const char *)pilot->Arg(i);
TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(ai);
if (Shape.IsNull()) { sout<<"pas un nom de shape draw:"<<arg1<<std::endl; continue; }
sout<<"Pour Shape : "<<ai;
Standard_Integer stat = TW->TransferWriteShape (XSControl::Session(pilot)->Model(),Shape);
sout<<" Transfer Write Status = "<<stat<<std::endl;
}
pilot->Session()->ComputeGraph();
// Transient ? (Geom) : ignore
return IFSelect_RetDone;
}
// ######################################################################
// #### TIMERS ####
// ######################################################################
// ######################################################################
// #### ####
// #### Initialising Commands ####
// #### ####
// ######################################################################
static int THE_XSControl_FuncShape_initactor = 0;
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void XSControl_FuncShape::Init ()
{
if (THE_XSControl_FuncShape_initactor)
{
return;
}
THE_XSControl_FuncShape_initactor = 1;
IFSelect_Act::SetGroup("DE: General");
IFSelect_Act::AddFunc ("tpdraw","[mode:item or root] num|* [nomvar] Passes an ITEM to Shape Draw (Start or Result)",XSControl_tpdraw);
IFSelect_Act::AddFunc ("tpcompound","name:cstring [givelist] : -> compound with Shapes Root or from givelist",XSControl_tpcompound);
IFSelect_Act::AddFunc ("trdraw","results ->DRAW : all; or num [name] : from ent.num -> DRAW [name/tread_num]",XSControl_traccess);
IFSelect_Act::AddFunc ("trsave","results ->files : all; or num [name] : from ent.num -> DRAW [name/tread_num]",XSControl_traccess);
IFSelect_Act::AddFunc ("trcomp","results -> 1 compound -> DRAW + name optional",XSControl_traccess);
IFSelect_Act::AddFunc ("trscomp","results -> 1 compound -> file + name optional",XSControl_traccess);
IFSelect_Act::AddFunc ("fromshape","shape [level=1]: imported/exported entity (when known)",XSControl_fromshape);
IFSelect_Act::AddFunc ("trconnexent","name of draw shape : entities -> connected shapes (when known)",XSControl_trconnexentities);
IFSelect_Act::AddFunc ("trimport","filename or . varname givelist -> 1 shape per entity",XSControl_trimport);
IFSelect_Act::AddFunc ("trimpcomp","filename or . varname givelist -> one xcompound",XSControl_trimport);
IFSelect_Act::AddFunc ("twrite","shape : transfer write for this shape, AFTER newmodel !",XSControl_twrite);
//skl IFSelect_Act::AddFunc ("checkbrep","shapename or * [+ rootname for expurged and faulties [+ mode f-s]]",XSHAPE_checkbrep);
//skl IFSelect_Act::AddFunc ("dblist","option : clear nb index set n1 data n1 n2",XSHAPE_dblist);
}
// ######################################################################
// #### ####
// #### Additional Methods ####
// #### ####
// ######################################################################
//=======================================================================
//function : MoreShapes
//purpose :
//=======================================================================
Standard_Integer XSControl_FuncShape::MoreShapes
(const Handle(XSControl_WorkSession)& session,
Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name)
{
// name = un nom -> Draw
// name = "*" -> tous les transferts RACINES du TP
// name = "**" -> tous les transferts du TP : VRAIMENT TOUS
// name = "." -> reperage graphique (not yet impl)
// name = nom(n1-n2) avec n1,n2 entiers : les variables de nom nomn1 a nomn2
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (list.IsNull()) list = new TopTools_HSequenceOfShape();
if (name[0] == '*' && (name[1] == '\0' || (name[1] == '*' && name[2] == '\0'))) {
const Handle(Transfer_TransientProcess) &TP = session->TransferReader()->TransientProcess();
if (TP.IsNull()) { sout<<"last transfer : unknown"<<std::endl;return 0; }
Handle(TopTools_HSequenceOfShape) li = TransferBRep::Shapes(TP,(name[1] == '\0'));
if (li.IsNull()) return 0;
list->Append (li);
return li->Length();
}
Standard_Integer i, paro = 0, parf = 0, moins = 0, n1 = 0, n2 = 0;
for (i = 0; name[i] != '\0'; i ++) {
if (name[i] == '(') paro = i;
if (name[i] == '-') moins = i;
if (name[i] == ')') parf = i;
}
if (paro && moins && parf) {
n2 = atoi (&name[moins+1]);
n1 = atoi (&name[paro +1]); if (n1 < 0) n1 += n2; // sinon on a n1-n2
}
// liste
if (n1 <= n2 && n1 > 0) {
char nom[50], nomsh[60]; Standard_Integer nbsh = 0;
for (i = 0; i < paro; i ++)
{
nom[i]=name[i];
}
nom[paro] = '\0';
sout<<"Shapes DRAW named : "<<nom<<n1<<" to "<<nom<<n2;
for (i = n1; i <= n2 ; i ++) {
const char* nomshh = &nomsh[0];
sprintf (nomsh,"%s%d",nom,i);
TopoDS_Shape Shape;// = session->Vars()->GetShape(nomshh);
if (Shape.IsNull()) continue;
list->Append(Shape);
nbsh ++;
}
sout<<" -> taken "<<nbsh<<" Shapes"<<std::endl;
return nbsh;
}
const char* a1 = (const char *)name;
TopoDS_Shape Shape;// = session->Vars()->GetShape(a1);
if (Shape.IsNull()) { sout<<"not a shape draw:"<<a1<<std::endl; return 0; }
list->Append(Shape);
return 1;
}
//=======================================================================
//function : FileAndVar
//purpose :
//=======================================================================
Standard_Boolean XSControl_FuncShape::FileAndVar
(const Handle(XSControl_WorkSession)& session,
const Standard_CString file, const Standard_CString var,
const Standard_CString def,
TCollection_AsciiString& resfile, TCollection_AsciiString& resvar)
{
Standard_Boolean iafic = Standard_True;
resfile.Clear(); resvar.Clear();
if (file)
if ( file[0] == '\0' ||
(file[0] == '.' && file[1] == '\0')) iafic = Standard_False;
if (!iafic) resfile.AssignCat (session->LoadedFile());
else resfile.AssignCat (file);
if (var && var[0] != '\0' && (var[0] != '.' || var[1] != '\0') )
resvar.AssignCat (var);
else if (resfile.Length() == 0) resvar.AssignCat (def);
else {
Standard_Integer nomdeb, nomfin;
nomdeb = resfile.SearchFromEnd ("/");
if (nomdeb <= 0) nomdeb = resfile.SearchFromEnd("\\"); // pour NT
if (nomdeb < 0) nomdeb = 0;
nomfin = resfile.SearchFromEnd (".");
if (nomfin < nomdeb) nomfin = resfile.Length() + 1;
resvar = resfile.SubString(nomdeb+1,nomfin-1);
}
return iafic;
}

View File

@@ -1,99 +0,0 @@
// Created on: 1995-03-16
// Created by: Christian CAILLET
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSControl_FuncShape_HeaderFile
#define _XSControl_FuncShape_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Integer.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <Standard_CString.hxx>
class XSControl_WorkSession;
class TCollection_AsciiString;
//! Defines additional commands for XSControl to :
//! - control of initialisation (xinit, xnorm, newmodel)
//! - analyse of the result of a transfer (recorded in a
//! TransientProcess for Read, FinderProcess for Write) :
//! statistics, various lists (roots,complete,abnormal), what
//! about one specific entity, producing a model with the
//! abnormal result
//!
//! This appendix of XSControl is compiled separately to distinguish
//! basic features from user callable forms
class XSControl_FuncShape
{
public:
DEFINE_STANDARD_ALLOC
//! Defines and loads all functions which work on shapes for XSControl (as ActFunc)
Standard_EXPORT static void Init();
//! Analyses a name as designating Shapes from a Vars or from
//! XSTEP transfer (last Transfer on Reading). <name> can be :
//! "*" : all the root shapes produced by last Transfer (Read)
//! i.e. considers roots of the TransientProcess
//! a name : a name of a variable DRAW
//!
//! Returns the count of designated Shapes. Their list is put in
//! <list>. If <list> is null, it is firstly created. Then it is
//! completed (Append without Clear) by the Shapes found
//! Returns 0 if no Shape could be found
Standard_EXPORT static Standard_Integer MoreShapes (const Handle(XSControl_WorkSession)& session, Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name);
//! Analyses given file name and variable name, with a default
//! name for variables. Returns resulting file name and variable
//! name plus status "file to read"(True) or "already read"(False)
//! In the latter case, empty resfile means no file available
//!
//! If <file> is null or empty or equates ".", considers Session
//! and returned status is False
//! Else, returns resfile = file and status is True
//! If <var> is neither null nor empty, resvar = var
//! Else, the root part of <resfile> is considered, if defined
//! Else, <def> is taken
Standard_EXPORT static Standard_Boolean FileAndVar (const Handle(XSControl_WorkSession)& session, const Standard_CString file, const Standard_CString var, const Standard_CString def, TCollection_AsciiString& resfile, TCollection_AsciiString& resvar);
protected:
private:
};
#endif // _XSControl_FuncShape_HeaderFile

View File

@@ -1,505 +0,0 @@
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <IFSelect_Act.hxx>
#include <IFSelect_CheckCounter.hxx>
#include <IFSelect_Functions.hxx>
#include <IFSelect_SessionPilot.hxx>
#include <Interface_Static.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <Transfer_ResultFromModel.hxx>
#include <Transfer_TransientProcess.hxx>
#include <XSControl.hxx>
#include <XSControl_Controller.hxx>
#include <XSControl_Functions.hxx>
#include <XSControl_SelectForTransfer.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_TransferWriter.hxx>
#include <XSControl_WorkSession.hxx>
// #######################################################################
// ## ##
// ## ##
// ## FUNCTIONS ##
// ## ##
// ## ##
// #######################################################################
//=======================================================================
//function : xinit
//=======================================================================
static IFSelect_ReturnStatus XSControl_xinit(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** xinit ****
if (argc > 1) return (XSControl::Session(pilot)->SelectNorm(arg1) ?
IFSelect_RetDone : IFSelect_RetFail);
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout<<"Selected Norm:"<<XSControl::Session(pilot)->SelectedNorm()<<std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : xnorm
//=======================================================================
static IFSelect_ReturnStatus XSControl_xnorm(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** xnorm ****
Handle(XSControl_WorkSession) WS = XSControl::Session(pilot);
Handle(XSControl_Controller) control = WS->NormAdaptor();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (argc == 1)
sout<<"Current Norm. xnorm newnorm to change"<<std::endl;
else sout<<"Current Norm :"<<std::endl;
if (control.IsNull()) sout<<"no norm currently defined"<<std::endl;
else
sout<<" Long Name (complete) : "<<control->Name(Standard_False)<<std::endl
<< " Short name (resource) : "<<control->Name(Standard_True)<<std::endl;
if (argc == 1) return IFSelect_RetVoid;
control = XSControl_Controller::Recorded(arg1);
if (control.IsNull()) {
sout<<" No norm named : "<<arg1<<std::endl;
return IFSelect_RetError;
}
WS->SetController(control);
sout<<"new norm : "<<control->Name()<<std::endl;
return IFSelect_RetDone;
}
//=======================================================================
//function : newmodel
//=======================================================================
static IFSelect_ReturnStatus XSControl_newmodel(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** newmodel ****
if (!XSControl::Session(pilot)->NewModel().IsNull()) return IFSelect_RetDone;
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout<<"No new Model produced"<<std::endl;
return IFSelect_RetFail;
}
//=======================================================================
//function : tpclear
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpclear(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** tpclear/twclear ****
const Standard_Boolean modew = (pilot->Word(0).Value(2) == 'w');
const Handle(Transfer_FinderProcess) &FP = XSControl::Session(pilot)->TransferWriter()->FinderProcess();
const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (modew) { if(!FP.IsNull()) FP->Clear(); else sout<<"No Transfer Write"<<std::endl; }
else { if(!TP.IsNull()) TP->Clear(); else sout<<"No Transfer Read"<<std::endl; }
return IFSelect_RetDone;
}
//=======================================================================
//function : tpstat
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpstat(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
//const Standard_CString arg2 = pilot->Arg(2);
const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout<<"No Transfer Read"<<std::endl; return IFSelect_RetError;}
// **** tpstat ****
Standard_Integer mod1 = -1;
Standard_Integer mod2 = 0;
// g : general c : check (compte) C (liste) f : fails(compte) F (liste)
// resultats racines : n : n0s entites s : status b : binders
// t : compte par type r : compte par resultat l : liste(type-resultat)
// *n *s *b *t *r *l : idem sur tout
// ?n etc.. : idem sur resultats anormaux
// ? tout court pour help
if (argc > 1) {
char a2 = arg1[1]; if (a2 == '\0') a2 = '!';
switch (arg1[0]) {
case 'g' : mod1 = 0; break;
case 'c' : mod1 = 4; mod2 = 4; break;
case 'C' : mod1 = 4; mod2 = 2; break;
case 'f' : mod1 = 5; mod2 = 4; break;
case 'F' : mod1 = 5; mod2 = 2; break;
case '*' : mod1 = 2; break;
case '?' : mod1 = 3; break;
default : mod1 = 1; if (argc > 2) mod1 = 2; a2 = arg1[0]; break;
}
if (mod1 < 1 || mod1 > 3) a2 = '!';
switch (a2) {
case 'n' : mod2 = 0; break;
case 's' : mod2 = 1; break;
case 'b' : mod2 = 2; break;
case 't' : mod2 = 3; break;
case 'r' : mod2 = 4; break;
case 'l' : mod2 = 5; break;
case 'L' : mod2 = 6; break;
case '!' : break;
case '?' : mod1 = -1; break;
default : mod1 = -2; break;
}
}
// A present help eventuel
if (mod1 < -1) sout<<"Unknown Mode"<<std::endl;
if (mod1 < 0) {
sout<<"Modes available :\n"
<<"g : general c : checks (count) C (list)\n"
<<" f : fails (count) F (list)\n"
<<" n : numbers of transferred entities (on TRANSFER ROOTS)\n"
<<" s : their status (type entity-result , presence checks)\n"
<<" b : detail of binders\n"
<<" t : count per entity type r : per type/status result\n"
<<" l : count per couple type entity/result\n"
<<" L : list per couple type entity/result\n"
<<" *n *s *b *t *r *l *L : idem on ALL recorded items\n"
<<" ?n ?s ?b ?t ... : idem on abnormal items\n"
<<" n select : n applied on a selection idem for s b t r l"<<std::endl;
if (mod1 < -1) return IFSelect_RetError;
return IFSelect_RetVoid;
}
if (!TP.IsNull()) {
sout<<"TransferRead :";
if (TP->Model() != pilot->Session()->Model()) sout<<"Model differs from the session";
Handle(TColStd_HSequenceOfTransient) list =
IFSelect_Functions::GiveList(pilot->Session(),pilot->CommandPart(2));
XSControl_TransferReader::PrintStatsOnList (TP,list,mod1,mod2);
// TP->PrintStats (1,sout);
}
else sout<<"TransferRead : not defined"<<std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : tpent
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpent(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
// **** tpent ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout<<"No Transfer Read"<<std::endl; return IFSelect_RetError;}
Handle(Interface_InterfaceModel) model = TP->Model();
if (model.IsNull()) return IFSelect_RetFail;
if (argc < 2) { sout<<"Give ENTITY NUMBER (IN MODEL TransferProcess)"<<std::endl; return IFSelect_RetError; }
Standard_Integer num = atoi(arg1);
if (num <= 0 || num > model->NbEntities()) { sout<<"Number not in [1 - "<<model->NbEntities()<<"]"<<std::endl; return IFSelect_RetError; }
Handle(Standard_Transient) ent = model->Value(num);
Standard_Integer index = TP->MapIndex (ent);
if (index == 0) sout<<"Entity "<<num<<" not recorded in transfer"<<std::endl;
else XSControl::Session(pilot)->PrintTransferStatus (index,Standard_False,sout);
return IFSelect_RetVoid;
}
//=======================================================================
//function : tpitem
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpitem(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** tpitem/tproot/twitem/twroot ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (argc < 2) { sout<<"Give ITEM NUMBER (in TransferProcess)"<<std::endl; return IFSelect_RetError; }
Standard_Integer num = atoi(arg1);
if (pilot->Word(0).Value(3) == 'r') num = -num;
Standard_Boolean modew = Standard_False;
if (pilot->Word(0).Value(2) == 'w') modew = Standard_True;
Handle(Transfer_Binder) binder;
Handle(Transfer_Finder) finder;
Handle(Standard_Transient) ent;
if (!XSControl::Session(pilot)->PrintTransferStatus(num,modew,sout))
{
sout<<" - Num="<<num<<" incorrect"<<std::endl;
}
return IFSelect_RetVoid;
}
//=======================================================================
//function : trecord
//=======================================================================
static IFSelect_ReturnStatus XSControl_trecord(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
// **** trecord : TransferReader ****
Standard_Boolean tous = (argc == 1);
Standard_Integer num = -1;
const Handle(Interface_InterfaceModel) &mdl = XSControl::Session(pilot)->Model();
const Handle(XSControl_TransferReader) &TR = XSControl::Session(pilot)->TransferReader();
Handle(Standard_Transient) ent;
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (mdl.IsNull() || TR.IsNull() || TP.IsNull())
{ sout<<" init not done"<<std::endl; return IFSelect_RetError; }
if (!tous) num = atoi(arg1);
// Enregistrer les racines
if (tous) {
Standard_Integer nb = TP->NbRoots();
sout<<" Recording "<<nb<<" Roots"<<std::endl;
for (Standard_Integer i = 1; i <= nb; i ++) {
ent = TP->Root(i);
if (TR->RecordResult (ent)) sout<<" Root n0."<<i<<std::endl;
else sout<<" Root n0."<<i<<" not recorded"<<std::endl;
}
} else {
if (num < 1 || num > mdl->NbEntities()) sout<<"incorrect number:"<<num<<std::endl;
else if (TR->RecordResult(mdl->Value(num))) sout<<" Entity n0."<<num<<std::endl;
else sout<<" Entity n0."<<num<<" not recorded"<<std::endl;
}
return IFSelect_RetDone;
}
//=======================================================================
//function : trstat
//=======================================================================
static IFSelect_ReturnStatus XSControl_trstat(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
Message_Messenger::StreamBuffer sout = Message::SendInfo();
// **** trstat : TransferReader ****
const Handle(XSControl_TransferReader) &TR = XSControl::Session(pilot)->TransferReader();
if (TR.IsNull()) { sout<<" init not done"<<std::endl; return IFSelect_RetError; }
Handle(Interface_InterfaceModel) mdl = TR->Model();
if (mdl.IsNull()) { sout<<" No model"<<std::endl; return IFSelect_RetError; }
sout<<" Statistics : FileName : "<<TR->FileName()<<std::endl;
if (argc == 1) {
// stats generales
TR->PrintStats (sout, 10, 0);
} else {
// stats unitaires
Standard_Integer num = atoi(arg1);
if (num < 1 || num > mdl->NbEntities()) { sout<<" incorrect number:"<<arg1<<std::endl; return IFSelect_RetError; }
Handle(Standard_Transient) ent = mdl->Value(num);
if (!TR->IsRecorded(ent)) { sout<<" Entity "<<num<<" not recorded"<<std::endl; return IFSelect_RetError; }
Handle(Transfer_ResultFromModel) RM = TR->FinalResult(ent);
Handle(TColStd_HSequenceOfTransient) list = TR->CheckedList(ent);
Standard_Integer i, nb = list->Length();
if (nb > 0) sout<<" Entities implied by Check/Result :"<<nb<<" i.e.:";
for (i = 1; i <= nb; i ++) { sout<<" "; mdl->Print(list->Value(i), sout); }
sout<<std::endl;
if (RM.IsNull()) { sout<<" no other info"<<std::endl; return IFSelect_RetVoid; }
Interface_CheckIterator chl = RM->CheckList(Standard_False);
pilot->Session()->PrintCheckList (sout, chl, Standard_False, IFSelect_EntitiesByItem);
}
return IFSelect_RetVoid;
}
//=======================================================================
//function : trbegin
//=======================================================================
static IFSelect_ReturnStatus XSControl_trbegin(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** trbegin : TransferReader ****
Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader();
Standard_Boolean init = TR.IsNull();
if (pilot->NbWords() > 1) { if (pilot->Arg(1)[0] == 'i') init = Standard_True; }
if (init) {
XSControl::Session(pilot)->InitTransferReader (0);
TR = XSControl::Session(pilot)->TransferReader();
if (TR.IsNull()) {
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout<<" init not done or failed"<<std::endl;
return IFSelect_RetError;
}
}
TR->BeginTransfer();
return IFSelect_RetDone;
}
//=======================================================================
//function : tread
//=======================================================================
static IFSelect_ReturnStatus XSControl_tread(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
//const Standard_CString arg1 = pilot->Arg(1);
// **** tread : TransferReader ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
const Handle(XSControl_TransferReader) &TR = XSControl::Session(pilot)->TransferReader();
if (TR.IsNull()) { sout<<" init not done"<<std::endl; return IFSelect_RetError; }
const Handle(Interface_InterfaceModel) &mdl = TR->Model();
if (mdl.IsNull()) { sout<<" No model"<<std::endl; return IFSelect_RetError; }
if (argc < 2) {
// DeclareAndCast(IFSelect_Selection,sel,pilot->Session()->NamedItem("xst-model-roots"));
Handle(Standard_Transient) sel = pilot->Session()->NamedItem("xst-model-roots");
if (sel.IsNull()) { sout<<"Select Roots absent"<<std::endl; return IFSelect_RetError; }
Handle(TColStd_HSequenceOfTransient) list = pilot->Session()->GiveList(sel);
sout<<" Transferring all roots i.e. : "<<TR->TransferList(list)<<std::endl;
} else {
Handle(TColStd_HSequenceOfTransient) list =
IFSelect_Functions::GiveList(pilot->Session(),pilot->CommandPart(1));
sout<<" Transfer of "<<list->Length()<<" entities"<<std::endl;
Standard_Integer nb = TR->TransferList(list);
sout<<" Gives "<<nb<<" results"<<std::endl;
}
return IFSelect_RetDone;
}
//=======================================================================
//function : trtp
//=======================================================================
static IFSelect_ReturnStatus XSControl_trtp(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** TReader -> TProcess ****
const Handle(XSControl_TransferReader) &TR = XSControl::Session(pilot)->TransferReader();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TR.IsNull()) sout<<" No TransferReader"<<std::endl;
else if (TR->TransientProcess().IsNull()) sout<<" Transfer Reader without Process"<<std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : tptr
//=======================================================================
static IFSelect_ReturnStatus XSControl_tptr(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** TProcess -> TReader ****
XSControl::Session(pilot)->InitTransferReader (3);
return IFSelect_RetDone;
}
//=======================================================================
//function : twmode
//=======================================================================
static IFSelect_ReturnStatus XSControl_twmode(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** twmode ****
Handle(XSControl_TransferWriter) TW = XSControl::Session(pilot)->TransferWriter();
Handle(XSControl_Controller) control = XSControl::Session(pilot)->NormAdaptor();
Standard_Integer modemin,modemax;
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (control->ModeWriteBounds (modemin,modemax)) {
sout<<"Write Mode : allowed values "<<modemin<<" to "<<modemax<<std::endl;
for (Standard_Integer modd = modemin; modd <= modemax; modd ++) {
sout<<modd<<" : "<<control->ModeWriteHelp (modd)<<std::endl;
}
}
sout<<"Write Mode : actual = "<<TW->TransferMode()<<std::endl;
if (argc <= 1) return IFSelect_RetVoid;
Standard_Integer mod = atoi(arg1);
sout<<"New value -> "<<arg1<<std::endl;
TW->SetTransferMode(mod);
if (!control->IsModeWrite (mod)) sout<<"Warning : this new value is not supported"<<std::endl;
return IFSelect_RetDone;
}
//=======================================================================
//function : twstat
//=======================================================================
static IFSelect_ReturnStatus XSControl_twstat(const Handle(IFSelect_SessionPilot)& pilot)
{
//Standard_Integer argc = pilot->NbWords();
//const Standard_CString arg1 = pilot->Arg(1);
//const Standard_CString arg2 = pilot->Arg(2);
const Handle(Transfer_FinderProcess) &FP = XSControl::Session(pilot)->TransferWriter()->FinderProcess();
// **** twstat ****
// Pour Write
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (!FP.IsNull()) {
sout<<"TransferWrite:";
// XSControl_TransferWriter::PrintStatsProcess (FP,mod1,mod2);
FP->PrintStats (1,sout);
}
else sout<<"TransferWrite: not defined"<<std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : settransfert
//=======================================================================
static IFSelect_ReturnStatus XSControl_settransfert(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** SelectForTransfer ****
return pilot->RecordItem(new XSControl_SelectForTransfer(XSControl::Session(pilot)->TransferReader()));
}
static int THE_XSControl_Functions_initactor = 0;
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void XSControl_Functions::Init ()
{
if (THE_XSControl_Functions_initactor)
{
return;
}
THE_XSControl_Functions_initactor = 1;
IFSelect_Act::SetGroup("DE: General");
IFSelect_Act::AddFunc ("xinit","[norm:string to change norme] reinitialises according to the norm",XSControl_xinit);
IFSelect_Act::AddFunc ("xnorm","displays current norm +norm : changes it",XSControl_xnorm);
IFSelect_Act::AddFunc ("newmodel","produces a new empty model, for the session",XSControl_newmodel);
IFSelect_Act::AddFunc ("tpclear","Clears TransferProcess (READ)",XSControl_tpclear);
IFSelect_Act::AddFunc ("twclear","Clears TransferProcess (WRITE)",XSControl_tpclear);
IFSelect_Act::AddFunc ("tpstat","Statistics on TransferProcess (READ)",XSControl_tpstat);
IFSelect_Act::AddFunc ("tpent","[num:integer] Statistics on an entity of the model (READ)",XSControl_tpent);
IFSelect_Act::AddFunc ("tpitem","[num:integer] Statistics on ITEM of transfer (READ)" ,XSControl_tpitem);
IFSelect_Act::AddFunc ("tproot","[num:integer] Statistics on a ROOT of transfert (READ)" ,XSControl_tpitem);
IFSelect_Act::AddFunc ("twitem","[num:integer] Statistics on an ITEM of transfer (WRITE)" ,XSControl_tpitem);
IFSelect_Act::AddFunc ("twroot","[num:integer] Statistics on a ROOT of transfer (WRITE)",XSControl_tpitem);
IFSelect_Act::AddFunc ("trecord","record : all root results; or num : for entity n0.num",XSControl_trecord);
IFSelect_Act::AddFunc ("trstat","general statistics; or num : stats on entity n0 num",XSControl_trstat);
IFSelect_Act::AddFunc ("trbegin","begin-transfer-reader [init]",XSControl_trbegin);
IFSelect_Act::AddFunc ("tread","transfers all roots, or num|sel|sel num : entity list, by transfer-reader",XSControl_tread);
IFSelect_Act::AddFunc ("trtp","feeds commands tp... with results from tr...",XSControl_trtp);
IFSelect_Act::AddFunc ("tptr","feeds tr... from tp... (may be incomplete)",XSControl_tptr);
IFSelect_Act::AddFunc ("twmode","displays mode transfer write, + num changes it",XSControl_twmode);
IFSelect_Act::AddFunc ("twstat","Statistics on TransferProcess (WRITE)",XSControl_twstat);
IFSelect_Act::AddFSet ("selecttransfer","selection (recognize from transfer actor)",XSControl_settransfert);
}

View File

@@ -2,5 +2,7 @@ XSDRAW.cxx
XSDRAW.hxx
XSDRAW_Functions.cxx
XSDRAW_Functions.hxx
XSDRAW_Vars.cxx
XSDRAW_Vars.hxx
XSDRAW_FunctionsSession.cxx
XSDRAW_FunctionsSession.hxx
XSDRAW_FunctionsShape.cxx
XSDRAW_FunctionsShape.hxx

View File

@@ -41,7 +41,7 @@ class TCollection_AsciiString;
//! Works with some "static" data : a SessionPilot (used to run)
//! with its WorkSession and Model and TransferReader, a
//! FinderProcess
class XSDRAW
class XSDRAW
{
public:

View File

@@ -12,10 +12,492 @@
// commercial license or contractual agreement.
#include <XSControl_FuncShape.hxx>
#include <IFSelect_Act.hxx>
#include <IFSelect_CheckCounter.hxx>
#include <IFSelect_Functions.hxx>
#include <IFSelect_SessionPilot.hxx>
#include <Interface_Static.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <Transfer_ResultFromModel.hxx>
#include <Transfer_TransientProcess.hxx>
#include <XSControl.hxx>
#include <XSControl_Controller.hxx>
#include <XSDRAW_Functions.hxx>
#include <XSControl_SelectForTransfer.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_TransferWriter.hxx>
#include <XSControl_WorkSession.hxx>
void XSDRAW_Functions::Init ()
//=======================================================================
//function : xinit
//=======================================================================
static IFSelect_ReturnStatus XSControl_xinit(const Handle(IFSelect_SessionPilot)& pilot)
{
XSControl_FuncShape::Init ();
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** xinit ****
if (argc > 1) return (XSControl::Session(pilot)->SelectNorm(arg1) ?
IFSelect_RetDone : IFSelect_RetFail);
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << "Selected Norm:" << XSControl::Session(pilot)->SelectedNorm() << std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : xnorm
//=======================================================================
static IFSelect_ReturnStatus XSControl_xnorm(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** xnorm ****
Handle(XSControl_WorkSession) WS = XSControl::Session(pilot);
Handle(XSControl_Controller) control = WS->NormAdaptor();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (argc == 1)
sout << "Current Norm. xnorm newnorm to change" << std::endl;
else sout << "Current Norm :" << std::endl;
if (control.IsNull()) sout << "no norm currently defined" << std::endl;
else
sout << " Long Name (complete) : " << control->Name(Standard_False) << std::endl
<< " Short name (resource) : " << control->Name(Standard_True) << std::endl;
if (argc == 1) return IFSelect_RetVoid;
control = XSControl_Controller::Recorded(arg1);
if (control.IsNull())
{
sout << " No norm named : " << arg1 << std::endl;
return IFSelect_RetError;
}
WS->SetController(control);
sout << "new norm : " << control->Name() << std::endl;
return IFSelect_RetDone;
}
//=======================================================================
//function : newmodel
//=======================================================================
static IFSelect_ReturnStatus XSControl_newmodel(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** newmodel ****
if (!XSControl::Session(pilot)->NewModel().IsNull()) return IFSelect_RetDone;
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << "No new Model produced" << std::endl;
return IFSelect_RetFail;
}
//=======================================================================
//function : tpclear
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpclear(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** tpclear/twclear ****
const Standard_Boolean modew = (pilot->Word(0).Value(2) == 'w');
const Handle(Transfer_FinderProcess)& FP = XSControl::Session(pilot)->TransferWriter()->FinderProcess();
const Handle(Transfer_TransientProcess)& TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (modew) { if (!FP.IsNull()) FP->Clear(); else sout << "No Transfer Write" << std::endl; }
else { if (!TP.IsNull()) TP->Clear(); else sout << "No Transfer Read" << std::endl; }
return IFSelect_RetDone;
}
//=======================================================================
//function : tpstat
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpstat(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
//const Standard_CString arg2 = pilot->Arg(2);
const Handle(Transfer_TransientProcess)& TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout << "No Transfer Read" << std::endl; return IFSelect_RetError; }
// **** tpstat ****
Standard_Integer mod1 = -1;
Standard_Integer mod2 = 0;
// g : general c : check (compte) C (liste) f : fails(compte) F (liste)
// resultats racines : n : n0s entites s : status b : binders
// t : compte par type r : compte par resultat l : liste(type-resultat)
// *n *s *b *t *r *l : idem sur tout
// ?n etc.. : idem sur resultats anormaux
// ? tout court pour help
if (argc > 1)
{
char a2 = arg1[1]; if (a2 == '\0') a2 = '!';
switch (arg1[0])
{
case 'g': mod1 = 0; break;
case 'c': mod1 = 4; mod2 = 4; break;
case 'C': mod1 = 4; mod2 = 2; break;
case 'f': mod1 = 5; mod2 = 4; break;
case 'F': mod1 = 5; mod2 = 2; break;
case '*': mod1 = 2; break;
case '?': mod1 = 3; break;
default: mod1 = 1; if (argc > 2) mod1 = 2; a2 = arg1[0]; break;
}
if (mod1 < 1 || mod1 > 3) a2 = '!';
switch (a2)
{
case 'n': mod2 = 0; break;
case 's': mod2 = 1; break;
case 'b': mod2 = 2; break;
case 't': mod2 = 3; break;
case 'r': mod2 = 4; break;
case 'l': mod2 = 5; break;
case 'L': mod2 = 6; break;
case '!': break;
case '?': mod1 = -1; break;
default: mod1 = -2; break;
}
}
// A present help eventuel
if (mod1 < -1) sout << "Unknown Mode" << std::endl;
if (mod1 < 0)
{
sout << "Modes available :\n"
<< "g : general c : checks (count) C (list)\n"
<< " f : fails (count) F (list)\n"
<< " n : numbers of transferred entities (on TRANSFER ROOTS)\n"
<< " s : their status (type entity-result , presence checks)\n"
<< " b : detail of binders\n"
<< " t : count per entity type r : per type/status result\n"
<< " l : count per couple type entity/result\n"
<< " L : list per couple type entity/result\n"
<< " *n *s *b *t *r *l *L : idem on ALL recorded items\n"
<< " ?n ?s ?b ?t ... : idem on abnormal items\n"
<< " n select : n applied on a selection idem for s b t r l" << std::endl;
if (mod1 < -1) return IFSelect_RetError;
return IFSelect_RetVoid;
}
if (!TP.IsNull())
{
sout << "TransferRead :";
if (TP->Model() != pilot->Session()->Model()) sout << "Model differs from the session";
Handle(TColStd_HSequenceOfTransient) list =
IFSelect_Functions::GiveList(pilot->Session(), pilot->CommandPart(2));
XSControl_TransferReader::PrintStatsOnList(TP, list, mod1, mod2);
// TP->PrintStats (1,sout);
}
else sout << "TransferRead : not defined" << std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : tpent
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpent(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Handle(Transfer_TransientProcess)& TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
// **** tpent ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout << "No Transfer Read" << std::endl; return IFSelect_RetError; }
Handle(Interface_InterfaceModel) model = TP->Model();
if (model.IsNull()) return IFSelect_RetFail;
if (argc < 2) { sout << "Give ENTITY NUMBER (IN MODEL TransferProcess)" << std::endl; return IFSelect_RetError; }
Standard_Integer num = atoi(arg1);
if (num <= 0 || num > model->NbEntities()) { sout << "Number not in [1 - " << model->NbEntities() << "]" << std::endl; return IFSelect_RetError; }
Handle(Standard_Transient) ent = model->Value(num);
Standard_Integer index = TP->MapIndex(ent);
if (index == 0) sout << "Entity " << num << " not recorded in transfer" << std::endl;
else XSControl::Session(pilot)->PrintTransferStatus(index, Standard_False, sout);
return IFSelect_RetVoid;
}
//=======================================================================
//function : tpitem
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpitem(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** tpitem/tproot/twitem/twroot ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (argc < 2) { sout << "Give ITEM NUMBER (in TransferProcess)" << std::endl; return IFSelect_RetError; }
Standard_Integer num = atoi(arg1);
if (pilot->Word(0).Value(3) == 'r') num = -num;
Standard_Boolean modew = Standard_False;
if (pilot->Word(0).Value(2) == 'w') modew = Standard_True;
Handle(Transfer_Binder) binder;
Handle(Transfer_Finder) finder;
Handle(Standard_Transient) ent;
if (!XSControl::Session(pilot)->PrintTransferStatus(num, modew, sout))
{
sout << " - Num=" << num << " incorrect" << std::endl;
}
return IFSelect_RetVoid;
}
//=======================================================================
//function : trecord
//=======================================================================
static IFSelect_ReturnStatus XSControl_trecord(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Handle(Transfer_TransientProcess)& TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
// **** trecord : TransferReader ****
Standard_Boolean tous = (argc == 1);
Standard_Integer num = -1;
const Handle(Interface_InterfaceModel)& mdl = XSControl::Session(pilot)->Model();
const Handle(XSControl_TransferReader)& TR = XSControl::Session(pilot)->TransferReader();
Handle(Standard_Transient) ent;
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (mdl.IsNull() || TR.IsNull() || TP.IsNull())
{
sout << " init not done" << std::endl; return IFSelect_RetError;
}
if (!tous) num = atoi(arg1);
// Enregistrer les racines
if (tous)
{
Standard_Integer nb = TP->NbRoots();
sout << " Recording " << nb << " Roots" << std::endl;
for (Standard_Integer i = 1; i <= nb; i++)
{
ent = TP->Root(i);
if (TR->RecordResult(ent)) sout << " Root n0." << i << std::endl;
else sout << " Root n0." << i << " not recorded" << std::endl;
}
}
else
{
if (num < 1 || num > mdl->NbEntities()) sout << "incorrect number:" << num << std::endl;
else if (TR->RecordResult(mdl->Value(num))) sout << " Entity n0." << num << std::endl;
else sout << " Entity n0." << num << " not recorded" << std::endl;
}
return IFSelect_RetDone;
}
//=======================================================================
//function : trstat
//=======================================================================
static IFSelect_ReturnStatus XSControl_trstat(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
Message_Messenger::StreamBuffer sout = Message::SendInfo();
// **** trstat : TransferReader ****
const Handle(XSControl_TransferReader)& TR = XSControl::Session(pilot)->TransferReader();
if (TR.IsNull()) { sout << " init not done" << std::endl; return IFSelect_RetError; }
Handle(Interface_InterfaceModel) mdl = TR->Model();
if (mdl.IsNull()) { sout << " No model" << std::endl; return IFSelect_RetError; }
sout << " Statistics : FileName : " << TR->FileName() << std::endl;
if (argc == 1)
{
// stats generales
TR->PrintStats(sout, 10, 0);
}
else
{
// stats unitaires
Standard_Integer num = atoi(arg1);
if (num < 1 || num > mdl->NbEntities()) { sout << " incorrect number:" << arg1 << std::endl; return IFSelect_RetError; }
Handle(Standard_Transient) ent = mdl->Value(num);
if (!TR->IsRecorded(ent)) { sout << " Entity " << num << " not recorded" << std::endl; return IFSelect_RetError; }
Handle(Transfer_ResultFromModel) RM = TR->FinalResult(ent);
Handle(TColStd_HSequenceOfTransient) list = TR->CheckedList(ent);
Standard_Integer i, nb = list->Length();
if (nb > 0) sout << " Entities implied by Check/Result :" << nb << " i.e.:";
for (i = 1; i <= nb; i++) { sout << " "; mdl->Print(list->Value(i), sout); }
sout << std::endl;
if (RM.IsNull()) { sout << " no other info" << std::endl; return IFSelect_RetVoid; }
Interface_CheckIterator chl = RM->CheckList(Standard_False);
pilot->Session()->PrintCheckList(sout, chl, Standard_False, IFSelect_EntitiesByItem);
}
return IFSelect_RetVoid;
}
//=======================================================================
//function : trbegin
//=======================================================================
static IFSelect_ReturnStatus XSControl_trbegin(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** trbegin : TransferReader ****
Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader();
Standard_Boolean init = TR.IsNull();
if (pilot->NbWords() > 1) { if (pilot->Arg(1)[0] == 'i') init = Standard_True; }
if (init)
{
XSControl::Session(pilot)->InitTransferReader(0);
TR = XSControl::Session(pilot)->TransferReader();
if (TR.IsNull())
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " init not done or failed" << std::endl;
return IFSelect_RetError;
}
}
TR->BeginTransfer();
return IFSelect_RetDone;
}
//=======================================================================
//function : tread
//=======================================================================
static IFSelect_ReturnStatus XSControl_tread(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
//const Standard_CString arg1 = pilot->Arg(1);
// **** tread : TransferReader ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
const Handle(XSControl_TransferReader)& TR = XSControl::Session(pilot)->TransferReader();
if (TR.IsNull()) { sout << " init not done" << std::endl; return IFSelect_RetError; }
const Handle(Interface_InterfaceModel)& mdl = TR->Model();
if (mdl.IsNull()) { sout << " No model" << std::endl; return IFSelect_RetError; }
if (argc < 2)
{
// DeclareAndCast(IFSelect_Selection,sel,pilot->Session()->NamedItem("xst-model-roots"));
Handle(Standard_Transient) sel = pilot->Session()->NamedItem("xst-model-roots");
if (sel.IsNull()) { sout << "Select Roots absent" << std::endl; return IFSelect_RetError; }
Handle(TColStd_HSequenceOfTransient) list = pilot->Session()->GiveList(sel);
sout << " Transferring all roots i.e. : " << TR->TransferList(list) << std::endl;
}
else
{
Handle(TColStd_HSequenceOfTransient) list =
IFSelect_Functions::GiveList(pilot->Session(), pilot->CommandPart(1));
sout << " Transfer of " << list->Length() << " entities" << std::endl;
Standard_Integer nb = TR->TransferList(list);
sout << " Gives " << nb << " results" << std::endl;
}
return IFSelect_RetDone;
}
//=======================================================================
//function : trtp
//=======================================================================
static IFSelect_ReturnStatus XSControl_trtp(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** TReader -> TProcess ****
const Handle(XSControl_TransferReader)& TR = XSControl::Session(pilot)->TransferReader();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TR.IsNull()) sout << " No TransferReader" << std::endl;
else if (TR->TransientProcess().IsNull()) sout << " Transfer Reader without Process" << std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : tptr
//=======================================================================
static IFSelect_ReturnStatus XSControl_tptr(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** TProcess -> TReader ****
XSControl::Session(pilot)->InitTransferReader(3);
return IFSelect_RetDone;
}
//=======================================================================
//function : twmode
//=======================================================================
static IFSelect_ReturnStatus XSControl_twmode(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** twmode ****
Handle(XSControl_TransferWriter) TW = XSControl::Session(pilot)->TransferWriter();
Handle(XSControl_Controller) control = XSControl::Session(pilot)->NormAdaptor();
Standard_Integer modemin, modemax;
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (control->ModeWriteBounds(modemin, modemax))
{
sout << "Write Mode : allowed values " << modemin << " to " << modemax << std::endl;
for (Standard_Integer modd = modemin; modd <= modemax; modd++)
{
sout << modd << " : " << control->ModeWriteHelp(modd) << std::endl;
}
}
sout << "Write Mode : actual = " << TW->TransferMode() << std::endl;
if (argc <= 1) return IFSelect_RetVoid;
Standard_Integer mod = atoi(arg1);
sout << "New value -> " << arg1 << std::endl;
TW->SetTransferMode(mod);
if (!control->IsModeWrite(mod)) sout << "Warning : this new value is not supported" << std::endl;
return IFSelect_RetDone;
}
//=======================================================================
//function : twstat
//=======================================================================
static IFSelect_ReturnStatus XSControl_twstat(const Handle(IFSelect_SessionPilot)& pilot)
{
//Standard_Integer argc = pilot->NbWords();
//const Standard_CString arg1 = pilot->Arg(1);
//const Standard_CString arg2 = pilot->Arg(2);
const Handle(Transfer_FinderProcess)& FP = XSControl::Session(pilot)->TransferWriter()->FinderProcess();
// **** twstat ****
// Pour Write
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (!FP.IsNull())
{
sout << "TransferWrite:";
// XSControl_TransferWriter::PrintStatsProcess (FP,mod1,mod2);
FP->PrintStats(1, sout);
}
else sout << "TransferWrite: not defined" << std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : settransfert
//=======================================================================
static IFSelect_ReturnStatus XSControl_settransfert(const Handle(IFSelect_SessionPilot)& pilot)
{
// **** SelectForTransfer ****
return pilot->RecordItem(new XSControl_SelectForTransfer(XSControl::Session(pilot)->TransferReader()));
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void XSDRAW_Functions::Init()
{
static int THE_XSDRAW_Functions_initactor = 0;
if (THE_XSDRAW_Functions_initactor)
{
return;
}
THE_XSDRAW_Functions_initactor = 1;
IFSelect_Act::SetGroup("DE: General");
IFSelect_Act::AddFunc("xinit", "[norm:string to change norme] reinitialises according to the norm", XSControl_xinit);
IFSelect_Act::AddFunc("xnorm", "displays current norm +norm : changes it", XSControl_xnorm);
IFSelect_Act::AddFunc("newmodel", "produces a new empty model, for the session", XSControl_newmodel);
IFSelect_Act::AddFunc("tpclear", "Clears TransferProcess (READ)", XSControl_tpclear);
IFSelect_Act::AddFunc("twclear", "Clears TransferProcess (WRITE)", XSControl_tpclear);
IFSelect_Act::AddFunc("tpstat", "Statistics on TransferProcess (READ)", XSControl_tpstat);
IFSelect_Act::AddFunc("tpent", "[num:integer] Statistics on an entity of the model (READ)", XSControl_tpent);
IFSelect_Act::AddFunc("tpitem", "[num:integer] Statistics on ITEM of transfer (READ)", XSControl_tpitem);
IFSelect_Act::AddFunc("tproot", "[num:integer] Statistics on a ROOT of transfert (READ)", XSControl_tpitem);
IFSelect_Act::AddFunc("twitem", "[num:integer] Statistics on an ITEM of transfer (WRITE)", XSControl_tpitem);
IFSelect_Act::AddFunc("twroot", "[num:integer] Statistics on a ROOT of transfer (WRITE)", XSControl_tpitem);
IFSelect_Act::AddFunc("trecord", "record : all root results; or num : for entity n0.num", XSControl_trecord);
IFSelect_Act::AddFunc("trstat", "general statistics; or num : stats on entity n0 num", XSControl_trstat);
IFSelect_Act::AddFunc("trbegin", "begin-transfer-reader [init]", XSControl_trbegin);
IFSelect_Act::AddFunc("tread", "transfers all roots, or num|sel|sel num : entity list, by transfer-reader", XSControl_tread);
IFSelect_Act::AddFunc("trtp", "feeds commands tp... with results from tr...", XSControl_trtp);
IFSelect_Act::AddFunc("tptr", "feeds tr... from tp... (may be incomplete)", XSControl_tptr);
IFSelect_Act::AddFunc("twmode", "displays mode transfer write, + num changes it", XSControl_twmode);
IFSelect_Act::AddFunc("twstat", "Statistics on TransferProcess (WRITE)", XSControl_twstat);
IFSelect_Act::AddFSet("selecttransfer", "selection (recognize from transfer actor)", XSControl_settransfert);
}

View File

@@ -1,7 +1,4 @@
// Created on: 1995-03-16
// Created by: Christian CAILLET
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
@@ -17,21 +14,21 @@
#ifndef _XSDRAW_Functions_HeaderFile
#define _XSDRAW_Functions_HeaderFile
//! Defines additional commands for XSDRAW to :
//! - control of initialisation (xinit, xnorm, newmodel)
//! - analyse of the result of a transfer (recorded in a
//! TransientProcess for Read, FinderProcess for Write) :
//! statistics, various lists (roots,complete,abnormal), what
//! about one specific entity, producing a model with the
//! abnormal result
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
//! Functions from XSControl gives access to actions which can be
//! commanded with the resources provided by XSControl: especially
//! Controller and Transfer
//!
//! This appendix of XSDRAW is compiled separately to distinguish
//! basic features from user callable forms
class XSDRAW_Functions
//! It works by adding functions by method Init
class XSDRAW_Functions
{
public:
//! Defines and loads all basic functions for XSDRAW (as ActFunc)
DEFINE_STANDARD_ALLOC
public:
//! Defines and loads all functions for XSControl (as ActFunc)
Standard_EXPORT static void Init();
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,4 @@
// Created on: 1996-03-26
// Created by: Christian CAILLET
// Copyright (c) 1996-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
@@ -14,20 +11,25 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSControl_Functions_HeaderFile
#define _XSControl_Functions_HeaderFile
#ifndef _XSDRAW_FunctionsSession_HeaderFile
#define _XSDRAW_FunctionsSession_HeaderFile
//! Functions from XSControl gives access to actions which can be
//! commanded with the resources provided by XSControl: especially
//! Controller and Transfer
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
//! Functions gives access to all the actions which can be
//! commanded with the resources provided by IFSelect : especially
//! WorkSession and various types of Selections and Dispatches
//!
//! It works by adding functions by method Init
class XSControl_Functions
class XSDRAW_FunctionsSession
{
public:
DEFINE_STANDARD_ALLOC
public:
//! Defines and loads all functions for XSControl (as ActFunc)
//! Defines and loads all basic functions (as ActFunc)
Standard_EXPORT static void Init();
};
#endif // _XSControl_Functions_HeaderFile
#endif // _XSDRAW_FunctionsSession_HeaderFile

View File

@@ -0,0 +1,780 @@
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <Geom_Geometry.hxx>
#include <IFSelect_Act.hxx>
#include <IFSelect_Functions.hxx>
#include <IFSelect_SessionPilot.hxx>
#include <Interface_Macros.hxx>
#include <Interface_InterfaceModel.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <ShapeExtend_Explorer.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <Transfer_SimpleBinderOfTransient.hxx>
#include <Transfer_FinderProcess.hxx>
#include <Transfer_TransientListBinder.hxx>
#include <Transfer_TransientProcess.hxx>
#include <TransferBRep.hxx>
#include <TransferBRep_ShapeListBinder.hxx>
#include <TransferBRep_ShapeMapper.hxx>
#include <XSControl.hxx>
#include <XSControl_ConnectedShapes.hxx>
#include <XSControl_Controller.hxx>
#include <XSDRAW_FunctionsShape.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_TransferWriter.hxx>
#include <XSControl_Vars.hxx>
#include <XSControl_WorkSession.hxx>
#include <stdio.h>
//=======================================================================
//function : XSControl_tpdraw
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpdraw
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Standard_CString arg2 = pilot->Arg(2);
const Standard_CString arg3 = pilot->Arg(3);
const Handle(Transfer_TransientProcess)& TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout << "No Transfer Read" << std::endl; return IFSelect_RetError; }
// **** tpdraw ****
if (argc < 2)
{
sout << "Donner [mode facultatif : item ou root] , NUMERO , nom DRAW facultatif" << std::endl;
sout << " mode si present : item ou root, sinon n0 d entite modele" << std::endl;
sout << " NUMERO entier : d entite, d item transfert ou de root transfert\n"
<< " ou * pour dire tous" << std::endl;
return IFSelect_RetError;
}
Standard_Integer mode = 0, num = 0;
if (arg1[0] == 'i') mode = 1;
else if (arg1[0] == 'r') mode = 2;
Standard_Boolean tout = Standard_False;
if (mode == 0)
{
if (argc < 2) { sout << "Donner au moins un NUMERO ou *" << std::endl; return IFSelect_RetError; }
if (arg1[0] == '*') tout = Standard_True;
else num = IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot), arg1);
}
else
{
if (arg2[0] == '*') tout = Standard_True;
else num = IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot), arg2);
}
Standard_Integer nbvar = 0;
Handle(Transfer_Binder) binder;
Handle(Standard_Transient) ent;
TopoDS_Shape sh; char nomvar[40];
// Standard_Boolean moderoot = (pilot->Word(0).Value(3) == 'r');
Standard_Integer n1, n2, i, max = 0, index = 0;
Handle(Interface_InterfaceModel) model = TP->Model();
if (model.IsNull())
{
if (mode == 0)
{
sout << "Pas de modele, preciser n0 d item de transfert" << std::endl;
return IFSelect_RetError;
}
}
if (mode == 0) { sout << "Entite de modele"; max = model->NbEntities(); }
if (mode == 1) { sout << "Item de transfert"; max = TP->NbMapped(); }
if (mode == 2) { sout << "Racine de transfert"; max = TP->NbRoots(); }
if (tout)
{
n1 = 1; n2 = max;
sout << ", listage de 1 a " << max << std::endl;
}
else if (num <= 0 || num > max)
{
sout << " - Num=" << num << " hors limite (de 1 a " << max << ")" << std::endl;
return IFSelect_RetError;
}
else
{
n1 = n2 = num; nbvar = -1; // nbvar : 1ere shape simple = pas de n0
sout << ", n0 " << num << std::endl;
}
for (i = n1; i <= n2; i++)
{
if (mode == 0)
{
ent = model->Value(i);
num = i;
index = TP->MapIndex(ent);
}
else if (mode == 1)
{
ent = TP->Mapped(i);
if (model.IsNull()) num = 0;
else num = model->Number(ent);
index = i;
}
else if (mode == 2)
{
ent = TP->Root(i);
if (model.IsNull()) num = 0;
else num = model->Number(ent);
index = TP->MapIndex(ent);
}
if (index > 0) binder = TP->MapItem(index);
if (binder.IsNull()) index = 0;
if (index == 0)
{
if (!tout) sout << "Entite n0 " << num << " : non repertoriee" << std::endl;
continue;
}
if (!binder->HasResult())
{
if (!tout) sout << "Entite n0 " << num << " : pas de resultat" << std::endl;
continue;
}
sh = TransferBRep::ShapeResult(binder);
//DeclareAndCast(TransferBRep_ShapeBinder,shb,binder);
if (!sh.IsNull())
{
//sh = shb->Result();
nbvar++;
if (sh.IsNull()) { sout << " (no Shape recorded)" << std::endl; continue; }
if (tout) sout << "[ " << i << " ]:";
if (num == 0) sout << " pas dans le modele";
else sout << " ent.n0 " << num;
sout << ", item transfert n0 " << index;
if (nbvar == 0)
{
if (argc > 3 && mode > 0) sprintf(nomvar, "%s", arg3);
else if (argc > 2 && mode == 0) sprintf(nomvar, "%s", arg2);
else sprintf(nomvar, "tp_%d", i);
}
else
{
if (argc > 3 && mode > 0) sprintf(nomvar, "%s_%d", arg3, nbvar);
else if (argc > 2 && mode == 0) sprintf(nomvar, "%s_%d", arg2, nbvar);
else sprintf(nomvar, "tp_%d", i);
}
sout << " -> 1 DRAW Shape: " << nomvar << std::endl;
XSControl::Vars(pilot)->SetShape(nomvar, sh);
continue;
}
DeclareAndCast(TransferBRep_ShapeListBinder, slb, binder);
if (!slb.IsNull())
{
Standard_Integer nbs = slb->NbShapes();
if (tout) sout << "[ " << i << " ]:";
if (num == 0) sout << " pas dans le modele";
else sout << " ent.n0 " << num;
sout << ", item transfert n0 " << index;
sout << " -> " << nbs << " DRAW Shapes :";
for (Standard_Integer j = 1; j <= nbs; j++)
{
sh = slb->Shape(j); if (nbvar < 0) nbvar = 0; nbvar++;
if (sh.IsNull()) { sout << " (no Shape recorded)" << std::endl; continue; }
if (argc > 3 && mode > 0) sprintf(nomvar, "%s_%d", arg3, nbvar);
else if (argc > 2 && mode == 0) sprintf(nomvar, "%s_%d", arg2, nbvar);
else sprintf(nomvar, "tp_%d_%d", i, nbvar);
sout << " " << nomvar;
XSControl::Vars(pilot)->SetShape(nomvar, sh);
}
sout << std::endl;
continue;
}
DeclareAndCast(Transfer_SimpleBinderOfTransient, trb, binder);
if (!trb.IsNull())
{
Handle(Standard_Transient) resu = trb->Result();
if (resu.IsNull())
{
sout << "Entite n0 " << num << " : pas de resultat" << std::endl;
continue;
}
DeclareAndCast(Geom_Geometry, geom, resu);
sout << "Entite n0 " << num << " : resultat " << resu->DynamicType()->Name();
if (geom.IsNull()) { sout << std::endl; continue; }
nbvar++;
if (nbvar == 0)
{
if (argc > 3 && mode > 0) sprintf(nomvar, "%s", arg3);
else if (argc > 2 && mode == 0) sprintf(nomvar, "%s", arg2);
else sprintf(nomvar, "tp_%d", i);
}
else
{
if (argc > 3 && mode > 0) sprintf(nomvar, "%s_%d", arg3, nbvar);
else if (argc > 2 && mode == 0) sprintf(nomvar, "%s_%d", arg2, nbvar);
else sprintf(nomvar, "tp_%d", i);
}
char* nomv = nomvar;
XSControl::Vars(pilot)->Set(nomv, geom);
sout << " -> DRAW Geom : " << nomvar << std::endl;
continue;
}
if (sh.IsNull() && trb.IsNull())
if (!tout) sout << "Entite n0 " << num << " : resultat pas une Shape mais " << binder->ResultTypeName() << std::endl;
}
if (sh.IsNull()) sout << " (No Shape)" << std::endl;
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_tpcompound
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_tpcompound
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Handle(Transfer_TransientProcess)& TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout << "No Transfer Read" << std::endl; return IFSelect_RetError; }
// **** tpcompound ****
if (argc < 2) { sout << "Give a NAME for the Compound + optional givelist, else roots are taken" << std::endl; return IFSelect_RetError; }
Handle(TopTools_HSequenceOfShape) list;
if (argc == 2) list = TransferBRep::Shapes(TP);
else
{
Handle(TColStd_HSequenceOfTransient) lise = IFSelect_Functions::GiveList(pilot->Session(), pilot->CommandPart(2));
if (lise.IsNull()) { sout << "Not a valid entity list : " << pilot->CommandPart(2) << std::endl; return IFSelect_RetError; }
list = TransferBRep::Shapes(TP, lise);
sout << lise->Length() << " Entities, ";
}
if (list.IsNull()) { sout << "No Shape listed" << std::endl; return IFSelect_RetError; }
Standard_Integer nb = list->Length();
sout << nb << " Shape(s) listed" << std::endl;
TopoDS_Compound C;
BRep_Builder B;
B.MakeCompound(C);
for (Standard_Integer i = 1; i <= nb; i++) B.Add(C, list->Value(i));
XSControl::Vars(pilot)->SetShape(arg1, C);
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_traccess
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_traccess
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
const Standard_CString arg2 = pilot->Arg(2);
// **** trdraw : TransferReader **** 26
// **** trsave : TransferReader **** 27
// **** trcomp (comp -> DRAW) **** 28
// **** trscomp (comp -> save) **** 29
Standard_Boolean cascomp = (pilot->Word(0).Location(1, 'o', 1, 5) > 0);
Standard_Boolean cassave = (pilot->Word(0).Location(1, 's', 1, 5) > 0);
TCollection_AsciiString nomsh, noms;
const Handle(XSControl_TransferReader)& TR = XSControl::Session(pilot)->TransferReader();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TR.IsNull()) { sout << " manque init" << std::endl; return IFSelect_RetError; }
const Handle(Interface_InterfaceModel)& mdl = TR->Model();
if (mdl.IsNull()) { sout << " modele absent" << std::endl; return IFSelect_RetError; }
Standard_Integer num = (argc > 1 ? IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot), arg1) : 0);
if (argc > 1) nomsh = arg1;
else nomsh = cascomp ? "TREAD_COMP" : "TREAD_LIST";
if (cassave) sout << " save shapes -> current directory" << std::endl;
if (num == 0 || cascomp)
{
TopoDS_Compound C; // pour cas compound
BRep_Builder B;
B.MakeCompound(C);
const Handle(TopTools_HSequenceOfShape)& list = TR->ShapeResultList(Standard_True);
sout << " TOUS RESULTATS par ShapeResultList, soit " << list->Length() << std::endl;
for (Standard_Integer i = 1, nb = list->Length(); i <= nb; ++i)
{
noms = nomsh + "_" + i;
if ((i % 1000) == 0) sout << "(" << i << ")" << std::endl;
else if ((i % 100) == 0) sout << "*";
else if ((i % 10) == 0) sout << "0";
else sout << ".";
if (list->Value(i).IsNull()) continue;
if (!cascomp && !cassave) XSControl::Vars(pilot)->SetShape(noms.ToCString(), list->Value(i));
else if (!cascomp && cassave) BRepTools::Write(list->Value(i), noms.ToCString());
else if (cascomp) B.Add(C, list->Value(i));
}
sout << std::endl;
if (cascomp && !cassave) XSControl::Vars(pilot)->SetShape(nomsh.ToCString(), C);
else if (cascomp && cassave) BRepTools::Write(C, nomsh.ToCString());
}
else
{
if (num < 1 || num > mdl->NbEntities()) { sout << " incorrect:" << arg1 << std::endl; return IFSelect_RetError; }
TopoDS_Shape sh = TR->ShapeResult(mdl->Value(num));
if (sh.IsNull()) { sout << " Pas de resultat pour " << arg1 << std::endl; return IFSelect_RetError; }
if (argc > 2) nomsh = arg2;
else nomsh = TCollection_AsciiString("TREAD_") + num;
if (!cascomp && !cassave) XSControl::Vars(pilot)->SetShape(nomsh.ToCString(), sh);
else if (!cascomp && cassave) BRepTools::Write(sh, nomsh.ToCString());
else sout << "Option non comprise" << std::endl;
}
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_IsEqualSubShape
//purpose :
//=======================================================================
// PTV 23.08.2000 Added for checking where are an entity from.
static Standard_Boolean XSControl_IsEqualSubShape(const TopoDS_Shape& Shape,
TopoDS_Shape& sh, Standard_Integer aLevel)
{
if (sh.IsSame(Shape)) return Standard_True;
if (aLevel > 0)
{
TopoDS_Shape varShape;
aLevel--;
TopoDS_Iterator it(sh);
for (; it.More(); it.Next())
{
varShape = it.Value();
if (XSControl_IsEqualSubShape(Shape, varShape, aLevel)) return Standard_True;
}
}
return Standard_False;
}
//=======================================================================
//function : XSControl_fromshape
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_fromshape
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** fromshape (tread) ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (argc < 2)
{
sout << "Give name of a DRAW Shape" << std::endl;
return IFSelect_RetError;
}
const char* a1 = (char*)arg1;
TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(a1);
if (Shape.IsNull())
{
sout << "Not a DRAW Shape:" << arg1 << std::endl;
return IFSelect_RetError;
}
Standard_Boolean yena = Standard_False;
Standard_Integer aLevel = 1;
if (argc >= 3)
aLevel = atoi(pilot->Arg(2));
Standard_Boolean silent = Standard_False;
if (aLevel < 0)
{
silent = Standard_True;
aLevel = -aLevel;
}
// IMPORT
const Handle(XSControl_TransferReader)& TR = XSControl::Session(pilot)->TransferReader();
if (TR.IsNull()) {} // sout<<"No read transfer (import) recorded"<<std::endl;
else
{
yena = Standard_True;
if (!silent) sout << "Shape " << arg1 << " : ";
Standard_Integer modrec = 1;
Handle(Standard_Transient) ent = TR->EntityFromShapeResult(Shape, modrec);
if (ent.IsNull())
{
modrec = -1;
ent = TR->EntityFromShapeResult(Shape, modrec);
}
if (ent.IsNull())
{
modrec = 2;
Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
if (TP.IsNull())
{
if (silent)
sout << "Shape " << arg1 << " : ";
sout << "no map" << std::endl;
}
else
{
TopoDS_Shape S0 = Shape;
TopLoc_Location L;
S0.Location(L);
Standard_Integer i, nb = TP->NbMapped();
if (!silent) sout << "searching in map among " << nb << " ...";
for (i = 1; i <= nb; i++)
{
ent = TP->Mapped(i);
TopoDS_Shape sh = TransferBRep::ShapeResult(TP, ent);
if (sh.IsNull())
{
ent.Nullify();
continue;
}
if (XSControl_IsEqualSubShape(Shape, sh, aLevel)) break;
modrec = -2;
sh.Location(L);
if (XSControl_IsEqualSubShape(S0, sh, aLevel)) break;
ent.Nullify();
modrec = 2;
}
}
}
if (!ent.IsNull())
{
if (silent) sout << "Shape " << arg1 << ": ";
if (modrec < 0) sout << "(moved from origin) ";
//else sout<<"(origin) ";
}
// on affiche
if (ent.IsNull())
{
if (!silent) sout << " unknown as imported";
// skl 11.05.2004
// if Shape is a compound try to make "fromshape" for its subshapes
if (Shape.ShapeType() == TopAbs_COMPOUND)
{
sout << std::endl << "Subshapes imported from entities:";
TopoDS_Iterator Iter(Shape);
for (; Iter.More(); Iter.Next())
{
TopoDS_Shape subsh = Iter.Value();
Standard_Integer submodrec = 1;
Handle(Standard_Transient) subent = TR->EntityFromShapeResult(subsh, submodrec);
if (subent.IsNull())
{
submodrec = -1;
subent = TR->EntityFromShapeResult(subsh, submodrec);
}
if (!subent.IsNull())
{
sout << " " << XSControl::Session(pilot)->Model()->Number(subent);
}
}
}
}
else
{
sout << "imported from entity ";
XSControl::Session(pilot)->Model()->Print(ent, sout);
if (silent) sout << " in file " << XSControl::Session(pilot)->LoadedFile() << std::endl;
}
if (!silent) sout << std::endl;
}
// ET EN EXPORT ?
const Handle(Transfer_FinderProcess)& FP = XSControl::Session(pilot)->TransferWriter()->FinderProcess();
if (FP.IsNull()) {}
else
{
yena = Standard_True;
Handle(Transfer_Finder) fnd = TransferBRep::ShapeMapper(FP, Shape);
Handle(Standard_Transient) ent;
if (!fnd.IsNull()) ent = FP->FindTransient(fnd);
if (!ent.IsNull())
{
sout << "Shape " << arg1 << ": exported to entity ";
XSControl::Session(pilot)->Model()->Print(ent, sout);
if (silent) sout << " in file " << XSControl::Session(pilot)->LoadedFile();
sout << std::endl;
}
// abv 31.08.00: treat case of split shape (several results)
// it is supposed that results are of the same type and lie in one-level comp
else
{
Handle(Transfer_Binder) bnd = FP->Find(fnd);
if (!bnd.IsNull())
{
Handle(Transfer_TransientListBinder) TransientListBinder =
//Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) ); //skl
Handle(Transfer_TransientListBinder)::DownCast(bnd); //skl
if (!TransientListBinder.IsNull())
{
Standard_Integer i = 1, nb = TransientListBinder->NbTransients();
if (nb > 0) sout << "Shape " << arg1 << ": exported to entities ";
for (; i <= nb; i++)
{
XSControl::Session(pilot)->Model()->Print(TransientListBinder->Transient(i), sout);
if (i < nb) sout << ", ";
}
if (nb > 0)
{
if (silent) sout << " in file " << XSControl::Session(pilot)->LoadedFile();
sout << std::endl;
}
}
/* else {
TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
if ( ! comp.IsNull() && comp.ShapeType() < Shape.ShapeType() ) {
Standard_Boolean start = Standard_True;
for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
Handle(Transfer_Finder) cfnd = TransferBRep::ShapeMapper (FP,it.Value());
if ( cfnd.IsNull() ) continue;
Handle(Standard_Transient) cent = FP->FindTransient (cfnd);
if ( cent.IsNull() ) continue;
if ( start )
sout<<"Shape "<<arg1<<" : exported to entities ";
else sout << ", ";
start = Standard_False;
XSControl::Session(pilot)->Model()->Print(cent,sout);
}
if ( ! start ) sout<<std::endl;
}
} */
}
}
}
if (!yena) sout << "No transfer (either import or export) recorded" << std::endl;
return IFSelect_RetVoid;
}
//=======================================================================
//function : XSControl_trconnexentities
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_trconnexentities
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** connected entities (last transfer) ****
const Handle(XSControl_TransferReader)& TR = XSControl::Session(pilot)->TransferReader();
Handle(Transfer_TransientProcess) TP;
if (!TR.IsNull()) TP = TR->TransientProcess();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (TP.IsNull()) { sout << "no transfer map" << std::endl; return IFSelect_RetVoid; }
if (argc < 2)
{
sout << "Give name of a DRAW Shape + optional shape type v-e-w-f(D)-s" << std::endl;
return IFSelect_RetError;
}
const char* a1 = (const char*)arg1;
TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(a1);
if (Shape.IsNull()) { sout << "Not a DRAW Shape:" << arg1 << std::endl; return IFSelect_RetError; }
sout << "Shape " << arg1 << " : ";
Handle(TColStd_HSequenceOfTransient) list =
XSControl_ConnectedShapes::AdjacentEntities(Shape, TP, TopAbs_FACE);
Standard_Integer i, nb = list->Length();
sout << nb << " Entities produced Connected Shapes :" << std::endl;
const Handle(Interface_InterfaceModel)& model = XSControl::Session(pilot)->Model();
sout << "(";
for (i = 1; i <= nb; i++)
{
if (i > 1) sout << ",";
sout << model->Number(list->Value(i));
}
sout << ")" << std::endl;
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_trimport
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_trimport
(const Handle(IFSelect_SessionPilot)& pilot)
{
// FileName ou . (pour courant) VarName GiveList (obligatoire)
// GiveList : * pour xst-transferrable-roots
Handle(XSControl_WorkSession) WS = XSControl::Session(pilot);
Standard_Integer argc = pilot->NbWords();
Message_Messenger::StreamBuffer sout = Message::SendInfo();
if (argc < 4)
{
sout << "Give : filename or . for current model; varname or . to take fileroot\n GiveList, * for all transferrable roots" << std::endl;
return IFSelect_RetError;
}
const Standard_CString arg1 = pilot->Arg(1);
const Standard_CString arg2 = pilot->Arg(2);
const Standard_CString arg3 = pilot->Arg(3);
// File Name and Variable (root) Name
TCollection_AsciiString fnom, rnom;
Standard_Boolean modfic = XSDRAW_FunctionsShape::FileAndVar
(WS, arg1, arg2, "IMPORT", fnom, rnom);
if (modfic) sout << " File to read : " << fnom << std::endl;
else sout << " Model taken from the session : " << fnom << std::endl;
sout << " -- Names of variables BREP-DRAW prefixed by : " << rnom << std::endl;
// keep the current command, because sub-commands will be called
TCollection_AsciiString compart = pilot->CommandPart(3);
// Reading file if required
if (modfic)
{
TCollection_AsciiString comload("xload ");
comload.AssignCat(arg1);
IFSelect_ReturnStatus status = pilot->Execute(comload);
if (status != IFSelect_RetDone)
{
sout << "Abandon import" << std::endl; return status;
}
}
else
{
sout << "Currently Loaded Model" << std::endl;
}
// Selecting Entities
Handle(TColStd_HSequenceOfTransient) list;
if (arg3[0] == '*' && arg3[1] == '\0')
{
list = WS->GiveList("xst-transferrable-roots");
sout << "All Transferrable Roots : ";
}
else
{
sout << "List given by " << compart.ToCString() << " : ";
list = WS->GiveList(compart.ToCString());
}
if (list.IsNull()) { sout << "No list defined. Abandon" << std::endl; return IFSelect_RetError; }
Standard_Integer nbl = list->Length();
sout << "Nb entities selected : " << nbl << std::endl;
// Starting Transfer
WS->InitTransferReader(0);
const Handle(XSControl_TransferReader)& TR = WS->TransferReader();
if (TR.IsNull()) { sout << " init not done or failed" << std::endl; return IFSelect_RetError; }
TR->BeginTransfer();
// Transferring
Standard_Integer nbt = TR->TransferList(list);
sout << "Nb Entities Selected : " << nbl << " have given " << nbt << " results" << std::endl;
// Filling VARS. one compound (trimpcomp) or one shape per ent (trimport)
Standard_Boolean iscomp = (pilot->Arg(0)[5] == 'c');
Standard_Integer nbs = 0;
TopoDS_Shape sh;
TopoDS_Compound C;
BRep_Builder B;
B.MakeCompound(C);
Handle(Interface_InterfaceModel) mdl = TR->Model();
if (mdl.IsNull()) { sout << " modele absent" << std::endl; return IFSelect_RetError; }
for (Standard_Integer il = 1; il <= nbl; il++)
{
Handle(Standard_Transient) ent = list->Value(il);
sh = TR->ShapeResult(ent);
if (sh.IsNull()) continue;
nbs++;
if (iscomp) B.Add(C, sh);
else
{
char nomsh[50];
sprintf(nomsh, "%s_%d", rnom.ToCString(), nbs);
XSControl::Vars(pilot)->SetShape(nomsh, sh);
}
}
if (nbs == 0) sout << "No Shape produced" << std::endl;
else if (nbs == 1)
{
sout << "One Shape produced, named " << rnom.ToCString() << std::endl;
XSControl::Vars(pilot)->SetShape(rnom.ToCString(), sh);
}
else if (iscomp)
{
sout << "One compound made of " << nbs << " Shapes, named " << rnom.ToCString() << std::endl;
XSControl::Vars(pilot)->SetShape(rnom.ToCString(), C);
}
else
{ // several individual shapes
sout << nbs << " Shapes, named " << rnom.ToCString() << "_1 to " << rnom.ToCString() << "_" << nbs << std::endl;
}
return IFSelect_RetDone;
}
//=======================================================================
//function : XSControl_twrite
//purpose :
//=======================================================================
static IFSelect_ReturnStatus XSControl_twrite
(const Handle(IFSelect_SessionPilot)& pilot)
{
Standard_Integer argc = pilot->NbWords();
const Standard_CString arg1 = pilot->Arg(1);
// **** twrite ****
Message_Messenger::StreamBuffer sout = Message::SendInfo();
Handle(XSControl_TransferWriter) TW = XSControl::Session(pilot)->TransferWriter();
if (argc < 2) { sout << " donner nom de shape draw" << std::endl; return IFSelect_RetError; }
sout << "Attention, on alimente le modele courant ..." << std::endl;
// Shape
for (Standard_Integer i = 1; i < argc; i++)
{
const char* ai = (const char*)pilot->Arg(i);
TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(ai);
if (Shape.IsNull()) { sout << "pas un nom de shape draw:" << arg1 << std::endl; continue; }
sout << "Pour Shape : " << ai;
Standard_Integer stat = TW->TransferWriteShape(XSControl::Session(pilot)->Model(), Shape);
sout << " Transfer Write Status = " << stat << std::endl;
}
pilot->Session()->ComputeGraph();
// Transient ? (Geom) : ignore
return IFSelect_RetDone;
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void XSDRAW_FunctionsShape::Init()
{
static int THE_XSDRAW_FunctionsShape_initactor = 0;
if (THE_XSDRAW_FunctionsShape_initactor)
{
return;
}
THE_XSDRAW_FunctionsShape_initactor = 1;
IFSelect_Act::SetGroup("DE: General");
IFSelect_Act::AddFunc("tpdraw", "[mode:item or root] num|* [nomvar] Passes an ITEM to Shape Draw (Start or Result)", XSControl_tpdraw);
IFSelect_Act::AddFunc("tpcompound", "name:cstring [givelist] : -> compound with Shapes Root or from givelist", XSControl_tpcompound);
IFSelect_Act::AddFunc("trdraw", "results ->DRAW : all; or num [name] : from ent.num -> DRAW [name/tread_num]", XSControl_traccess);
IFSelect_Act::AddFunc("trsave", "results ->files : all; or num [name] : from ent.num -> DRAW [name/tread_num]", XSControl_traccess);
IFSelect_Act::AddFunc("trcomp", "results -> 1 compound -> DRAW + name optional", XSControl_traccess);
IFSelect_Act::AddFunc("trscomp", "results -> 1 compound -> file + name optional", XSControl_traccess);
IFSelect_Act::AddFunc("fromshape", "shape [level=1]: imported/exported entity (when known)", XSControl_fromshape);
IFSelect_Act::AddFunc("trconnexent", "name of draw shape : entities -> connected shapes (when known)", XSControl_trconnexentities);
IFSelect_Act::AddFunc("trimport", "filename or . varname givelist -> 1 shape per entity", XSControl_trimport);
IFSelect_Act::AddFunc("trimpcomp", "filename or . varname givelist -> one xcompound", XSControl_trimport);
IFSelect_Act::AddFunc("twrite", "shape : transfer write for this shape, AFTER newmodel !", XSControl_twrite);
}

View File

@@ -0,0 +1,39 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAW_FunctionsShape_HeaderFile
#define _XSDRAW_FunctionsShape_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
//! Defines additional commands for XSControl to :
//! - control of initialisation (xinit, xnorm, newmodel)
//! - analyse of the result of a transfer (recorded in a
//! TransientProcess for Read, FinderProcess for Write) :
//! statistics, various lists (roots,complete,abnormal), what
//! about one specific entity, producing a model with the
//! abnormal result
//!
//! This appendix of XSControl is compiled separately to distinguish
//! basic features from user callable forms
class XSDRAW_FunctionsShape
{
DEFINE_STANDARD_ALLOC
public:
//! Defines and loads all functions which work on shapes for XSControl (as ActFunc)
Standard_EXPORT static void Init();
};
#endif // _XSDRAW_FunctionsShape_HeaderFile

View File

@@ -1,115 +0,0 @@
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <DBRep.hxx>
#include <DrawTrSurf.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Geometry.hxx>
#include <Geom_Surface.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <Interface_Macros.hxx>
#include <Standard_Transient.hxx>
#include <Standard_Type.hxx>
#include <TopoDS_Shape.hxx>
#include <XSDRAW_Vars.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XSDRAW_Vars,XSControl_Vars)
XSDRAW_Vars::XSDRAW_Vars () { }
void XSDRAW_Vars::Set
(const Standard_CString name,
const Handle(Standard_Transient)& val)
{
//char* nam = name;
// selon type
DeclareAndCast(Geom_Geometry,geom,val);
if (!geom.IsNull()) {
DrawTrSurf::Set(name,geom);
return;
}
DeclareAndCast(Geom2d_Curve,g2d,val);
if (!g2d.IsNull()) {
DrawTrSurf::Set(name,geom);
return;
}
// ??
}
/*
Handle(Standard_Transient) XSDRAW_Vars::Get (const Standard_CString name) const
{
Handle(Standard_Transient) val;
if (!thevars->GetItem (name,val)) val.Nullify();
return val;
}
*/
Handle(Geom_Geometry) XSDRAW_Vars::GetGeom (Standard_CString& name) const
{ //char* nam = name;
return DrawTrSurf::Get(name);
}
Handle(Geom2d_Curve) XSDRAW_Vars::GetCurve2d (Standard_CString& name) const
{ //char* nam = name;
return DrawTrSurf::GetCurve2d(name);
}
Handle(Geom_Curve) XSDRAW_Vars::GetCurve (Standard_CString& name) const
{ //char* nam = name;
return DrawTrSurf::GetCurve(name);
}
Handle(Geom_Surface) XSDRAW_Vars::GetSurface (Standard_CString& name) const
{ //char* nam = name;
return DrawTrSurf::GetSurface(name);
}
void XSDRAW_Vars::SetPoint (const Standard_CString name, const gp_Pnt& val)
{
//char* nam = name;
DrawTrSurf::Set (name, val);
}
Standard_Boolean XSDRAW_Vars::GetPoint (Standard_CString& name, gp_Pnt& pnt) const
{ //char* nam = name;
return DrawTrSurf::GetPoint (name,pnt); }
void XSDRAW_Vars::SetPoint2d (const Standard_CString name, const gp_Pnt2d& val)
{
//char* nam = name;
DrawTrSurf::Set (name, val);
}
Standard_Boolean XSDRAW_Vars::GetPoint2d (Standard_CString& name, gp_Pnt2d& pnt) const
{
//char* nam = name;
return DrawTrSurf::GetPoint2d (name,pnt); }
void XSDRAW_Vars::SetShape (const Standard_CString name, const TopoDS_Shape& val)
{
DBRep::Set (name, val);
}
TopoDS_Shape XSDRAW_Vars::GetShape (Standard_CString& name) const
{
//char* nam = name;
return DBRep::Get (name);
}

View File

@@ -1,91 +0,0 @@
// Created on: 1998-07-22
// Created by: Christian CAILLET
// Copyright (c) 1998-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAW_Vars_HeaderFile
#define _XSDRAW_Vars_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <XSControl_Vars.hxx>
class Standard_Transient;
class Geom_Geometry;
class Geom2d_Curve;
class Geom_Curve;
class Geom_Surface;
class gp_Pnt;
class gp_Pnt2d;
class TopoDS_Shape;
class XSDRAW_Vars;
DEFINE_STANDARD_HANDLE(XSDRAW_Vars, XSControl_Vars)
//! Vars for DRAW session (i.e. DBRep and DrawTrSurf)
class XSDRAW_Vars : public XSControl_Vars
{
public:
Standard_EXPORT XSDRAW_Vars();
Standard_EXPORT virtual void Set (const Standard_CString name, const Handle(Standard_Transient)& val) Standard_OVERRIDE;
Standard_EXPORT virtual Handle(Geom_Geometry) GetGeom (Standard_CString& name) const Standard_OVERRIDE;
Standard_EXPORT virtual Handle(Geom2d_Curve) GetCurve2d (Standard_CString& name) const Standard_OVERRIDE;
Standard_EXPORT virtual Handle(Geom_Curve) GetCurve (Standard_CString& name) const Standard_OVERRIDE;
Standard_EXPORT virtual Handle(Geom_Surface) GetSurface (Standard_CString& name) const Standard_OVERRIDE;
Standard_EXPORT virtual void SetPoint (const Standard_CString name, const gp_Pnt& val) Standard_OVERRIDE;
Standard_EXPORT virtual void SetPoint2d (const Standard_CString name, const gp_Pnt2d& val) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean GetPoint (Standard_CString& name, gp_Pnt& pnt) const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean GetPoint2d (Standard_CString& name, gp_Pnt2d& pnt) const Standard_OVERRIDE;
Standard_EXPORT virtual void SetShape (const Standard_CString name, const TopoDS_Shape& val) Standard_OVERRIDE;
Standard_EXPORT virtual TopoDS_Shape GetShape (Standard_CString& name) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XSDRAW_Vars,XSControl_Vars)
protected:
private:
};
#endif // _XSDRAW_Vars_HeaderFile

2
src/XSDRAWBase/FILES Normal file
View File

@@ -0,0 +1,2 @@
XSDRAWBase.cxx
XSDRAWBase.hxx

View File

@@ -0,0 +1,614 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <DBRep.hxx>
#include <Draw_Appli.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <IFSelect_SessionPilot.hxx>
#include <Interface_Macros.hxx>
#include <Interface_Static.hxx>
#include <Message.hxx>
#include <Message_ProgressScope.hxx>
#include <OSD_OpenFile.hxx>
#include <OSD_Path.hxx>
#include <STEPControl_ActorWrite.hxx>
#include <STEPControl_Controller.hxx>
#include <STEPControl_Reader.hxx>
#include <STEPControl_StepModelType.hxx>
#include <STEPControl_Writer.hxx>
#include <StepData_StepModel.hxx>
#include <StepGeom_Axis2Placement3d.hxx>
#include <StepSelect_Activator.hxx>
#include <STEPSelections_AssemblyExplorer.hxx>
#include <STEPSelections_Counter.hxx>
#include <StepToTopoDS_MakeTransformed.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <TopExp_Explorer.hxx>
#include <Transfer_TransientProcess.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSControl_Controller.hxx>
#include <XSControl_WorkSession.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWSTEP.hxx>
#include <UnitsMethods.hxx>
#include <stdio.h>
// Pour le transfert (write)
// Pour NewModel et Write : definition de produit (temporaire ...)
// steptrans
extern "C" {
static void cleanpilot ()
{
XSDRAW::Session()->ClearData(1);
}
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void XSDRAWSTEP::Init ()
{
Handle(StepSelect_Activator) stepact = new StepSelect_Activator;
if (STEPControl_Controller::Init()) // XSDRAW::SetNorm("STEP AP-214"); trop tot
XSDRAW::SetController(XSControl_Controller::Recorded("STEP"));
atexit (cleanpilot);
}
// ######## COMMANDE stepread : teste le Reader #########
//=======================================================================
//function : stepread
//purpose :
//=======================================================================
static Standard_Integer stepread (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc < 3) {
di << "Use: stepread [file] [f or r (type of model full or reduced)]\n";
return 1;
}
// On admet le controller AP214 ou une variante
DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller());
if (ctl.IsNull()) XSDRAW::SetNorm("STEP");
// Progress indicator
Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 );
Message_ProgressScope aPSRoot (progress->Start(), "Reading", 100);
STEPControl_Reader sr (XSDRAW::Session(),Standard_False);
TCollection_AsciiString fnom,rnom;
Standard_Boolean modfic = XSDRAW::FileAndVar
(argv[1],argv[2],"STEP",fnom,rnom);
if (modfic) di<<" File STEP to read : "<<fnom.ToCString()<<"\n";
else di<<" Model taken from the session : "<<fnom.ToCString()<<"\n";
di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom.ToCString()<<"\n";
IFSelect_ReturnStatus readstat = IFSelect_RetVoid;
aPSRoot.SetName("Loading");
progress->Show(aPSRoot);
Standard_Boolean fromtcl = Standard_False;
Standard_Boolean aFullMode = Standard_False;
Standard_Integer k = 3;
if(argc > k )
{
if(argv[k][0] == 'f' || argv[3][0] == 'F')
{
aFullMode = Standard_True;
k++;
}
else if(argv[k][0] == 'r' || argv[3][0] == 'R')
{
aFullMode = Standard_False;
k++;
}
else
fromtcl = Standard_True;
}
if(!fromtcl)
fromtcl = argc > k;
if(aFullMode)
std::cout<<"Full model for translation with additional info will be used \n"<<std::flush;
else
std::cout<<"Reduced model for translation without additional info will be used \n"<<std::flush;
sr.WS()->SetModeStat(aFullMode);
if (modfic) readstat = sr.ReadFile (fnom.ToCString());
else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone;
aPSRoot.Next(20); // On average loading takes 20%
if (aPSRoot.UserBreak())
return 1;
if (readstat != IFSelect_RetDone) {
if (modfic) di<<"Could not read file "<<fnom.ToCString()<<" , abandon\n";
else di<<"No model loaded\n";
return 1;
}
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
sr.SetSystemLengthUnit(UnitsMethods::GetCasCadeLengthUnit());
// nom = "." -> fichier deja lu
Standard_Integer i, num, nbs, modepri = 1;
if (fromtcl) modepri = 4;
while (modepri) {
num = sr.NbRootsForTransfer();
if (!fromtcl) {
di<<"NbRootsForTransfer="<<num<<" :\n";
for (i = 1; i <= num; i ++) {
di<<"Root."<<i<<", Ent. ";
Standard_SStream aTmpStream;
sr.Model()->Print (sr.RootForTransfer(i), aTmpStream);
di << aTmpStream.str().c_str();
di<<" Type:"<<sr.RootForTransfer(i)->DynamicType()->Name()<<"\n";
}
std::cout<<"Mode (0 End, 1 root n0 1, 2 one root/n0, 3 one entity/n0, 4 Selection) : "<<std::flush;
std::cin>>modepri;
}
if (modepri == 0) { di<<"End Reading STEP\n"; return 0; }
if (modepri <= 2) {
num = 1;
if (modepri == 2) {
std::cout<<"Root N0 : "<<std::flush; std::cin>>num;
}
aPSRoot.SetName("Translation");
progress->Show(aPSRoot);
if (!sr.TransferRoot (num, aPSRoot.Next(80)))
di<<"Transfer root n0 "<<num<<" : no result\n";
else {
nbs = sr.NbShapes();
char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),nbs);
di<<"Transfer root n0 "<<num<<" OK -> DRAW Shape: "<<shname<<"\n";
di<<"Now, "<<nbs<<" Shapes produced\n";
TopoDS_Shape sh = sr.Shape(nbs);
DBRep::Set (shname,sh);
}
if (aPSRoot.UserBreak())
return 1;
}
else if (modepri == 3) {
std::cout<<"Entity : "<<std::flush; num = XSDRAW::GetEntityNumber();
if (!sr.TransferOne (num))
di<<"Transfer entity n0 "<<num<<" : no result\n";
else {
nbs = sr.NbShapes();
char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),num);
di<<"Transfer entity n0 "<<num<<" OK -> DRAW Shape: "<<shname<<"\n";
di<<"Now, "<<nbs<<" Shapes produced\n";
TopoDS_Shape sh = sr.Shape(nbs);
DBRep::Set (shname,sh);
}
}
else if (modepri == 4) {
// char snm[100]; Standard_Integer answer = 1;
Handle(TColStd_HSequenceOfTransient) list;
// Selection, nommee ou via tcl. tcl : raccourcis admis
// * donne xst-transferrable-roots
if (fromtcl) {
modepri = 0; // d ioffice une seule passe
if (argv[k][0] == '*' && argv[k][1] == '\0') {
di<<"Transferrable Roots : ";
list = XSDRAW::GetList("xst-transferrable-roots");
//list = new TColStd_HSequenceOfTransient;
//for(Standard_Integer j=1; j<=num; j++)
// list->Append(sr.RootForTransfer(j));
}
else {
di<<"List given by "<<argv[k];
if (argc > k+1) di<<" "<<argv[k+1];
di<<" : ";
list = XSDRAW::GetList (argv[k], ( argc > (k+1) ? argv[k+1] : 0 ) );
}
if (list.IsNull()) { di<<"No list defined. Give a selection name or * for all transferrable roots\n"; continue; }
} else {
std::cout<<"Name of Selection :"<<std::flush;
list = XSDRAW::GetList();
if (list.IsNull()) { di<<"No list defined\n"; continue; }
}
Standard_Integer ill, nbl = list->Length();
di<<"Nb entities selected : "<<nbl<<"\n";
if (nbl == 0) continue;
aPSRoot.SetName("Translation");
progress->Show(aPSRoot);
Message_ProgressScope aPS(aPSRoot.Next(80), "Root", nbl);
for (ill = 1; ill <= nbl && aPS.More(); ill++) {
num = sr.Model()->Number(list->Value(ill));
if (num == 0) continue;
if (!sr.TransferOne(num, aPS.Next()))
di<<"Transfer entity n0 "<<num<<" : no result\n";
else {
nbs = sr.NbShapes();
char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),nbs);
di<<"Transfer entity n0 "<<num<<" OK -> DRAW Shape: "<<shname<<"\n";
di<<"Now, "<<nbs<<" Shapes produced\n";
TopoDS_Shape sh = sr.Shape(nbs);
DBRep::Set (shname,sh);
}
}
if (aPSRoot.UserBreak())
return 1;
}
else di<<"Unknown mode n0 "<<modepri<<"\n";
}
return 0;
}
//=======================================================================
//function : testreadstep
//purpose :
//=======================================================================
static Standard_Integer testreadstep (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc < 3 || argc > 4)
{
di << "ERROR in " << argv[0] << "Wrong Number of Arguments.\n";
di << " Usage : " << argv[0] << " file_name shape_name [-stream]\n";
di << " Option -stream forces usage of API accepting stream\n";
return 1;
}
Standard_Boolean useStream = (argc > 3 && ! strcasecmp (argv[3], "-stream"));
STEPControl_Reader Reader;
Standard_CString filename = argv[1];
IFSelect_ReturnStatus readstat;
if (useStream)
{
std::ifstream aStream;
OSD_OpenStream (aStream, filename, std::ios::in | std::ios::binary);
TCollection_AsciiString aFolder, aFileNameShort;
OSD_Path::FolderAndFileFromPath (filename, aFolder, aFileNameShort);
readstat = Reader.ReadStream (aFileNameShort.ToCString(), aStream);
}
else
{
readstat = Reader.ReadFile(filename);
}
di<<"Status from reading STEP file "<<filename<<" : ";
switch(readstat) {
case IFSelect_RetVoid : { di<<"empty file\n"; return 1; }
case IFSelect_RetDone : { di<<"file read\n"; break; }
case IFSelect_RetError : { di<<"file not found\n"; return 1; }
case IFSelect_RetFail : { di<<"error during read\n"; return 1; }
default : { di<<"failure\n"; return 1; }
}
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
Reader.SetSystemLengthUnit(UnitsMethods::GetCasCadeLengthUnit());
Reader.TransferRoots();
TopoDS_Shape shape = Reader.OneShape();
DBRep::Set(argv[2],shape);
di<<"Count of shapes produced : "<<Reader.NbShapes()<<"\n";
return 0;
}
// ######## COMMANDE steptrans : teste les transformations #########
//=======================================================================
//function : steptrans
//purpose :
//=======================================================================
static Standard_Integer steptrans (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc < 5) { di<<"give shape-name new-shape + entity-n0 entity-n0: AXIS2\n";
return 1; }
TopoDS_Shape shape = DBRep::Get(argv[1]);
if (shape.IsNull()) { di<<"Not a shape : "<<argv[1]<<"\n"; return 1; }
Handle(StepGeom_Axis2Placement3d) ax1,ax2;
Standard_Integer n1 = 0, n2 = 0;
n1 = XSDRAW::GetEntityNumber(argv[3]);
if (argc > 4) n2 = XSDRAW::GetEntityNumber(argv[4]);
if (n1 > 0) ax1 = Handle(StepGeom_Axis2Placement3d)::DownCast
(XSDRAW::Entity(n1));
if (n2 > 0) ax2 = Handle(StepGeom_Axis2Placement3d)::DownCast
(XSDRAW::Entity(n2));
StepToTopoDS_MakeTransformed mktrans;
if (mktrans.Compute (ax1,ax2)) {
TopLoc_Location loc (mktrans.Transformation());
shape.Move (loc);
// mktrans.Transform (shape);
DBRep::Set (argv[2],shape);
di<<"Transformed Shape as "<<argv[2]<<"\n";
}
else di<<"No transformation computed\n";
return 0;
}
// ######## COMMANDE stepwrite : teste le Writer #########
//=======================================================================
//function : stepwrite
//purpose :
//=======================================================================
static Standard_Integer stepwrite (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
// On admet le controller AP214 ou une variante
DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller());
if (ctl.IsNull()) {
XSDRAW::SetNorm("STEP");
//sln 14.01.2002 OCC51: assign new value to ctl in order to avoid exception during using one in the function
ctl = Handle(STEPControl_Controller)::DownCast(XSDRAW::Controller());
}
if (argc < 3) {
di<<"Give mode[1-4] and Shape name + optional file. Mode possible\n";
di<<"f ou 1 : FacettedBRep s ou 2 : ShellBasedSurfaceModel\n"
<<"m ou 3 : ManifoldSolidBrep w ou 4 : GeometricCurveSet/WireFrame\n";
return 1; }
char modeshape = argv[1][0];
STEPControl_StepModelType mode;
switch (modeshape) {
case 'a' :
case '0' : mode = STEPControl_AsIs; break;
case 'f' :
case '1' : mode = STEPControl_FacetedBrep; break;
case 's' :
case '2' : mode = STEPControl_ShellBasedSurfaceModel; break;
case 'm' :
case '3' : mode = STEPControl_ManifoldSolidBrep; break;
case 'w' :
case '4' : mode = STEPControl_GeometricCurveSet; break;
default : di<<"1st arg = mode, incorrect [give fsmw]\n"; return 1;
}
//:k8 abv 6 Jan 98: using parameter for writing mode (assemblies/shapes)
Handle(STEPControl_ActorWrite) ActWrite =
Handle(STEPControl_ActorWrite)::DownCast ( ctl->ActorWrite() );
if ( ! ActWrite.IsNull() )
ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
TopoDS_Shape shape = DBRep::Get(argv[2]);
STEPControl_Writer sw (XSDRAW::Session(),Standard_False);
Handle(Interface_InterfaceModel) stepmodel = sw.Model();
Standard_Integer nbavant = (stepmodel.IsNull() ? 0 : stepmodel->NbEntities());
Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 );
Message_ProgressScope aPSRoot (progress->Start(), "Translating", 100);
progress->Show(aPSRoot);
Standard_Integer stat = sw.Transfer (shape, mode, Standard_True, aPSRoot.Next(90));
if (stat == IFSelect_RetDone)
{
di << "Translation: OK\n";
}
else
{
di << "Error: translation failed, status = " << stat << "\n";
}
if (aPSRoot.UserBreak())
return 1;
aPSRoot.SetName("Writing");
progress->Show(aPSRoot);
// Que s est-il passe
stepmodel = sw.Model();
Standard_Integer nbapres = (stepmodel.IsNull() ? 0 : stepmodel->NbEntities());
if (nbavant > 0) di<<"Beware : Model not empty before transferring\n";
if (nbapres <= nbavant) di<<"Beware : No data produced by this transfer\n";
if (nbapres == 0) { di<<"No data to write\n"; return 0; }
if (argc <= 3) {
di<<" Now, to write a file, command : writeall filename\n";
return 0;
}
const char *nomfic = argv[3];
stat = sw.Write(nomfic);
switch (stat) {
case IFSelect_RetVoid : di<<"Error: No file written\n"; break;
case IFSelect_RetDone : di<<"File "<<nomfic<<" written\n"; break;
case IFSelect_RetStop : di<<"Error on writing file: no space on disk or destination is write protected\n"; break;
default : di<<"Error: File "<<nomfic<<" written with fail messages\n"; break;
}
return 0;
}
//=======================================================================
//function : testwritestep
//purpose :
//=======================================================================
static Standard_Integer testwrite (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
TCollection_AsciiString aFilePath;
TopoDS_Shape aShape;
bool toTestStream = false;
for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
{
TCollection_AsciiString anArgCase (argv[anArgIter]);
anArgCase.LowerCase();
if (anArgCase == "-stream")
{
toTestStream = true;
}
else if (aFilePath.IsEmpty())
{
aFilePath = argv[anArgIter];
}
else if (aShape.IsNull())
{
aShape = DBRep::Get (argv[anArgIter]);
if (aShape.IsNull())
{
di << "Syntax error: '" << argv[anArgIter] << "' is not a shape";
return 1;
}
}
else
{
di << "Syntax error: unknown argument '" << argv[anArgIter] << "'";
return 1;
}
}
if (aShape.IsNull())
{
di << "Syntax error: wrong number of arguments";
return 1;
}
STEPControl_Writer aWriter;
IFSelect_ReturnStatus aStat = aWriter.Transfer (aShape, STEPControl_AsIs);
if (aStat != IFSelect_RetDone)
{
di << "Error on transferring shape";
return 1;
}
if (toTestStream)
{
std::ofstream aStream;
OSD_OpenStream (aStream, aFilePath, std::ios::out | std::ios::binary);
aStat = aWriter.WriteStream (aStream);
aStream.close();
if (!aStream.good()
&& aStat == IFSelect_RetDone)
{
aStat = IFSelect_RetFail;
}
}
else
{
aStat = aWriter.Write (aFilePath.ToCString());
}
if (aStat != IFSelect_RetDone)
{
di << "Error on writing file";
return 1;
}
di << "File Is Written";
return 0;
}
//=======================================================================
//function : countexpected
//purpose :
//=======================================================================
static Standard_Integer countexpected
(Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
{
Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot();
Handle(IFSelect_WorkSession) WS = pilot->Session();
const Interface_Graph& graph = WS->Graph();
Handle(TColStd_HSequenceOfTransient) roots = WS->GiveList("xst-transferrable-roots", "");
STEPSelections_Counter cnt;
for (Standard_Integer i =1 ; i <= roots->Length(); i++) {
cnt.Count(graph,roots->Value(i));
}
di<< "Instances of Faces \t: "<<cnt.NbInstancesOfFaces()<<"\n";
di<< "Instances of Shells\t: "<<cnt.NbInstancesOfShells()<<"\n";
di<< "Instances of Solids\t: "<<cnt.NbInstancesOfSolids()<<"\n";
di<< "Instances of Wires in GS\t: "<<cnt.NbInstancesOfWires()<<"\n";
di<< "Instances of Edges in GS\t: "<<cnt.NbInstancesOfEdges()<<"\n";
di<< "Source Faces \t: "<<cnt.NbSourceFaces()<<"\n";
di<< "Source Shells\t: "<<cnt.NbSourceShells()<<"\n";
di<< "Source Solids\t: "<<cnt.NbSourceSolids()<<"\n";
di<< "Source Wires in GS\t: "<<cnt.NbSourceWires()<<"\n";
di<< "Source Edges in GS\t: "<<cnt.NbSourceEdges()<<"\n";
return 1;
}
static Standard_Integer dumpassembly
(Draw_Interpretor& /*di*/, Standard_Integer /*argc*/, const char** /*argv*/)
{
Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot();
Handle(IFSelect_WorkSession) WS = pilot->Session();
const Interface_Graph& graph = WS->Graph();
STEPSelections_AssemblyExplorer exp(graph);
exp.Dump(std::cout);
return 0;
}
static Standard_Integer stepfileunits (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if( argc < 2)
{
di << "Error: Invalid number of parameters. Should be: getfileunits name_file\n";
return 1;
}
STEPControl_Reader aStepReader;
IFSelect_ReturnStatus readstat = IFSelect_RetVoid;
readstat = aStepReader.ReadFile (argv[1]);
if (readstat != IFSelect_RetDone) {
di<<"No model loaded\n";
return 1;
}
TColStd_SequenceOfAsciiString anUnitLengthNames;
TColStd_SequenceOfAsciiString anUnitAngleNames;
TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
aStepReader.FileUnits( anUnitLengthNames,anUnitAngleNames,anUnitSolidAngleNames);
Standard_Integer i =1;
di<<"=====================================================\n";
di<<"LENGTH Unit\n";
for( ; i <= anUnitLengthNames.Length() ; i++)
di<<anUnitLengthNames(i).ToCString()<<"\n";
di<<"=====================================================\n";
di<<"Angle Unit\n";
for( i =1 ; i <= anUnitAngleNames.Length() ; i++)
di<<anUnitAngleNames(i).ToCString()<<"\n";
di<<"=====================================================\n";
di<<"Solid Angle Unit\n";
for( i =1 ; i <= anUnitSolidAngleNames.Length() ; i++)
di<<anUnitSolidAngleNames(i).ToCString()<<"\n";
return 0;
}
// ######## COMMANDE stepwrite : teste le Writer #########
void XSDRAWSTEP::InitCommands (Draw_Interpretor& theCommands)
{
const char* g = "DE: STEP"; // Step transfer file commands
XSDRAWSTEP::Init();
XSDRAW::LoadDraw(theCommands);
theCommands.Add("stepwrite" , "stepwrite mode[0-4 afsmw] shape", __FILE__, stepwrite, g);
theCommands.Add("testwritestep", "testwritestep filename.stp shape [-stream]",
__FILE__, testwrite, g);
theCommands.Add("stepread", "stepread [file] [f or r (type of model full or reduced)]",__FILE__, stepread, g);
theCommands.Add("testreadstep", "testreadstep file shape [-stream]",__FILE__, testreadstep, g);
theCommands.Add("steptrans", "steptrans shape stepax1 stepax2", __FILE__, steptrans, g);
theCommands.Add("countexpected","TEST", __FILE__, countexpected, g);
theCommands.Add("dumpassembly", "TEST", __FILE__, dumpassembly, g);
theCommands.Add("stepfileunits" , "stepfileunits name_file", __FILE__, stepfileunits, g);
}

View File

@@ -0,0 +1,205 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAWBase_HeaderFile
#define _XSDRAWBase_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Draw_Interpretor.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <TopTools_HSequenceOfShape.hxx>
class IFSelect_SessionPilot;
class XSControl_WorkSession;
class XSControl_Controller;
class Interface_Protocol;
class Interface_InterfaceModel;
class Standard_Transient;
class Transfer_TransientProcess;
class Transfer_FinderProcess;
class XSControl_TransferReader;
class TCollection_AsciiString;
//! Basic package to work functions of X-STEP (IFSelect & Co)
//! under control of DRAW
//!
//! Works with some "static" data : a SessionPilot (used to run)
//! with its WorkSession and Model and TransferReader, a
//! FinderProcess
class XSDRAWBase
{
DEFINE_STANDARD_ALLOC
public:
//! Takes variables to/from the DRAW session
//! Implements ProgressIndicator for DRAW
//! Changes the name under which a command of xstep is known by
//! Draw. This allows to avoid collisions
//! To be called before LoadDraw or any other xstep initialisation
Standard_EXPORT static void ChangeCommand(const Standard_CString oldname, const Standard_CString newname);
//! Removes a command from the interpretation list of Draw
//! To be called before LoadDraw or any other xstep initialisation
Standard_EXPORT static void RemoveCommand(const Standard_CString oldname);
//! Defines the basic context to work with a X-STEP Session :
//! it performs the basic inits, also records the Controller
//! If the Controller is not yet set, it must be set after
//! (call to SetController)
//! LoadSession is called by LoadDraw
//! Returns True the first time, False if already called
Standard_EXPORT static Standard_Boolean LoadSession();
//! Defines the context for using a X-STEP Session under DRAW
//! Once the various INITs have been done, a call to LoadDraw
//! records the defined commands for the X-STEP SessionPilot,
//! into the DRAW interpretation list.
//! "Set" commands are accessed under command xset
//! SDS>xset name command ...
//! Other commands can be accessed directly or under command xstep
//! SDS>command ... and SDS>xstep command ... are equivalent
//!
//! Only the command xinit is accessed directly only :
//! SDS>xinit (from the already defined Controller)
//! SDS>xinit iges (first defines the Controller as for "iges")
//!
//! It also records the function to be called by DRAW (not
//! declared because specific).
//! And it defines the context variables, i.e. a WorkSession, then
//! it calls SetController with the currently defined Controller
//! Remark : at least, the standard commands are recorded
//!
//! See also Controller : it is part of the Context, but it must
//! be precised separately
Standard_EXPORT static void LoadDraw(Draw_Interpretor& theCommands);
//! Allows to execute a xstep-draw command from C++ program
//! Fixed form : Execute("command args...");
//! Form with a variable text part : add %s for the variable :
//! Execute ("command args %s args..",var) [var is a CString]
//! Returns the same value as returned by call from DRAW
Standard_EXPORT static Standard_Integer Execute(const Standard_CString command, const Standard_CString var = "");
//! Returns the SessionPilot (can be used for direct call)
Standard_EXPORT static Handle(IFSelect_SessionPilot) Pilot();
//! Returns the WorkSession defined in AddDraw (through Pilot)
//! It is from XSControl, it brings functionalities for Transfers
Standard_EXPORT static Handle(XSControl_WorkSession) Session();
//! Defines a Controller for the command "xinit" and applies it
//! (i.e. calls its method Customise)
Standard_EXPORT static void SetController(const Handle(XSControl_Controller)& control);
//! Returns the Controller, a Null Handle if not yet defined
Standard_EXPORT static Handle(XSControl_Controller) Controller();
//! Sets a norm by its name (controller recorded as <normname> )
//! Returns True if done, False if this norm is unknown
Standard_EXPORT static Standard_Boolean SetNorm(const Standard_CString normname);
//! Returns the actually defined Protocol
Standard_EXPORT static Handle(Interface_Protocol) Protocol();
//! Returns the Model of the Session (it is Session()->Model() )
Standard_EXPORT static Handle(Interface_InterfaceModel) Model();
//! Sets a Model in session (it is Session()->SetModel(model) )
//! If <file> is defined, SetLoadedFile is also done
Standard_EXPORT static void SetModel(const Handle(Interface_InterfaceModel)& model, const Standard_CString file = "");
//! Produces a new model (from the Controller), can be Null
//! Does not set it in the session
Standard_EXPORT static Handle(Interface_InterfaceModel) NewModel();
//! Returns the entity n0 <num> of the Model of the Session
//! (it is StartingEntity)
//! Null Handle if <num> is not suitable
Standard_EXPORT static Handle(Standard_Transient) Entity(const Standard_Integer num);
//! Returns the number of an entity in the Model (StartingNumber)
//! 0 if <ent> unknown in the model, or null
Standard_EXPORT static Standard_Integer Number(const Handle(Standard_Transient)& ent);
//! Sets a TransferProcess in order to analyse it (see Activator)
//! It can be either a FinderProcess or a TransientProcess, in
//! that case a new TransferReader is created on it
Standard_EXPORT static void SetTransferProcess(const Handle(Standard_Transient)& TP);
//! Returns the TransferProcess : TransientProcess detained by
//! the TransferReader
Standard_EXPORT static Handle(Transfer_TransientProcess) TransientProcess();
//! Returns the FinderProcess, detained by the TransferWriter
Standard_EXPORT static Handle(Transfer_FinderProcess) FinderProcess();
//! Initialises a TransferReader, according to mode :
//! 0 nullifies it, 1 clears it (not nullify)
//! 2 sets it with TransientProcess & Model
//! 3 idem plus roots of TransientProcess
//! Remark : called with 0 at least at each SetModel/NewModel
Standard_EXPORT static void InitTransferReader(const Standard_Integer mode);
//! Returns the current TransferReader, can be null
//! It detains the TransientProcess
Standard_EXPORT static Handle(XSControl_TransferReader) TransferReader();
//! Takes the name of an entity, either as argument, or (if <name>
//! is empty) on keyboard, and returns the entity
//! name can be a label or a number (in alphanumeric), it is
//! searched by NumberFromLabel from WorkSession.
//! If <name> doesn't match en entity, a Null Handle is returned
Standard_EXPORT static Handle(Standard_Transient) GetEntity(const Standard_CString name = "");
//! Same as GetEntity, but returns the number in the model of the
//! entity. Returns 0 for null handle
Standard_EXPORT static Standard_Integer GetEntityNumber(const Standard_CString name = "");
//! Evaluates and returns a list of entity, from :
//! keyboard if <first> and <second> are empty, see below
//! first if second is empty : can be a number/label of an entity
//! or the name of a selection to be evaluated (standard)
//! first : name of a selection, evaluated from a list defined by
//! second
//! In case of failure, returns a Null Handle
Standard_EXPORT static Handle(TColStd_HSequenceOfTransient) GetList(const Standard_CString first = "", const Standard_CString second = "");
//! Analyses given file name and variable name, with a default
//! name for variables. Returns resulting file name and variable
//! name plus status "file to read"(True) or "already read"(False)
//! In the latter case, empty resfile means no file available
//!
//! If <file> is null or empty or equates ".", considers Session
//! and returned status is False
//! Else, returns resfile = file and status is True
//! If <var> is neither null nor empty, resvar = var
//! Else, the root part of <resfile> is considered, if defined
//! Else, <def> is taken
Standard_EXPORT static Standard_Boolean FileAndVar(const Standard_CString file, const Standard_CString var, const Standard_CString def, TCollection_AsciiString& resfile, TCollection_AsciiString& resvar);
//! Analyses a name as designating Shapes from DRAW variables or
//! XSTEP transfer (last Transfer on Reading). <name> can be :
//! "*" : all the root shapes produced by last Transfer (Read)
//! i.e. considers roots of the TransientProcess
//! a name : a name of a variable DRAW
//!
//! Returns the count of designated Shapes. Their list is put in
//! <list>. If <list> is null, it is firstly created. Then it is
//! completed (Append without Clear) by the Shapes found
//! Returns 0 if no Shape could be found
Standard_EXPORT static Standard_Integer MoreShapes(Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name);
};
#endif // _XSDRAWBase_HeaderFile

View File

@@ -0,0 +1,2 @@
XSDRAWDEWrapper.cxx
XSDRAWDEWrapper.hxx

View File

@@ -0,0 +1,433 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <DBRep.hxx>
#include <Draw_Appli.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <IFSelect_SessionPilot.hxx>
#include <Interface_Macros.hxx>
#include <Interface_Static.hxx>
#include <Message.hxx>
#include <Message_ProgressScope.hxx>
#include <OSD_OpenFile.hxx>
#include <OSD_Path.hxx>
#include <STEPControl_ActorWrite.hxx>
#include <STEPControl_Controller.hxx>
#include <STEPControl_Reader.hxx>
#include <STEPControl_StepModelType.hxx>
#include <STEPControl_Writer.hxx>
#include <StepData_StepModel.hxx>
#include <StepGeom_Axis2Placement3d.hxx>
#include <StepSelect_Activator.hxx>
#include <STEPSelections_AssemblyExplorer.hxx>
#include <STEPSelections_Counter.hxx>
#include <StepToTopoDS_MakeTransformed.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <TopExp_Explorer.hxx>
#include <Transfer_TransientProcess.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSControl_Controller.hxx>
#include <XSControl_WorkSession.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWDEWrapper.hxx>
#include <UnitsMethods.hxx>
#include <stdio.h>
//=======================================================================
//function : DumpConfiguration
//purpose :
//=======================================================================
static Standard_Integer DumpConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper();
TCollection_AsciiString aPath;
Standard_Boolean aIsRecursive = Standard_True;
Standard_Boolean isHandleFormat = Standard_False;
Standard_Boolean isHandleVendors = Standard_False;
TColStd_ListOfAsciiString aFormats;
TColStd_ListOfAsciiString aVendors;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArg(theArgVec[anArgIter]);
anArg.LowerCase();
if ((anArg == "-path") &&
(anArgIter + 1 < theNbArgs))
{
++anArgIter;
aPath = theArgVec[anArgIter];
}
else if ((anArg == "-recursive") &&
(anArgIter + 1 < theNbArgs) &&
Draw::ParseOnOff(theArgVec[anArgIter + 1], aIsRecursive))
{
++anArgIter;
}
else if (anArg == "-format")
{
isHandleFormat = Standard_True;
isHandleVendors = Standard_False;
}
else if (anArg == "-vendor")
{
isHandleFormat = Standard_False;
isHandleVendors = Standard_True;
}
else if (isHandleFormat)
{
aFormats.Append(theArgVec[anArgIter]);
}
else if (isHandleVendors)
{
aVendors.Append(theArgVec[anArgIter]);
}
else if (!isHandleFormat && !isHandleVendors)
{
theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
Standard_Boolean aStat = Standard_True;
if (!aPath.IsEmpty())
{
aStat = aConf->Save(aPath, aIsRecursive, aFormats, aVendors);
}
else
{
theDI << aConf->Save(aIsRecursive, aFormats, aVendors) << "\n";
}
if (!aStat)
{
return 1;
}
return 0;
}
//=======================================================================
//function : CompareConfiguration
//purpose :
//=======================================================================
static Standard_Integer CompareConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs > 5)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
Handle(DE_ConfigurationContext) aResourceFirst = new DE_ConfigurationContext();
if (!aResourceFirst->Load(theArgVec[1]))
{
theDI << "Error: Can't load first configuration\n";
return 1;
}
Handle(DE_ConfigurationContext) aResourceSecond = new DE_ConfigurationContext();
if (!aResourceSecond->Load(theArgVec[2]))
{
theDI << "Error: Can't load second configuration\n";
return 1;
}
const DE_ResourceMap& aResourceMapFirst = aResourceFirst->GetInternalMap();
const DE_ResourceMap& aResourceMapSecond = aResourceSecond->GetInternalMap();
Standard_Integer anDiffers = 0;
for (DE_ResourceMap::Iterator anOrigIt(aResourceMapFirst);
anOrigIt.More(); anOrigIt.Next())
{
const TCollection_AsciiString& anOrigValue = anOrigIt.Value();
const TCollection_AsciiString& anOrigKey = anOrigIt.Key();
TCollection_AsciiString aCompValue;
if (!aResourceMapSecond.Find(anOrigKey, aCompValue))
{
Message::SendWarning() << "Second configuration don't have the next scope : " << anOrigKey;
anDiffers++;
}
if (!aCompValue.IsEqual(anOrigValue))
{
Message::SendWarning() << "Configurations have differs value with the next scope :" << anOrigKey
<< " First value : " << anOrigValue << " Second value : " << aCompValue;
anDiffers++;
}
}
TCollection_AsciiString aMessage;
if (aResourceMapFirst.Extent() != aResourceMapSecond.Extent() || anDiffers > 0)
{
theDI << "Error: Configurations are not same : " << " Differs count : "
<< anDiffers << " Count of first's scopes : " << aResourceMapFirst.Extent()
<< " Count of second's scopes : " << aResourceMapSecond.Extent() << "\n";
return 1;
}
return 0;
}
//=======================================================================
//function : LoadConfiguration
//purpose :
//=======================================================================
static Standard_Integer LoadConfiguration(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs > 4)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper();
TCollection_AsciiString aString = theArgVec[1];
Standard_Boolean aIsRecursive = Standard_True;
if (theNbArgs == 4)
{
TCollection_AsciiString anArg = theArgVec[2];
anArg.LowerCase();
if (!(anArg == "-recursive") ||
!Draw::ParseOnOff(theArgVec[3], aIsRecursive))
{
theDI << "Syntax error at argument '" << theArgVec[3] << "'\n";
return 1;
}
}
if (!aConf->Load(aString, aIsRecursive))
{
theDI << "Error: configuration is incorrect\n";
return 1;
}
return 0;
}
//=======================================================================
//function : ReadFile
//purpose :
//=======================================================================
static Standard_Integer ReadFile(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs > 6)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
TCollection_AsciiString aDocShapeName;
TCollection_AsciiString aFilePath;
Handle(TDocStd_Document) aDoc;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
TCollection_AsciiString aConfString;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readfile");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArg(theArgVec[anArgIter]);
anArg.LowerCase();
if ((anArg == "-conf") &&
(anArgIter + 1 < theNbArgs))
{
++anArgIter;
aConfString = theArgVec[anArgIter];
}
else if (aDocShapeName.IsEmpty())
{
aDocShapeName = theArgVec[anArgIter];
Standard_CString aNameVar = aDocShapeName.ToCString();
if (!isNoDoc)
{
DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
}
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aDocShapeName.IsEmpty() || aFilePath.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
if (aDoc.IsNull() && !isNoDoc)
{
anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
TDataStd_Name::Set(aDoc->GetData()->Root(), theArgVec[1]);
Draw::Set(theArgVec[1], aDrawDoc);
}
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy();
Standard_Boolean aStat = Standard_True;
if (!aConfString.IsEmpty())
{
aStat = aConf->Load(aConfString);
}
if (aStat)
{
TopoDS_Shape aShape;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
aStat = isNoDoc ? aConf->Read(aFilePath, aShape, aWS) : aConf->Read(aFilePath, aDoc, aWS);
if (isNoDoc && aStat)
{
DBRep::Set(aDocShapeName.ToCString(), aShape);
}
CollectActiveWorkSessions(aWS, aFilePath, THE_PREVIOUS_WORK_SESSIONS);
}
if (!aStat)
{
return 1;
}
return 0;
}
//=======================================================================
//function : WriteFile
//purpose :
//=======================================================================
static Standard_Integer WriteFile(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs > 6)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
TCollection_AsciiString aDocShapeName;
TCollection_AsciiString aFilePath;
Handle(TDocStd_Document) aDoc;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
TCollection_AsciiString aConfString;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "writefile");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArg(theArgVec[anArgIter]);
anArg.LowerCase();
if ((anArg == "-conf") &&
(anArgIter + 1 < theNbArgs))
{
++anArgIter;
aConfString = theArgVec[anArgIter];
}
else if (aDocShapeName.IsEmpty())
{
aDocShapeName = theArgVec[anArgIter];
Standard_CString aNameVar = aDocShapeName.ToCString();
if (!isNoDoc)
{
DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
}
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at argument '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aDocShapeName.IsEmpty() || aFilePath.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
if (aDoc.IsNull() && !isNoDoc)
{
theDI << "Error: incorrect document\n";
return 1;
}
Handle(DE_Wrapper) aConf = DE_Wrapper::GlobalWrapper()->Copy();
Standard_Boolean aStat = Standard_True;
if (!aConfString.IsEmpty())
{
aStat = aConf->Load(aConfString);
}
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (aStat)
{
if (isNoDoc)
{
TopoDS_Shape aShape = DBRep::Get(aDocShapeName);
if (aShape.IsNull())
{
theDI << "Error: incorrect shape " << aDocShapeName << "\n";
return 1;
}
aStat = aConf->Write(aFilePath, aShape, aWS);
}
else
{
aStat = aConf->Write(aFilePath, aDoc, aWS);
}
}
if (!aStat)
{
return 1;
}
CollectActiveWorkSessions(aWS, aFilePath, THE_PREVIOUS_WORK_SESSIONS);
return 0;
}
void XSDRAWDEWrapper::InitCommands(Draw_Interpretor& theDI)
{
static Standard_Boolean initactor = Standard_False;
if (initactor)
{
return;
}
initactor = Standard_True;
Standard_CString g = "XDE translation commands";
theDI.Add("DumpConfiguration",
"DumpConfiguration [-path <path>] [-recursive {on|off}] [-format fmt1 fmt2 ...] [-vendor vend1 vend2 ...]\n"
"\n\t\t: Dump special resource generated from global configuration."
"\n\t\t: '-path' - save resource configuration to the file"
"\n\t\t: '-recursive' - flag to generate a resource from providers. Default is On. Off disables other options"
"\n\t\t: '-format' - flag to generate a resource for choosen formats. If list is empty, generate it for all"
"\n\t\t: '-vendor' - flag to generate a resource for choosen vendors. If list is empty, generate it for all",
__FILE__, DumpConfiguration, g);
theDI.Add("LoadConfiguration",
"LoadConfiguration conf [-recursive {on|off}]\n"
"\n\t\t: 'conf' - path to the resouce file or string value in the special format"
"\n\t\t: '-recursive' - flag to generate a resource for all providers. Default is true"
"\n\t\t: Configure global configuration according special resource",
__FILE__, LoadConfiguration, g);
theDI.Add("CompareConfiguration",
"CompareConfiguration conf1 conf2\n"
"\n\t\t: 'conf1' - path to the first resouce file or string value in the special format"
"\n\t\t: 'conf2' - path to the second resouce file or string value in the special format"
"\n\t\t: Compare two configurations",
__FILE__, CompareConfiguration, g);
theDI.Add("ReadFile",
"ReadFile docName filePath [-conf <value|path>]\n"
"\n\t\t: Read CAD file to document with registered format's providers. Use global configuration by default.",
__FILE__, ReadFile, g);
theDI.Add("readfile",
"readfile shapeName filePath [-conf <value|path>]\n"
"\n\t\t: Read CAD file to shape with registered format's providers. Use global configuration by default.",
__FILE__, ReadFile, g);
theDI.Add("WriteFile",
"WriteFile docName filePath [-conf <value|path>]\n"
"\n\t\t: Write CAD file to document with registered format's providers. Use global configuration by default.",
__FILE__, WriteFile, g);
theDI.Add("writefile",
"writefile shapeName filePath [-conf <value|path>]\n"
"\n\t\t: Write CAD file to shape with registered format's providers. Use global configuration by default.",
__FILE__, WriteFile, g);
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAWDEWrapper_HeaderFile
#define _XSDRAWDEWrapper_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Draw_Interpretor.hxx>
class XSDRAWDEWrapper
{
DEFINE_STANDARD_ALLOC
public:
Standard_EXPORT static void Init();
//! Loads all Draw commands of XSDRAWSTL. Used for plugin.
Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
};
#endif // _XSDRAWDEWrapper_HeaderFile

2
src/XSDRAWGLTF/FILES Normal file
View File

@@ -0,0 +1,2 @@
XSDRAWGLTF.cxx
XSDRAWGLTF.hxx

View File

@@ -0,0 +1,717 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <XSDRAWGLTF.hxx>
#include <AIS_InteractiveContext.hxx>
//#include <Aspect_TypeOfMarker.hxx>
//#include <Bnd_Box.hxx>
#include <BRep_Builder.hxx>
#include <BRepLib_PointCloudShape.hxx>
#include <DBRep.hxx>
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_PluginMacro.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <MeshVS_DataMapOfIntegerAsciiString.hxx>
#include <MeshVS_DeformedDataSource.hxx>
#include <MeshVS_Drawer.hxx>
#include <MeshVS_DrawerAttribute.hxx>
#include <MeshVS_ElementalColorPrsBuilder.hxx>
#include <MeshVS_Mesh.hxx>
#include <MeshVS_MeshEntityOwner.hxx>
#include <MeshVS_MeshPrsBuilder.hxx>
#include <MeshVS_NodalColorPrsBuilder.hxx>
#include <MeshVS_PrsBuilder.hxx>
#include <MeshVS_TextPrsBuilder.hxx>
#include <MeshVS_VectorPrsBuilder.hxx>
#include <OSD_Path.hxx>
#include <Quantity_Color.hxx>
//#include <Quantity_HArray1OfColor.hxx>
#include <Quantity_NameOfColor.hxx>
#include <RWGltf_ConfigurationNode.hxx>
#include <RWGltf_Provider.hxx>
//#include <RWGltf_DracoParameters.hxx>
//#include <RWGltf_CafReader.hxx>
//#include <RWGltf_CafWriter.hxx>
#include <RWMesh_FaceIterator.hxx>
#include <RWStl.hxx>
#include <RWStl_ConfigurationNode.hxx>
#include <RWStl_Provider.hxx>
//#include <RWObj.hxx>
#include <RWObj_ConfigurationNode.hxx>
#include <RWObj_Provider.hxx>
//#include <RWObj_CafReader.hxx>
//#include <RWObj_CafWriter.hxx>
#include <RWPly_ConfigurationNode.hxx>
#include <RWPly_Provider.hxx>
//#include <RWPly_CafWriter.hxx>
#include <RWPly_PlyWriterContext.hxx>
//#include <SelectMgr_SelectionManager.hxx>
//#include <Standard_ErrorHandler.hxx>
//#include <StdSelect_ViewerSelector3d.hxx>
//#include <StlAPI.hxx>
//#include <StlAPI_Writer.hxx>
//#include <TColgp_SequenceOfXYZ.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_HPackedMapOfInteger.hxx>
#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
#include <TDataStd_Name.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <UnitsAPI.hxx>
#include <UnitsMethods.hxx>
#include <V3d_View.hxx>
#include <ViewerTest.hxx>
#include <Vrml_ConfigurationNode.hxx>
#include <Vrml_Provider.hxx>
//#include <VrmlAPI.hxx>
//#include <VrmlAPI_Writer.hxx>
//#include <VrmlData_DataMapOfShapeAppearance.hxx>
//#include <VrmlData_Scene.hxx>
//#include <VrmlData_ShapeConvert.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFPrs_DocumentExplorer.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWIGES.hxx>
#include <XSDRAWSTEP.hxx>
#ifndef _STDIO_H
#include <stdio.h>
#endif
extern Standard_Boolean VDisplayAISObject(const TCollection_AsciiString& theName,
const Handle(AIS_InteractiveObject)& theAISObj,
Standard_Boolean theReplaceIfExists = Standard_True);
//=============================================================================
//function : parseNameFormat
//purpose : Parse RWMesh_NameFormat enumeration
//=============================================================================
static bool parseNameFormat(const char* theArg,
RWMesh_NameFormat& theFormat)
{
TCollection_AsciiString aName(theArg);
aName.LowerCase();
if (aName == "empty")
{
theFormat = RWMesh_NameFormat_Empty;
}
else if (aName == "product"
|| aName == "prod")
{
theFormat = RWMesh_NameFormat_Product;
}
else if (aName == "instance"
|| aName == "inst")
{
theFormat = RWMesh_NameFormat_Instance;
}
else if (aName == "instanceorproduct"
|| aName == "instance||product"
|| aName == "instance|product"
|| aName == "instorprod"
|| aName == "inst||prod"
|| aName == "inst|prod")
{
theFormat = RWMesh_NameFormat_InstanceOrProduct;
}
else if (aName == "productorinstance"
|| aName == "product||instance"
|| aName == "product|instance"
|| aName == "prodorinst"
|| aName == "prod||inst"
|| aName == "prod|inst")
{
theFormat = RWMesh_NameFormat_ProductOrInstance;
}
else if (aName == "productandinstance"
|| aName == "prodandinst"
|| aName == "product&instance"
|| aName == "prod&inst")
{
theFormat = RWMesh_NameFormat_ProductAndInstance;
}
else if (aName == "productandinstanceandocaf"
|| aName == "verbose"
|| aName == "debug")
{
theFormat = RWMesh_NameFormat_ProductAndInstanceAndOcaf;
}
else
{
return false;
}
return true;
}
//=============================================================================
//function : parseCoordinateSystem
//purpose : Parse RWMesh_CoordinateSystem enumeration
//=============================================================================
static bool parseCoordinateSystem(const char* theArg,
RWMesh_CoordinateSystem& theSystem)
{
TCollection_AsciiString aCSStr(theArg);
aCSStr.LowerCase();
if (aCSStr == "zup")
{
theSystem = RWMesh_CoordinateSystem_Zup;
}
else if (aCSStr == "yup")
{
theSystem = RWMesh_CoordinateSystem_Yup;
}
else
{
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : GetLengthUnit
//purpose : Gets length unit value from static interface and document in M
//=======================================================================
static Standard_Real GetLengthUnit(const Handle(TDocStd_Document)& theDoc = nullptr)
{
if (!theDoc.IsNull())
{
Standard_Real aUnit = 1.;
if (XCAFDoc_DocumentTool::GetLengthUnit(theDoc, aUnit,
UnitsMethods_LengthUnit_Millimeter))
{
return aUnit;
}
}
XSAlgo::AlgoContainer()->PrepareForTransfer();
return UnitsMethods::GetCasCadeLengthUnit();
}
//=============================================================================
//function : ReadGltf
//purpose : Reads glTF file
//=============================================================================
static Standard_Integer ReadGltf(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
TCollection_AsciiString aDestName, aFilePath;
Handle(RWGltf_ConfigurationNode) aNode =
new RWGltf_ConfigurationNode();
Standard_Boolean toUseExistingDoc = Standard_False;
//Standard_Boolean toListExternalFiles = Standard_False;
//Standard_Boolean isParallel = Standard_False;
//Standard_Boolean isDoublePrec = Standard_False;
//Standard_Boolean toSkipLateDataLoading = Standard_False;
//Standard_Boolean toKeepLateData = Standard_True;
//Standard_Boolean toPrintDebugInfo = Standard_False;
//Standard_Boolean toLoadAllScenes = Standard_False;
//Standard_Boolean toPrintAssetInfo = Standard_False;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readgltf");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (!isNoDoc
&& (anArgCase == "-nocreate"
|| anArgCase == "-nocreatedoc"))
{
toUseExistingDoc = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-parallel")
{
aNode->InternalParameters.ReadParallel =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-doubleprec"
|| anArgCase == "-doubleprecision"
|| anArgCase == "-singleprec"
|| anArgCase == "-singleprecision")
{
aNode->InternalParameters.ReadSinglePrecision =
!Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
if (anArgCase.StartsWith("-single"))
{
aNode->InternalParameters.ReadSinglePrecision =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
}
else if (anArgCase == "-skiplateloading")
{
aNode->InternalParameters.ReadSkipLateDataLoading =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-keeplate")
{
aNode->InternalParameters.ReadKeepLateData =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-allscenes")
{
aNode->InternalParameters.ReadLoadAllScenes =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-toprintinfo"
|| anArgCase == "-toprintdebuginfo")
{
aNode->InternalParameters.ReadPrintDebugMessages =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
//else if (anArgCase == "-listexternalfiles"
// || anArgCase == "-listexternals"
// || anArgCase == "-listexternal"
// || anArgCase == "-external"
// || anArgCase == "-externalfiles")
//{
// toListExternalFiles = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
//}
//else if (anArgCase == "-assetinfo"
// || anArgCase == "-metadata")
//{
// toPrintAssetInfo = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
//}
else if (aDestName.IsEmpty())
{
aDestName = theArgVec[anArgIter];
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
//if (aFilePath.IsEmpty() && !aDestName.IsEmpty())
//{
// if (toListExternalFiles || toPrintAssetInfo)
// {
// std::swap (aFilePath, aDestName);
// }
//}
if (aFilePath.IsEmpty() || aDestName.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(TDocStd_Document) aDoc;
if (!aDestName.IsEmpty()
&& !isNoDoc)
{
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
Standard_CString aNameVar = aDestName.ToCString();
DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
if (aDoc.IsNull())
{
if (toUseExistingDoc)
{
theDI << "Error: document with name " << aDestName << " does not exist\n";
return 1;
}
anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
}
else if (!toUseExistingDoc)
{
theDI << "Error: document with name " << aDestName << " already exists\n";
return 1;
}
}
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
Handle(RWGltf_Provider) aProvider =
new RWGltf_Provider(aNode);
Standard_Boolean aReadStat = Standard_False;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (isNoDoc)
{
TopoDS_Shape aResShape;
aReadStat = aProvider->Read(aFilePath, aResShape, aWS, aProgress->Start());
if (aReadStat)
{
DBRep::Set(aDestName.ToCString(), aResShape);
}
}
else
{
aReadStat = aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start());
if (aReadStat)
{
Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
TDataStd_Name::Set(aDoc->GetData()->Root(), aDestName);
Draw::Set(aDestName.ToCString(), aDrawDoc);
}
}
if (!aReadStat)
{
theDI << "Cannot read any relevant data from the GLTF file\n";
return 1;
}
//bool isFirstLine = true;
//if (toPrintAssetInfo)
//{
// for (TColStd_IndexedDataMapOfStringString::Iterator aKeyIter (aReader.Metadata()); aKeyIter.More(); aKeyIter.Next())
// {
// if (!isFirstLine)
// {
// theDI << "\n";
// }
// isFirstLine = false;
// theDI << aKeyIter.Key() << ": " << aKeyIter.Value();
// }
//}
//if (toListExternalFiles)
//{
// if (!isFirstLine)
// {
// theDI << "\n";
// }
// for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
// {
// theDI << "\"" << aFileIter.Value() << "\" ";
// }
//}
return 0;
}
//=============================================================================
//function : WriteGltf
//purpose : Writes glTF file
//=============================================================================
static Standard_Integer WriteGltf(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
TCollection_AsciiString aGltfFilePath;
Handle(TDocStd_Document) aDoc;
TopoDS_Shape aShape;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
Handle(RWGltf_ConfigurationNode) aNode =
new RWGltf_ConfigurationNode();
//TColStd_IndexedDataMapOfStringString aFileInfo;
//RWGltf_WriterTrsfFormat aTrsfFormat = RWGltf_WriterTrsfFormat_Compact;
//RWMesh_CoordinateSystem aSystemCoordSys = RWMesh_CoordinateSystem_Zup;
//bool toForceUVExport = false, toEmbedTexturesInGlb = true;
//bool toMergeFaces = false, toSplitIndices16 = false;
//bool isParallel = false;
//RWMesh_NameFormat aNodeNameFormat = RWMesh_NameFormat_InstanceOrProduct;
//RWMesh_NameFormat aMeshNameFormat = RWMesh_NameFormat_Product;
//RWGltf_DracoParameters aDracoParameters;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgCase == "-comments"
&& anArgIter + 1 < theNbArgs)
{
aNode->InternalParameters.WriteComment = theArgVec[++anArgIter];
}
else if (anArgCase == "-author"
&& anArgIter + 1 < theNbArgs)
{
aNode->InternalParameters.WriteAuthor = theArgVec[++anArgIter];
}
else if (anArgCase == "-forceuvexport"
|| anArgCase == "-forceuv")
{
aNode->InternalParameters.WriteForcedUVExport = true;
if (anArgIter + 1 < theNbArgs
&& Draw::ParseOnOff(theArgVec[anArgIter + 1], aNode->InternalParameters.WriteForcedUVExport))
{
++anArgIter;
}
}
else if (anArgCase == "-mergefaces")
{
aNode->InternalParameters.WriteMergeFaces = true;
if (anArgIter + 1 < theNbArgs
&& Draw::ParseOnOff(theArgVec[anArgIter + 1], aNode->InternalParameters.WriteMergeFaces))
{
++anArgIter;
}
}
else if (anArgCase == "-splitindices16"
|| anArgCase == "-splitindexes16"
|| anArgCase == "-splitindices"
|| anArgCase == "-splitindexes"
|| anArgCase == "-splitind")
{
aNode->InternalParameters.WriteSplitIndices16 = true;
if (anArgIter + 1 < theNbArgs
&& Draw::ParseOnOff(theArgVec[anArgIter + 1], aNode->InternalParameters.WriteSplitIndices16))
{
++anArgIter;
}
}
else if (anArgIter + 1 < theNbArgs
&& (anArgCase == "-systemcoordinatesystem"
|| anArgCase == "-systemcoordsystem"
|| anArgCase == "-systemcoordsys"
|| anArgCase == "-syscoordsys"))
{
if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.SystemCS))
{
theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgCase == "-trsfformat"
&& anArgIter + 1 < theNbArgs)
{
TCollection_AsciiString aTrsfStr(theArgVec[++anArgIter]);
aTrsfStr.LowerCase();
if (aTrsfStr == "compact")
{
aNode->InternalParameters.WriteTrsfFormat = RWGltf_WriterTrsfFormat_Compact;
}
else if (aTrsfStr == "mat4")
{
aNode->InternalParameters.WriteTrsfFormat = RWGltf_WriterTrsfFormat_Mat4;
}
else if (aTrsfStr == "trs")
{
aNode->InternalParameters.WriteTrsfFormat = RWGltf_WriterTrsfFormat_TRS;
}
else
{
theDI << "Syntax error at '" << anArgCase << "'\n";
return 1;
}
}
else if (anArgCase == "-nodenameformat"
|| anArgCase == "-nodename")
{
++anArgIter;
if (anArgIter >= theNbArgs
|| !parseNameFormat(theArgVec[anArgIter], aNode->InternalParameters.WriteNodeNameFormat))
{
theDI << "Syntax error at '" << anArgCase << "'\n";
return 1;
}
}
else if (anArgCase == "-meshnameformat"
|| anArgCase == "-meshname")
{
++anArgIter;
if (anArgIter >= theNbArgs
|| !parseNameFormat(theArgVec[anArgIter], aNode->InternalParameters.WriteMeshNameFormat))
{
theDI << "Syntax error at '" << anArgCase << "'\n";
return 1;
}
}
else if (aDoc.IsNull())
{
Standard_CString aNameVar = theArgVec[anArgIter];
DDocStd::GetDocument(aNameVar, aDoc, false);
if (aDoc.IsNull())
{
aShape = DBRep::Get(aNameVar);
if (aShape.IsNull())
{
theDI << "Syntax error: '" << aNameVar << "' is not a shape nor document\n";
return 1;
}
aNode->InternalParameters.WriteNodeNameFormat = RWMesh_NameFormat_Product;
}
}
else if (aGltfFilePath.IsEmpty())
{
aGltfFilePath = theArgVec[anArgIter];
}
else if (anArgCase == "-texturesSeparate")
{
aNode->InternalParameters.WriteEmbedTexturesInGlb = false;
}
else if (anArgCase == "-draco")
{
aNode->InternalParameters.WriteDracoParameters.DracoCompression =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-compressionlevel" && (anArgIter + 1) < theNbArgs
&& Draw::ParseInteger(theArgVec[anArgIter + 1],
aNode->InternalParameters.WriteDracoParameters.CompressionLevel))
{
++anArgIter;
}
else if (anArgCase == "-quantizepositionbits" && (anArgIter + 1) < theNbArgs
&& Draw::ParseInteger(theArgVec[anArgIter + 1],
aNode->InternalParameters.WriteDracoParameters.QuantizePositionBits))
{
++anArgIter;
}
else if (anArgCase == "-quantizenormalbits" && (anArgIter + 1) < theNbArgs
&& Draw::ParseInteger(theArgVec[anArgIter + 1],
aNode->InternalParameters.WriteDracoParameters.QuantizeNormalBits))
{
++anArgIter;
}
else if (anArgCase == "-quantizetexcoordbits" && (anArgIter + 1) < theNbArgs
&& Draw::ParseInteger(theArgVec[anArgIter + 1],
aNode->InternalParameters.WriteDracoParameters.QuantizeTexcoordBits))
{
++anArgIter;
}
else if (anArgCase == "-quantizecolorbits" && (anArgIter + 1) < theNbArgs
&& Draw::ParseInteger(theArgVec[anArgIter + 1],
aNode->InternalParameters.WriteDracoParameters.QuantizeColorBits))
{
++anArgIter;
}
else if (anArgCase == "-quantizegenericbits" && (anArgIter + 1) < theNbArgs
&& Draw::ParseInteger(theArgVec[anArgIter + 1],
aNode->InternalParameters.WriteDracoParameters.QuantizeGenericBits))
{
++anArgIter;
}
else if (anArgCase == "-unifiedquantization")
{
aNode->InternalParameters.WriteDracoParameters.UnifiedQuantization =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArgCase == "-parallel")
{
aNode->InternalParameters.WriteParallel =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else
{
theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aGltfFilePath.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
TCollection_AsciiString anExt = aGltfFilePath;
anExt.LowerCase();
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
Handle(RWGltf_Provider) aProvider =
new RWGltf_Provider(aNode);
Standard_Boolean aWriteStat = Standard_False;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aDoc.IsNull())
{
aWriteStat = aProvider->Write(aGltfFilePath, aDoc, aWS, aProgress->Start());
}
else if (!aShape.IsNull())
{
aWriteStat = aProvider->Write(aGltfFilePath, aShape, aWS, aProgress->Start());
}
if (!aWriteStat)
{
theDI << "Cannot write any relevant data to the GLTF file\n";
return 1;
}
return 0;
}
//=======================================================================
//function : InitCommands
//purpose :
//=======================================================================
void XSDRAWGLTF::InitCommands(Draw_Interpretor& theCommands)
{
const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
//XSDRAW::LoadDraw(theCommands);
theCommands.Add("ReadGltf",
"ReadGltf Doc file [-parallel {on|off}] [-listExternalFiles] [-noCreateDoc] [-doublePrecision {on|off}] [-assetInfo]"
"\n\t\t: Read glTF file into XDE document."
"\n\t\t: -listExternalFiles do not read mesh and only list external files"
"\n\t\t: -noCreateDoc read into existing XDE document"
"\n\t\t: -doublePrecision store triangulation with double or single floating point"
"\n\t\t: precision (single by default)"
"\n\t\t: -skipLateLoading data loading is skipped and can be performed later"
"\n\t\t: (false by default)"
"\n\t\t: -keepLate data is loaded into itself with preservation of information"
"\n\t\t: about deferred storage to load/unload this data later."
"\n\t\t: -allScenes load all scenes defined in the document instead of default one (false by default)"
"\n\t\t: -toPrintDebugInfo print additional debug information during data reading"
"\n\t\t: -assetInfo print asset information",
__FILE__, ReadGltf, g);
theCommands.Add("readgltf",
"readgltf shape file"
"\n\t\t: Same as ReadGltf but reads glTF file into a shape instead of a document.",
__FILE__, ReadGltf, g);
theCommands.Add("WriteGltf",
"WriteGltf Doc file [-trsfFormat {compact|TRS|mat4}]=compact"
"\n\t\t: [-systemCoordSys {Zup|Yup}]=Zup"
"\n\t\t: [-comments Text] [-author Name]"
"\n\t\t: [-forceUVExport]=0 [-texturesSeparate]=0 [-mergeFaces]=0 [-splitIndices16]=0"
"\n\t\t: [-nodeNameFormat {empty|product|instance|instOrProd|prodOrInst|prodAndInst|verbose}]=instOrProd"
"\n\t\t: [-meshNameFormat {empty|product|instance|instOrProd|prodOrInst|prodAndInst|verbose}]=product"
"\n\t\t: [-draco]=0 [-compressionLevel {0-10}]=7 [-quantizePositionBits Value]=14 [-quantizeNormalBits Value]=10"
"\n\t\t: [-quantizeTexcoordBits Value]=12 [-quantizeColorBits Value]=8 [-quantizeGenericBits Value]=12"
"\n\t\t: [-unifiedQuantization]=0 [-parallel]=0"
"\n\t\t: Write XDE document into glTF file."
"\n\t\t: -trsfFormat preferred transformation format"
"\n\t\t: -systemCoordSys system coordinate system; Zup when not specified"
"\n\t\t: -mergeFaces merge Faces within the same Mesh"
"\n\t\t: -splitIndices16 split Faces to keep 16-bit indices when -mergeFaces is enabled"
"\n\t\t: -forceUVExport always export UV coordinates"
"\n\t\t: -texturesSeparate write textures to separate files"
"\n\t\t: -nodeNameFormat name format for Nodes"
"\n\t\t: -meshNameFormat name format for Meshes"
"\n\t\t: -draco use Draco compression 3D geometric meshes"
"\n\t\t: -compressionLevel draco compression level [0-10] (by default 7), a value of 0 will apply sequential encoding and preserve face order"
"\n\t\t: -quantizePositionBits quantization bits for position attribute when using Draco compression (by default 14)"
"\n\t\t: -quantizeNormalBits quantization bits for normal attribute when using Draco compression (by default 10)"
"\n\t\t: -quantizeTexcoordBits quantization bits for texture coordinate attribute when using Draco compression (by default 12)"
"\n\t\t: -quantizeColorBits quantization bits for color attribute when using Draco compression (by default 8)"
"\n\t\t: -quantizeGenericBits quantization bits for skinning attribute (joint indices and joint weights)"
"\n and custom attributes when using Draco compression (by default 12)"
"\n\t\t: -unifiedQuantization quantization is applied on each primitive separately if this option is false"
"\n\t\t: -parallel use multithreading for Draco compression",
__FILE__, WriteGltf, g);
theCommands.Add("writegltf",
"writegltf shape file",
__FILE__, WriteGltf, g);
}
//=======================================================================
//function : Factory
//purpose :
//=======================================================================
void XSDRAWGLTF::Factory(Draw_Interpretor& theDI)
{
XSDRAWIGES::InitSelect();
XSDRAWIGES::InitToBRep(theDI);
XSDRAWIGES::InitFromBRep(theDI);
XSDRAWSTEP::InitCommands(theDI);
XSDRAWGLTF::InitCommands(theDI);
XSDRAW::LoadDraw(theDI);
#ifdef OCCT_DEBUG
theDI << "Draw Plugin : All TKXSDRAW commands are loaded\n";
#endif
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAWGLTF_HeaderFile
#define _XSDRAWGLTF_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Draw_Interpretor.hxx>
class XSDRAWGLTF
{
DEFINE_STANDARD_ALLOC
public:
Standard_EXPORT static void Init();
//! Loads all Draw commands of XSDRAWSTL. Used for plugin.
Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
};
#endif // _XSDRAWGLTF_HeaderFile

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,4 @@
// Created on: 1995-03-15
// Created by: Christian CAILLET
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
@@ -22,45 +19,15 @@
#include <Draw_Interpretor.hxx>
//! XSDRAW for IGES : commands IGESSelect, Controller, transfer
class XSDRAWIGES
{
DEFINE_STANDARD_ALLOC
public:
DEFINE_STANDARD_ALLOC
//! Inits IGESSelect commands, for DRAW
Standard_EXPORT static void InitSelect();
//! Inits IGESToBRep for DRAW
Standard_EXPORT static void InitToBRep (Draw_Interpretor& theCommands);
//! Inits BRepToIGES for DRAW
Standard_EXPORT static void InitFromBRep (Draw_Interpretor& theCommands);
protected:
private:
Standard_EXPORT static void Init();
//! Loads all Draw commands of XSDRAWSTL. Used for plugin.
Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
};
#endif // _XSDRAWIGES_HeaderFile

2
src/XSDRAWOBJ/FILES Normal file
View File

@@ -0,0 +1,2 @@
XSDRAWOBJ.cxx
XSDRAWOBJ.hxx

522
src/XSDRAWOBJ/XSDRAWOBJ.cxx Normal file
View File

@@ -0,0 +1,522 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <XSDRAWOBJ.hxx>
#include <AIS_InteractiveContext.hxx>
//#include <Aspect_TypeOfMarker.hxx>
//#include <Bnd_Box.hxx>
#include <BRep_Builder.hxx>
#include <BRepLib_PointCloudShape.hxx>
#include <DBRep.hxx>
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_PluginMacro.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <MeshVS_DataMapOfIntegerAsciiString.hxx>
#include <MeshVS_DeformedDataSource.hxx>
#include <MeshVS_Drawer.hxx>
#include <MeshVS_DrawerAttribute.hxx>
#include <MeshVS_ElementalColorPrsBuilder.hxx>
#include <MeshVS_Mesh.hxx>
#include <MeshVS_MeshEntityOwner.hxx>
#include <MeshVS_MeshPrsBuilder.hxx>
#include <MeshVS_NodalColorPrsBuilder.hxx>
#include <MeshVS_PrsBuilder.hxx>
#include <MeshVS_TextPrsBuilder.hxx>
#include <MeshVS_VectorPrsBuilder.hxx>
#include <OSD_Path.hxx>
#include <Quantity_Color.hxx>
//#include <Quantity_HArray1OfColor.hxx>
#include <Quantity_NameOfColor.hxx>
#include <RWGltf_ConfigurationNode.hxx>
#include <RWGltf_Provider.hxx>
//#include <RWGltf_DracoParameters.hxx>
//#include <RWGltf_CafReader.hxx>
//#include <RWGltf_CafWriter.hxx>
#include <RWMesh_FaceIterator.hxx>
#include <RWStl.hxx>
#include <RWStl_ConfigurationNode.hxx>
#include <RWStl_Provider.hxx>
//#include <RWObj.hxx>
#include <RWObj_ConfigurationNode.hxx>
#include <RWObj_Provider.hxx>
//#include <RWObj_CafReader.hxx>
//#include <RWObj_CafWriter.hxx>
#include <RWPly_ConfigurationNode.hxx>
#include <RWPly_Provider.hxx>
//#include <RWPly_CafWriter.hxx>
#include <RWPly_PlyWriterContext.hxx>
//#include <SelectMgr_SelectionManager.hxx>
//#include <Standard_ErrorHandler.hxx>
//#include <StdSelect_ViewerSelector3d.hxx>
//#include <StlAPI.hxx>
//#include <StlAPI_Writer.hxx>
//#include <TColgp_SequenceOfXYZ.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_HPackedMapOfInteger.hxx>
#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
#include <TDataStd_Name.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <UnitsAPI.hxx>
#include <UnitsMethods.hxx>
#include <V3d_View.hxx>
#include <ViewerTest.hxx>
#include <Vrml_ConfigurationNode.hxx>
#include <Vrml_Provider.hxx>
//#include <VrmlAPI.hxx>
//#include <VrmlAPI_Writer.hxx>
//#include <VrmlData_DataMapOfShapeAppearance.hxx>
//#include <VrmlData_Scene.hxx>
//#include <VrmlData_ShapeConvert.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFPrs_DocumentExplorer.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWIGES.hxx>
#include <XSDRAWSTEP.hxx>
#ifndef _STDIO_H
#include <stdio.h>
#endif
extern Standard_Boolean VDisplayAISObject(const TCollection_AsciiString& theName,
const Handle(AIS_InteractiveObject)& theAISObj,
Standard_Boolean theReplaceIfExists = Standard_True);
//=============================================================================
//function : parseNameFormat
//purpose : Parse RWMesh_NameFormat enumeration
//=============================================================================
static bool parseNameFormat(const char* theArg,
RWMesh_NameFormat& theFormat)
{
TCollection_AsciiString aName(theArg);
aName.LowerCase();
if (aName == "empty")
{
theFormat = RWMesh_NameFormat_Empty;
}
else if (aName == "product"
|| aName == "prod")
{
theFormat = RWMesh_NameFormat_Product;
}
else if (aName == "instance"
|| aName == "inst")
{
theFormat = RWMesh_NameFormat_Instance;
}
else if (aName == "instanceorproduct"
|| aName == "instance||product"
|| aName == "instance|product"
|| aName == "instorprod"
|| aName == "inst||prod"
|| aName == "inst|prod")
{
theFormat = RWMesh_NameFormat_InstanceOrProduct;
}
else if (aName == "productorinstance"
|| aName == "product||instance"
|| aName == "product|instance"
|| aName == "prodorinst"
|| aName == "prod||inst"
|| aName == "prod|inst")
{
theFormat = RWMesh_NameFormat_ProductOrInstance;
}
else if (aName == "productandinstance"
|| aName == "prodandinst"
|| aName == "product&instance"
|| aName == "prod&inst")
{
theFormat = RWMesh_NameFormat_ProductAndInstance;
}
else if (aName == "productandinstanceandocaf"
|| aName == "verbose"
|| aName == "debug")
{
theFormat = RWMesh_NameFormat_ProductAndInstanceAndOcaf;
}
else
{
return false;
}
return true;
}
//=============================================================================
//function : parseCoordinateSystem
//purpose : Parse RWMesh_CoordinateSystem enumeration
//=============================================================================
static bool parseCoordinateSystem(const char* theArg,
RWMesh_CoordinateSystem& theSystem)
{
TCollection_AsciiString aCSStr(theArg);
aCSStr.LowerCase();
if (aCSStr == "zup")
{
theSystem = RWMesh_CoordinateSystem_Zup;
}
else if (aCSStr == "yup")
{
theSystem = RWMesh_CoordinateSystem_Yup;
}
else
{
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : GetLengthUnit
//purpose : Gets length unit value from static interface and document in M
//=======================================================================
static Standard_Real GetLengthUnit(const Handle(TDocStd_Document)& theDoc = nullptr)
{
if (!theDoc.IsNull())
{
Standard_Real aUnit = 1.;
if (XCAFDoc_DocumentTool::GetLengthUnit(theDoc, aUnit,
UnitsMethods_LengthUnit_Millimeter))
{
return aUnit;
}
}
XSAlgo::AlgoContainer()->PrepareForTransfer();
return UnitsMethods::GetCasCadeLengthUnit();
}
//=============================================================================
//function : ReadObj
//purpose : Reads OBJ file
//=============================================================================
static Standard_Integer ReadObj(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
TCollection_AsciiString aDestName, aFilePath;
Handle(RWObj_ConfigurationNode) aNode = new RWObj_ConfigurationNode();
aNode->GlobalParameters.LengthUnit = GetLengthUnit();
Standard_Boolean toUseExistingDoc = Standard_False;
//Standard_Real aFileUnitFactor = -1.0;
//RWMesh_CoordinateSystem aResultCoordSys = RWMesh_CoordinateSystem_Zup, aFileCoordSys = RWMesh_CoordinateSystem_Yup;
//Standard_Boolean toListExternalFiles = Standard_False, isSingleFace = Standard_False, isSinglePrecision = Standard_False;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readobj");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgIter + 1 < theNbArgs
&& (anArgCase == "-unit"
|| anArgCase == "-units"
|| anArgCase == "-fileunit"
|| anArgCase == "-fileunits"))
{
const TCollection_AsciiString aUnitStr(theArgVec[++anArgIter]);
aNode->InternalParameters.FileLengthUnit = UnitsAPI::AnyToSI(1.0, aUnitStr.ToCString());
if (aNode->InternalParameters.FileLengthUnit <= 0.0)
{
theDI << "Syntax error: wrong length unit '" << aUnitStr << "'\n";
return 1;
}
}
else if (anArgIter + 1 < theNbArgs
&& (anArgCase == "-filecoordinatesystem"
|| anArgCase == "-filecoordsystem"
|| anArgCase == "-filecoordsys"))
{
if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.FileCS))
{
theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgIter + 1 < theNbArgs
&& (anArgCase == "-resultcoordinatesystem"
|| anArgCase == "-resultcoordsystem"
|| anArgCase == "-resultcoordsys"
|| anArgCase == "-rescoordsys"))
{
if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.SystemCS))
{
theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgCase == "-singleprecision"
|| anArgCase == "-singleprec")
{
aNode->InternalParameters.ReadSinglePrecision = Standard_True;
if (anArgIter + 1 < theNbArgs
&& Draw::ParseOnOff(theArgVec[anArgIter + 1],
aNode->InternalParameters.ReadSinglePrecision))
{
++anArgIter;
}
}
else if (isNoDoc
&& (anArgCase == "-singleface"
|| anArgCase == "-singletriangulation"))
{
aNode->InternalParameters.ReadCreateShapes = Standard_True;
}
else if (!isNoDoc
&& (anArgCase == "-nocreate"
|| anArgCase == "-nocreatedoc"))
{
toUseExistingDoc = Standard_True;
if (anArgIter + 1 < theNbArgs
&& Draw::ParseOnOff(theArgVec[anArgIter + 1], toUseExistingDoc))
{
++anArgIter;
}
}
//else if (anArgCase == "-listexternalfiles"
// || anArgCase == "-listexternals"
// || anArgCase == "-listexternal"
// || anArgCase == "-external"
// || anArgCase == "-externalfiles")
//{
// toListExternalFiles = Standard_True;
//}
else if (aDestName.IsEmpty())
{
aDestName = theArgVec[anArgIter];
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
Handle(TDocStd_Document) aDoc;
if (!isNoDoc)
{
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
Standard_CString aNameVar = aDestName.ToCString();
DDocStd::GetDocument(aNameVar, aDoc, Standard_False);
if (aDoc.IsNull())
{
if (toUseExistingDoc)
{
theDI << "Error: document with name " << aDestName << " does not exist\n";
return 1;
}
anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
}
else if (!toUseExistingDoc)
{
theDI << "Error: document with name " << aDestName << " already exists\n";
return 1;
}
}
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(RWStl_Provider) aProvider = new RWStl_Provider(aNode);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
Standard_Boolean aReadStat = Standard_False;
if (isNoDoc)
{
TopoDS_Shape aShape;
aReadStat = aProvider->Read(aFilePath, aShape, aWS, aProgress->Start());
if (aReadStat)
{
DBRep::Set(aDestName.ToCString(), aShape);
}
}
else
{
aReadStat = aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start());
if (aReadStat)
{
Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);
TDataStd_Name::Set(aDoc->GetData()->Root(), aDestName);
Draw::Set(aDestName.ToCString(), aDrawDoc);
}
}
if (!aReadStat)
{
theDI << "Cannot read any relevant data from the Obj file\n";
return 1;
}
return 0;
}
//=============================================================================
//function : WriteObj
//purpose : Writes OBJ file
//=============================================================================
static Standard_Integer WriteObj(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
TCollection_AsciiString anObjFilePath;
Handle(TDocStd_Document) aDoc;
Handle(RWObj_ConfigurationNode) aNode = new RWObj_ConfigurationNode();
aNode->GlobalParameters.LengthUnit = GetLengthUnit();
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
//TColStd_IndexedDataMapOfStringString aFileInfo;
//Standard_Real aFileUnitFactor = -1.0;
//RWMesh_CoordinateSystem aSystemCoordSys = RWMesh_CoordinateSystem_Zup, aFileCoordSys = RWMesh_CoordinateSystem_Yup;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArgCase(theArgVec[anArgIter]);
anArgCase.LowerCase();
if (anArgIter + 1 < theNbArgs
&& (anArgCase == "-unit"
|| anArgCase == "-units"
|| anArgCase == "-fileunit"
|| anArgCase == "-fileunits"))
{
const TCollection_AsciiString aUnitStr(theArgVec[++anArgIter]);
aNode->InternalParameters.FileLengthUnit = UnitsAPI::AnyToSI(1.0, aUnitStr.ToCString());
if (aNode->InternalParameters.FileLengthUnit <= 0.0)
{
theDI << "Syntax error: wrong length unit '" << aUnitStr << "'\n";
return 1;
}
}
else if (anArgIter + 1 < theNbArgs
&& (anArgCase == "-filecoordinatesystem"
|| anArgCase == "-filecoordsystem"
|| anArgCase == "-filecoordsys"))
{
if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.FileCS))
{
theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgIter + 1 < theNbArgs
&& (anArgCase == "-systemcoordinatesystem"
|| anArgCase == "-systemcoordsystem"
|| anArgCase == "-systemcoordsys"
|| anArgCase == "-syscoordsys"))
{
if (!parseCoordinateSystem(theArgVec[++anArgIter], aNode->InternalParameters.SystemCS))
{
theDI << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
else if (anArgCase == "-comments"
&& anArgIter + 1 < theNbArgs)
{
aNode->InternalParameters.WriteComment = theArgVec[++anArgIter];
}
else if (anArgCase == "-author"
&& anArgIter + 1 < theNbArgs)
{
aNode->InternalParameters.WriteAuthor = theArgVec[++anArgIter];
}
else if (aDoc.IsNull())
{
Standard_CString aNameVar = theArgVec[anArgIter];
DDocStd::GetDocument(aNameVar, aDoc, false);
if (aDoc.IsNull())
{
TopoDS_Shape aShape = DBRep::Get(aNameVar);
if (aShape.IsNull())
{
theDI << "Syntax error: '" << aNameVar << "' is not a shape nor document\n";
return 1;
}
anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
aShapeTool->AddShape(aShape);
}
}
else if (anObjFilePath.IsEmpty())
{
anObjFilePath = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (anObjFilePath.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(RWStl_Provider) aProvider = new RWStl_Provider(aNode);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Write(theArgVec[2], aDoc, aWS, aProgress->Start()))
{
theDI << "Error: Mesh writing has been failed.\n";
}
return 0;
}
//=======================================================================
//function : InitCommands
//purpose :
//=======================================================================
void XSDRAWOBJ::InitCommands(Draw_Interpretor& theCommands)
{
const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
theCommands.Add("ReadObj",
"ReadObj Doc file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
"\n\t\t: [-resultCoordSys {Zup|Yup}] [-singlePrecision]"
"\n\t\t: [-listExternalFiles] [-noCreateDoc]"
"\n\t\t: Read OBJ file into XDE document."
"\n\t\t: -fileUnit length unit of OBJ file content;"
"\n\t\t: -fileCoordSys coordinate system defined by OBJ file; Yup when not specified."
"\n\t\t: -resultCoordSys result coordinate system; Zup when not specified."
"\n\t\t: -singlePrecision truncate vertex data to single precision during read; FALSE by default."
"\n\t\t: -listExternalFiles do not read mesh and only list external files."
"\n\t\t: -noCreateDoc read into existing XDE document.",
__FILE__, ReadObj, g);
theCommands.Add("readobj",
"readobj shape file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
"\n\t\t: [-resultCoordSys {Zup|Yup}] [-singlePrecision]"
"\n\t\t: [-singleFace]"
"\n\t\t: Same as ReadObj but reads OBJ file into a shape instead of a document."
"\n\t\t: -singleFace merge OBJ content into a single triangulation Face.",
__FILE__, ReadObj, g);
theCommands.Add("WriteObj",
"WriteObj Doc file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
"\n\t\t: [-systemCoordSys {Zup|Yup}]"
"\n\t\t: [-comments Text] [-author Name]"
"\n\t\t: Write XDE document into OBJ file."
"\n\t\t: -fileUnit length unit of OBJ file content;"
"\n\t\t: -fileCoordSys coordinate system defined by OBJ file; Yup when not specified."
"\n\t\t: -systemCoordSys system coordinate system; Zup when not specified.",
__FILE__, WriteObj, g);
theCommands.Add("writeobj",
"writeobj shape file",
__FILE__, WriteObj, g);
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAWOBJ_HeaderFile
#define _XSDRAWOBJ_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Draw_Interpretor.hxx>
class XSDRAWOBJ
{
DEFINE_STANDARD_ALLOC
public:
Standard_EXPORT static void Init();
//! Loads all Draw commands of XSDRAWSTL. Used for plugin.
Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
};
#endif // _XSDRAWOBJ_HeaderFile

2
src/XSDRAWPLY/FILES Normal file
View File

@@ -0,0 +1,2 @@
XSDRAWPLY.cxx
XSDRAWPLY.hxx

542
src/XSDRAWPLY/XSDRAWPLY.cxx Normal file
View File

@@ -0,0 +1,542 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <XSDRAWSTLVRML.hxx>
#include <AIS_InteractiveContext.hxx>
//#include <Aspect_TypeOfMarker.hxx>
//#include <Bnd_Box.hxx>
#include <BRep_Builder.hxx>
#include <BRepLib_PointCloudShape.hxx>
#include <DBRep.hxx>
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_PluginMacro.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <MeshVS_DataMapOfIntegerAsciiString.hxx>
#include <MeshVS_DeformedDataSource.hxx>
#include <MeshVS_Drawer.hxx>
#include <MeshVS_DrawerAttribute.hxx>
#include <MeshVS_ElementalColorPrsBuilder.hxx>
#include <MeshVS_Mesh.hxx>
#include <MeshVS_MeshEntityOwner.hxx>
#include <MeshVS_MeshPrsBuilder.hxx>
#include <MeshVS_NodalColorPrsBuilder.hxx>
#include <MeshVS_PrsBuilder.hxx>
#include <MeshVS_TextPrsBuilder.hxx>
#include <MeshVS_VectorPrsBuilder.hxx>
#include <OSD_Path.hxx>
#include <Quantity_Color.hxx>
//#include <Quantity_HArray1OfColor.hxx>
#include <Quantity_NameOfColor.hxx>
#include <RWGltf_ConfigurationNode.hxx>
#include <RWGltf_Provider.hxx>
//#include <RWGltf_DracoParameters.hxx>
//#include <RWGltf_CafReader.hxx>
//#include <RWGltf_CafWriter.hxx>
#include <RWMesh_FaceIterator.hxx>
#include <RWStl.hxx>
#include <RWStl_ConfigurationNode.hxx>
#include <RWStl_Provider.hxx>
//#include <RWObj.hxx>
#include <RWObj_ConfigurationNode.hxx>
#include <RWObj_Provider.hxx>
//#include <RWObj_CafReader.hxx>
//#include <RWObj_CafWriter.hxx>
#include <RWPly_ConfigurationNode.hxx>
#include <RWPly_Provider.hxx>
//#include <RWPly_CafWriter.hxx>
#include <RWPly_PlyWriterContext.hxx>
//#include <SelectMgr_SelectionManager.hxx>
//#include <Standard_ErrorHandler.hxx>
//#include <StdSelect_ViewerSelector3d.hxx>
//#include <StlAPI.hxx>
//#include <StlAPI_Writer.hxx>
//#include <TColgp_SequenceOfXYZ.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_HPackedMapOfInteger.hxx>
#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
#include <TDataStd_Name.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <UnitsAPI.hxx>
#include <UnitsMethods.hxx>
#include <V3d_View.hxx>
#include <ViewerTest.hxx>
#include <Vrml_ConfigurationNode.hxx>
#include <Vrml_Provider.hxx>
//#include <VrmlAPI.hxx>
//#include <VrmlAPI_Writer.hxx>
//#include <VrmlData_DataMapOfShapeAppearance.hxx>
//#include <VrmlData_Scene.hxx>
//#include <VrmlData_ShapeConvert.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFPrs_DocumentExplorer.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWIGES.hxx>
#include <XSDRAWPLY.hxx>
#include <XSDRAWSTLVRML_DataSource.hxx>
#include <XSDRAWSTLVRML_DataSource3D.hxx>
#include <XSDRAWSTLVRML_DrawableMesh.hxx>
#ifndef _STDIO_H
#include <stdio.h>
#endif
extern Standard_Boolean VDisplayAISObject(const TCollection_AsciiString& theName,
const Handle(AIS_InteractiveObject)& theAISObj,
Standard_Boolean theReplaceIfExists = Standard_True);
//=============================================================================
//function : parseNameFormat
//purpose : Parse RWMesh_NameFormat enumeration
//=============================================================================
static bool parseNameFormat(const char* theArg,
RWMesh_NameFormat& theFormat)
{
TCollection_AsciiString aName(theArg);
aName.LowerCase();
if (aName == "empty")
{
theFormat = RWMesh_NameFormat_Empty;
}
else if (aName == "product"
|| aName == "prod")
{
theFormat = RWMesh_NameFormat_Product;
}
else if (aName == "instance"
|| aName == "inst")
{
theFormat = RWMesh_NameFormat_Instance;
}
else if (aName == "instanceorproduct"
|| aName == "instance||product"
|| aName == "instance|product"
|| aName == "instorprod"
|| aName == "inst||prod"
|| aName == "inst|prod")
{
theFormat = RWMesh_NameFormat_InstanceOrProduct;
}
else if (aName == "productorinstance"
|| aName == "product||instance"
|| aName == "product|instance"
|| aName == "prodorinst"
|| aName == "prod||inst"
|| aName == "prod|inst")
{
theFormat = RWMesh_NameFormat_ProductOrInstance;
}
else if (aName == "productandinstance"
|| aName == "prodandinst"
|| aName == "product&instance"
|| aName == "prod&inst")
{
theFormat = RWMesh_NameFormat_ProductAndInstance;
}
else if (aName == "productandinstanceandocaf"
|| aName == "verbose"
|| aName == "debug")
{
theFormat = RWMesh_NameFormat_ProductAndInstanceAndOcaf;
}
else
{
return false;
}
return true;
}
//=============================================================================
//function : parseCoordinateSystem
//purpose : Parse RWMesh_CoordinateSystem enumeration
//=============================================================================
static bool parseCoordinateSystem(const char* theArg,
RWMesh_CoordinateSystem& theSystem)
{
TCollection_AsciiString aCSStr(theArg);
aCSStr.LowerCase();
if (aCSStr == "zup")
{
theSystem = RWMesh_CoordinateSystem_Zup;
}
else if (aCSStr == "yup")
{
theSystem = RWMesh_CoordinateSystem_Yup;
}
else
{
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : GetLengthUnit
//purpose : Gets length unit value from static interface and document in M
//=======================================================================
static Standard_Real GetLengthUnit(const Handle(TDocStd_Document)& theDoc = nullptr)
{
if (!theDoc.IsNull())
{
Standard_Real aUnit = 1.;
if (XCAFDoc_DocumentTool::GetLengthUnit(theDoc, aUnit,
UnitsMethods_LengthUnit_Millimeter))
{
return aUnit;
}
}
XSAlgo::AlgoContainer()->PrepareForTransfer();
return UnitsMethods::GetCasCadeLengthUnit();
}
//=======================================================================
//function : writeply
//purpose : write PLY file
//=======================================================================
static Standard_Integer WritePly(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
Handle(TDocStd_Document) aDoc;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
TCollection_AsciiString aShapeName, aFileName;
Handle(RWPly_ConfigurationNode) aNode = new RWPly_ConfigurationNode();
Standard_Real aDist = 0.0;
Standard_Real aDens = Precision::Infinite();
Standard_Real aTol = Precision::Confusion();
//bool hasColors = true, hasNormals = true, hasTexCoords = false, hasPartId = true, hasFaceId = false;
//TColStd_IndexedDataMapOfStringString aFileInfo;
bool isPntSet = false, isDensityPoints = false;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
TCollection_AsciiString anArg(theArgVec[anArgIter]);
anArg.LowerCase();
if (anArg == "-normal")
{
aNode->InternalParameters.WriteNormals =
Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArg == "-nonormal")
{
aNode->InternalParameters.WriteNormals =
!Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArg == "-color"
|| anArg == "-nocolor"
|| anArg == "-colors"
|| anArg == "-nocolors")
{
aNode->InternalParameters.WriteColors =
Draw::ParseOnOffNoIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArg == "-uv"
|| anArg == "-nouv")
{
aNode->InternalParameters.WriteTexCoords =
Draw::ParseOnOffNoIterator(theNbArgs, theArgVec, anArgIter);
}
else if (anArg == "-partid")
{
aNode->InternalParameters.WritePartId =
Draw::ParseOnOffNoIterator(theNbArgs, theArgVec, anArgIter);
aNode->InternalParameters.WriteFaceId =
aNode->InternalParameters.WriteFaceId &&
!aNode->InternalParameters.WritePartId;
}
else if (anArg == "-surfid"
|| anArg == "-surfaceid"
|| anArg == "-faceid")
{
aNode->InternalParameters.WriteFaceId =
Draw::ParseOnOffNoIterator(theNbArgs, theArgVec, anArgIter);
aNode->InternalParameters.WritePartId =
aNode->InternalParameters.WritePartId &&
!aNode->InternalParameters.WriteFaceId;
}
else if (anArg == "-pntset"
|| anArg == "-pntcloud"
|| anArg == "-pointset"
|| anArg == "-pointcloud"
|| anArg == "-cloud"
|| anArg == "-points")
{
isPntSet = Draw::ParseOnOffIterator(theNbArgs, theArgVec, anArgIter);
}
else if ((anArg == "-dist"
|| anArg == "-distance")
&& anArgIter + 1 < theNbArgs
&& Draw::ParseReal(theArgVec[anArgIter + 1], aDist))
{
++anArgIter;
isPntSet = true;
if (aDist < 0.0)
{
theDI << "Syntax error: -distance value should be >= 0.0\n";
return 1;
}
aDist = Max(aDist, Precision::Confusion());
}
else if ((anArg == "-dens"
|| anArg == "-density")
&& anArgIter + 1 < theNbArgs
&& Draw::ParseReal(theArgVec[anArgIter + 1], aDens))
{
++anArgIter;
isDensityPoints = Standard_True;
isPntSet = true;
if (aDens <= 0.0)
{
theDI << "Syntax error: -density value should be > 0.0\n";
return 1;
}
}
else if ((anArg == "-tol"
|| anArg == "-tolerance")
&& anArgIter + 1 < theNbArgs
&& Draw::ParseReal(theArgVec[anArgIter + 1], aTol))
{
++anArgIter;
isPntSet = true;
if (aTol < Precision::Confusion())
{
theDI << "Syntax error: -tol value should be >= "
<< Precision::Confusion() << "\n";
return 1;
}
}
else if (anArg == "-comments"
&& anArgIter + 1 < theNbArgs)
{
aNode->InternalParameters.WriteComment = theArgVec[++anArgIter];
}
else if (anArg == "-author"
&& anArgIter + 1 < theNbArgs)
{
aNode->InternalParameters.WriteAuthor = theArgVec[++anArgIter];
}
else if (aDoc.IsNull())
{
if (aShapeName.IsEmpty())
{
aShapeName = theArgVec[anArgIter];
}
Standard_CString aNameVar = theArgVec[anArgIter];
DDocStd::GetDocument(aNameVar, aDoc, false);
if (aDoc.IsNull())
{
TopoDS_Shape aShape = DBRep::Get(aNameVar);
if (!aShape.IsNull())
{
anApp->NewDocument(TCollection_ExtendedString("BinXCAF"), aDoc);
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
aShapeTool->AddShape(aShape);
}
}
}
else if (aFileName.IsEmpty())
{
aFileName = theArgVec[anArgIter];
}
else
{
theDI << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
return 1;
}
}
if (aDoc.IsNull()
&& !aShapeName.IsEmpty())
{
theDI << "Syntax error: '" << aShapeName << "' is not a shape nor document\n";
return 1;
}
else if (aDoc.IsNull()
|| aFileName.IsEmpty())
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
if (isPntSet)
{
TDF_LabelSequence aRootLabels;
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
aShapeTool->GetFreeShapes(aRootLabels);
if (aRootLabels.IsEmpty())
{
theDI << "Error: empty document\n";
return 1;
}
class PointCloudPlyWriter : public BRepLib_PointCloudShape, public RWPly_PlyWriterContext
{
public:
PointCloudPlyWriter(Standard_Real theTol)
: BRepLib_PointCloudShape(TopoDS_Shape(), theTol)
{}
void AddFaceColor(const TopoDS_Shape& theFace, const Graphic3d_Vec4ub& theColor)
{
myFaceColor.Bind(theFace, theColor);
}
protected:
virtual void addPoint(const gp_Pnt& thePoint,
const gp_Vec& theNorm,
const gp_Pnt2d& theUV,
const TopoDS_Shape& theFace)
{
Graphic3d_Vec4ub aColor;
myFaceColor.Find(theFace, aColor);
RWPly_PlyWriterContext::WriteVertex(thePoint,
Graphic3d_Vec3((float)theNorm.X(), (float)theNorm.Y(), (float)theNorm.Z()),
Graphic3d_Vec2((float)theUV.X(), (float)theUV.Y()),
aColor);
}
private:
NCollection_DataMap<TopoDS_Shape, Graphic3d_Vec4ub> myFaceColor;
};
PointCloudPlyWriter aPlyCtx(aTol);
aPlyCtx.SetNormals(aNode->InternalParameters.WriteNormals);
aPlyCtx.SetColors(aNode->InternalParameters.WriteColors);
aPlyCtx.SetTexCoords(aNode->InternalParameters.WriteTexCoords);
TopoDS_Compound aComp;
BRep_Builder().MakeCompound(aComp);
for (XCAFPrs_DocumentExplorer aDocExplorer(aDoc, aRootLabels, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
aDocExplorer.More(); aDocExplorer.Next())
{
const XCAFPrs_DocumentNode& aDocNode = aDocExplorer.Current();
for (RWMesh_FaceIterator aFaceIter(aDocNode.RefLabel, aDocNode.Location, true, aDocNode.Style); aFaceIter.More(); aFaceIter.Next())
{
BRep_Builder().Add(aComp, aFaceIter.Face());
Graphic3d_Vec4ub aColorVec(255);
if (aFaceIter.HasFaceColor())
{
Graphic3d_Vec4 aColorF = aFaceIter.FaceColor();
aColorVec.SetValues((unsigned char)int(aColorF.r() * 255.0f),
(unsigned char)int(aColorF.g() * 255.0f),
(unsigned char)int(aColorF.b() * 255.0f),
(unsigned char)int(aColorF.a() * 255.0f));
}
aPlyCtx.AddFaceColor(aFaceIter.Face(), aColorVec);
}
}
aPlyCtx.SetShape(aComp);
Standard_Integer aNbPoints = isDensityPoints
? aPlyCtx.NbPointsByDensity(aDens)
: aPlyCtx.NbPointsByTriangulation();
if (aNbPoints <= 0)
{
theDI << "Error: unable to generate points\n";
return 1;
}
if (!aPlyCtx.Open(aFileName)
|| !aPlyCtx.WriteHeader(aNbPoints, 0, TColStd_IndexedDataMapOfStringString()))
{
theDI << "Error: unable to create file '" << aFileName << "'\n";
return 1;
}
Standard_Boolean isDone = isDensityPoints
? aPlyCtx.GeneratePointsByDensity(aDens)
: aPlyCtx.GeneratePointsByTriangulation();
if (!isDone)
{
theDI << "Error: Point cloud was not generated in file '" << aFileName << "'\n";
return 1;
}
else if (!aPlyCtx.Close())
{
theDI << "Error: Point cloud file '" << aFileName << "' was not written\n";
return 1;
}
else
{
theDI << aNbPoints << "\n";
}
}
else
{
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(RWPly_Provider) aProvider = new RWPly_Provider(aNode);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Write(theArgVec[2], aDoc, aWS, aProgress->Start()))
{
theDI << "Error: file writing failed '" << theArgVec[2] << "'\n";
return 1;
}
}
return 0;
}
//=======================================================================
//function : InitCommands
//purpose :
//=======================================================================
void XSDRAWSTLVRML::InitCommands(Draw_Interpretor& theCommands)
{
const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
//XSDRAW::LoadDraw(theCommands);
theCommands.Add("WritePly", R"(
WritePly Doc file [-normals {0|1}]=1 [-colors {0|1}]=1 [-uv {0|1}]=0 [-partId {0|1}]=1 [-faceId {0|1}]=0
[-pointCloud {0|1}]=0 [-distance Value]=0.0 [-density Value] [-tolerance Value]
Write document or triangulated shape into PLY file.
-normals write per-vertex normals
-colors write per-vertex colors
-uv write per-vertex UV coordinates
-partId write per-element part index (alternative to -faceId)
-faceId write per-element face index (alternative to -partId)
Generate point cloud out of the shape and write it into PLY file.
-pointCloud write point cloud instead without triangulation indices
-distance sets distance from shape into the range [0, Value];
-density sets density of points to generate randomly on surface;
-tolerance sets tolerance; default value is Precision::Confusion();
)", __FILE__, WritePly, g);
theCommands.Add("writeply",
"writeply shape file",
__FILE__, WritePly, g);
}
//=======================================================================
//function : Factory
//purpose :
//=======================================================================
void XSDRAWPLY::Factory(Draw_Interpretor& theDI)
{
XSDRAWIGES::InitSelect();
XSDRAWIGES::InitToBRep(theDI);
XSDRAWIGES::InitFromBRep(theDI);
XSDRAWSTLVRML::InitCommands(theDI);
XSDRAW::LoadDraw(theDI);
#ifdef OCCT_DEBUG
theDI << "Draw Plugin : All TKXSDRAW commands are loaded\n";
#endif
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAWPLY_HeaderFile
#define _XSDRAWPLY_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Draw_Interpretor.hxx>
class XSDRAWPLY
{
DEFINE_STANDARD_ALLOC
public:
Standard_EXPORT static void Init();
//! Loads all Draw commands of XSDRAWSTL. Used for plugin.
Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
};
#endif // _XSDRAWPLY_HeaderFile

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,4 @@
// Created on: 1996-01-12
// Created by: Christian CAILLET
// Copyright (c) 1996-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
@@ -22,41 +19,15 @@
#include <Draw_Interpretor.hxx>
//! XSDRAW for STEP AP214 and AP203
class XSDRAWSTEP
class XSDRAWSTEP
{
DEFINE_STANDARD_ALLOC
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT static void Init();
//! Inits commands to access product data and to write shapes
Standard_EXPORT static void InitCommands (Draw_Interpretor& theCommands);
protected:
private:
//! Loads all Draw commands of XSDRAWSTL. Used for plugin.
Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
};
#endif // _XSDRAWSTEP_HeaderFile

2
src/XSDRAWSTL/FILES Normal file
View File

@@ -0,0 +1,2 @@
XSDRAWSTL.cxx
XSDRAWSTL.hxx

369
src/XSDRAWSTL/XSDRAWSTL.cxx Normal file
View File

@@ -0,0 +1,369 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <XSDRAWSTL.hxx>
#include <AIS_InteractiveContext.hxx>
//#include <Aspect_TypeOfMarker.hxx>
//#include <Bnd_Box.hxx>
#include <BRep_Builder.hxx>
#include <BRepLib_PointCloudShape.hxx>
#include <DBRep.hxx>
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_PluginMacro.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <MeshVS_DataMapOfIntegerAsciiString.hxx>
#include <MeshVS_DeformedDataSource.hxx>
#include <MeshVS_Drawer.hxx>
#include <MeshVS_DrawerAttribute.hxx>
#include <MeshVS_ElementalColorPrsBuilder.hxx>
#include <MeshVS_Mesh.hxx>
#include <MeshVS_MeshEntityOwner.hxx>
#include <MeshVS_MeshPrsBuilder.hxx>
#include <MeshVS_NodalColorPrsBuilder.hxx>
#include <MeshVS_PrsBuilder.hxx>
#include <MeshVS_TextPrsBuilder.hxx>
#include <MeshVS_VectorPrsBuilder.hxx>
#include <OSD_Path.hxx>
#include <Quantity_Color.hxx>
//#include <Quantity_HArray1OfColor.hxx>
#include <Quantity_NameOfColor.hxx>
#include <RWGltf_ConfigurationNode.hxx>
#include <RWGltf_Provider.hxx>
//#include <RWGltf_DracoParameters.hxx>
//#include <RWGltf_CafReader.hxx>
//#include <RWGltf_CafWriter.hxx>
#include <RWMesh_FaceIterator.hxx>
#include <RWStl.hxx>
#include <RWStl_ConfigurationNode.hxx>
#include <RWStl_Provider.hxx>
//#include <RWObj.hxx>
#include <RWObj_ConfigurationNode.hxx>
#include <RWObj_Provider.hxx>
//#include <RWObj_CafReader.hxx>
//#include <RWObj_CafWriter.hxx>
#include <RWPly_ConfigurationNode.hxx>
#include <RWPly_Provider.hxx>
//#include <RWPly_CafWriter.hxx>
#include <RWPly_PlyWriterContext.hxx>
//#include <SelectMgr_SelectionManager.hxx>
//#include <Standard_ErrorHandler.hxx>
//#include <StdSelect_ViewerSelector3d.hxx>
//#include <StlAPI.hxx>
//#include <StlAPI_Writer.hxx>
//#include <TColgp_SequenceOfXYZ.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_HPackedMapOfInteger.hxx>
#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
#include <TDataStd_Name.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <UnitsAPI.hxx>
#include <UnitsMethods.hxx>
#include <V3d_View.hxx>
#include <ViewerTest.hxx>
#include <Vrml_ConfigurationNode.hxx>
#include <Vrml_Provider.hxx>
//#include <VrmlAPI.hxx>
//#include <VrmlAPI_Writer.hxx>
//#include <VrmlData_DataMapOfShapeAppearance.hxx>
//#include <VrmlData_Scene.hxx>
//#include <VrmlData_ShapeConvert.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFPrs_DocumentExplorer.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWIGES.hxx>
#include <XSDRAWSTEP.hxx>
#ifndef _STDIO_H
#include <stdio.h>
#endif
extern Standard_Boolean VDisplayAISObject(const TCollection_AsciiString& theName,
const Handle(AIS_InteractiveObject)& theAISObj,
Standard_Boolean theReplaceIfExists = Standard_True);
//=============================================================================
//function : parseNameFormat
//purpose : Parse RWMesh_NameFormat enumeration
//=============================================================================
static bool parseNameFormat(const char* theArg,
RWMesh_NameFormat& theFormat)
{
TCollection_AsciiString aName(theArg);
aName.LowerCase();
if (aName == "empty")
{
theFormat = RWMesh_NameFormat_Empty;
}
else if (aName == "product"
|| aName == "prod")
{
theFormat = RWMesh_NameFormat_Product;
}
else if (aName == "instance"
|| aName == "inst")
{
theFormat = RWMesh_NameFormat_Instance;
}
else if (aName == "instanceorproduct"
|| aName == "instance||product"
|| aName == "instance|product"
|| aName == "instorprod"
|| aName == "inst||prod"
|| aName == "inst|prod")
{
theFormat = RWMesh_NameFormat_InstanceOrProduct;
}
else if (aName == "productorinstance"
|| aName == "product||instance"
|| aName == "product|instance"
|| aName == "prodorinst"
|| aName == "prod||inst"
|| aName == "prod|inst")
{
theFormat = RWMesh_NameFormat_ProductOrInstance;
}
else if (aName == "productandinstance"
|| aName == "prodandinst"
|| aName == "product&instance"
|| aName == "prod&inst")
{
theFormat = RWMesh_NameFormat_ProductAndInstance;
}
else if (aName == "productandinstanceandocaf"
|| aName == "verbose"
|| aName == "debug")
{
theFormat = RWMesh_NameFormat_ProductAndInstanceAndOcaf;
}
else
{
return false;
}
return true;
}
//=============================================================================
//function : parseCoordinateSystem
//purpose : Parse RWMesh_CoordinateSystem enumeration
//=============================================================================
static bool parseCoordinateSystem(const char* theArg,
RWMesh_CoordinateSystem& theSystem)
{
TCollection_AsciiString aCSStr(theArg);
aCSStr.LowerCase();
if (aCSStr == "zup")
{
theSystem = RWMesh_CoordinateSystem_Zup;
}
else if (aCSStr == "yup")
{
theSystem = RWMesh_CoordinateSystem_Yup;
}
else
{
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : GetLengthUnit
//purpose : Gets length unit value from static interface and document in M
//=======================================================================
static Standard_Real GetLengthUnit(const Handle(TDocStd_Document)& theDoc = nullptr)
{
if (!theDoc.IsNull())
{
Standard_Real aUnit = 1.;
if (XCAFDoc_DocumentTool::GetLengthUnit(theDoc, aUnit,
UnitsMethods_LengthUnit_Millimeter))
{
return aUnit;
}
}
XSAlgo::AlgoContainer()->PrepareForTransfer();
return UnitsMethods::GetCasCadeLengthUnit();
}
//=============================================================================
//function : writestl
//purpose :
//=============================================================================
static Standard_Integer writestl(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3 || theNbArgs > 4)
{
theDI << "Use: " << theArgVec[0]
<< " shape file [ascii/binary (0/1) : 1 by default]\n";
}
else
{
TopoDS_Shape aShape = DBRep::Get(theArgVec[1]);
Standard_Boolean isASCIIMode = Standard_False;
if (theNbArgs == 4)
{
isASCIIMode = (Draw::Atoi(theArgVec[3]) == 0);
}
Handle(RWStl_ConfigurationNode) aNode = new RWStl_ConfigurationNode();
aNode->GlobalParameters.LengthUnit = GetLengthUnit();
Handle(RWStl_Provider) aProvider = new RWStl_Provider(aNode);
aNode->InternalParameters.WriteAscii = isASCIIMode;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI);
if (!aProvider->Write(theArgVec[2], aShape, aWS, aProgress->Start()))
{
theDI << "Error: Mesh writing has been failed.\n";
}
}
return 0;
}
//=============================================================================
//function : readstl
//purpose : Reads stl file
//=============================================================================
static Standard_Integer readstl(Draw_Interpretor& theDI,
Standard_Integer theArgc,
const char** theArgv)
{
TCollection_AsciiString aShapeName, aFilePath;
Handle(RWStl_ConfigurationNode) aNode = new RWStl_ConfigurationNode();
aNode->GlobalParameters.LengthUnit = GetLengthUnit();
//bool toCreateCompOfTris = false;
//bool anIsMulti = false;
//double aMergeAngle = M_PI / 2.0;
for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
{
TCollection_AsciiString anArg(theArgv[anArgIter]);
anArg.LowerCase();
if (aShapeName.IsEmpty())
{
aShapeName = theArgv[anArgIter];
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgv[anArgIter];
}
else if (anArg == "-brep")
{
Standard_Boolean toCreateCompOfTris = Standard_True;
if (anArgIter + 1 < theArgc
&& Draw::ParseOnOff(theArgv[anArgIter + 1], toCreateCompOfTris))
{
++anArgIter;
}
if (!toCreateCompOfTris)
{
aNode->InternalParameters.ReadShapeType =
RWStl_ConfigurationNode::ReadMode_ShapeType_CompShape;
}
}
else if (anArg == "-multi")
{
Standard_Boolean anIsMulti = Standard_True;
if (anArgIter + 1 < theArgc
&& Draw::ParseOnOff(theArgv[anArgIter + 1], anIsMulti))
{
++anArgIter;
}
if (anIsMulti)
{
aNode->InternalParameters.ReadShapeType =
RWStl_ConfigurationNode::ReadMode_ShapeType_MultiMesh;
}
}
else if (anArg == "-mergeangle"
|| anArg == "-smoothangle"
|| anArg == "-nomergeangle"
|| anArg == "-nosmoothangle")
{
if (anArg.StartsWith("-no"))
{
aNode->InternalParameters.ReadMergeAngle = M_PI / 2.0;
}
else
{
aNode->InternalParameters.ReadMergeAngle = M_PI / 4.0;
if (anArgIter + 1 < theArgc
&& Draw::ParseReal(theArgv[anArgIter + 1], aNode->InternalParameters.ReadMergeAngle))
{
if (aNode->InternalParameters.ReadMergeAngle < 0.0 ||
aNode->InternalParameters.ReadMergeAngle > 90.0)
{
theDI << "Syntax error: angle should be within [0,90] range";
return 1;
}
++anArgIter;
}
}
}
else
{
theDI << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty())
{
theDI << "Syntax error: not enough arguments\n";
return 1;
}
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(RWStl_Provider) aProvider = new RWStl_Provider(aNode);
TopoDS_Shape aShape;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Read(aFilePath, aShape, aWS, aProgress->Start()))
{
theDI << "Cannot read any relevant data from the STL file\n";
return 1;
}
DBRep::Set(aShapeName.ToCString(), aShape);
return 0;
}
//=======================================================================
//function : InitCommands
//purpose :
//=======================================================================
void XSDRAWSTL::InitCommands(Draw_Interpretor& theCommands)
{
const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
//XSDRAW::LoadDraw(theCommands);
theCommands.Add("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]", __FILE__, writestl, g);
theCommands.Add("readstl",
"readstl shape file [-brep] [-mergeAngle Angle] [-multi]"
"\n\t\t: Reads STL file and creates a new shape with specified name."
"\n\t\t: When -brep is specified, creates a Compound of per-triangle Faces."
"\n\t\t: Single triangulation-only Face is created otherwise (default)."
"\n\t\t: -mergeAngle specifies maximum angle in degrees between triangles to merge equal nodes; disabled by default."
"\n\t\t: -multi creates a face per solid in multi-domain files; ignored when -brep is set.",
__FILE__, readstl, g);
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAWSTL_HeaderFile
#define _XSDRAWSTL_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Draw_Interpretor.hxx>
class XSDRAWSTL
{
DEFINE_STANDARD_ALLOC
public:
Standard_EXPORT static void Init();
//! Loads all Draw commands of XSDRAWSTL. Used for plugin.
Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
};
#endif // _XSDRAWSTL_HeaderFile

File diff suppressed because it is too large Load Diff

2
src/XSDRAWVRML/FILES Normal file
View File

@@ -0,0 +1,2 @@
XSDRAWVRML.cxx
XSDRAWVRML.hxx

View File

@@ -0,0 +1,317 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <DE_ConfigurationContext.hxx>
#include <DE_Wrapper.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Message.hxx>
#include <IFSelect_SessionPilot.hxx>
#include <IGESCAFControl_ConfigurationNode.hxx>
#include <IGESCAFControl_Provider.hxx>
#include <OSD_OpenFile.hxx>
#include <OSD_Path.hxx>
#include <STEPCAFControl_ConfigurationNode.hxx>
#include <STEPCAFControl_Provider.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <XSDRAWVRML.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSControl_WorkSession.hxx>
#include <XSDRAW.hxx>
#include <Vrml_ConfigurationNode.hxx>
#include <Vrml_Provider.hxx>
#include <DBRep.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_Editor.hxx>
#include <TDF_Tool.hxx>
#include <TopoDS_Shape.hxx>
#include <Interface_Static.hxx>
#include <UnitsAPI.hxx>
#include <UnitsMethods.hxx>
#include <stdio.h>
//=======================================================================
//function : ReadVrml
//purpose :
//=======================================================================
static Standard_Integer ReadVrml(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI.PrintHelp(theArgVec[0]);
return 1;
}
Handle(Vrml_ConfigurationNode) aNode =
new Vrml_ConfigurationNode();
Handle(TDocStd_Document) aDoc;
Standard_Boolean toUseExistingDoc = Standard_False;
Standard_CString aDocName = NULL;
TCollection_AsciiString aFilePath;
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
for (Standard_Integer anArgIt = 1; anArgIt < theNbArgs; anArgIt++)
{
TCollection_AsciiString anArg(theArgVec[anArgIt]);
anArg.LowerCase();
if (anArgIt + 1 < theNbArgs && anArg == "-fileunit")
{
const TCollection_AsciiString aUnitStr(theArgVec[++anArgIt]);
aNode->InternalParameters.ReadFileUnit = UnitsAPI::AnyToSI(1.0, aUnitStr.ToCString());
if (aNode->InternalParameters.ReadFileUnit <= 0.0)
{
theDI << "Error: wrong length unit '" << aUnitStr << "'\n";
return 1;
}
}
else if (anArgIt + 1 < theNbArgs && anArg == "-filecoordsys")
{
if (!parseCoordinateSystem(theArgVec[++anArgIt], aNode->InternalParameters.ReadFileCoordinateSys))
{
theDI << "Error: unknown coordinate system '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
else if (anArgIt + 1 < theNbArgs && anArg == "-systemcoordsys")
{
if (!parseCoordinateSystem(theArgVec[++anArgIt], aNode->InternalParameters.ReadSystemCoordinateSys))
{
theDI << "Error: unknown coordinate system '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
else if (anArg == "-fillincomplete")
{
aNode->InternalParameters.ReadFillIncomplete = true;
if (anArgIt + 1 < theNbArgs &&
Draw::ParseOnOff(theArgVec[anArgIt + 1], aNode->InternalParameters.ReadFillIncomplete))
{
++anArgIt;
}
}
else if (anArg == "-nocreatedoc")
{
toUseExistingDoc = true;
}
else if (aDocName == nullptr)
{
aDocName = theArgVec[anArgIt];
DDocStd::GetDocument(aDocName, aDoc, Standard_False);
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgVec[anArgIt];
}
else
{
theDI << "Syntax error at '" << theArgVec[anArgIt] << "'\n";
return 1;
}
}
if (aFilePath.IsEmpty() || aDocName == nullptr)
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
if (aDoc.IsNull())
{
if (toUseExistingDoc)
{
theDI << "Error: document with name " << aDocName << " does not exist\n";
return 1;
}
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
anApp->NewDocument("BinXCAF", aDoc);
}
else if (!toUseExistingDoc)
{
theDI << "Error: document with name " << aDocName << " already exists\n";
return 1;
}
Handle(Vrml_Provider) aProvider =
new Vrml_Provider(aNode);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Read(aFilePath, aDoc, aWS, aProgress->Start()))
{
theDI << "Error: file reading failed '" << aFilePath << "'\n";
return 1;
}
TDataStd_Name::Set(aDoc->GetData()->Root(), aDocName);
Handle(DDocStd_DrawDocument) aDD = new DDocStd_DrawDocument(aDoc);
Draw::Set(aDocName, aDD);
CollectActiveWorkSessions(aWS, aFilePath, THE_PREVIOUS_WORK_SESSIONS);
return 0;
}
//=======================================================================
//function : WriteVrml
//purpose : Write DECAF document to Vrml
//=======================================================================
static Standard_Integer WriteVrml(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI << "Use: " << theArgVec[0] << " Doc filename: write document to Vrml file\n";
return 0;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(theArgVec[1], aDoc);
if (aDoc.IsNull())
{
theDI << theArgVec[1] << " is not a document\n";
return 1;
}
if (theNbArgs < 3 || theNbArgs > 5)
{
theDI << "wrong number of parameters\n";
return 0;
}
Handle(Vrml_ConfigurationNode) aNode =
new Vrml_ConfigurationNode();
aNode->GlobalParameters.LengthUnit = GetLengthUnit(aDoc);
Handle(Vrml_Provider) aProvider =
new Vrml_Provider(aNode);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Write(theArgVec[2], aDoc, aWS, aProgress->Start()))
{
theDI << "Error: file writing failed '" << theArgVec[2] << "'\n";
return 1;
}
CollectActiveWorkSessions(aWS, theArgVec[2], THE_PREVIOUS_WORK_SESSIONS);
return 0;
}
//=======================================================================
//function : loadvrml
//purpose :
//=======================================================================
static Standard_Integer loadvrml(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI << "Error: wrong number of parameters" << "\n";
return 1;
}
Handle(Vrml_ConfigurationNode) aNode =
new Vrml_ConfigurationNode();
aNode->GlobalParameters.LengthUnit = GetLengthUnit();
Handle(Vrml_Provider) aProvider =
new Vrml_Provider(aNode);
TopoDS_Shape aShape;
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
if (!aProvider->Read(theArgVec[2], aShape, aWS, aProgress->Start()))
{
theDI << "Error: file reading failed '" << theArgVec[2] << "'\n";
return 1;
}
DBRep::Set(theArgVec[1], aShape);
return 0;
}
//=============================================================================
//function : writevrml
//purpose :
//=============================================================================
static Standard_Integer writevrml(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3 || theNbArgs > 5)
{
theDI << "wrong number of parameters\n";
return 0;
}
TopoDS_Shape aShape = DBRep::Get(theArgVec[1]);
// Get the optional parameters
Standard_Integer aVersion = 2;
Standard_Integer aType = 1;
if (theNbArgs >= 4)
{
aVersion = Draw::Atoi(theArgVec[3]);
if (theNbArgs == 5)
aType = Draw::Atoi(theArgVec[4]);
}
// Bound parameters
aVersion = Max(1, aVersion);
aVersion = Min(2, aVersion);
aType = Max(0, aType);
aType = Min(2, aType);
Handle(Vrml_ConfigurationNode) aNode =
new Vrml_ConfigurationNode();
aNode->GlobalParameters.LengthUnit = GetLengthUnit();
Handle(Vrml_Provider) aProvider =
new Vrml_Provider(aNode);
aNode->InternalParameters.WriterVersion =
(Vrml_ConfigurationNode::WriteMode_WriterVersion)aVersion;
aNode->InternalParameters.WriteRepresentationType =
(Vrml_ConfigurationNode::WriteMode_RepresentationType)aType;
Handle(XSControl_WorkSession) aWS = XSDRAW::Session();
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
if (!aProvider->Write(theArgVec[2], aShape, aWS, aProgress->Start()))
{
theDI << "Error: file writing failed '" << theArgVec[2] << "'\n";
return 1;
}
return 0;
}
void XSDRAWVRML::InitCommands(Draw_Interpretor& theDI)
{
static Standard_Boolean initactor = Standard_False;
if (initactor)
{
return;
}
initactor = Standard_True;
Standard_CString g = "XDE translation commands";
theDI.Add("ReadVrml",
"ReadVrml docName filePath [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
"\n\t\t: [-systemCoordSys {Zup|Yup}] [-noCreateDoc] [-fillIncomplete {ON|OFF}]"
"\n\t\t: Read Vrml file into XDE document."
"\n\t\t: -fileCoordSys coordinate system defined by Vrml file; Yup when not specified."
"\n\t\t: -fileUnit length unit of Vrml file content."
"\n\t\t: -systemCoordSys result coordinate system; Zup when not specified."
"\n\t\t: -noCreateDoc read into existing XDE document."
"\n\t\t: -fillIncomplete fill the document with partially retrieved data even if reader has failed with "
"error; true when not specified",
__FILE__, ReadVrml, g);
theDI.Add("WriteVrml",
"WriteVrml Doc filename [version VRML#1.0/VRML#2.0 (1/2): 2 by default] [representation shaded/wireframe/both (0/1/2): 0 by default]",
__FILE__, WriteVrml, g);
theDI.Add("loadvrml", "shape file", __FILE__, loadvrml, g);
theDI.Add("writevrml", "shape file [version VRML#1.0/VRML#2.0 (1/2): 2 by default] [representation shaded/wireframe/both (0/1/2): 1 by default]", __FILE__, writevrml, g);
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _XSDRAWVRML_HeaderFile
#define _XSDRAWVRML_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Draw_Interpretor.hxx>
class XSDRAWVRML
{
DEFINE_STANDARD_ALLOC
public:
Standard_EXPORT static void Init();
//! Loads all Draw commands of XSDRAWSTL. Used for plugin.
Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
};
#endif // _XSDRAWVRML_HeaderFile