From 87252edaac1826d32206ec0614c31f89b11432f1 Mon Sep 17 00:00:00 2001 From: skv Date: Tue, 19 Feb 2013 08:41:42 +0000 Subject: [PATCH] 0022012: [CEA 737] A modified object by Translate or Rotate in the python interpretor is not updated in 3D view --- src/DisplayGUI/DisplayGUI.cxx | 2 +- src/GEOMBase/GEOMBase.cxx | 15 +-- src/GEOMBase/GEOMBase_Helper.cxx | 25 +---- src/GEOMGUI/GeometryGUI.cxx | 112 ++++++++++++++++++++++ src/GEOMGUI/GeometryGUI.h | 8 ++ src/GEOM_I/GEOM_Gen_i.hh | 5 + src/GEOM_I/GEOM_IOperations_i.cc | 33 +++++++ src/GEOM_I/GEOM_IOperations_i.hh | 2 + src/GEOM_I/GEOM_ITransformOperations_i.cc | 45 +++++++++ 9 files changed, 209 insertions(+), 38 deletions(-) diff --git a/src/DisplayGUI/DisplayGUI.cxx b/src/DisplayGUI/DisplayGUI.cxx index 0dc9455d4..ec4ef5ad2 100644 --- a/src/DisplayGUI/DisplayGUI.cxx +++ b/src/DisplayGUI/DisplayGUI.cxx @@ -204,7 +204,7 @@ void DisplayGUI::EraseAll() SUIT_ViewManager* vman = vw->getViewManager(); if ( vman->getType() == OCCViewer_Viewer::Type() || vman->getType() == SVTK_Viewer::Type() ) { - GEOM_Displayer( appStudy ).EraseAll(); + GEOM_Displayer( appStudy ).EraseAll(true); } } } diff --git a/src/GEOMBase/GEOMBase.cxx b/src/GEOMBase/GEOMBase.cxx index 0e13b280e..fb56bdeaf 100644 --- a/src/GEOMBase/GEOMBase.cxx +++ b/src/GEOMBase/GEOMBase.cxx @@ -728,13 +728,7 @@ void GEOMBase::ShowErrorMessage( const QString& errorCode, const QString& commen //======================================================================= GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const QString& IOR ) { - GEOM::GEOM_Object_var geomObj; - if ( !IOR.isEmpty() ) { - CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object( IOR.toLatin1().constData() ); - if ( !CORBA::is_nil( corbaObj ) ) - geomObj = GEOM::GEOM_Object::_narrow( corbaObj ); - } - return geomObj._retn(); + return GeometryGUI::GetObjectFromIOR (IOR); } //======================================================================= @@ -743,12 +737,7 @@ GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const QString& IOR ) //======================================================================= QString GEOMBase::GetIORFromObject( GEOM::GEOM_Object_ptr object ) { - QString IOR; - if ( !CORBA::is_nil( object ) ) { - CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( object ); - IOR = anIOR.in(); - } - return IOR; + return GeometryGUI::GetIORFromObject (object); } //======================================================================= diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index 4a051722c..4d3358874 100755 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -676,30 +676,7 @@ GEOM_Displayer* GEOMBase_Helper::getDisplayer() //================================================================ void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj ) { - if ( CORBA::is_nil( theObj ) ) - return; - - CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj ); - TCollection_AsciiString asciiIOR( (char *)IOR.in() ); - GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR ); - - if ( !getStudy() || !getStudy()->studyDS() ) - return; - - _PTR(Study) aStudy = getStudy()->studyDS(); - _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) ); - if ( !aSObj ) - return; - - _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) ); - for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) { - _PTR(GenericAttribute) anAttr; - if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) { - _PTR(AttributeIOR) anIOR ( anAttr ); - TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() ); - GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR ); - } - } + GeometryGUI::ClearShapeBuffer(theObj); } //================================================================ diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 10c4d4ec6..ddc668c97 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -2326,6 +2326,118 @@ QAction* GeometryGUI::getAction(const int id) { return action(id); } +/*! + \brief GEOM module message handler + + This method can be re-implemented in the subclasses. + This is a GEOM module message handler. + + \param msg the message received. +*/ +void GeometryGUI::message(const QString& msg) +{ + // dispatch message + QStringList data = msg.split("/"); + const int nbStrings = data.count(); + + if (nbStrings > 0) { + if (data[0] == "modified") { + // get mesh entry + QString anIOR = nbStrings > 1 ? data[1] : QString(); + + if ( anIOR.isEmpty() ) { + return; + } + + // Get the geom object. + GEOM::GEOM_Object_ptr anObj = GeometryGUI::GetObjectFromIOR (anIOR); + + // Clear the shape buffer + GeometryGUI::ClearShapeBuffer (anObj); + } + } +} + +/*! + \brief Clears the shape buffer. + + This is a static method. It clears the shape buffer. + + \param theObj the object +*/ +void GeometryGUI::ClearShapeBuffer( GEOM::GEOM_Object_ptr theObj ) +{ + if ( CORBA::is_nil( theObj ) ) + return; + + CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj ); + TCollection_AsciiString asciiIOR( (char *)IOR.in() ); + GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR ); + + SALOMEDSClient_StudyManager *aManager = SalomeApp_Application::studyMgr(); + + if (!aManager) + return; + + _PTR(Study) aStudy = aManager->GetStudyByID(theObj->GetStudyID()); + + if ( !aStudy ) + return; + + _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) ); + if ( !aSObj ) + return; + + _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) ); + for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) { + _PTR(GenericAttribute) anAttr; + if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) { + _PTR(AttributeIOR) anIOR ( anAttr ); + TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() ); + GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR ); + } + } +} + +/*! + \brief Returns the object from IOR. + + This is a static method. It returns the object from its IOR. + + \param IOR object IOR + \return GEOM object. +*/ +GEOM::GEOM_Object_ptr GeometryGUI::GetObjectFromIOR( const QString& IOR ) +{ + GEOM::GEOM_Object_var geomObj; + if ( !IOR.isEmpty() ) { + CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object + ( IOR.toLatin1().constData() ); + if ( !CORBA::is_nil( corbaObj ) ) + geomObj = GEOM::GEOM_Object::_narrow( corbaObj ); + } + return geomObj._retn(); +} + +/*! + \brief Returns IOR of the object. + + This is a static method. It returns the object's IOR. + + \param object the GEOM object. + \return object's IOR. +*/ +QString GeometryGUI::GetIORFromObject( GEOM::GEOM_Object_ptr object ) +{ + QString IOR; + if ( !CORBA::is_nil( object ) ) { + CORBA::String_var anIOR = + SalomeApp_Application::orb()->object_to_string( object ); + IOR = anIOR.in(); + } + return IOR; +} + /*! \brief Check if this object is can't be renamed in place diff --git a/src/GEOMGUI/GeometryGUI.h b/src/GEOMGUI/GeometryGUI.h index 9bf6e6326..34c19c6b2 100644 --- a/src/GEOMGUI/GeometryGUI.h +++ b/src/GEOMGUI/GeometryGUI.h @@ -135,6 +135,14 @@ public: QAction* getAction(const int id); + virtual void message( const QString& msg); + static void ClearShapeBuffer( GEOM::GEOM_Object_ptr ); + static GEOM::GEOM_Object_ptr + GetObjectFromIOR( const QString& IOR ); + + static QString GetIORFromObject( GEOM::GEOM_Object_ptr object ); + + public slots: virtual bool deactivateModule( SUIT_Study* ); virtual bool activateModule( SUIT_Study* ); diff --git a/src/GEOM_I/GEOM_Gen_i.hh b/src/GEOM_I/GEOM_Gen_i.hh index 021ce1bcb..0f45c54fe 100644 --- a/src/GEOM_I/GEOM_Gen_i.hh +++ b/src/GEOM_I/GEOM_Gen_i.hh @@ -85,6 +85,11 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi // generic method to be put in a super class void register_name(char * name); + // Get ORB object + CORBA::ORB_ptr GetORB() { return CORBA::ORB::_duplicate(_orb); } + + // Get Naming Service object + SALOME_NamingService* GetNS() { return name_service; } //-----------------------------------------------------------------------// // Inherited methods from SALOMEDS::Driver // diff --git a/src/GEOM_I/GEOM_IOperations_i.cc b/src/GEOM_I/GEOM_IOperations_i.cc index b56c32942..aecbee269 100644 --- a/src/GEOM_I/GEOM_IOperations_i.cc +++ b/src/GEOM_I/GEOM_IOperations_i.cc @@ -23,6 +23,8 @@ #include "GEOM_IOperations_i.hh" #include "GEOM_Engine.hxx" +#include "GEOM_Gen_i.hh" +#include #include "utilities.h" #include "OpUtil.hxx" @@ -32,6 +34,8 @@ #include #include +#include CORBA_SERVER_HEADER(SALOME_Session) + //============================================================================= /*! * default constructor: @@ -155,3 +159,32 @@ Handle(GEOM_Object) GEOM_IOperations_i::GetObjectImpl(GEOM::GEOM_Object_ptr theO } return anImpl; } + +//============================================================================= +/*! + * UpdateGUIForObject + */ +//============================================================================= +void GEOM_IOperations_i::UpdateGUIForObject(GEOM::GEOM_Object_ptr theObj) +{ + if (!CORBA::is_nil (theObj)) { + // Cast _engine to GEOM_Gen_i type. + PortableServer::Servant aServant = myPOA->reference_to_servant(_engine.in()); + GEOM_Gen_i *anEngine = dynamic_cast(aServant); + + if (anEngine) { + SALOME_NamingService *aNameService = anEngine->GetNS(); + CORBA::Object_var aSessionObj = aNameService->Resolve("/Kernel/Session"); + SALOME::Session_var aSession = SALOME::Session::_narrow(aSessionObj); + + if (!aSession->_is_nil()) + { + std::string aMsg("GEOM/modified/"); + CORBA::String_var anIOR = anEngine->GetORB()->object_to_string(theObj); + + aMsg += anIOR.in(); + aSession->emitMessageOneWay(aMsg.c_str()); + } + } + } +} diff --git a/src/GEOM_I/GEOM_IOperations_i.hh b/src/GEOM_I/GEOM_IOperations_i.hh index dc45fffa3..9c1ea32b2 100644 --- a/src/GEOM_I/GEOM_IOperations_i.hh +++ b/src/GEOM_I/GEOM_IOperations_i.hh @@ -59,6 +59,8 @@ class GEOM_I_EXPORT GEOM_IOperations_i : public virtual POA_GEOM::GEOM_IOperatio ::GEOM_IOperations* GetImpl() { return _impl; } + virtual void UpdateGUIForObject(GEOM::GEOM_Object_ptr theObj); + private: ::GEOM_IOperations* _impl; diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.cc b/src/GEOM_I/GEOM_ITransformOperations_i.cc index 05b132959..27a3893bf 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.cc +++ b/src/GEOM_I/GEOM_ITransformOperations_i.cc @@ -100,6 +100,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::TranslateTwoPoints //Perform the translation GetOperations()->TranslateTwoPoints(anObject, aPoint1, aPoint2); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -169,6 +172,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::TranslateDXDYDZ //Perform the translation GetOperations()->TranslateDXDYDZ(anObject, theDX, theDY, theDZ); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -233,6 +239,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::TranslateVector //Perform the translation GetOperations()->TranslateVector(anObject, aVector); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -310,6 +319,10 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::TranslateVectorDistance } GetOperations()->TranslateVectorDistance(aBasicObject, aVector, theDistance, theCopy); + + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -347,6 +360,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::Rotate (GEOM::GEOM_Object_ptr //Perform the rotation GetOperations()->Rotate(anObject, anAxis, theAngle); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -413,6 +429,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::MirrorPlane //Perform the mirror GetOperations()->MirrorPlane(anObject, aPlane); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -479,6 +498,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::MirrorAxis //Perform the mirror GetOperations()->MirrorAxis(anObject, aAxis); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -545,6 +567,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::MirrorPoint //Perform the mirror GetOperations()->MirrorPoint(anObject, aPoint); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -607,6 +632,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::OffsetShape //Create the offset shape GetOperations()->OffsetShape(aBasicObject, theOffset); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -700,6 +728,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShape //Perform the scale GetOperations()->ScaleShape(anObject, aPoint, theFactor); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -778,6 +809,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShapeAlongAxes GetOperations()->ScaleShapeAlongAxes (anObject, aPoint, theFactorX, theFactorY, theFactorZ, /*doCopy*/false); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -860,6 +894,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::PositionShape //Perform the Position GetOperations()->PositionShape(anObject, aStartLCS, aEndLCS); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } @@ -933,6 +970,11 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::PositionAlongPath if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn(); + if (!theCopy) { + // Update GUI. + UpdateGUIForObject(theObject); + } + return GetObject(anObject); } @@ -1209,6 +1251,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::RotateThreePoints //Perform the translation GetOperations()->RotateThreePoints(anObject, aCentPoint, aPoint1, aPoint2); + // Update GUI. + UpdateGUIForObject(theObject); + return aGEOMObject._retn(); } -- 2.39.2