29#include <wx/filename.h>
30#include <wx/wfstream.h>
33#include <TDocStd_Document.hxx>
34#include <XCAFApp_Application.hxx>
35#include <XCAFDoc_DocumentTool.hxx>
36#include <XCAFDoc_ShapeTool.hxx>
37#include <XCAFDoc_ColorTool.hxx>
40#include <TopExp_Explorer.hxx>
43#include <BRepBndLib.hxx>
45#include <BRepTools.hxx>
46#include <BRep_Builder.hxx>
47#include <BRepBuilderAPI_Transform.hxx>
48#include <BRepBuilderAPI_GTransform.hxx>
50#include <STEPCAFControl_Reader.hxx>
51#include <STEPCAFControl_Writer.hxx>
52#include <Interface_Static.hxx>
54#include <XCAFDoc_Color.hxx>
55#include <Quantity_Color.hxx>
56#include <ShapeCustom.hxx>
59#define USER_PREC ( 0.14 )
62static void transformDoc( Handle( TDocStd_Document ) & source, Handle( TDocStd_Document ) & dest,
63 const gp_GTrsf& transform )
66 BRepBuilderAPI_GTransform brep( transform );
69 Handle( XCAFDoc_ShapeTool ) s_assy = XCAFDoc_DocumentTool::ShapeTool( source->Main() );
72 TDF_LabelSequence frshapes;
73 s_assy->GetFreeShapes( frshapes );
76 Handle( XCAFDoc_ShapeTool ) d_assy = XCAFDoc_DocumentTool::ShapeTool( dest->Main() );
78 int nshapes = frshapes.Length();
80 Handle( XCAFDoc_ColorTool ) scolor = XCAFDoc_DocumentTool::ColorTool( source->Main() );
81 Handle( XCAFDoc_ColorTool ) dcolor = XCAFDoc_DocumentTool::ColorTool( dest->Main() );
85 while(
id <= nshapes )
87 TopoDS_Shape shape = s_assy->GetShape( frshapes.Value(
id ) );
91 TopoDS_Shape transformed_shape( shape );
93 if( transform.Trsf().ScaleFactor() != 1.0 )
96 ShapeCustom::ScaleShape( shape, transform.Trsf().ScaleFactor() );
100 brep.Perform( shape, Standard_False );
103 transformed_shape = brep.Shape();
106 TDF_Label niulab = d_assy->AddShape( transformed_shape,
false,
false );
109 stop.Init( shape, TopAbs_FACE );
110 dtop.Init( d_assy->GetShape( niulab ), TopAbs_FACE );
112 while( stop.More() && dtop.More() )
114 Quantity_Color face_color;
119 if( s_assy->FindShape( stop.Current(), tl ) )
121 if( scolor->GetColor( tl, XCAFDoc_ColorSurf, face_color )
122 || scolor->GetColor( tl, XCAFDoc_ColorGen, face_color )
123 || scolor->GetColor( tl, XCAFDoc_ColorCurv, face_color ) )
125 dcolor->SetColor( dtop.Current(), face_color, XCAFDoc_ColorSurf );
128 else if( scolor->GetColor( stop.Current(), XCAFDoc_ColorSurf, face_color )
129 || scolor->GetColor( stop.Current(), XCAFDoc_ColorGen, face_color )
130 || scolor->GetColor( stop.Current(), XCAFDoc_ColorCurv, face_color ) )
132 dcolor->SetColor( dtop.Current(), face_color, XCAFDoc_ColorSurf );
140 stop.Init( shape, TopAbs_SOLID );
141 dtop.Init( d_assy->GetShape( niulab ), TopAbs_SOLID, TopAbs_FACE );
143 while( stop.More() && dtop.More() )
145 Quantity_Color face_color;
150 if( s_assy->FindShape( stop.Current(), tl ) )
152 if( scolor->GetColor( tl, XCAFDoc_ColorSurf, face_color )
153 || scolor->GetColor( tl, XCAFDoc_ColorGen, face_color )
154 || scolor->GetColor( tl, XCAFDoc_ColorCurv, face_color ) )
156 dcolor->SetColor( dtop.Current(), face_color, XCAFDoc_ColorGen );
159 else if( scolor->GetColor( stop.Current(), XCAFDoc_ColorSurf, face_color )
160 || scolor->GetColor( stop.Current(), XCAFDoc_ColorGen, face_color )
161 || scolor->GetColor( stop.Current(), XCAFDoc_ColorCurv, face_color ) )
163 dcolor->SetColor( dtop.Current(), face_color, XCAFDoc_ColorSurf );
211 std::unique_ptr<UTILS_STEP_MODEL::DATA> data = std::make_unique<UTILS_STEP_MODEL::DATA>();
213 Handle( XCAFApp_Application ) m_app = XCAFApp_Application::GetApplication();
214 m_app->NewDocument(
"MDTV-XCAF", data->m_frontDoc );
215 m_app->NewDocument(
"MDTV-XCAF", data->m_backDoc );
217 STEPCAFControl_Reader reader;
218 IFSelect_ReturnStatus stat = reader.ReadFile( aFileName.ToStdString().c_str() );
220 if( stat != IFSelect_RetDone )
224 if( !Interface_Static::SetIVal(
"read.precision.mode", 1 ) )
228 if( !Interface_Static::SetRVal(
"read.precision.val",
USER_PREC ) )
232 reader.SetColorMode(
true );
233 reader.SetNameMode(
true );
234 reader.SetLayerMode(
false );
236 if( !reader.Transfer( data->m_frontDoc ) )
239 data->m_cafReader = reader;
242 model->
m_data = data.release();
255 Handle( XCAFDoc_ShapeTool ) assy =
256 XCAFDoc_DocumentTool::ShapeTool(
m_data->m_frontDoc->Main() );
258 TDF_LabelSequence frshapes;
259 assy->GetFreeShapes( frshapes );
261 int nshapes = frshapes.Length();
268 for(
const TDF_Label& label : frshapes )
270 TopoDS_Shape shape = assy->GetShape( label );
271 BRepBndLib::Add( shape, bbox );
274 gp_Pnt min = bbox.CornerMin();
275 gp_Pnt max = bbox.CornerMax();
277 result.
Min().
x = min.X();
278 result.
Min().
y = min.Y();
279 result.
Min().
z = min.Z();
281 result.
Max().
x = max.X();
282 result.
Max().
y = max.Y();
283 result.
Max().
z = max.Z();
293 transform.SetTranslation( gp_Vec( aX, aY, aZ ) );
298 Handle( XCAFApp_Application ) m_app = XCAFApp_Application::GetApplication();
300 m_data->m_backDoc->Main().ForgetAllAttributes();
301 m_app->Close(
m_data->m_backDoc );
302 m_app->NewDocument(
"MDTV-XCAF",
m_data->m_backDoc );
311 transform.SetScaleFactor( aScale );
316 Handle( XCAFApp_Application ) m_app = XCAFApp_Application::GetApplication();
318 m_data->m_backDoc->Main().ForgetAllAttributes();
319 m_app->Close(
m_data->m_backDoc );
320 m_app->NewDocument(
"MDTV-XCAF",
m_data->m_backDoc );
326 STEPCAFControl_Writer writer;
327 writer.SetColorMode(
true );
328 writer.SetNameMode(
true );
331 if( !Interface_Static::SetIVal(
"write.surfacecurve.mode", 0 ) )
334 if( !writer.Transfer(
m_data->m_frontDoc, STEPControl_AsIs ) )
337 if( writer.Write( aFileName.ToStdString().c_str() ) != IFSelect_RetDone )
340 Handle( XCAFApp_Application ) m_app = XCAFApp_Application::GetApplication();
342 m_data->m_frontDoc->Main().ForgetAllAttributes();
343 m_data->m_backDoc->Main().ForgetAllAttributes();
345 m_app->Close(
m_data->m_frontDoc );
346 m_app->Close(
m_data->m_backDoc );
static UTILS_STEP_MODEL * LoadSTEP(const wxString &aFileName)
bool SaveSTEP(const wxString &aFileName)
void Scale(double aScale)
UTILS_BOX3D GetBoundingBox()
void Translate(double aX, double aY, double aZ)
static void transformDoc(Handle(TDocStd_Document) &source, Handle(TDocStd_Document) &dest, const gp_GTrsf &transform)
Handle(TDocStd_Document) m_frontDoc
STEPCAFControl_Reader m_cafReader
Handle(TDocStd_Document) m_backDoc
VECTOR3< double > VECTOR3D