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
35 #include "GEOMToolsGUI_NameDlg.h"
37 #include <SALOME_ListIO.hxx>
38 #include <SALOME_ListIteratorOfListIO.hxx>
40 #include <VTKViewer_ViewModel.h>
41 #include <OCCViewer_ViewModel.h>
42 #include <OCCViewer_ViewWindow.h>
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_RenderWindowInteractor.h>
47 #include <SUIT_ViewManager.h>
48 #include <SUIT_Application.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_MessageBox.h>
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_SelectionMgr.h>
57 #include <SalomeApp_Study.h>
58 #include <SalomeApp_Module.h>
60 #include <AIS_Drawer.hxx>
61 #include <AIS_ListOfInteractive.hxx>
62 #include <AIS_ListIteratorOfListOfInteractive.hxx>
63 #include <Prs3d_IsoAspect.hxx>
65 #include <vtkBMPReader.h>
66 #include <vtkTexture.h>
67 #include <vtkTextureMapToPlane.h>
68 #include <vtkTransformTextureCoords.h>
69 #include <vtkDataSetMapper.h>
70 #include <vtkRenderer.h>
72 #include <qfileinfo.h>
73 #include <qcolordialog.h>
75 #include <qapplication.h>
77 #include "utilities.h"
81 #include "SALOMEDSClient.hxx"
82 #include "SALOMEDS_Study.hxx"
86 void GEOMToolsGUI::OnSettingsColor()
88 SUIT_Session* sess = SUIT_Session::session();
89 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
90 SUIT_Desktop* desk = sess->activeApplication()->desktop();
92 QColor anInitColor = resMgr->colorValue( "Geometry:SettingsShadingColor", QColor( "yellow" ) );
94 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
95 if( aDialogColor.isValid() )
97 QString type = desk->activeWindow()->getViewManager()->getType();
98 if( type != OCCViewer_Viewer::Type() && type != VTKViewer_Viewer::Type() )
99 MESSAGE("Settings Color is not supported for current Viewer");
101 resMgr->setValue( "Geometry:SettingsShadingColor", aDialogColor );
105 void GEOMToolsGUI::OnSettingsIsos()
108 SUIT_Session* sess = SUIT_Session::session();
109 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
110 SUIT_Desktop* desk = sess->activeApplication()->desktop();
112 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
113 QString type = vman->getType();
115 if ( type != OCCViewer_Viewer::Type() )
118 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
119 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
121 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
122 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
124 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
125 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
127 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
129 NbIsosDlg->SpinBoxU->setValue(IsoU);
130 NbIsosDlg->SpinBoxV->setValue(IsoV);
132 if(NbIsosDlg->exec()) {
133 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
134 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
136 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
137 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
138 resMgr->setValue("Geometry:SettingsIsoU", isoU);
139 resMgr->setValue("Geometry:SettingsIsoV", isoV);
144 void GEOMToolsGUI::OnSettingsStep()
146 SUIT_Session* sess = SUIT_Session::session();
147 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
149 double step = resMgr->doubleValue( "Geometry:SettingsGeomStep", 100. );
151 Standard_Boolean res = false;
152 double dd = GEOMBase::Parameter(res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
154 resMgr->setValue( "Geometry:SettingsGeomStep", dd );
156 /* Emit signal to GeometryGUI_SpinBoxes */
157 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
160 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
163 void GEOMToolsGUI::OnRename()
165 SALOME_ListIO selected;
166 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
168 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
169 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
170 if ( aSelMgr && appStudy ) {
171 aSelMgr->selectedObjects( selected );
172 if ( !selected.IsEmpty() ) {
173 _PTR(Study) aStudy = appStudy->studyDS();
175 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
177 SUIT_MessageBox::warn1 ( app->desktop(),
178 QObject::tr("WRN_WARNING"),
179 QObject::tr("WRN_STUDY_LOCKED"),
180 QObject::tr("BUT_OK") );
184 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
185 Handle(SALOME_InteractiveObject) IObject = It.Value();
187 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
188 _PTR(GenericAttribute) anAttr;
190 if( obj->FindAttribute(anAttr, "AttributeName") ) {
191 _PTR(AttributeName) aName (anAttr);
193 QString newName = GEOMToolsGUI_NameDlg::getName( app->desktop(), aName->Value().c_str() );
194 if ( !newName.isEmpty() ) {
195 aName->SetValue( newName.latin1() ); // rename the SObject
196 IObject->setName( newName.latin1() );// rename the InteractiveObject
197 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
199 } // if ( name attribute )
207 void GEOMToolsGUI::OnCheckGeometry()
210 QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
211 PyEditor->setText("from GEOM_usinggeom import *\n");
212 PyEditor->handleReturn();
216 void GEOMToolsGUI::OnLoadScript()
219 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
220 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties())->IsLocked();
222 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
223 QObject::tr("WRN_WARNING"),
224 QObject::tr("WRN_STUDY_LOCKED"),
225 QObject::tr("BUT_OK") );
229 QStringList filtersList;
230 filtersList.append(tr("GEOM_MEN_LOAD_SCRIPT"));
231 filtersList.append(tr("GEOM_MEN_ALL_FILES"));
233 QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
234 if(!aFile.isEmpty()) {
235 QFileInfo file = aFile;
236 QApplication::setOverrideCursor(Qt::waitCursor);
237 QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
239 QStringList aTextList = QStringList::split(".", file.fileName());
241 PyEditor->setText("import geompy; geompy.addPath('" + file.dirPath() + "'); from " + aTextList.first() + " import *\n" );
242 PyEditor->handleReturn();
244 QApplication::restoreOverrideCursor();
248 void GEOMToolsGUI::OnColor()
250 SALOME_ListIO selected;
251 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
253 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
255 aSelMgr->selectedObjects( selected );
256 if ( !selected.IsEmpty() ) {
257 SUIT_ViewWindow* window = app->desktop()->activeWindow();
258 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
259 bool isVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
261 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
264 SVTK_RenderWindowInteractor* rwi = vtkVW->getRWInteractor();
265 QColor initcolor = rwi->GetColor( selected.First() );
266 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
268 SUIT_OverrideCursor();
269 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
270 rwi->SetColor( It.Value(), c );
275 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
276 if ( !io.IsNull() ) {
277 Quantity_Color aColor;
279 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
280 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
282 SUIT_OverrideCursor();
283 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
284 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
285 io = GEOMBase::GetAIS( It.Value(), true );
286 if ( !io.IsNull() ) {
287 io->SetColor( aColor );
288 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
289 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
291 io->Redisplay( Standard_True );
295 } // first IO is not null
297 } // if ( selection not empty )
302 void GEOMToolsGUI::OnTransparency()
304 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
308 void GEOMToolsGUI::OnNbIsos()
310 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
311 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
316 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
317 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
320 if ( ic->MoreCurrent() ) {
321 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
322 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
324 int UIso = CurDrawer->UIsoAspect()->Number();
325 int VIso = CurDrawer->VIsoAspect()->Number();
327 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
328 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
330 NbIsosDlg->setU( UIso );
331 NbIsosDlg->setV( VIso );
333 if ( NbIsosDlg->exec() ) {
334 SUIT_OverrideCursor();
335 for(; ic->MoreCurrent(); ic->NextCurrent()) {
336 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
337 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
339 int nbUIso = NbIsosDlg->getU();
340 int nbVIso = NbIsosDlg->getV();
342 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
343 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
345 ic->SetLocalAttributes(CurObject, CurDrawer);
346 ic->Redisplay(CurObject);
352 void GEOMToolsGUI::OnOpen()
355 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
356 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
358 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
359 Handle(SALOME_InteractiveObject) anIObject;
360 for(;It.More();It.Next()) {
361 anIObject = It.Value();
362 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
363 _PTR(AttributePersistentRef) aPersist;
364 _PTR(AttributeIOR) anIOR;
366 // this SObject may be GEOM module root SObject
367 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
368 _PTR(GenericAttribute) anAttr;
369 bool useSubItems = false;
370 while (anIter->More() && !useSubItems) {
371 _PTR(SObject) subobj ( anIter->Value() );
372 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
379 obj->FindAttribute(anAttr, "AttributePersistentRef");
381 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
382 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
383 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
384 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
386 if (FComp->FindAttribute(anAttr, "AttributeName")) {
387 _PTR(AttributeName) aName ( anAttr );
388 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
389 // parent->loadComponentData(parent->getComponentName(aName->Value()));
390 Engines::Component_var comp ;
391 if ( compName.compare("SUPERV") == 0 ) {
392 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
395 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
396 if ( comp->_is_nil() )
397 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
400 if (!CORBA::is_nil(comp)) {
401 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
402 if (!CORBA::is_nil(driver)) {
403 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
404 if (!CORBA::is_nil(B)) {
405 B->LoadWith(FComp,driver);
411 MESSAGE("loadComponentData(): Driver is null");
416 MESSAGE("loadComponentData(): Engine is null");
420 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
421 // if (!CORBA::is_nil(comp)) {
422 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
423 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
424 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
425 // if (!CORBA::is_nil(SC))
426 // aStudyBuilder->LoadWith(SC,driver);
430 MESSAGE("Component is null");
435 obj.reset( anIter->Value() );