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.com
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
37 #include "GEOM_Actor.h"
40 #include "SALOME_ListIO.hxx"
41 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include <SVTK_ViewModel.h>
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_View.h>
47 #include <OCCViewer_ViewModel.h>
48 #include <OCCViewer_ViewWindow.h>
50 #include <SUIT_ViewManager.h>
51 #include <SUIT_Application.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_OverrideCursor.h>
56 #include <SUIT_MessageBox.h>
58 #include <SalomeApp_Application.h>
59 #include <SalomeApp_Study.h>
60 #include <SalomeApp_Module.h>
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_NameDlg.h>
65 #include "SALOMEDSClient.hxx"
67 #include "utilities.h"
70 #include <AIS_Drawer.hxx>
71 #include <AIS_ListOfInteractive.hxx>
72 #include <AIS_ListIteratorOfListOfInteractive.hxx>
73 #include <Prs3d_IsoAspect.hxx>
74 #include <Prs3d_PointAspect.hxx>
75 #include <Graphic3d_AspectMarker3d.hxx>
78 #include <vtkBMPReader.h>
79 #include <vtkTexture.h>
80 #include <vtkTextureMapToPlane.h>
81 #include <vtkTransformTextureCoords.h>
82 #include <vtkDataSetMapper.h>
83 #include <vtkRenderer.h>
86 #include <qfileinfo.h>
87 #include <qcolordialog.h>
89 #include <qapplication.h>
94 void GEOMToolsGUI::OnSettingsColor()
96 SUIT_Session* sess = SUIT_Session::session();
97 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
98 SUIT_Desktop* desk = sess->activeApplication()->desktop();
100 QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
102 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
103 if( aDialogColor.isValid() )
105 QString type = desk->activeWindow()->getViewManager()->getType();
106 if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
107 MESSAGE("Settings Color is not supported for current Viewer");
109 resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
113 void GEOMToolsGUI::OnSettingsIsos()
116 SUIT_Session* sess = SUIT_Session::session();
117 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
118 SUIT_Desktop* desk = sess->activeApplication()->desktop();
120 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
121 QString type = vman->getType();
123 if ( type != OCCViewer_Viewer::Type() )
126 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
127 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
129 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
130 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
132 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
133 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
135 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
137 NbIsosDlg->SpinBoxU->setValue(IsoU);
138 NbIsosDlg->SpinBoxV->setValue(IsoV);
140 if(NbIsosDlg->exec()) {
141 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
142 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
144 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
145 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
146 resMgr->setValue("Geometry:SettingsIsoU", isoU);
147 resMgr->setValue("Geometry:SettingsIsoV", isoV);
152 void GEOMToolsGUI::OnSettingsStep()
154 SUIT_Session* sess = SUIT_Session::session();
155 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
157 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
159 Standard_Boolean res = false;
160 double dd = GEOMBase::Parameter( res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
162 resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
164 /* Emit signal to GeometryGUI_SpinBoxes */
165 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
168 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
171 void GEOMToolsGUI::OnRename()
173 SALOME_ListIO selected;
174 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
176 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
177 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
178 if ( aSelMgr && appStudy ) {
179 aSelMgr->selectedObjects( selected );
180 if ( !selected.IsEmpty() ) {
181 _PTR(Study) aStudy = appStudy->studyDS();
183 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
185 SUIT_MessageBox::warn1 ( app->desktop(),
186 QObject::tr("WRN_WARNING"),
187 QObject::tr("WRN_STUDY_LOCKED"),
188 QObject::tr("BUT_OK") );
192 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
193 Handle(SALOME_InteractiveObject) IObject = It.Value();
195 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
196 _PTR(GenericAttribute) anAttr;
198 if( obj->FindAttribute(anAttr, "AttributeName") ) {
199 _PTR(AttributeName) aName (anAttr);
201 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
202 if ( !newName.isEmpty() ) {
203 aName->SetValue( newName.latin1() ); // rename the SObject
204 IObject->setName( newName.latin1() );// rename the InteractiveObject
205 // Rename the corresponding GEOM_Object
206 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
207 if (!CORBA::is_nil( anObj ))
208 anObj->SetName( newName.latin1() );
209 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
211 } // if ( name attribute )
218 app->updateActions(); //SRN: To update a Save button in the toolbar
221 void GEOMToolsGUI::OnCheckGeometry()
223 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
224 PythonConsole* pyConsole = app->pythonConsole();
227 pyConsole->exec("from GEOM_usinggeom import *");
230 void GEOMToolsGUI::OnColor()
232 SALOME_ListIO selected;
233 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
235 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
237 aSelMgr->selectedObjects( selected );
238 if ( !selected.IsEmpty() ) {
239 SUIT_ViewWindow* window = app->desktop()->activeWindow();
240 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
241 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
243 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
246 SVTK_View* aView = vtkVW->getView();
247 QColor initcolor = aView->GetColor( selected.First() );
248 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
250 SUIT_OverrideCursor();
251 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
252 aView->SetColor( It.Value(), c );
257 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
258 if ( !io.IsNull() ) {
259 Quantity_Color aColor;
261 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
262 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
264 SUIT_OverrideCursor();
265 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
266 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
267 io = GEOMBase::GetAIS( It.Value(), true );
268 if ( !io.IsNull() ) {
269 // Set color for a point
270 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
271 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
272 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
273 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
274 Quantity_Color aCurColor;
275 Standard_Real aCurScale;
276 Aspect_TypeOfMarker aCurTypeOfMarker;
277 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
278 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
279 ic->SetLocalAttributes(io, aCurDrawer);
281 io->SetColor( aColor );
282 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
283 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
285 io->Redisplay( Standard_True );
289 } // first IO is not null
291 } // if ( selection not empty )
295 app->updateActions(); //SRN: To update a Save button in the toolbar
298 void GEOMToolsGUI::OnTransparency()
300 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
304 void GEOMToolsGUI::OnNbIsos()
306 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
307 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
312 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
313 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
316 if ( ic->MoreCurrent() ) {
317 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
318 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
320 int UIso = CurDrawer->UIsoAspect()->Number();
321 int VIso = CurDrawer->VIsoAspect()->Number();
323 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
324 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
326 NbIsosDlg->setU( UIso );
327 NbIsosDlg->setV( VIso );
329 if ( NbIsosDlg->exec() ) {
330 SUIT_OverrideCursor();
331 for(; ic->MoreCurrent(); ic->NextCurrent()) {
332 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
333 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
335 int nbUIso = NbIsosDlg->getU();
336 int nbVIso = NbIsosDlg->getV();
338 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
339 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
341 ic->SetLocalAttributes(CurObject, CurDrawer);
342 ic->Redisplay(CurObject);
348 void GEOMToolsGUI::OnOpen()
351 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
352 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
354 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
355 Handle(SALOME_InteractiveObject) anIObject;
356 for(;It.More();It.Next()) {
357 anIObject = It.Value();
358 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
359 _PTR(AttributePersistentRef) aPersist;
360 _PTR(AttributeIOR) anIOR;
362 // this SObject may be GEOM module root SObject
363 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
364 _PTR(GenericAttribute) anAttr;
365 bool useSubItems = false;
366 while (anIter->More() && !useSubItems) {
367 _PTR(SObject) subobj ( anIter->Value() );
368 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
375 obj->FindAttribute(anAttr, "AttributePersistentRef");
377 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
378 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
379 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
380 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
382 if (FComp->FindAttribute(anAttr, "AttributeName")) {
383 _PTR(AttributeName) aName ( anAttr );
384 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
385 // parent->loadComponentData(parent->getComponentName(aName->Value()));
386 Engines::Component_var comp ;
387 if ( compName.compare("SUPERV") == 0 ) {
388 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
391 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
392 if ( comp->_is_nil() )
393 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
396 if (!CORBA::is_nil(comp)) {
397 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
398 if (!CORBA::is_nil(driver)) {
399 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
400 if (!CORBA::is_nil(B)) {
401 B->LoadWith(FComp,driver);
407 MESSAGE("loadComponentData(): Driver is null");
412 MESSAGE("loadComponentData(): Engine is null");
416 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
417 // if (!CORBA::is_nil(comp)) {
418 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
419 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
420 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
421 // if (!CORBA::is_nil(SC))
422 // aStudyBuilder->LoadWith(SC,driver);
426 MESSAGE("Component is null");
431 obj.reset( anIter->Value() );
441 void GEOMToolsGUI::OnSelectOnly(int mode)
443 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
445 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
446 GEOM_Displayer aDisp (appStudy);
447 aDisp.GlobalSelection(mode);
448 getGeometryGUI()->setLocalSelectionMode(mode);