1 #include "Application.h"
7 #include <QMdiSubWindow>
9 ApplicationWindow::ApplicationWindow()
10 : ApplicationCommonWindow( ),
14 createTranslatePopups();
17 ApplicationWindow::~ApplicationWindow()
21 void ApplicationWindow::createTranslatePopups()
24 myImportPopup = new QMenu( QObject::tr( "MNU_FILE_IMPORT" ), this );
27 myExportPopup = new QMenu( QObject::tr( "MNU_FILE_EXPORT" ), this );
30 a = new QAction( QObject::tr("MNU_IMPORT_BREP"), this );
31 a->setStatusTip( QObject::tr("TBR_IMPORT_BREP") );
32 connect( a, SIGNAL( triggered() ), this, SLOT( onImport() ) );
33 myCasCadeTranslateActions.insert( FileImportBREPId, a );
34 myImportPopup->addAction( a );
36 a = new QAction( QObject::tr("MNU_EXPORT_BREP"), this );
37 a->setStatusTip( QObject::tr("TBR_EXPORT_BREP") );
38 connect( a, SIGNAL( triggered() ), this, SLOT( onExport() ) );
39 myCasCadeTranslateActions.insert( FileExportBREPId, a );
40 myExportPopup->addAction( a );
42 a = new QAction( QObject::tr("MNU_IMPORT_CSFDB"), this );
43 a->setStatusTip( QObject::tr("TBR_IMPORT_CSFDB") );
44 connect( a, SIGNAL( triggered() ), this, SLOT( onImport() ) );
45 myCasCadeTranslateActions.insert( FileImportCSFDBId, a );
46 myImportPopup->addAction( a );
48 a = new QAction( QObject::tr("MNU_EXPORT_CSFDB"), this );
49 a->setStatusTip( QObject::tr("TBR_EXPORT_CSFDB") );
50 connect( a, SIGNAL( triggered() ), this, SLOT( onExport() ) );
51 myCasCadeTranslateActions.insert( FileExportCSFDBId, a );
52 myExportPopup->addAction( a );
54 a = new QAction( QObject::tr("MNU_IMPORT_IGES"), this );
55 a->setStatusTip( QObject::tr("TBR_IMPORT_IGES") );
56 connect( a, SIGNAL( triggered() ), this, SLOT( onImport() ) );
57 myCasCadeTranslateActions.insert( FileImportIGESId, a );
58 myImportPopup->addAction( a );
60 a = new QAction( QObject::tr("MNU_EXPORT_IGES"), this );
61 a->setStatusTip( QObject::tr("TBR_EXPORT_IGES") );
62 connect( a, SIGNAL( triggered() ), this, SLOT( onExport() ) );
63 myCasCadeTranslateActions.insert( FileExportIGESId, a );
64 myExportPopup->addAction( a );
66 a = new QAction( QObject::tr("MNU_IMPORT_STEP"), this );
67 a->setStatusTip( QObject::tr("TBR_IMPORT_STEP") );
68 connect( a, SIGNAL( triggered() ), this, SLOT( onImport() ) );
69 myCasCadeTranslateActions.insert( FileImportSTEPId, a );
70 myImportPopup->addAction( a );
72 a = new QAction( QObject::tr("MNU_EXPORT_STEP"), this );
73 a->setStatusTip( QObject::tr("TBR_EXPORT_STEP") );
74 connect( a, SIGNAL( triggered() ), this, SLOT( onExport() ) );
75 myCasCadeTranslateActions.insert( FileExportSTEPId, a );
76 myExportPopup->addAction( a );
78 a = new QAction( QObject::tr("MNU_EXPORT_STL"), this );
79 a->setStatusTip( QObject::tr("TBR_EXPORT_STL") );
80 connect( a, SIGNAL( triggered() ), this, SLOT( onExport() ) );
81 myCasCadeTranslateActions.insert( FileExportSTLId, a );
82 myExportPopup->addAction( a );
84 a = new QAction( QObject::tr("MNU_EXPORT_VRML"), this );
85 a->setStatusTip( QObject::tr("TBR_EXPORT_VRML") );
86 connect( a, SIGNAL( triggered() ), this, SLOT( onExport() ) );
87 myCasCadeTranslateActions.insert( FileExportVRMLId, a );
88 myExportPopup->addAction( a );
90 myExportPopup->addSeparator();
92 a = new QAction( QObject::tr("MNU_EXPORT_IMAGE"), this );
93 a->setStatusTip( QObject::tr("TBR_EXPORT_IMAGE") );
94 connect( a, SIGNAL( triggered() ), this, SLOT( onExportImage() ) );
95 myExportPopup->addAction( a );
98 void ApplicationWindow::updateFileActions()
100 if ( myDocuments.isEmpty() )
104 getFilePopup()->insertMenu( getFileSeparator(), myExportPopup );
105 getFilePopup()->insertMenu( myExportPopup->menuAction(), myImportPopup );
106 mySeparator = getFilePopup()->insertSeparator( myImportPopup->menuAction() );
110 getFilePopup()->removeAction( myImportPopup->menuAction() );
111 getFilePopup()->removeAction( myExportPopup->menuAction() );
112 getFilePopup()->removeAction( mySeparator );
115 ApplicationCommonWindow::updateFileActions();
118 void ApplicationWindow::onImport()
120 QAction* a = (QAction*)sender();
121 int type = translationFormat( a );
125 bool stat = translate( type, true );
128 DocumentCommon* doc = qobject_cast<MDIWindow*>( getWorkspace()->activeSubWindow()->widget() )->getDocument();
133 void ApplicationWindow::onExport()
135 QAction* a = (QAction*)sender();
136 int type = translationFormat( a );
140 translate( type, false );
143 int ApplicationWindow::translationFormat( const QAction* a )
146 for ( int i = FileImportBREPId; i <= FileExportVRMLId; i++ )
148 if ( myCasCadeTranslateActions.at( i ) == a )
156 case FileImportBREPId:
157 case FileExportBREPId:
158 type = Translate::FormatBREP;
160 case FileImportIGESId:
161 case FileExportIGESId:
162 type = Translate::FormatIGES;
164 case FileImportSTEPId:
165 case FileExportSTEPId:
166 type = Translate::FormatSTEP;
168 case FileImportCSFDBId:
169 case FileExportCSFDBId:
170 type = Translate::FormatCSFDB;
172 case FileExportSTLId:
173 type = Translate::FormatSTL;
175 case FileExportVRMLId:
176 type = Translate::FormatVRML;
182 bool ApplicationWindow::translate( const int format, const bool import )
184 static Translate* anTrans = createTranslator();
185 DocumentCommon* doc = qobject_cast<MDIWindow*>( getWorkspace()->activeSubWindow()->widget() )->getDocument();
186 Handle(AIS_InteractiveContext) context = doc->getContext();
189 status = anTrans->importModel( format, context );
191 status = anTrans->exportModel( format, context );
195 QString msg = QObject::tr( "INF_TRANSLATE_ERROR" );
196 if ( !anTrans->info().isEmpty() )
197 msg += QString( "\n" ) + anTrans->info();
198 QMessageBox::critical( this, QObject::tr( "TIT_ERROR" ), msg, QObject::tr( "BTN_OK" ), QString::null, QString::null, 0, 0 );
204 Translate* ApplicationWindow::createTranslator()
206 Translate* anTrans = new Translate( this/*, "Translator"*/ );
210 void ApplicationWindow::onSelectionChanged()
212 ApplicationCommonWindow::onSelectionChanged();
214 QMdiArea* ws = getWorkspace();
215 DocumentCommon* doc = qobject_cast<MDIWindow*>( ws->activeSubWindow()->widget() )->getDocument();
216 Handle(AIS_InteractiveContext) context = doc->getContext();
217 int numSel = context->NbSelected();
219 myCasCadeTranslateActions.at( FileExportBREPId )->setEnabled( numSel );
220 myCasCadeTranslateActions.at( FileExportCSFDBId )->setEnabled( numSel );
221 myCasCadeTranslateActions.at( FileExportIGESId )->setEnabled( numSel );
222 myCasCadeTranslateActions.at( FileExportSTEPId )->setEnabled( numSel );
223 myCasCadeTranslateActions.at( FileExportSTLId )->setEnabled( numSel );
224 myCasCadeTranslateActions.at( FileExportVRMLId )->setEnabled( numSel );
227 QString ApplicationWindow::getIEResourceDir()
229 static QString aResourceDir =
230 QString::fromUtf8 (qgetenv ("CSF_IEResourcesDefaults").constData());
235 void ApplicationWindow::onExportImage()
237 MDIWindow* w = qobject_cast<MDIWindow*>( getWorkspace()->activeSubWindow()->widget() );