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 <PythonConsole_PyConsole.h>
31 #include "GEOMToolsGUI.h"
33 #include "GeometryGUI.h"
34 #include "GEOMToolsGUI_TransparencyDlg.h"
35 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
36 #include "GEOMToolsGUI_NameDlg.h"
38 #include "GEOM_Actor.h"
41 #include <SALOME_ListIO.hxx>
42 #include <SALOME_ListIteratorOfListIO.hxx>
44 #include <VTKViewer_ViewModel.h>
45 #include <OCCViewer_ViewModel.h>
46 #include <OCCViewer_ViewWindow.h>
48 #include <SVTK_ViewWindow.h>
49 #include <SVTK_RenderWindowInteractor.h>
51 #include <SUIT_ViewManager.h>
52 #include <SUIT_Application.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ResourceMgr.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_OverrideCursor.h>
57 #include <SUIT_MessageBox.h>
59 #include <SalomeApp_Application.h>
60 #include <SalomeApp_SelectionMgr.h>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Module.h>
64 #include "SALOMEDSClient.hxx"
66 #include "utilities.h"
69 #include <AIS_Drawer.hxx>
70 #include <AIS_ListOfInteractive.hxx>
71 #include <AIS_ListIteratorOfListOfInteractive.hxx>
72 #include <Prs3d_IsoAspect.hxx>
75 #include <vtkBMPReader.h>
76 #include <vtkTexture.h>
77 #include <vtkTextureMapToPlane.h>
78 #include <vtkTransformTextureCoords.h>
79 #include <vtkDataSetMapper.h>
80 #include <vtkRenderer.h>
83 #include <qfileinfo.h>
84 #include <qcolordialog.h>
86 #include <qapplication.h>
91 void GEOMToolsGUI::OnSettingsColor()
93 SUIT_Session* sess = SUIT_Session::session();
94 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
95 SUIT_Desktop* desk = sess->activeApplication()->desktop();
97 QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
99 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
100 if( aDialogColor.isValid() )
102 QString type = desk->activeWindow()->getViewManager()->getType();
103 if( type != OCCViewer_Viewer::Type() && type != VTKViewer_Viewer::Type() )
104 MESSAGE("Settings Color is not supported for current Viewer");
106 resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
110 void GEOMToolsGUI::OnSettingsIsos()
113 SUIT_Session* sess = SUIT_Session::session();
114 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
115 SUIT_Desktop* desk = sess->activeApplication()->desktop();
117 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
118 QString type = vman->getType();
120 if ( type != OCCViewer_Viewer::Type() )
123 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
124 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
126 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
127 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
129 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
130 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
132 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
134 NbIsosDlg->SpinBoxU->setValue(IsoU);
135 NbIsosDlg->SpinBoxV->setValue(IsoV);
137 if(NbIsosDlg->exec()) {
138 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
139 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
141 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
142 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
143 resMgr->setValue("Geometry:SettingsIsoU", isoU);
144 resMgr->setValue("Geometry:SettingsIsoV", isoV);
149 void GEOMToolsGUI::OnSettingsStep()
151 SUIT_Session* sess = SUIT_Session::session();
152 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
154 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
156 Standard_Boolean res = false;
157 double dd = GEOMBase::Parameter( res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
159 resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
161 /* Emit signal to GeometryGUI_SpinBoxes */
162 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
165 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
168 void GEOMToolsGUI::OnRename()
170 SALOME_ListIO selected;
171 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
173 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
174 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
175 if ( aSelMgr && appStudy ) {
176 aSelMgr->selectedObjects( selected );
177 if ( !selected.IsEmpty() ) {
178 _PTR(Study) aStudy = appStudy->studyDS();
180 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
182 SUIT_MessageBox::warn1 ( app->desktop(),
183 QObject::tr("WRN_WARNING"),
184 QObject::tr("WRN_STUDY_LOCKED"),
185 QObject::tr("BUT_OK") );
189 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
190 Handle(SALOME_InteractiveObject) IObject = It.Value();
192 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
193 _PTR(GenericAttribute) anAttr;
195 if( obj->FindAttribute(anAttr, "AttributeName") ) {
196 _PTR(AttributeName) aName (anAttr);
198 QString newName = GEOMToolsGUI_NameDlg::getName( app->desktop(), aName->Value().c_str() );
199 if ( !newName.isEmpty() ) {
200 aName->SetValue( newName.latin1() ); // rename the SObject
201 IObject->setName( newName.latin1() );// rename the InteractiveObject
202 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
204 } // if ( name attribute )
211 app->updateActions(); //SRN: To update a Save button in the toolbar
214 void GEOMToolsGUI::OnCheckGeometry()
216 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
217 PythonConsole* pyConsole = app->pythonConsole();
220 pyConsole->exec("from GEOM_usinggeom import *");
223 void GEOMToolsGUI::OnColor()
225 SALOME_ListIO selected;
226 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
228 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
230 aSelMgr->selectedObjects( selected );
231 if ( !selected.IsEmpty() ) {
232 SUIT_ViewWindow* window = app->desktop()->activeWindow();
233 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
234 bool isVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
236 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
239 SVTK_RenderWindowInteractor* rwi = vtkVW->getRWInteractor();
240 QColor initcolor = rwi->GetColor( selected.First() );
241 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
243 SUIT_OverrideCursor();
244 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
245 rwi->SetColor( It.Value(), c );
250 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
251 if ( !io.IsNull() ) {
252 Quantity_Color aColor;
254 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
255 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
257 SUIT_OverrideCursor();
258 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
259 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
260 io = GEOMBase::GetAIS( It.Value(), true );
261 if ( !io.IsNull() ) {
262 io->SetColor( aColor );
263 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
264 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
266 io->Redisplay( Standard_True );
270 } // first IO is not null
272 } // if ( selection not empty )
276 app->updateActions(); //SRN: To update a Save button in the toolbar
279 void GEOMToolsGUI::OnTransparency()
281 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
285 void GEOMToolsGUI::OnNbIsos()
287 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
288 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
293 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
294 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
297 if ( ic->MoreCurrent() ) {
298 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
299 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
301 int UIso = CurDrawer->UIsoAspect()->Number();
302 int VIso = CurDrawer->VIsoAspect()->Number();
304 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
305 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
307 NbIsosDlg->setU( UIso );
308 NbIsosDlg->setV( VIso );
310 if ( NbIsosDlg->exec() ) {
311 SUIT_OverrideCursor();
312 for(; ic->MoreCurrent(); ic->NextCurrent()) {
313 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
314 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
316 int nbUIso = NbIsosDlg->getU();
317 int nbVIso = NbIsosDlg->getV();
319 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
320 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
322 ic->SetLocalAttributes(CurObject, CurDrawer);
323 ic->Redisplay(CurObject);
329 void GEOMToolsGUI::OnOpen()
332 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
333 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
335 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
336 Handle(SALOME_InteractiveObject) anIObject;
337 for(;It.More();It.Next()) {
338 anIObject = It.Value();
339 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
340 _PTR(AttributePersistentRef) aPersist;
341 _PTR(AttributeIOR) anIOR;
343 // this SObject may be GEOM module root SObject
344 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
345 _PTR(GenericAttribute) anAttr;
346 bool useSubItems = false;
347 while (anIter->More() && !useSubItems) {
348 _PTR(SObject) subobj ( anIter->Value() );
349 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
356 obj->FindAttribute(anAttr, "AttributePersistentRef");
358 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
359 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
360 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
361 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
363 if (FComp->FindAttribute(anAttr, "AttributeName")) {
364 _PTR(AttributeName) aName ( anAttr );
365 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
366 // parent->loadComponentData(parent->getComponentName(aName->Value()));
367 Engines::Component_var comp ;
368 if ( compName.compare("SUPERV") == 0 ) {
369 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
372 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
373 if ( comp->_is_nil() )
374 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
377 if (!CORBA::is_nil(comp)) {
378 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
379 if (!CORBA::is_nil(driver)) {
380 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
381 if (!CORBA::is_nil(B)) {
382 B->LoadWith(FComp,driver);
388 MESSAGE("loadComponentData(): Driver is null");
393 MESSAGE("loadComponentData(): Engine is null");
397 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
398 // if (!CORBA::is_nil(comp)) {
399 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
400 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
401 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
402 // if (!CORBA::is_nil(SC))
403 // aStudyBuilder->LoadWith(SC,driver);
407 MESSAGE("Component is null");
412 obj.reset( anIter->Value() );