1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
24 // File : GEOMToolsGUI_1.cxx
25 // Author : Sergey ANIKIN
29 #include "GEOMToolsGUI.h"
30 #include "GeometryGUI.h"
31 #include "GEOM_Actor.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "QAD_FileDlg.h"
37 #include "QAD_PyEditor.h"
38 #include "QAD_RightFrame.h"
39 #include "QAD_MessageBox.h"
40 #include "SALOMEGUI_NameDlg.h"
42 #include "OCCViewer_Viewer3d.h"
43 #include "OCCViewer_ViewFrame.h"
44 #include "VTKViewer_ViewFrame.h"
45 #include "VTKViewer_RenderWindowInteractor.h"
47 #include "SALOME_ListIO.hxx"
48 #include "SALOME_ListIteratorOfListIO.hxx"
50 #include <AIS_Drawer.hxx>
51 #include <AIS_ListOfInteractive.hxx>
52 #include <AIS_ListIteratorOfListOfInteractive.hxx>
53 #include <Prs3d_IsoAspect.hxx>
55 #include <vtkBMPReader.h>
56 #include <vtkTexture.h>
57 #include <vtkTextureMapToPlane.h>
58 #include <vtkTransformTextureCoords.h>
59 #include <vtkDataSetMapper.h>
60 #include <vtkRenderer.h>
62 #include <qfileinfo.h>
63 #include <qcolordialog.h>
65 #include <qapplication.h>
67 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
68 #include "GEOMToolsGUI_TransparencyDlg.h" // Method TRANSPARENCY adjustement
70 #include "utilities.h"
74 void GEOMToolsGUI::OnSettingsColor()
77 QString aSCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed");
78 QString aSCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen");
79 QString aSCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue");
81 if(!aSCr.isEmpty() && !aSCg.isEmpty() && !aSCb.isEmpty()) {
82 anInitColor = QColor (aSCr.toInt(), aSCg.toInt(), aSCb.toInt());
85 Quantity_Color aDefColor = Quantity_Color();
87 QColor ((int)( aDefColor.Red() * 255.0 ), (int)( aDefColor.Green() * 255.0 ), (int)( aDefColor.Blue() * 255.0 ) );
90 QColor aDialogColor = QColorDialog::getColor(anInitColor, QAD_Application::getDesktop());
91 if(aDialogColor.isValid()) {
92 QApplication::setOverrideCursor(Qt::waitCursor);
94 if( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC &&
95 QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
96 MESSAGE("Settings Color is not supported for current Viewer");
98 QAD_CONFIG->addSetting("Geometry:SettingsShadingColorRed", aDialogColor.red());
99 QAD_CONFIG->addSetting("Geometry:SettingsShadingColorGreen", aDialogColor.green());
100 QAD_CONFIG->addSetting("Geometry:SettingsShadingColorBlue", aDialogColor.blue());
101 QApplication::restoreOverrideCursor();
105 void GEOMToolsGUI::OnSettingsIsos()
107 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
110 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
111 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
113 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
114 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
117 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
121 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
125 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(QAD_Application::getDesktop(), tr("GEOM_MEN_ISOS"), TRUE);
126 int UIso = IsoU.toInt();
127 int VIso = IsoV.toInt();
129 NbIsosDlg->SpinBoxU->setValue(UIso);
130 NbIsosDlg->SpinBoxV->setValue(VIso);
132 if(NbIsosDlg->exec()) {
133 UIso = NbIsosDlg->SpinBoxU->text().toInt();
134 VIso = NbIsosDlg->SpinBoxV->text().toInt();
136 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
137 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
138 QAD_CONFIG->addSetting("Geometry:SettingsIsoU", NbIsosDlg->SpinBoxU->text()); /* text format */
139 QAD_CONFIG->addSetting("Geometry:SettingsIsoV", NbIsosDlg->SpinBoxV->text()); /* text format */
143 void GEOMToolsGUI::OnSettingsStep()
145 QString step = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
149 Standard_Boolean res = false;
150 double dd = GEOMBase::Parameter(res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
152 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", QString("%1").arg(dd));
154 /* Emit signal to GeometryGUI_SpinBoxes */
155 GeometryGUI::GetGeomGUI()->EmitSignalDefaultStepValueChanged(dd);
158 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
161 void GEOMToolsGUI::OnRename()
163 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
164 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
166 bool aLocked = aStudy->GetProperties()->IsLocked();
168 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
169 QObject::tr("WRN_WARNING"),
170 QObject::tr("WRN_STUDY_LOCKED"),
171 QObject::tr("BUT_OK") );
175 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
176 for(; It.More(); It.Next()) {
177 Handle(SALOME_InteractiveObject) IObject = It.Value();
179 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
180 SALOMEDS::GenericAttribute_var anAttr;
181 SALOMEDS::AttributeName_var aName;
182 if(!obj->_is_nil()) {
183 if(obj->FindAttribute(anAttr, "AttributeName")) {
184 aName = SALOMEDS::AttributeName::_narrow(anAttr);
186 QString nm = QString(aName->Value());
187 nm = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), nm);
189 QApplication::setOverrideCursor(Qt::waitCursor);
190 QAD_Application::getDesktop()->getActiveStudy()->renameIObject(IObject, nm);
191 QApplication::restoreOverrideCursor();
198 void GEOMToolsGUI::OnCheckGeometry()
200 QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
201 PyEditor->setText("from GEOM_usinggeom import *\n");
202 PyEditor->handleReturn();
205 void GEOMToolsGUI::OnLoadScript()
207 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
208 bool aLocked = aStudy->GetProperties()->IsLocked();
210 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
211 QObject::tr("WRN_WARNING"),
212 QObject::tr("WRN_STUDY_LOCKED"),
213 QObject::tr("BUT_OK") );
217 QStringList filtersList;
218 filtersList.append(tr("GEOM_MEN_LOAD_SCRIPT"));
219 filtersList.append(tr("GEOM_MEN_ALL_FILES"));
221 QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
222 if(!aFile.isEmpty()) {
223 QFileInfo file = aFile;
224 QApplication::setOverrideCursor(Qt::waitCursor);
225 QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
227 QStringList aTextList = QStringList::split(".", file.fileName());
229 PyEditor->setText("import geompy; geompy.addPath('" + file.dirPath() + "'); from " + aTextList.first() + " import *\n" );
230 PyEditor->handleReturn();
232 QApplication::restoreOverrideCursor();
235 void GEOMToolsGUI::OnColor()
237 SALOME_Selection* Sel = SALOME_Selection::Selection(
238 QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
240 if ( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
242 VTKViewer_RenderWindowInteractor* myRenderInter =
243 ( (VTKViewer_ViewFrame*)QAD_Application::getDesktop()->
244 getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
246 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
247 Handle(SALOME_InteractiveObject) FirstIOS = Sel->firstIObject();
248 if ( !FirstIOS.IsNull() )
250 QColor initcolor = myRenderInter->GetColor(FirstIOS);
251 QColor c = QColorDialog::getColor( initcolor, QAD_Application::getDesktop() );
255 QApplication::setOverrideCursor( Qt::waitCursor );
256 for ( ;It.More();It.Next() )
258 Handle(SALOME_InteractiveObject) IOS = It.Value();
259 myRenderInter->SetColor(IOS,c);
262 QApplication::restoreOverrideCursor();
265 else if( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC )
267 Handle(AIS_InteractiveObject) anIO = GEOMBase::GetAIS( Sel->firstIObject() );
268 if ( !anIO.IsNull() )
270 Quantity_Color aColor;
271 anIO->Color( aColor );
273 QColor qColor = QColorDialog::getColor( QColor( (int)( aColor.Red() * 255.0 ),
274 (int)( aColor.Green() * 255.0 ),
275 (int)( aColor.Blue() * 255.0 ) ),
276 QAD_Application::getDesktop());
278 if ( qColor.isValid() )
280 aColor = Quantity_Color( qColor.red() / 255.,
281 qColor.green() / 255.,
282 qColor.blue() / 255.,
285 QApplication::setOverrideCursor( Qt::waitCursor );
287 SALOME_ListIteratorOfListIO anIter ( Sel->StoredIObjects() );
288 for( ;anIter.More();anIter.Next() )
290 Handle(SALOME_InteractiveObject) IObject = anIter.Value();
291 Handle(AIS_InteractiveObject) anIO = GEOMBase::GetAIS( IObject, true );
292 if ( !anIO.IsNull() )
294 anIO->SetColor( aColor );
296 if ( anIO->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
297 Handle(GEOM_AISShape)::DownCast( anIO )->SetShadingColor( aColor );
299 anIO->Redisplay( Standard_True );
306 QApplication::restoreOverrideCursor();
309 void GEOMToolsGUI::OnTransparency()
311 Handle(AIS_InteractiveContext) ic;
312 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
313 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
314 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
315 ic = v3d->getAISContext();
317 new GEOMBase_TransparencyDlg(QAD_Application::getDesktop(), "", Sel, ic);
320 void GEOMToolsGUI::OnNbIsos()
322 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
325 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
326 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
329 if(ic->MoreCurrent()) {
330 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
331 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
333 int UIso = CurDrawer->UIsoAspect()->Number();
334 int VIso = CurDrawer->VIsoAspect()->Number();
336 GEOMBase_NbIsosDlg * NbIsosDlg =
337 new GEOMBase_NbIsosDlg(QAD_Application::getDesktop(), tr("GEOM_MEN_ISOS"), TRUE);
339 NbIsosDlg->SpinBoxU->setValue( UIso );
340 NbIsosDlg->SpinBoxV->setValue( VIso );
342 if(NbIsosDlg->exec()) {
343 QApplication::setOverrideCursor(Qt::waitCursor);
344 for(; ic->MoreCurrent(); ic->NextCurrent()) {
345 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
346 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
348 int nbUIso = NbIsosDlg->SpinBoxU->text().toInt();
349 int nbVIso = NbIsosDlg->SpinBoxV->text().toInt();
351 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
352 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
354 ic->SetLocalAttributes(CurObject, CurDrawer);
355 ic->Redisplay(CurObject);
359 QApplication::restoreOverrideCursor();
362 void GEOMToolsGUI::OnOpen()
364 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
365 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
367 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
368 Handle(SALOME_InteractiveObject) anIObject;
369 for(;It.More();It.Next()) {
370 anIObject = It.Value();
371 SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry());
372 SALOMEDS::AttributePersistentRef_var aPersist;
373 SALOMEDS::AttributeIOR_var anIOR;
374 if(!obj->_is_nil()) {
375 // this SObject may be GEOM module root SObject
376 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(obj);
377 SALOMEDS::GenericAttribute_var anAttr;
378 bool useSubItems = false;
379 while (anIter->More() && !useSubItems) {
380 SALOMEDS::SObject_var subobj = anIter->Value();
381 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
388 obj->FindAttribute(anAttr, "AttributePersistentRef");
390 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
391 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
392 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
393 SALOMEDS::SComponent_var FComp = obj->GetFatherComponent();
394 if (!CORBA::is_nil(FComp)) {
395 if (FComp->FindAttribute(anAttr, "AttributeName")) {
396 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
397 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value());
398 // parent->loadComponentData(parent->getComponentName(aName->Value()));
399 Engines::Component_var comp ;
400 if ( compName.compare("SUPERV") == 0 ) {
401 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
404 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
405 if ( comp->_is_nil() )
406 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
409 if (!CORBA::is_nil(comp)) {
410 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
411 if (!CORBA::is_nil(driver)) {
412 SALOMEDS::StudyBuilder_var B = aStudy->NewBuilder();
413 if (!CORBA::is_nil(B)) {
414 B->LoadWith(FComp,driver);
420 MESSAGE("loadComponentData(): Driver is null");
425 MESSAGE("loadComponentData(): Engine is null");
429 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
430 // if (!CORBA::is_nil(comp)) {
431 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
432 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
433 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
434 // if (!CORBA::is_nil(SC))
435 // aStudyBuilder->LoadWith(SC,driver);
439 MESSAGE("Component is null");
444 obj = anIter->Value();
447 anAttr = SALOMEDS::GenericAttribute::_nil();