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"
33 #include "GEOMToolsGUI_TransparencyDlg.h"
34 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
36 #include <SALOME_ListIO.hxx>
37 #include <SALOME_ListIteratorOfListIO.hxx>
39 #include <VTKViewer_ViewModel.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewWindow.h>
43 #include <SVTK_ViewWindow.h>
44 #include <SVTK_RenderWindowInteractor.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_Application.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_OverrideCursor.h>
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_SelectionMgr.h>
56 #include <AIS_Drawer.hxx>
57 #include <AIS_ListOfInteractive.hxx>
58 #include <AIS_ListIteratorOfListOfInteractive.hxx>
59 #include <Prs3d_IsoAspect.hxx>
61 #include <vtkBMPReader.h>
62 #include <vtkTexture.h>
63 #include <vtkTextureMapToPlane.h>
64 #include <vtkTransformTextureCoords.h>
65 #include <vtkDataSetMapper.h>
66 #include <vtkRenderer.h>
68 #include <qfileinfo.h>
69 #include <qcolordialog.h>
71 #include <qapplication.h>
73 #include "utilities.h"
77 #include "SALOMEDSClient.hxx"
78 #include "SALOMEDS_Study.hxx"
82 void GEOMToolsGUI::OnSettingsColor()
84 SUIT_Session* sess = SUIT_Session::session();
85 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
86 SUIT_Desktop* desk = sess->activeApplication()->desktop();
88 QColor anInitColor = resMgr->colorValue( "Geometry:SettingsShadingColor", QColor( "yellow" ) );
90 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
91 if( aDialogColor.isValid() )
93 QString type = desk->activeWindow()->getViewManager()->getType();
94 if( type != OCCViewer_Viewer::Type() && type != VTKViewer_Viewer::Type() )
95 MESSAGE("Settings Color is not supported for current Viewer");
97 resMgr->setValue( "Geometry:SettingsShadingColor", aDialogColor );
101 void GEOMToolsGUI::OnSettingsIsos()
104 SUIT_Session* sess = SUIT_Session::session();
105 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
106 SUIT_Desktop* desk = sess->activeApplication()->desktop();
108 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
109 QString type = vman->getType();
111 if ( type != OCCViewer_Viewer::Type() )
114 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
115 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
117 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
118 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
120 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
121 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
123 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
125 NbIsosDlg->SpinBoxU->setValue(IsoU);
126 NbIsosDlg->SpinBoxV->setValue(IsoV);
128 if(NbIsosDlg->exec()) {
129 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
130 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
132 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
133 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
134 resMgr->setValue("Geometry:SettingsIsoU", isoU);
135 resMgr->setValue("Geometry:SettingsIsoV", isoV);
140 void GEOMToolsGUI::OnSettingsStep()
142 SUIT_Session* sess = SUIT_Session::session();
143 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
145 double step = resMgr->doubleValue( "Geometry:SettingsGeomStep", 100. );
147 Standard_Boolean res = false;
148 double dd = GEOMBase::Parameter(res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
150 resMgr->setValue( "Geometry:SettingsGeomStep", dd );
152 /* Emit signal to GeometryGUI_SpinBoxes */
153 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
156 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
159 void GEOMToolsGUI::OnRename()
162 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
163 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
165 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
167 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
168 QObject::tr("WRN_WARNING"),
169 QObject::tr("WRN_STUDY_LOCKED"),
170 QObject::tr("BUT_OK") );
174 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
175 for(; It.More(); It.Next()) {
176 Handle(SALOME_InteractiveObject) IObject = It.Value();
178 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
179 _PTR(GenericAttribute) anAttr;
181 if(obj->FindAttribute(anAttr, "AttributeName")) {
182 _PTR(AttributeName) aName (anAttr);
184 QString nm = QString(aName->Value().c_str());
185 nm = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), nm);
187 QApplication::setOverrideCursor(Qt::waitCursor);
188 QAD_Application::getDesktop()->getActiveStudy()->renameIObject(IObject, nm);
189 QApplication::restoreOverrideCursor();
197 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();
206 void GEOMToolsGUI::OnLoadScript()
209 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
210 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties())->IsLocked();
212 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
213 QObject::tr("WRN_WARNING"),
214 QObject::tr("WRN_STUDY_LOCKED"),
215 QObject::tr("BUT_OK") );
219 QStringList filtersList;
220 filtersList.append(tr("GEOM_MEN_LOAD_SCRIPT"));
221 filtersList.append(tr("GEOM_MEN_ALL_FILES"));
223 QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
224 if(!aFile.isEmpty()) {
225 QFileInfo file = aFile;
226 QApplication::setOverrideCursor(Qt::waitCursor);
227 QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
229 QStringList aTextList = QStringList::split(".", file.fileName());
231 PyEditor->setText("import geompy; geompy.addPath('" + file.dirPath() + "'); from " + aTextList.first() + " import *\n" );
232 PyEditor->handleReturn();
234 QApplication::restoreOverrideCursor();
238 void GEOMToolsGUI::OnColor()
240 SALOME_ListIO selected;
241 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
243 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
245 aSelMgr->selectedObjects( selected );
246 if ( !selected.IsEmpty() ) {
247 SUIT_ViewWindow* window = app->desktop()->activeWindow();
248 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
249 bool isVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
251 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
254 SVTK_RenderWindowInteractor* rwi = vtkVW->getRWInteractor();
255 QColor initcolor = rwi->GetColor( selected.First() );
256 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
258 SUIT_OverrideCursor();
259 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
260 rwi->SetColor( It.Value(), c );
265 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
266 if ( !io.IsNull() ) {
267 Quantity_Color aColor;
269 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
270 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
272 SUIT_OverrideCursor();
273 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
274 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
275 io = GEOMBase::GetAIS( It.Value(), true );
276 if ( !io.IsNull() ) {
277 io->SetColor( aColor );
278 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
279 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
281 io->Redisplay( Standard_True );
285 } // first IO is not null
287 } // if ( selection not empty )
292 void GEOMToolsGUI::OnTransparency()
294 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
298 void GEOMToolsGUI::OnNbIsos()
300 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
301 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
306 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
307 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
310 if ( ic->MoreCurrent() ) {
311 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
312 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
314 int UIso = CurDrawer->UIsoAspect()->Number();
315 int VIso = CurDrawer->VIsoAspect()->Number();
317 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
318 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
320 NbIsosDlg->setU( UIso );
321 NbIsosDlg->setV( VIso );
323 if ( NbIsosDlg->exec() ) {
324 SUIT_OverrideCursor();
325 for(; ic->MoreCurrent(); ic->NextCurrent()) {
326 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
327 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
329 int nbUIso = NbIsosDlg->getU();
330 int nbVIso = NbIsosDlg->getV();
332 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
333 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
335 ic->SetLocalAttributes(CurObject, CurDrawer);
336 ic->Redisplay(CurObject);
342 void GEOMToolsGUI::OnOpen()
345 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
346 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
348 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
349 Handle(SALOME_InteractiveObject) anIObject;
350 for(;It.More();It.Next()) {
351 anIObject = It.Value();
352 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
353 _PTR(AttributePersistentRef) aPersist;
354 _PTR(AttributeIOR) anIOR;
356 // this SObject may be GEOM module root SObject
357 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
358 _PTR(GenericAttribute) anAttr;
359 bool useSubItems = false;
360 while (anIter->More() && !useSubItems) {
361 _PTR(SObject) subobj ( anIter->Value() );
362 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
369 obj->FindAttribute(anAttr, "AttributePersistentRef");
371 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
372 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
373 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
374 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
376 if (FComp->FindAttribute(anAttr, "AttributeName")) {
377 _PTR(AttributeName) aName ( anAttr );
378 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
379 // parent->loadComponentData(parent->getComponentName(aName->Value()));
380 Engines::Component_var comp ;
381 if ( compName.compare("SUPERV") == 0 ) {
382 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
385 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
386 if ( comp->_is_nil() )
387 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
390 if (!CORBA::is_nil(comp)) {
391 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
392 if (!CORBA::is_nil(driver)) {
393 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
394 if (!CORBA::is_nil(B)) {
395 B->LoadWith(FComp,driver);
401 MESSAGE("loadComponentData(): Driver is null");
406 MESSAGE("loadComponentData(): Engine is null");
410 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
411 // if (!CORBA::is_nil(comp)) {
412 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
413 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
414 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
415 // if (!CORBA::is_nil(SC))
416 // aStudyBuilder->LoadWith(SC,driver);
420 MESSAGE("Component is null");
425 obj.reset( anIter->Value() );