mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
239
samples/qt/Interface/src/Application.cxx
Executable file
239
samples/qt/Interface/src/Application.cxx
Executable file
@@ -0,0 +1,239 @@
|
||||
#include "Application.h"
|
||||
|
||||
#include "Translate.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <stdlib.h>
|
||||
|
||||
ApplicationWindow::ApplicationWindow()
|
||||
: ApplicationCommonWindow( ),
|
||||
myImportPopup( 0 ),
|
||||
myExportPopup( 0 )
|
||||
{
|
||||
createTranslatePopups();
|
||||
}
|
||||
|
||||
ApplicationWindow::~ApplicationWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void ApplicationWindow::createTranslatePopups()
|
||||
{
|
||||
if ( !myImportPopup )
|
||||
myImportPopup = new QMenu( QObject::tr( "MNU_FILE_IMPORT" ), this );
|
||||
|
||||
if ( !myExportPopup )
|
||||
myExportPopup = new QMenu( QObject::tr( "MNU_FILE_EXPORT" ), this );
|
||||
|
||||
QAction* a;
|
||||
a = new QAction( QObject::tr("MNU_IMPORT_BREP"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_IMPORT_BREP") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onImport() ) );
|
||||
myCasCadeTranslateActions.insert( FileImportBREPId, a );
|
||||
myImportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_EXPORT_BREP"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_EXPORT_BREP") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onExport() ) );
|
||||
myCasCadeTranslateActions.insert( FileExportBREPId, a );
|
||||
myExportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_IMPORT_CSFDB"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_IMPORT_CSFDB") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onImport() ) );
|
||||
myCasCadeTranslateActions.insert( FileImportCSFDBId, a );
|
||||
myImportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_EXPORT_CSFDB"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_EXPORT_CSFDB") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onExport() ) );
|
||||
myCasCadeTranslateActions.insert( FileExportCSFDBId, a );
|
||||
myExportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_IMPORT_IGES"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_IMPORT_IGES") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onImport() ) );
|
||||
myCasCadeTranslateActions.insert( FileImportIGESId, a );
|
||||
myImportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_EXPORT_IGES"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_EXPORT_IGES") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onExport() ) );
|
||||
myCasCadeTranslateActions.insert( FileExportIGESId, a );
|
||||
myExportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_IMPORT_STEP"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_IMPORT_STEP") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onImport() ) );
|
||||
myCasCadeTranslateActions.insert( FileImportSTEPId, a );
|
||||
myImportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_EXPORT_STEP"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_EXPORT_STEP") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onExport() ) );
|
||||
myCasCadeTranslateActions.insert( FileExportSTEPId, a );
|
||||
myExportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_EXPORT_STL"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_EXPORT_STL") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onExport() ) );
|
||||
myCasCadeTranslateActions.insert( FileExportSTLId, a );
|
||||
myExportPopup->addAction( a );
|
||||
|
||||
a = new QAction( QObject::tr("MNU_EXPORT_VRML"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_EXPORT_VRML") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onExport() ) );
|
||||
myCasCadeTranslateActions.insert( FileExportVRMLId, a );
|
||||
myExportPopup->addAction( a );
|
||||
|
||||
myExportPopup->addSeparator();
|
||||
|
||||
a = new QAction( QObject::tr("MNU_EXPORT_IMAGE"), this );
|
||||
a->setStatusTip( QObject::tr("TBR_EXPORT_IMAGE") );
|
||||
connect( a, SIGNAL( activated() ), this, SLOT( onExportImage() ) );
|
||||
myExportPopup->addAction( a );
|
||||
}
|
||||
|
||||
void ApplicationWindow::updateFileActions()
|
||||
{
|
||||
if ( getWorkspace()->windowList().isEmpty() )
|
||||
{
|
||||
if ( !isDocument() )
|
||||
{
|
||||
getFilePopup()->insertMenu( getFileSeparator(), myExportPopup );
|
||||
getFilePopup()->insertMenu( myExportPopup->menuAction(), myImportPopup );
|
||||
mySeparator = getFilePopup()->insertSeparator( myImportPopup->menuAction() );
|
||||
}
|
||||
else
|
||||
{
|
||||
getFilePopup()->removeAction( myImportPopup->menuAction() );
|
||||
getFilePopup()->removeAction( myExportPopup->menuAction() );
|
||||
getFilePopup()->removeAction( mySeparator );
|
||||
}
|
||||
}
|
||||
ApplicationCommonWindow::updateFileActions();
|
||||
}
|
||||
|
||||
void ApplicationWindow::onImport()
|
||||
{
|
||||
QAction* a = (QAction*)sender();
|
||||
int type = translationFormat( a );
|
||||
if ( type < 0 )
|
||||
return;
|
||||
|
||||
bool stat = translate( type, true );
|
||||
if ( stat )
|
||||
{
|
||||
DocumentCommon* doc = ((MDIWindow*) getWorkspace()->activeWindow())->getDocument();
|
||||
doc->fitAll();
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationWindow::onExport()
|
||||
{
|
||||
QAction* a = (QAction*)sender();
|
||||
int type = translationFormat( a );
|
||||
if ( type < 0 )
|
||||
return;
|
||||
|
||||
bool stat = translate( type, false );
|
||||
}
|
||||
|
||||
int ApplicationWindow::translationFormat( const QAction* a )
|
||||
{
|
||||
int type = -1;
|
||||
for ( int i = FileImportBREPId; i <= FileExportVRMLId; i++ )
|
||||
{
|
||||
if ( myCasCadeTranslateActions.at( i ) == a )
|
||||
{
|
||||
type = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch ( type )
|
||||
{
|
||||
case FileImportBREPId:
|
||||
case FileExportBREPId:
|
||||
type = Translate::FormatBREP;
|
||||
break;
|
||||
case FileImportIGESId:
|
||||
case FileExportIGESId:
|
||||
type = Translate::FormatIGES;
|
||||
break;
|
||||
case FileImportSTEPId:
|
||||
case FileExportSTEPId:
|
||||
type = Translate::FormatSTEP;
|
||||
break;
|
||||
case FileImportCSFDBId:
|
||||
case FileExportCSFDBId:
|
||||
type = Translate::FormatCSFDB;
|
||||
break;
|
||||
case FileExportSTLId:
|
||||
type = Translate::FormatSTL;
|
||||
break;
|
||||
case FileExportVRMLId:
|
||||
type = Translate::FormatVRML;
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
bool ApplicationWindow::translate( const int format, const bool import )
|
||||
{
|
||||
static Translate* anTrans = createTranslator();
|
||||
DocumentCommon* doc = ((MDIWindow*) getWorkspace()->activeWindow())->getDocument();
|
||||
Handle(AIS_InteractiveContext) context = doc->getContext();
|
||||
bool status;
|
||||
if ( import )
|
||||
status = anTrans->importModel( format, context );
|
||||
else
|
||||
status = anTrans->exportModel( format, context );
|
||||
|
||||
if ( !status )
|
||||
{
|
||||
QString msg = QObject::tr( "INF_TRANSLATE_ERROR" );
|
||||
if ( !anTrans->info().isEmpty() )
|
||||
msg += QString( "\n" ) + anTrans->info();
|
||||
QMessageBox::critical( this, QObject::tr( "TIT_ERROR" ), msg, QObject::tr( "BTN_OK" ), QString::null, QString::null, 0, 0 );
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Translate* ApplicationWindow::createTranslator()
|
||||
{
|
||||
Translate* anTrans = new Translate( this/*, "Translator"*/ );
|
||||
return anTrans;
|
||||
}
|
||||
|
||||
void ApplicationWindow::onSelectionChanged()
|
||||
{
|
||||
ApplicationCommonWindow::onSelectionChanged();
|
||||
|
||||
QWorkspace* ws = getWorkspace();
|
||||
DocumentCommon* doc = ((MDIWindow*)ws->activeWindow())->getDocument();
|
||||
Handle(AIS_InteractiveContext) context = doc->getContext();
|
||||
int numSel = context->NbSelected();
|
||||
|
||||
myCasCadeTranslateActions.at( FileExportBREPId )->setEnabled( numSel );
|
||||
myCasCadeTranslateActions.at( FileExportCSFDBId )->setEnabled( numSel );
|
||||
myCasCadeTranslateActions.at( FileExportIGESId )->setEnabled( numSel );
|
||||
myCasCadeTranslateActions.at( FileExportSTEPId )->setEnabled( numSel );
|
||||
myCasCadeTranslateActions.at( FileExportSTLId )->setEnabled( numSel );
|
||||
myCasCadeTranslateActions.at( FileExportVRMLId )->setEnabled( numSel );
|
||||
}
|
||||
|
||||
QString ApplicationWindow::getIEResourceDir()
|
||||
{
|
||||
static QString resDir( ::getenv( "CSF_IEResourcesDefaults" ) );
|
||||
return resDir;
|
||||
}
|
||||
|
||||
void ApplicationWindow::onExportImage()
|
||||
{
|
||||
MDIWindow* w = (MDIWindow*)getWorkspace()->activeWindow();
|
||||
if ( w )
|
||||
w->dump();
|
||||
}
|
||||
|
||||
|
49
samples/qt/Interface/src/Application.h
Executable file
49
samples/qt/Interface/src/Application.h
Executable file
@@ -0,0 +1,49 @@
|
||||
#ifndef APPLICATION_H
|
||||
#define APPLICATION_H
|
||||
|
||||
#include "ApplicationCommon.h"
|
||||
#include "IESample.h"
|
||||
|
||||
class Translate;
|
||||
|
||||
class IESAMPLE_EXPORT ApplicationWindow: public ApplicationCommonWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
enum { FileImportBREPId=0, FileExportBREPId=1, FileImportCSFDBId=2, FileExportCSFDBId=3,
|
||||
FileImportIGESId=4, FileExportIGESId=5, FileImportSTEPId=6, FileExportSTEPId=7,
|
||||
FileExportSTLId=8, FileExportVRMLId=9 };
|
||||
|
||||
ApplicationWindow();
|
||||
~ApplicationWindow();
|
||||
|
||||
static QString getIEResourceDir();
|
||||
|
||||
virtual void updateFileActions();
|
||||
|
||||
public slots:
|
||||
void onImport();
|
||||
void onExport();
|
||||
void onExportImage();
|
||||
virtual void onSelectionChanged();
|
||||
|
||||
protected:
|
||||
virtual int translationFormat( const QAction* );
|
||||
virtual Translate* createTranslator();
|
||||
|
||||
private:
|
||||
void createTranslatePopups();
|
||||
bool translate( const int, const bool );
|
||||
|
||||
protected:
|
||||
QList<QAction*> myCasCadeTranslateActions;
|
||||
QMenu* myImportPopup;
|
||||
QMenu* myExportPopup;
|
||||
QAction* mySeparator;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
22
samples/qt/Interface/src/IESample.h
Executable file
22
samples/qt/Interface/src/IESample.h
Executable file
@@ -0,0 +1,22 @@
|
||||
#ifndef IESAMPLE_H
|
||||
#define IESAMPLE_H
|
||||
|
||||
#ifndef NO_IESAMPLE_EXPORTS
|
||||
#ifdef IESAMPLE_EXPORTS
|
||||
#ifdef WIN32
|
||||
#define IESAMPLE_EXPORT __declspec( dllexport )
|
||||
#else
|
||||
#define IESAMPLE_EXPORT
|
||||
#endif
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#define IESAMPLE_EXPORT __declspec( dllimport )
|
||||
#else
|
||||
#define IESAMPLE_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define IESAMPLE_EXPORT
|
||||
#endif
|
||||
|
||||
#endif
|
230
samples/qt/Interface/src/Interface-string.ts
Executable file
230
samples/qt/Interface/src/Interface-string.ts
Executable file
@@ -0,0 +1,230 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS><TS version="1.1">
|
||||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<source>INF_ABOUT</source>
|
||||
<translation>Qt based application for Import / Export CASCADE operations.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_EXPOR_CSFDB</source>
|
||||
<translation>Csfdb ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_NOTHING_ERROR</source>
|
||||
<translation>Nothing to transfer.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_APP_IMPORT</source>
|
||||
<translation>Import file</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_APP_EXPORT</source>
|
||||
<translation>Export file</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_EXPORT_STL</source>
|
||||
<translation>Stl ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TIT_SAMPLE</source>
|
||||
<translation>Sample Import / Export</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_DATA_ERROR</source>
|
||||
<translation>Incorrect Data.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_FACET_ERROR</source>
|
||||
<translation>At least one shape doesn't contain facetes.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_TRANSLATE_FILENOTFOUND</source>
|
||||
<translation>File "%1" not found.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_TRANSLATE_ERROR</source>
|
||||
<translation>The translation is not done.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_TRANSLATE_ERROR_CANTSAVEDATA</source>
|
||||
<translation>Can't store persistent data.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_TRANSLATE_ERROR_CANTSAVEFILE</source>
|
||||
<translation>Can't save file "%1".</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_EXPORT_STL</source>
|
||||
<translation>&Stl ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_FILE_EXPORT</source>
|
||||
<translation>&Export</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_FILE_IMPORT</source>
|
||||
<translation>&Import</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TIT_ABOUT</source>
|
||||
<translation>Sample ImportExport.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_EXPORT_CSFDB</source>
|
||||
<translation>&Csfdb ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_EXPORT_IMAGE</source>
|
||||
<translation>&Image</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_EXPORT_IMAGE</source>
|
||||
<translation>Image</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_IMPORT_CSFDB</source>
|
||||
<translation>&Csfdb ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_IMPORT_CSFDB</source>
|
||||
<translation>Csfdb ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_TRANSLATE_ERROR_INVALIDSHAPE</source>
|
||||
<translation>Some shapes are invalid.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_EXPORT_IGES</source>
|
||||
<translation>&Iges ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_EXPORT_BREP</source>
|
||||
<translation>&Brep ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_IMPORT_STEP</source>
|
||||
<translation>&Step ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_IMPORT_BREP</source>
|
||||
<translation>&Brep ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_IMPORT_IGES</source>
|
||||
<translation>&Iges ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_EXPORT_STEP</source>
|
||||
<translation>&Step ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MNU_EXPORT_VRML</source>
|
||||
<translation>&Vrml ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_EXPORT_IGES</source>
|
||||
<translation>Iges ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_EXPORT_BREP</source>
|
||||
<translation>Brep ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_IMPORT_STEP</source>
|
||||
<translation>Step ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_IMPORT_BREP</source>
|
||||
<translation>Brep ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_IMPORT_IGES</source>
|
||||
<translation>Iges ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_EXPORT_STEP</source>
|
||||
<translation>Step ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>TBR_EXPORT_VRML</source>
|
||||
<translation>Vrml ...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_TRIANGLES_NO</source>
|
||||
<translation>Export Without Triangles</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_BREP_MOIFOLD</source>
|
||||
<translation>Manifold Solid Brep</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_PATH_0</source>
|
||||
<translation>/../data/occ</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_PATH_1</source>
|
||||
<translation>/../data/iges</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_PATH_2</source>
|
||||
<translation>/../data/step</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_PATH_3</source>
|
||||
<translation>/../data/csfdb</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_PATH_4</source>
|
||||
<translation>/../data/vrml</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_PATH_5</source>
|
||||
<translation>/../data/stl</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_FILTER_FORMAT_ALL</source>
|
||||
<translation>All Files (*.*)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_BREP_SHELL</source>
|
||||
<translation>Shell Based Surface Model</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_BREP_CURVE</source>
|
||||
<translation>Geometric Curve Set</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_BREP_FACETED</source>
|
||||
<translation>Faceted Brep</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_TRIANGLES_YES</source>
|
||||
<translation>Export With Triangles</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_FILTER_FORMAT_0</source>
|
||||
<translation>BREP Files (*.brep *.rle)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_FILTER_FORMAT_1</source>
|
||||
<translation>IGES Files (*.igs *.iges)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_FILTER_FORMAT_2</source>
|
||||
<translation>STEP Files (*.stp *.step)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_FILTER_FORMAT_3</source>
|
||||
<translation>CSFDB Files (*.csfdb)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_FILTER_FORMAT_4</source>
|
||||
<translation>VRML Files (*.vrml)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>INF_FILTER_FORMAT_5</source>
|
||||
<translation>STL Files (*.stl)</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
714
samples/qt/Interface/src/Translate.cxx
Executable file
714
samples/qt/Interface/src/Translate.cxx
Executable file
@@ -0,0 +1,714 @@
|
||||
#if !defined(CSFDB)
|
||||
#error CSFDB precompiler directive is mandatory for CasCade
|
||||
#endif
|
||||
|
||||
#include "Translate.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QLayout>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QList>
|
||||
#include <QListView>
|
||||
#include <QFileDialog>
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
|
||||
#include <AIS_Shape.hxx>
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
|
||||
#include <FSD_File.hxx>
|
||||
|
||||
#include <ShapeSchema.hxx>
|
||||
#include <Storage_Data.hxx>
|
||||
#include <Storage_Root.hxx>
|
||||
#include <Storage_HSeqOfRoot.hxx>
|
||||
#include <PTopoDS_HShape.hxx>
|
||||
#include <PTColStd_PersistentTransientMap.hxx>
|
||||
#include <PTColStd_TransientPersistentMap.hxx>
|
||||
|
||||
#include <IGESControl_Reader.hxx>
|
||||
#include <IGESControl_Writer.hxx>
|
||||
#include <IGESControl_Controller.hxx>
|
||||
#include <STEPControl_Reader.hxx>
|
||||
#include <STEPControl_Writer.hxx>
|
||||
#include <STEPControl_StepModelType.hxx>
|
||||
#include <Interface_Static.hxx>
|
||||
//#include <Interface_TraceFile.hxx>
|
||||
|
||||
#include <StlAPI_Writer.hxx>
|
||||
#include <VrmlAPI_Writer.hxx>
|
||||
|
||||
#include <MgtBRep.hxx>
|
||||
#include <MgtBRep_TriangleMode.hxx>
|
||||
|
||||
#include <BRepTools.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopTools_HSequenceOfShape.hxx>
|
||||
|
||||
#include <Geom_Line.hxx>
|
||||
#include <Geom_Curve.hxx>
|
||||
#include <Geom_Plane.hxx>
|
||||
#include <Geom_Surface.hxx>
|
||||
|
||||
|
||||
#include <Standard_ErrorHandler.hxx>
|
||||
#include <Standard_CString.hxx>
|
||||
|
||||
// ---------------------------- TranslateDlg -----------------------------------------
|
||||
|
||||
class TranslateDlg : public QFileDialog
|
||||
{
|
||||
public:
|
||||
TranslateDlg( QWidget* = 0, Qt::WindowFlags flags = 0, bool = true );
|
||||
~TranslateDlg();
|
||||
int getMode() const;
|
||||
void setMode( const int );
|
||||
void addMode( const int, const QString& );
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
void showEvent ( QShowEvent* event );
|
||||
|
||||
private:
|
||||
QListView* findListView( const QObjectList& );
|
||||
|
||||
private:
|
||||
QComboBox* myBox;
|
||||
QList<int> myList;
|
||||
};
|
||||
|
||||
TranslateDlg::TranslateDlg( QWidget* parent, Qt::WindowFlags flags, bool modal )
|
||||
: QFileDialog( parent, flags )
|
||||
{
|
||||
setModal( modal );
|
||||
QGridLayout* grid = ::qobject_cast<QGridLayout*>( layout() );
|
||||
|
||||
if( grid )
|
||||
{
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
|
||||
QWidget* paramGroup = new QWidget( this );
|
||||
paramGroup->setLayout( vbox );
|
||||
|
||||
myBox = new QComboBox( paramGroup );
|
||||
vbox->addWidget( myBox );
|
||||
|
||||
int row = grid->rowCount();
|
||||
grid->addWidget( paramGroup, row, 1, 1, 3 ); // make combobox occupy 1 row and 3 columns starting from 1
|
||||
}
|
||||
}
|
||||
|
||||
TranslateDlg::~TranslateDlg()
|
||||
{
|
||||
}
|
||||
|
||||
int TranslateDlg::getMode() const
|
||||
{
|
||||
if ( myBox->currentIndex() < 0 || myBox->currentIndex() > (int)myList.count() - 1 )
|
||||
return -1;
|
||||
else
|
||||
return myList.at( myBox->currentIndex() );
|
||||
}
|
||||
|
||||
void TranslateDlg::setMode( const int mode )
|
||||
{
|
||||
int idx = myList.indexOf( mode );
|
||||
if ( idx >= 0 )
|
||||
myBox->setCurrentIndex( idx );
|
||||
}
|
||||
|
||||
void TranslateDlg::addMode( const int mode, const QString& name )
|
||||
{
|
||||
myBox->show();
|
||||
myBox->addItem( name );
|
||||
myList.append( mode );
|
||||
myBox->updateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void TranslateDlg::clear()
|
||||
{
|
||||
myList.clear();
|
||||
myBox->clear();
|
||||
myBox->hide();
|
||||
myBox->updateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
QListView* TranslateDlg::findListView( const QObjectList & childList )
|
||||
{
|
||||
QListView* listView = 0;
|
||||
for ( int i = 0, n = childList.count(); i < n && !listView; i++ )
|
||||
{
|
||||
listView = qobject_cast<QListView*>( childList.at( i ) );
|
||||
if ( !listView && childList.at( i ) )
|
||||
{
|
||||
listView = findListView( childList.at( i )->children() );
|
||||
}
|
||||
}
|
||||
return listView;
|
||||
}
|
||||
|
||||
void TranslateDlg::showEvent ( QShowEvent* event )
|
||||
{
|
||||
QFileDialog::showEvent ( event );
|
||||
QListView* aListView = findListView( children() );
|
||||
aListView->setViewMode( QListView::ListMode );
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------- Translate -----------------------------------------
|
||||
|
||||
Translate::Translate( QObject* parent )
|
||||
: QObject( parent ),
|
||||
myDlg( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
Translate::~Translate()
|
||||
{
|
||||
if ( myDlg )
|
||||
delete myDlg;
|
||||
}
|
||||
|
||||
QString Translate::info() const
|
||||
{
|
||||
return myInfo;
|
||||
}
|
||||
|
||||
bool Translate::importModel( const int format, const Handle(AIS_InteractiveContext)& ic )
|
||||
{
|
||||
myInfo = QString();
|
||||
QString fileName = selectFileName( format, true );
|
||||
if ( fileName.isEmpty() )
|
||||
return true;
|
||||
|
||||
if ( !QFileInfo( fileName ).exists() )
|
||||
{
|
||||
myInfo = QObject::tr( "INF_TRANSLATE_FILENOTFOUND" ).arg( fileName );
|
||||
return false;
|
||||
}
|
||||
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
Handle(TopTools_HSequenceOfShape) shapes = importModel( format, fileName );
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
return displayShSequence(ic, shapes);
|
||||
}
|
||||
|
||||
bool Translate::displayShSequence(const Handle(AIS_InteractiveContext)& ic,
|
||||
const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
if ( shapes.IsNull() || !shapes->Length() )
|
||||
return false;
|
||||
|
||||
for ( int i = 1; i <= shapes->Length(); i++ )
|
||||
ic->Display( new AIS_Shape( shapes->Value( i ) ), false );
|
||||
ic->UpdateCurrentViewer();
|
||||
return true;
|
||||
}
|
||||
|
||||
Handle(TopTools_HSequenceOfShape) Translate::importModel( const int format, const QString& file )
|
||||
{
|
||||
Handle(TopTools_HSequenceOfShape) shapes;
|
||||
try {
|
||||
switch ( format )
|
||||
{
|
||||
case FormatBREP:
|
||||
shapes = importBREP( file );
|
||||
break;
|
||||
case FormatIGES:
|
||||
shapes = importIGES( file );
|
||||
break;
|
||||
case FormatSTEP:
|
||||
shapes = importSTEP( file );
|
||||
break;
|
||||
case FormatCSFDB:
|
||||
shapes = importCSFDB( file );
|
||||
break;
|
||||
}
|
||||
} catch ( Standard_Failure ) {
|
||||
shapes.Nullify();
|
||||
}
|
||||
return shapes;
|
||||
}
|
||||
|
||||
bool Translate::exportModel( const int format, const Handle(AIS_InteractiveContext)& ic )
|
||||
{
|
||||
myInfo = QString();
|
||||
QString fileName = selectFileName( format, false );
|
||||
if ( fileName.isEmpty() )
|
||||
return true;
|
||||
|
||||
Handle(TopTools_HSequenceOfShape) shapes = getShapes( ic );
|
||||
if ( shapes.IsNull() || !shapes->Length() )
|
||||
return false;
|
||||
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
bool stat = exportModel( format, fileName, shapes );
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
bool Translate::exportModel( const int format, const QString& file, const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
bool status;
|
||||
try {
|
||||
switch ( format )
|
||||
{
|
||||
case FormatBREP:
|
||||
status = exportBREP( file, shapes );
|
||||
break;
|
||||
case FormatIGES:
|
||||
status = exportIGES( file, shapes );
|
||||
break;
|
||||
case FormatSTEP:
|
||||
status = exportSTEP( file, shapes );
|
||||
break;
|
||||
case FormatCSFDB:
|
||||
status = exportCSFDB( file, shapes );
|
||||
break;
|
||||
case FormatSTL:
|
||||
status = exportSTL( file, shapes );
|
||||
break;
|
||||
case FormatVRML:
|
||||
status = exportVRML( file, shapes );
|
||||
break;
|
||||
}
|
||||
} catch ( Standard_Failure ) {
|
||||
status = false;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Handle(TopTools_HSequenceOfShape) Translate::getShapes( const Handle(AIS_InteractiveContext)& ic )
|
||||
{
|
||||
Handle(TopTools_HSequenceOfShape) aSequence;
|
||||
Handle(AIS_InteractiveObject) picked;
|
||||
for ( ic->InitCurrent(); ic->MoreCurrent(); ic->NextCurrent() )
|
||||
{
|
||||
Handle(AIS_InteractiveObject) obj = ic->Current();
|
||||
if ( obj->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
|
||||
{
|
||||
TopoDS_Shape shape = Handle(AIS_Shape)::DownCast(obj)->Shape();
|
||||
if ( aSequence.IsNull() )
|
||||
aSequence = new TopTools_HSequenceOfShape();
|
||||
aSequence->Append( shape );
|
||||
}
|
||||
}
|
||||
return aSequence;
|
||||
}
|
||||
|
||||
/*!
|
||||
Selects a file from standard dialog acoording to selection 'filter'
|
||||
*/
|
||||
QString Translate::selectFileName( const int format, const bool import )
|
||||
{
|
||||
TranslateDlg* theDlg = getDialog( format, import );
|
||||
|
||||
int ret = theDlg->exec();
|
||||
|
||||
qApp->processEvents();
|
||||
|
||||
QString file;
|
||||
QStringList fileNames;
|
||||
if ( ret != QDialog::Accepted )
|
||||
return file;
|
||||
|
||||
fileNames = theDlg->selectedFiles();
|
||||
if (!fileNames.isEmpty())
|
||||
file = fileNames[0];
|
||||
|
||||
if ( !QFileInfo( file ).completeSuffix().length() )
|
||||
{
|
||||
QString selFilter = theDlg->selectedFilter();
|
||||
int idx = selFilter.indexOf( "(*." );
|
||||
if ( idx != -1 )
|
||||
{
|
||||
QString tail = selFilter.mid( idx + 3 );
|
||||
int idx = tail.indexOf( " " );
|
||||
if ( idx == -1 )
|
||||
idx = tail.indexOf( ")" );
|
||||
QString ext = tail.left( idx );
|
||||
if ( ext.length() )
|
||||
file += QString( "." ) + ext;
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
TranslateDlg* Translate::getDialog( const int format, const bool import )
|
||||
{
|
||||
if ( !myDlg )
|
||||
myDlg = new TranslateDlg( 0, 0, true );
|
||||
|
||||
if ( format < 0 )
|
||||
return myDlg;
|
||||
|
||||
QString formatFilter = QObject::tr( QString( "INF_FILTER_FORMAT_%1" ).arg( format ).toLatin1().constData() );
|
||||
QString allFilter = QObject::tr( "INF_FILTER_FORMAT_ALL" );
|
||||
|
||||
QString filter;
|
||||
filter.append( formatFilter );
|
||||
filter.append( "\t" );
|
||||
|
||||
if ( import )
|
||||
{
|
||||
filter.append( allFilter );
|
||||
filter.append( "\t" );
|
||||
}
|
||||
|
||||
cout << filter.toLatin1().constData() << endl;
|
||||
QStringList filters = filter.split( "\t" );
|
||||
myDlg->setFilters( filters );
|
||||
|
||||
if ( import )
|
||||
{
|
||||
myDlg->setWindowTitle( QObject::tr( "INF_APP_IMPORT" ) );
|
||||
((QFileDialog*)myDlg)->setFileMode( QFileDialog::ExistingFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
myDlg->setWindowTitle( QObject::tr( "INF_APP_EXPORT" ) );
|
||||
((QFileDialog*)myDlg)->setFileMode( QFileDialog::AnyFile );
|
||||
}
|
||||
|
||||
QString datadir = (QString(getenv("CASROOT")) + QObject::tr( QString("INF_PATH_%1").arg( format ).toLatin1().constData() ) );
|
||||
|
||||
myDlg->clear();
|
||||
|
||||
if ( !import )
|
||||
{
|
||||
switch ( format )
|
||||
{
|
||||
case FormatSTEP:
|
||||
myDlg->addMode( STEPControl_ManifoldSolidBrep, QObject::tr( "INF_BREP_MOIFOLD" ) );
|
||||
myDlg->addMode( STEPControl_FacetedBrep, QObject::tr( "INF_BREP_FACETED" ) );
|
||||
myDlg->addMode( STEPControl_ShellBasedSurfaceModel, QObject::tr( "INF_BREP_SHELL" ) );
|
||||
myDlg->addMode( STEPControl_GeometricCurveSet, QObject::tr( "INF_BREP_CURVE" ) );
|
||||
break;
|
||||
case FormatCSFDB:
|
||||
myDlg->addMode( MgtBRep_WithTriangle, QObject::tr( "INF_TRIANGLES_YES" ) );
|
||||
myDlg->addMode( MgtBRep_WithoutTriangle, QObject::tr( "INF_TRIANGLES_NO" ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return myDlg;
|
||||
}
|
||||
|
||||
// ----------------------------- Import functionality -----------------------------
|
||||
|
||||
Handle(TopTools_HSequenceOfShape) Translate::importBREP( const QString& file )
|
||||
{
|
||||
Handle(TopTools_HSequenceOfShape) aSequence;
|
||||
TopoDS_Shape aShape;
|
||||
BRep_Builder aBuilder;
|
||||
|
||||
Standard_Boolean result = BRepTools::Read( aShape, (Standard_CString)file.toLatin1().constData(), aBuilder );
|
||||
if ( result )
|
||||
{
|
||||
aSequence = new TopTools_HSequenceOfShape();
|
||||
aSequence->Append( aShape );
|
||||
}
|
||||
return aSequence;
|
||||
}
|
||||
|
||||
Handle(TopTools_HSequenceOfShape) Translate::importIGES( const QString& file )
|
||||
{
|
||||
Handle(TopTools_HSequenceOfShape) aSequence;
|
||||
IGESControl_Reader Reader;
|
||||
int status = Reader.ReadFile( (Standard_CString)file.toLatin1().constData() );
|
||||
|
||||
if ( status == IFSelect_RetDone )
|
||||
{
|
||||
aSequence = new TopTools_HSequenceOfShape();
|
||||
Reader.TransferRoots();
|
||||
TopoDS_Shape aShape = Reader.OneShape();
|
||||
aSequence->Append( aShape );
|
||||
}
|
||||
return aSequence;
|
||||
}
|
||||
|
||||
Handle(TopTools_HSequenceOfShape) Translate::importSTEP( const QString& file )
|
||||
{
|
||||
Handle(TopTools_HSequenceOfShape) aSequence;
|
||||
|
||||
STEPControl_Reader aReader;
|
||||
IFSelect_ReturnStatus status = aReader.ReadFile( (Standard_CString)file.toLatin1().constData() );
|
||||
if ( status == IFSelect_RetDone )
|
||||
{
|
||||
//Interface_TraceFile::SetDefault();
|
||||
bool failsonly = false;
|
||||
aReader.PrintCheckLoad( failsonly, IFSelect_ItemsByEntity );
|
||||
|
||||
int nbr = aReader.NbRootsForTransfer();
|
||||
aReader.PrintCheckTransfer( failsonly, IFSelect_ItemsByEntity );
|
||||
for ( Standard_Integer n = 1; n <= nbr; n++ )
|
||||
{
|
||||
bool ok = aReader.TransferRoot( n );
|
||||
int nbs = aReader.NbShapes();
|
||||
if ( nbs > 0 )
|
||||
{
|
||||
aSequence = new TopTools_HSequenceOfShape();
|
||||
for ( int i = 1; i <= nbs; i++ )
|
||||
{
|
||||
TopoDS_Shape shape = aReader.Shape( i );
|
||||
aSequence->Append( shape );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return aSequence;
|
||||
}
|
||||
|
||||
Handle(TopTools_HSequenceOfShape) Translate::importCSFDB( const QString& file )
|
||||
{
|
||||
Handle(TopTools_HSequenceOfShape) aSequence;
|
||||
|
||||
// Check file type
|
||||
if ( FSD_File::IsGoodFileType( (Standard_CString)file.toLatin1().constData() ) != Storage_VSOk )
|
||||
return aSequence;
|
||||
|
||||
static FSD_File fileDriver;
|
||||
TCollection_AsciiString aName( (Standard_CString)file.toLatin1().constData() );
|
||||
if ( fileDriver.Open( aName, Storage_VSRead ) != Storage_VSOk )
|
||||
return aSequence;
|
||||
|
||||
Handle(ShapeSchema) schema = new ShapeSchema();
|
||||
Handle(Storage_Data) data = schema->Read( fileDriver );
|
||||
if ( data->ErrorStatus() != Storage_VSOk )
|
||||
return aSequence;
|
||||
|
||||
fileDriver.Close();
|
||||
|
||||
aSequence = new TopTools_HSequenceOfShape();
|
||||
Handle(Storage_HSeqOfRoot) roots = data->Roots();
|
||||
for ( int i = 1; i <= roots->Length() ; i++ )
|
||||
{
|
||||
Handle(Storage_Root) r = roots->Value( i );
|
||||
Handle(Standard_Persistent) p = r->Object();
|
||||
Handle(PTopoDS_HShape) aPShape = Handle(PTopoDS_HShape)::DownCast(p);
|
||||
if ( !aPShape.IsNull() )
|
||||
{
|
||||
PTColStd_PersistentTransientMap aMap;
|
||||
TopoDS_Shape aTShape;
|
||||
MgtBRep::Translate( aPShape, aMap, aTShape, MgtBRep_WithTriangle );
|
||||
aSequence->Append( aTShape );
|
||||
}
|
||||
}
|
||||
|
||||
return aSequence;
|
||||
}
|
||||
|
||||
// ----------------------------- Export functionality -----------------------------
|
||||
|
||||
bool Translate::exportBREP( const QString& file, const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
if ( shapes.IsNull() || shapes->IsEmpty() )
|
||||
return false;
|
||||
|
||||
TopoDS_Shape shape = shapes->Value( 1 );
|
||||
return BRepTools::Write( shape, (Standard_CString)file.toLatin1().constData() );
|
||||
}
|
||||
|
||||
bool Translate::exportIGES( const QString& file, const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
if ( shapes.IsNull() || shapes->IsEmpty() )
|
||||
return false;
|
||||
|
||||
IGESControl_Controller::Init();
|
||||
IGESControl_Writer writer( Interface_Static::CVal( "XSTEP.iges.unit" ),
|
||||
Interface_Static::IVal( "XSTEP.iges.writebrep.mode" ) );
|
||||
|
||||
for ( int i = 1; i <= shapes->Length(); i++ )
|
||||
writer.AddShape ( shapes->Value( i ) );
|
||||
writer.ComputeModel();
|
||||
return writer.Write( (Standard_CString)file.toLatin1().constData() );
|
||||
}
|
||||
|
||||
bool Translate::exportSTEP( const QString& file, const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
if ( shapes.IsNull() || shapes->IsEmpty() )
|
||||
return false;
|
||||
|
||||
TranslateDlg* theDlg = getDialog( -1, false );
|
||||
STEPControl_StepModelType type = (STEPControl_StepModelType)theDlg->getMode();
|
||||
if ( type < 0 )
|
||||
return false;
|
||||
|
||||
IFSelect_ReturnStatus status;
|
||||
|
||||
if ( type == STEPControl_FacetedBrep && !checkFacetedBrep( shapes ) )
|
||||
{
|
||||
myInfo = QObject::tr( "INF_FACET_ERROR" );
|
||||
return false;
|
||||
}
|
||||
|
||||
STEPControl_Writer writer;
|
||||
for ( int i = 1; i <= shapes->Length(); i++ )
|
||||
{
|
||||
status = writer.Transfer( shapes->Value( i ), type );
|
||||
if ( status != IFSelect_RetDone )
|
||||
return false;
|
||||
}
|
||||
|
||||
status = writer.Write( (Standard_CString)file.toLatin1().constData() );
|
||||
|
||||
switch ( status )
|
||||
{
|
||||
case IFSelect_RetError:
|
||||
myInfo = QObject::tr( "INF_DATA_ERROR" );
|
||||
break;
|
||||
case IFSelect_RetFail:
|
||||
myInfo = QObject::tr( "INF_WRITING_ERROR" );
|
||||
break;
|
||||
case IFSelect_RetVoid:
|
||||
myInfo = QObject::tr( "INF_NOTHING_ERROR" );
|
||||
break;
|
||||
}
|
||||
return status == IFSelect_RetDone;
|
||||
}
|
||||
|
||||
bool Translate::exportCSFDB( const QString& file, const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
if ( shapes.IsNull() || shapes->IsEmpty() )
|
||||
return false;
|
||||
|
||||
TranslateDlg* theDlg = getDialog( -1, false );
|
||||
MgtBRep_TriangleMode type = (MgtBRep_TriangleMode)theDlg->getMode();
|
||||
if ( type < 0 )
|
||||
return false;
|
||||
|
||||
static FSD_File fileDriver;
|
||||
|
||||
Handle(ShapeSchema) schema = new ShapeSchema();
|
||||
Handle(Storage_Data) data = new Storage_Data();
|
||||
data->ClearErrorStatus();
|
||||
|
||||
data->SetApplicationName( TCollection_ExtendedString( "Sample Import / Export" ) );
|
||||
data->SetApplicationVersion( "1" );
|
||||
data->SetDataType( TCollection_ExtendedString( "Shapes" ) );
|
||||
data->AddToUserInfo( "Storing a persistent set of shapes in a flat file" );
|
||||
data->AddToComments( TCollection_ExtendedString( "Application is based on CasCade 5.0 Professional" ) );
|
||||
|
||||
if ( fileDriver.Open( (Standard_CString)file.toLatin1().constData(), Storage_VSWrite ) != Storage_VSOk )
|
||||
{
|
||||
myInfo = QObject::tr( "INF_TRANSLATE_ERROR_CANTSAVEFILE" ).arg( file );
|
||||
return false;
|
||||
}
|
||||
|
||||
PTColStd_TransientPersistentMap aMap;
|
||||
for ( int i = 1; i <= shapes->Length(); i++ )
|
||||
{
|
||||
TopoDS_Shape shape = shapes->Value( i );
|
||||
if ( shape.IsNull() )
|
||||
{
|
||||
myInfo = QObject::tr( "INF_TRANSLATE_ERROR_INVALIDSHAPE" );
|
||||
return false;
|
||||
}
|
||||
|
||||
Handle(PTopoDS_HShape) pshape = MgtBRep::Translate( shape, aMap, type );
|
||||
TCollection_AsciiString objName = TCollection_AsciiString( "Object_" ) + TCollection_AsciiString( i );
|
||||
data->AddRoot( objName, pshape );
|
||||
}
|
||||
|
||||
schema->Write( fileDriver, data );
|
||||
fileDriver.Close();
|
||||
|
||||
if ( data->ErrorStatus() != Storage_VSOk )
|
||||
{
|
||||
myInfo = QObject::tr( "INF_TRANSLATE_ERROR_CANTSAVEDATA" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Translate::exportSTL( const QString& file, const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
if ( shapes.IsNull() || shapes->IsEmpty() )
|
||||
return false;
|
||||
|
||||
TopoDS_Compound res;
|
||||
BRep_Builder builder;
|
||||
builder.MakeCompound( res );
|
||||
|
||||
for ( int i = 1; i <= shapes->Length(); i++ )
|
||||
{
|
||||
TopoDS_Shape shape = shapes->Value( i );
|
||||
if ( shape.IsNull() )
|
||||
{
|
||||
myInfo = QObject::tr( "INF_TRANSLATE_ERROR_INVALIDSHAPE" );
|
||||
return false;
|
||||
}
|
||||
builder.Add( res, shape );
|
||||
}
|
||||
|
||||
StlAPI_Writer writer;
|
||||
writer.Write( res, (Standard_CString)file.toLatin1().constData() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Translate::exportVRML( const QString& file, const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
if ( shapes.IsNull() || shapes->IsEmpty() )
|
||||
return false;
|
||||
|
||||
TopoDS_Compound res;
|
||||
BRep_Builder builder;
|
||||
builder.MakeCompound( res );
|
||||
|
||||
for ( int i = 1; i <= shapes->Length(); i++ )
|
||||
{
|
||||
TopoDS_Shape shape = shapes->Value( i );
|
||||
if ( shape.IsNull() )
|
||||
{
|
||||
myInfo = QObject::tr( "INF_TRANSLATE_ERROR_INVALIDSHAPE" );
|
||||
return false;
|
||||
}
|
||||
builder.Add( res, shape );
|
||||
}
|
||||
|
||||
VrmlAPI_Writer writer;
|
||||
writer.Write( res, (Standard_CString)file.toLatin1().constData() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Translate::checkFacetedBrep( const Handle(TopTools_HSequenceOfShape)& shapes )
|
||||
{
|
||||
bool err = false;
|
||||
for ( int i = 1; i <= shapes->Length(); i++ )
|
||||
{
|
||||
TopoDS_Shape shape = shapes->Value( i );
|
||||
for ( TopExp_Explorer fexp( shape, TopAbs_FACE ); fexp.More() && !err; fexp.Next() )
|
||||
{
|
||||
Handle(Geom_Surface) surface = BRep_Tool::Surface( TopoDS::Face( fexp.Current() ) );
|
||||
if ( !surface->IsKind( STANDARD_TYPE( Geom_Plane ) ) )
|
||||
err = true;
|
||||
}
|
||||
for ( TopExp_Explorer eexp( shape, TopAbs_EDGE ); eexp.More() && !err; eexp.Next() )
|
||||
{
|
||||
Standard_Real fd, ld;
|
||||
Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( eexp.Current() ), fd, ld );
|
||||
if ( !curve->IsKind( STANDARD_TYPE( Geom_Line ) ) )
|
||||
err = true;
|
||||
}
|
||||
}
|
||||
return !err;
|
||||
}
|
||||
|
||||
|
||||
|
59
samples/qt/Interface/src/Translate.h
Executable file
59
samples/qt/Interface/src/Translate.h
Executable file
@@ -0,0 +1,59 @@
|
||||
#ifndef TRANSLATE_H
|
||||
#define TRANSLATE_H
|
||||
#include "IESample.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <AIS_InteractiveContext.hxx>
|
||||
#include <TopTools_HSequenceOfShape.hxx>
|
||||
|
||||
class TranslateDlg;
|
||||
|
||||
class IESAMPLE_EXPORT Translate: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum { FormatBREP, FormatIGES, FormatSTEP, FormatCSFDB, FormatVRML, FormatSTL };
|
||||
|
||||
Translate( QObject* );
|
||||
~Translate();
|
||||
|
||||
bool importModel( const int, const Handle(AIS_InteractiveContext)& );
|
||||
bool exportModel( const int, const Handle(AIS_InteractiveContext)& );
|
||||
|
||||
QString info() const;
|
||||
|
||||
protected:
|
||||
virtual Handle(TopTools_HSequenceOfShape) importModel( const int, const QString& );
|
||||
virtual bool exportModel( const int, const QString&,
|
||||
const Handle(TopTools_HSequenceOfShape)& );
|
||||
virtual bool displayShSequence(const Handle(AIS_InteractiveContext)&,
|
||||
const Handle(TopTools_HSequenceOfShape)& );
|
||||
|
||||
private:
|
||||
QString selectFileName( const int, const bool );
|
||||
TranslateDlg* getDialog( const int, const bool );
|
||||
Handle(TopTools_HSequenceOfShape) getShapes( const Handle(AIS_InteractiveContext)& );
|
||||
|
||||
Handle(TopTools_HSequenceOfShape) importBREP( const QString& );
|
||||
Handle(TopTools_HSequenceOfShape) importIGES( const QString& );
|
||||
Handle(TopTools_HSequenceOfShape) importSTEP( const QString& );
|
||||
Handle(TopTools_HSequenceOfShape) importCSFDB( const QString& );
|
||||
|
||||
bool exportBREP( const QString&, const Handle(TopTools_HSequenceOfShape)& );
|
||||
bool exportIGES( const QString&, const Handle(TopTools_HSequenceOfShape)& );
|
||||
bool exportSTEP( const QString&, const Handle(TopTools_HSequenceOfShape)& );
|
||||
bool exportCSFDB( const QString&, const Handle(TopTools_HSequenceOfShape)& );
|
||||
bool exportSTL( const QString&, const Handle(TopTools_HSequenceOfShape)& );
|
||||
bool exportVRML( const QString&, const Handle(TopTools_HSequenceOfShape)& );
|
||||
|
||||
bool checkFacetedBrep( const Handle(TopTools_HSequenceOfShape)& );
|
||||
|
||||
protected:
|
||||
TranslateDlg* myDlg;
|
||||
QString myInfo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user