0023450: Fields are not displayed in GEOM

- Make color scale a property of the OCC view model
- Redesign color scale management
This commit is contained in:
vsr 2017-09-28 16:08:10 +03:00
parent 1f0425a582
commit 935cd27401
5 changed files with 94 additions and 153 deletions

View File

@ -462,7 +462,7 @@ static std::string getName( GEOM::GEOM_BaseObject_ptr object )
*/ */
//================================================================= //=================================================================
GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
: myUpdateColorScale(true), myIsRedisplayed( false ) : myUpdateColorScale( true ), myIsRedisplayed( false )
{ {
if( st ) if( st )
myApp = dynamic_cast<SalomeApp_Application*>( st->application() ); myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
@ -510,11 +510,6 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
myViewFrame = 0; myViewFrame = 0;
myColorScale = new AIS_ColorScale;
myColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
myColorScale->SetTransformPersistence (
Graphic3d_TransformPers::FromDeprecatedParams(Graphic3d_TMF_2d, gp_Pnt (-1,-1,0)));
myFieldDataType = GEOM::FDT_Double; myFieldDataType = GEOM::FDT_Double;
myFieldDimension = 0; myFieldDimension = 0;
myFieldStepRangeMin = 0; myFieldStepRangeMin = 0;
@ -2069,7 +2064,7 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p ) void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
{ {
UpdateColorScale(false,false); UpdateColorScale();
// visualize annotations for displayed presentation // visualize annotations for displayed presentation
SUIT_Session* session = SUIT_Session::session(); SUIT_Session* session = SUIT_Session::session();
@ -2093,7 +2088,7 @@ void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p ) void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
{ {
LightApp_Displayer::AfterErase( v, p ); LightApp_Displayer::AfterErase( v, p );
UpdateColorScale(false,false); UpdateColorScale();
if ( !myIsRedisplayed ) { if ( !myIsRedisplayed ) {
// hide annotations for erased presentation // hide annotations for erased presentation
@ -2967,140 +2962,91 @@ QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldS
return aResultList; return aResultList;
} }
void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) void GEOM_Displayer::UpdateColorScale()
{ {
SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() ); if ( !myUpdateColorScale )
if( !aStudy )
return; return;
SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() ); SUIT_Session* session = SUIT_Session::session();
if( !aViewModel ) SUIT_Application* app = session->activeApplication();
return; if ( !app ) return;
Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d(); Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject();
if( aViewer.IsNull() )
return;
aViewer->InitActiveViews(); QList<SUIT_ViewWindow*> windows = app->desktop()->windows();
if( !aViewer->MoreActiveViews() ) foreach( SUIT_ViewWindow* window, windows )
return;
Handle(V3d_View) aView = aViewer->ActiveView();
if( aView.IsNull() )
return;
Standard_Boolean anIsDisplayColorScale = Standard_False;
TCollection_AsciiString aColorScaleTitle;
Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
Standard_Boolean anIsBoolean = Standard_False;
Handle(SALOME_InteractiveObject) anIO;
if ( myUpdateColorScale )
anIO = myApp->selectionMgr()->soleSelectedObject();
if( !anIO.IsNull() )
{ {
SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) ); OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>( window );
if( aPrs ) if ( !occWindow->getViewManager() ) continue;
if ( !window->getViewManager() ) continue;
if ( !window->getViewManager()->getViewModel() ) continue;
SOCC_Viewer* view = dynamic_cast<SOCC_Viewer*>( window->getViewManager()->getViewModel() );
if ( !view ) continue;
Handle(V3d_Viewer) viewer = view->getViewer3d();
if ( !io.IsNull() && view->isVisible( io ) )
{ {
AIS_ListOfInteractive aList; bool visible = false;
aPrs->GetObjects( aList ); SOCC_Prs* prs = dynamic_cast<SOCC_Prs*>( view->CreatePrs( io->getEntry() ) );
AIS_ListIteratorOfListOfInteractive anIter( aList ); if ( prs )
for( ; anIter.More(); anIter.Next() )
{ {
Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() ); AIS_ListOfInteractive presentations;
if( !aShape.IsNull() ) prs->GetObjects( presentations );
AIS_ListIteratorOfListOfInteractive iter( presentations );
for ( ; iter.More(); iter.Next() )
{ {
GEOM::field_data_type aFieldDataType; Handle(GEOM_AISShape) shape = Handle(GEOM_AISShape)::DownCast( iter.Value() );
int aFieldDimension; if ( shape.IsNull() ) continue;
QList<QVariant> aFieldStepData; GEOM::field_data_type fieldDataType;
TCollection_AsciiString aFieldStepName; int fieldDimension;
double aFieldStepRangeMin, aFieldStepRangeMax; QList<QVariant> fieldStepData;
aShape->getFieldStepInfo( aFieldDataType, TCollection_AsciiString fieldStepName;
aFieldDimension, Standard_Real fieldStepRangeMin, fieldStepRangeMax;
aFieldStepData, shape->getFieldStepInfo( fieldDataType, fieldDimension, fieldStepData,
aFieldStepName, fieldStepName, fieldStepRangeMin, fieldStepRangeMax );
aFieldStepRangeMin, visible = !fieldStepData.isEmpty() && fieldDataType != GEOM::FDT_String;
aFieldStepRangeMax ); if ( visible )
if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
{ {
anIsDisplayColorScale = Standard_True; SUIT_Session* session = SUIT_Session::session();
aColorScaleTitle = aFieldStepName; SUIT_ResourceMgr* resMgr = session->resourceMgr();
aColorScaleMin = aFieldStepRangeMin;
aColorScaleMax = aFieldStepRangeMax; Standard_Real xPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
anIsBoolean = aFieldDataType == GEOM::FDT_Bool; Standard_Real yPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
} Standard_Real width = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
Standard_Real height = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
Standard_Integer textHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
Standard_Integer nbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
Standard_Integer viewWidth = 0, viewHeight = 0;
occWindow->getView(0)->getViewPort()->getView()->Window()->Size( viewWidth, viewHeight );
Handle(AIS_ColorScale) colorScale = view->getColorScale();
colorScale->SetPosition( viewWidth * xPos, viewHeight * yPos );
colorScale->SetBreadth( viewWidth * width );
colorScale->SetHeight( viewHeight * height );
colorScale->SetRange( fieldStepRangeMin, fieldStepRangeMax );
printf("fieldStepRangeMin, fieldStepRangeMax: %f, %f\n", fieldStepRangeMin, fieldStepRangeMax);
colorScale->SetNumberOfIntervals( fieldDataType == GEOM::FDT_Bool ? 2 : nbIntervals );
colorScale->SetTextHeight( textHeight );
colorScale->SetTitle( fieldStepName );
} // if ( visible )
} }
} }
} view->setColorScaleShown( visible );
} } // if ( view->isVisible( io ) )
else
if( anIsDisplayColorScale )
{
SUIT_Session* session = SUIT_Session::session();
SUIT_ResourceMgr* resMgr = session->resourceMgr();
Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
Standard_Integer aWinWidth = 0, aWinHeight = 0;
aView->Window()->Size (aWinWidth, aWinHeight);
myColorScale->SetPosition (aWinWidth*anXPos, aWinHeight*anYPos);
//myColorScale->SetBreadth (aWinWidth); // ???
myColorScale->SetBreadth (aWinWidth*aWidth); // ???
myColorScale->SetHeight (aWinHeight*aHeight);
myColorScale->SetRange( aColorScaleMin, aColorScaleMax );
myColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
myColorScale->SetTextHeight( aTextHeight );
myColorScale->SetTitle( aColorScaleTitle );
if( !aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
aViewModel->getAISContext()->Display( myColorScale, Standard_True);
}
else {
if( aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
aViewModel->getAISContext()->Erase( myColorScale, Standard_True );
}
if( theIsRedisplayFieldSteps )
{
_PTR(Study) aStudyDS = aStudy->studyDS();
QList<SUIT_ViewManager*> vmList;
myApp->viewManagers( vmList );
for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
{ {
if( SUIT_ViewManager* aViewManager = *vmIt ) view->setColorScaleShown( false );
{
const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
{
_PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
if( aSObj )
{
CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
if( !CORBA::is_nil( anObject ) )
{
GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
if( !aFieldStep->_is_nil() )
{
CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
Handle(SALOME_InteractiveObject) aStepIO =
new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
Redisplay( aStepIO, false, false );
}
}
}
}
}
} }
} } // foreach( SUIT_ViewWindow* window, windows )
if(updateViewer)
UpdateViewer();
} }
bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049
{
bool previous = myUpdateColorScale;
myUpdateColorScale = toUpdate;
if ( myUpdateColorScale && !previous )
UpdateColorScale();
return previous;
}

View File

@ -45,7 +45,6 @@ class SALOME_OCCViewType;
#include <LightApp_Displayer.h> #include <LightApp_Displayer.h>
#include <LightApp_Study.h> #include <LightApp_Study.h>
#include <Aspect_TypeOfMarker.hxx> #include <Aspect_TypeOfMarker.hxx>
#include <AIS_ColorScale.hxx>
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
#include <TColStd_MapOfInteger.hxx> #include <TColStd_MapOfInteger.hxx>
#include <QList> #include <QList>
@ -226,8 +225,8 @@ public:
SALOME_View* = 0); SALOME_View* = 0);
/* Update visibility and parameters of the currently selected field step's color scale */ /* Update visibility and parameters of the currently selected field step's color scale */
void UpdateColorScale( const bool theIsRedisplayFieldSteps = false, const bool updateViewer = true ); void UpdateColorScale();
void SetUpdateColorScale(bool toUpdate) { myUpdateColorScale = toUpdate; } // IPAL54049 bool SetUpdateColorScale(bool);
protected: protected:
/* internal methods */ /* internal methods */
@ -287,8 +286,7 @@ protected:
std::string myTexture; std::string myTexture;
int myType; int myType;
SALOME_View* myViewFrame; SALOME_View* myViewFrame;
Handle(AIS_ColorScale) myColorScale; bool myUpdateColorScale; // IPAL54049
int myUpdateColorScale; // IPAL54049
// Attributes // Attributes
Quantity_Color myShadingColor; Quantity_Color myShadingColor;

View File

@ -230,7 +230,7 @@ GeometryGUI::GeometryGUI() :
myTextTreeWdg = 0; myTextTreeWdg = 0;
myAnnotationMgr = 0; myAnnotationMgr = 0;
connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ) ); connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ), Qt::UniqueConnection );
Q_INIT_RESOURCE( GEOMGUI ); Q_INIT_RESOURCE( GEOMGUI );
} }
@ -1863,7 +1863,7 @@ bool GeometryGUI::activateModule( SUIT_Study* study )
// end of GEOM plugins loading // end of GEOM plugins loading
connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
// Reset actions accelerator keys // Reset actions accelerator keys
action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
@ -1874,9 +1874,9 @@ bool GeometryGUI::activateModule( SUIT_Study* study )
LightApp_SelectionMgr* sm = getApp()->selectionMgr(); LightApp_SelectionMgr* sm = getApp()->selectionMgr();
connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() )); connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() ), Qt::UniqueConnection );
connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( onAutoBringToFront() )); connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( onAutoBringToFront() ), Qt::UniqueConnection );
connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( updateFieldColorScale() )); connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( updateFieldColorScale() ), Qt::UniqueConnection );
if ( !myCreationInfoWdg ) if ( !myCreationInfoWdg )
myCreationInfoWdg = new GEOMGUI_CreationInfoWdg( getApp() ); myCreationInfoWdg = new GEOMGUI_CreationInfoWdg( getApp() );
@ -1913,7 +1913,7 @@ bool GeometryGUI::activateModule( SUIT_Study* study )
QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId ); QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
if ( viewMenu ) if ( viewMenu )
connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) ); connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ), Qt::UniqueConnection );
// 0020836 (Basic vectors and origin) // 0020836 (Basic vectors and origin)
SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
@ -1952,7 +1952,7 @@ bool GeometryGUI::deactivateModule( SUIT_Study* study )
LightApp_SelectionMgr* selMrg = getApp()->selectionMgr(); LightApp_SelectionMgr* selMrg = getApp()->selectionMgr();
disconnect( selMrg, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() )); disconnect( selMrg, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() ));
disconnect( selMrg, SIGNAL( currentSelectionChanged() ), this, SLOT( updateFieldColorScale() )); //disconnect( selMrg, SIGNAL( currentSelectionChanged() ), this, SLOT( updateFieldColorScale() ));
if ( myCreationInfoWdg ) { if ( myCreationInfoWdg ) {
getApp()->removeDockWindow( myCreationInfoWdg->getWinID() ); getApp()->removeDockWindow( myCreationInfoWdg->getWinID() );
myCreationInfoWdg = 0; myCreationInfoWdg = 0;
@ -2212,8 +2212,7 @@ void GeometryGUI::updateFieldColorScale()
{ {
if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) ) if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) )
{ {
GEOM_Displayer aDisplayer( aStudy ); GEOM_Displayer( aStudy ).UpdateColorScale();
aDisplayer.UpdateColorScale();
} }
} }
@ -2818,9 +2817,7 @@ void GeometryGUI::preferencesChanged( const QString& section, const QString& par
param == QString("scalar_bar_nb_intervals")) { param == QString("scalar_bar_nb_intervals")) {
if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) ) if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) )
{ {
GEOM_Displayer aDisplayer( aStudy ); updateFieldColorScale();
bool anIsRedisplayFieldSteps = param == QString("scalar_bar_nb_intervals");
aDisplayer.UpdateColorScale( anIsRedisplayFieldSteps, true );
} }
} }
else if ( param == QString("dimensions_color") || else if ( param == QString("dimensions_color") ||

View File

@ -467,7 +467,7 @@ void GEOMToolsGUI::OnEditDelete()
_PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder()); _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
GEOM_Displayer disp( appStudy ); GEOM_Displayer disp( appStudy );
disp.SetUpdateColorScale( false ); // IPAL54049 bool toUpdateColorScale = disp.SetUpdateColorScale( false ); // IPAL54049
if ( isComponentSelected ) { if ( isComponentSelected ) {
// GEOM component is selected: delete all objects recursively // GEOM component is selected: delete all objects recursively
@ -519,6 +519,7 @@ void GEOMToolsGUI::OnEditDelete()
} }
} }
disp.SetUpdateColorScale( toUpdateColorScale ); // IPAL54049
selected.Clear(); selected.Clear();
aSelMgr->setSelectedObjects( selected ); aSelMgr->setSelectedObjects( selected );
getGeometryGUI()->updateObjBrowser(); getGeometryGUI()->updateObjBrowser();

View File

@ -529,7 +529,7 @@ void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
} }
SUIT_OverrideCursor wc; SUIT_OverrideCursor wc;
disp->SetUpdateColorScale( false ); // IPAL54049 bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
Handle(SALOME_InteractiveObject) IObject = It.Value(); Handle(SALOME_InteractiveObject) IObject = It.Value();
@ -543,7 +543,7 @@ void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
} }
} // if ( obj ) } // if ( obj )
} // iterator } // iterator
disp->SetUpdateColorScale( true ); disp->SetUpdateColorScale( toUpdateColorScale );
} }
} }
app->updateObjectBrowser( false ); app->updateObjectBrowser( false );
@ -596,7 +596,7 @@ void GEOMToolsGUI::OnUnpublishObject() {
return; return;
} }
SUIT_OverrideCursor wc; SUIT_OverrideCursor wc;
disp->SetUpdateColorScale( false ); // IPAL54049 bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
Handle(SALOME_InteractiveObject) IObject = It.Value(); Handle(SALOME_InteractiveObject) IObject = It.Value();
@ -615,14 +615,13 @@ void GEOMToolsGUI::OnUnpublishObject() {
} }
} // if ( obj ) } // if ( obj )
} // iterator } // iterator
disp->SetUpdateColorScale( true ); // IPAL54049 disp->SetUpdateColorScale( toUpdateColorScale ); // IPAL54049
aSelMgr->clearSelected(); aSelMgr->clearSelected();
} }
} }
app->updateObjectBrowser( false ); app->updateObjectBrowser( false );
app->updateActions(); app->updateActions();
} }
} }
void GEOMToolsGUI::OnPublishObject() { void GEOMToolsGUI::OnPublishObject() {