geom/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx

414 lines
14 KiB
C++
Raw Normal View History

2004-12-01 15:39:14 +05:00
// GEOM GEOMGUI : GUI for Geometry component
//
// Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
//
//
//
// File : GEOMToolsGUI_1.cxx
// Author : Sergey ANIKIN
// Module : GEOM
// $Header$
#include <PythonConsole_PyConsole.h>
2004-12-01 15:39:14 +05:00
#include "GEOMToolsGUI.h"
#include "GeometryGUI.h"
#include "GEOM_Actor.h"
#include "GEOMBase.h"
#include "GEOMToolsGUI_TransparencyDlg.h"
#include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
#include "GEOMToolsGUI_NameDlg.h"
#include <SALOME_ListIO.hxx>
#include <SALOME_ListIteratorOfListIO.hxx>
#include <VTKViewer_ViewModel.h>
#include <OCCViewer_ViewModel.h>
#include <OCCViewer_ViewWindow.h>
2004-12-01 15:39:14 +05:00
#include <SVTK_ViewWindow.h>
#include <SVTK_RenderWindowInteractor.h>
2004-12-01 15:39:14 +05:00
#include <SUIT_ViewManager.h>
#include <SUIT_Application.h>
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <SUIT_OverrideCursor.h>
#include <SUIT_MessageBox.h>
2004-12-01 15:39:14 +05:00
#include <SalomeApp_Application.h>
#include <SalomeApp_SelectionMgr.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_Module.h>
2004-12-01 15:39:14 +05:00
#include <AIS_Drawer.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <vtkBMPReader.h>
#include <vtkTexture.h>
#include <vtkTextureMapToPlane.h>
#include <vtkTransformTextureCoords.h>
#include <vtkDataSetMapper.h>
#include <vtkRenderer.h>
#include <qfileinfo.h>
#include <qcolordialog.h>
#include <qspinbox.h>
#include <qapplication.h>
#include "utilities.h"
using namespace std;
#include "SALOMEDSClient.hxx"
#include "SALOMEDS_Study.hxx"
2004-12-01 15:39:14 +05:00
void GEOMToolsGUI::OnSettingsColor()
{
SUIT_Session* sess = SUIT_Session::session();
SUIT_ResourceMgr* resMgr = sess->resourceMgr();
SUIT_Desktop* desk = sess->activeApplication()->desktop();
QColor anInitColor = resMgr->colorValue( "Geometry:SettingsShadingColor", QColor( "yellow" ) );
2004-12-01 15:39:14 +05:00
QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
if( aDialogColor.isValid() )
{
QString type = desk->activeWindow()->getViewManager()->getType();
if( type != OCCViewer_Viewer::Type() && type != VTKViewer_Viewer::Type() )
2004-12-01 15:39:14 +05:00
MESSAGE("Settings Color is not supported for current Viewer");
resMgr->setValue( "Geometry:SettingsShadingColor", aDialogColor );
2004-12-01 15:39:14 +05:00
}
}
void GEOMToolsGUI::OnSettingsIsos()
{
/*
SUIT_Session* sess = SUIT_Session::session();
SUIT_ResourceMgr* resMgr = sess->resourceMgr();
SUIT_Desktop* desk = sess->activeApplication()->desktop();
SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
QString type = vman->getType();
if ( type != OCCViewer_Viewer::Type() )
2004-12-01 15:39:14 +05:00
return;
OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
Handle (AIS_InteractiveContext) ic = vm->getAISContext();
2004-12-01 15:39:14 +05:00
int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
2004-12-01 15:39:14 +05:00
ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
2004-12-01 15:39:14 +05:00
GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
2004-12-01 15:39:14 +05:00
NbIsosDlg->SpinBoxU->setValue(IsoU);
NbIsosDlg->SpinBoxV->setValue(IsoV);
2004-12-01 15:39:14 +05:00
if(NbIsosDlg->exec()) {
IsoU = NbIsosDlg->SpinBoxU->text().toInt();
IsoV = NbIsosDlg->SpinBoxV->text().toInt();
2004-12-01 15:39:14 +05:00
ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
resMgr->setValue("Geometry:SettingsIsoU", isoU);
resMgr->setValue("Geometry:SettingsIsoV", isoV);
2004-12-01 15:39:14 +05:00
}
*/
2004-12-01 15:39:14 +05:00
}
void GEOMToolsGUI::OnSettingsStep()
{
SUIT_Session* sess = SUIT_Session::session();
SUIT_ResourceMgr* resMgr = sess->resourceMgr();
double step = resMgr->doubleValue( "Geometry:SettingsGeomStep", 100. );
2004-12-01 15:39:14 +05:00
Standard_Boolean res = false;
double dd = GEOMBase::Parameter(res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
if(res) {
resMgr->setValue( "Geometry:SettingsGeomStep", dd );
2004-12-01 15:39:14 +05:00
/* Emit signal to GeometryGUI_SpinBoxes */
getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
2004-12-01 15:39:14 +05:00
}
else
sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
2004-12-01 15:39:14 +05:00
}
void GEOMToolsGUI::OnRename()
{
SALOME_ListIO selected;
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
if ( app ) {
SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
if ( aSelMgr && appStudy ) {
aSelMgr->selectedObjects( selected );
if ( !selected.IsEmpty() ) {
_PTR(Study) aStudy = appStudy->studyDS();
bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
if ( aLocked ) {
SUIT_MessageBox::warn1 ( app->desktop(),
QObject::tr("WRN_WARNING"),
QObject::tr("WRN_STUDY_LOCKED"),
QObject::tr("BUT_OK") );
return;
}
2004-12-01 15:39:14 +05:00
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
Handle(SALOME_InteractiveObject) IObject = It.Value();
2004-12-01 15:39:14 +05:00
_PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
_PTR(GenericAttribute) anAttr;
if ( obj ) {
if( obj->FindAttribute(anAttr, "AttributeName") ) {
_PTR(AttributeName) aName (anAttr);
2004-12-01 15:39:14 +05:00
QString newName = GEOMToolsGUI_NameDlg::getName( app->desktop(), aName->Value().c_str() );
if ( !newName.isEmpty() ) {
aName->SetValue( newName.latin1() ); // rename the SObject
IObject->setName( newName.latin1() );// rename the InteractiveObject
(dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
}
} // if ( name attribute )
} // if ( obj )
} // iterator
2004-12-01 15:39:14 +05:00
}
}
}
}
void GEOMToolsGUI::OnCheckGeometry()
{
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
PythonConsole* pyConsole = app->pythonConsole();
2004-12-01 15:39:14 +05:00
if(pyConsole)
pyConsole->exec("from GEOM_usinggeom import *");
2004-12-01 15:39:14 +05:00
}
void GEOMToolsGUI::OnColor()
{
SALOME_ListIO selected;
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
if ( app ) {
SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
if ( aSelMgr ) {
aSelMgr->selectedObjects( selected );
if ( !selected.IsEmpty() ) {
SUIT_ViewWindow* window = app->desktop()->activeWindow();
bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
bool isVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
if ( isVTK ) {
SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
if ( !vtkVW )
return;
SVTK_RenderWindowInteractor* rwi = vtkVW->getRWInteractor();
QColor initcolor = rwi->GetColor( selected.First() );
QColor c = QColorDialog::getColor( QColor(), app->desktop() );
if ( c.isValid() ) {
SUIT_OverrideCursor();
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
rwi->SetColor( It.Value(), c );
}
}
} // if ( isVTK )
else if ( isOCC ) {
Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
if ( !io.IsNull() ) {
Quantity_Color aColor;
io->Color( aColor );
QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
QColor c = QColorDialog::getColor( initcolor, app->desktop() );
if ( c.isValid() ) {
SUIT_OverrideCursor();
aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
io = GEOMBase::GetAIS( It.Value(), true );
if ( !io.IsNull() ) {
io->SetColor( aColor );
if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
2004-12-01 15:39:14 +05:00
io->Redisplay( Standard_True );
}
}
} // if c.isValid()
} // first IO is not null
} // if ( isOCC )
} // if ( selection not empty )
2004-12-01 15:39:14 +05:00
}
}
}
void GEOMToolsGUI::OnTransparency()
{
GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
dlg.exec();
2004-12-01 15:39:14 +05:00
}
void GEOMToolsGUI::OnNbIsos()
{
SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
if ( !isOCC )
2004-12-01 15:39:14 +05:00
return;
OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
Handle (AIS_InteractiveContext) ic = vm->getAISContext();
2004-12-01 15:39:14 +05:00
ic->InitCurrent();
if ( ic->MoreCurrent() ) {
2004-12-01 15:39:14 +05:00
Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
int UIso = CurDrawer->UIsoAspect()->Number();
int VIso = CurDrawer->VIsoAspect()->Number();
GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
2004-12-01 15:39:14 +05:00
NbIsosDlg->setU( UIso );
NbIsosDlg->setV( VIso );
2004-12-01 15:39:14 +05:00
if ( NbIsosDlg->exec() ) {
SUIT_OverrideCursor();
2004-12-01 15:39:14 +05:00
for(; ic->MoreCurrent(); ic->NextCurrent()) {
CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
int nbUIso = NbIsosDlg->getU();
int nbVIso = NbIsosDlg->getV();
2004-12-01 15:39:14 +05:00
CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
ic->SetLocalAttributes(CurObject, CurDrawer);
ic->Redisplay(CurObject);
}
}
}
}
void GEOMToolsGUI::OnOpen()
{
/*
2004-12-01 15:39:14 +05:00
SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
_PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
2004-12-01 15:39:14 +05:00
SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
Handle(SALOME_InteractiveObject) anIObject;
for(;It.More();It.Next()) {
anIObject = It.Value();
_PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
_PTR(AttributePersistentRef) aPersist;
_PTR(AttributeIOR) anIOR;
if(obj) {
2004-12-01 15:39:14 +05:00
// this SObject may be GEOM module root SObject
_PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
_PTR(GenericAttribute) anAttr;
2004-12-01 15:39:14 +05:00
bool useSubItems = false;
while (anIter->More() && !useSubItems) {
_PTR(SObject) subobj ( anIter->Value() );
2004-12-01 15:39:14 +05:00
if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
useSubItems = true;
obj = subobj;
2004-12-01 15:39:14 +05:00
}
else
anIter->Next();
}
obj->FindAttribute(anAttr, "AttributePersistentRef");
while(useSubItems?anIter->More():!anAttr->_is_nil()) {
if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
obj->FindAttribute(anAttr, "AttributePersistentRef")) {
_PTR(SComponent) FComp ( obj->GetFatherComponent() );
if (FComp) {
2004-12-01 15:39:14 +05:00
if (FComp->FindAttribute(anAttr, "AttributeName")) {
_PTR(AttributeName) aName ( anAttr );
QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
2004-12-01 15:39:14 +05:00
// parent->loadComponentData(parent->getComponentName(aName->Value()));
Engines::Component_var comp ;
if ( compName.compare("SUPERV") == 0 ) {
comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
}
else {
comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
if ( comp->_is_nil() )
comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
}
if (!CORBA::is_nil(comp)) {
SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
if (!CORBA::is_nil(driver)) {
SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
2004-12-01 15:39:14 +05:00
if (!CORBA::is_nil(B)) {
B->LoadWith(FComp,driver);
} else {
return;
}
}
else {
MESSAGE("loadComponentData(): Driver is null");
return;
}
}
else {
MESSAGE("loadComponentData(): Engine is null");
return;
}
// // load
// Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
// if (!CORBA::is_nil(comp)) {
// SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
// SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
// SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
// if (!CORBA::is_nil(SC))
// aStudyBuilder->LoadWith(SC,driver);
}
}
else {
MESSAGE("Component is null");
}
}
if(useSubItems) {
anIter->Next();
obj.reset( anIter->Value() );
2004-12-01 15:39:14 +05:00
}
else
anAttr = NULL;
2004-12-01 15:39:14 +05:00
}
}
}
*/
2004-12-01 15:39:14 +05:00
}