0021830: [CEA 652] TUI createAndDisplayGO (part 3)

This commit is contained in:
vsr 2013-02-01 09:37:57 +00:00
parent 549029bef0
commit cd35569bd0
3 changed files with 171 additions and 149 deletions

View File

@ -1457,88 +1457,38 @@ void GEOMToolsGUI::OnClsBringToFront() {
void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam ) void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
{ {
QString theName; if ( !theParam.canConvert<QString>() ) return;
if ( theParam.canConvert<QString>() ) theName = theParam.toString();
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); QString theName = theParam.toString();
if ( !app )
return; SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule()); if ( !app ) return;
if(!mod)
return; SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
GEOM_Displayer* disp = dynamic_cast<GEOM_Displayer*>(mod->displayer()); if ( !study ) return;
if(!disp)
return; LightApp_SelectionMgr* selMgr = app->selectionMgr();
LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ); SALOME_ListIO selected;
if ( !aSelMgr || !study ) selMgr->selectedObjects( selected );
return;
SALOME_ListIO selected; if ( selected.IsEmpty() ) return;
aSelMgr->selectedObjects( selected );
if ( selected.IsEmpty() ) GEOM_Displayer displayer( study );
return;
SUIT_ViewWindow* window = app->desktop()->activeWindow(); SALOME_View* window = displayer.GetActiveView();
int mgrId = window ? window->getViewManager()->getGlobalId() : -1; if ( !window ) return;
int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
// convert needed material properties to the string representation
Material_Model aModel; Material_Model aModel;
aModel.fromResources( theName ); aModel.fromResources( theName );
QString prop = aModel.toProperties(); QString prop = aModel.toProperties();
if ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ) {
// for VTK viewer
SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
if ( !vtkVW )
return;
SVTK_View* aView = vtkVW->getView(); for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
Handle(SALOME_InteractiveObject) io = It.Value();
// get VTK material properties from the current model study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
GEOM_VTKPropertyMaterial* vtkPropF = aModel.getMaterialVTKProperty(); if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
GEOM_VTKPropertyMaterial* vtkPropB = aModel.getMaterialVTKProperty( false );
SUIT_OverrideCursor wc();
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
// set material property to the presentation
aView->SetMaterial( It.Value(), vtkPropF, vtkPropB );
// store chosen material in the property map
study->setObjectProperty( mgrId, It.Value()->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
// set correct color for the non-physical material
}
aView->Repaint();
GeometryGUI::Modified();
}
else if ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
// for OCC viewer
OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
if ( !vm )
return;
Handle(AIS_InteractiveContext) ic = vm->getAISContext();
// get OCC material aspect from the current model
Graphic3d_MaterialAspect front_occAspect = aModel.getMaterialOCCAspect( true );
Graphic3d_MaterialAspect back_occAspect = aModel.getMaterialOCCAspect( false );
SUIT_OverrideCursor wc();
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
Handle(GEOM_AISShape) aisShape = GEOMBase::ConvertIOinGEOMAISShape( It.Value(), true );
if ( !aisShape.IsNull() ) {
// Set front material for the selected shape
aisShape->SetCurrentFacingModel(Aspect_TOFM_FRONT_SIDE);
aisShape->SetMaterial(front_occAspect);
// Set back material for the selected shape
aisShape->SetCurrentFacingModel(Aspect_TOFM_BACK_SIDE);
aisShape->SetMaterial(back_occAspect);
// Return to the default facing mode
aisShape->SetCurrentFacingModel(Aspect_TOFM_BOTH_SIDE);
// store chosen material in the property map
study->setObjectProperty( mgrId, It.Value()->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
//if ( aisShape->DisplayMode() != AIS_Shaded)
ic->Redisplay( aisShape, Standard_False );
}
}
ic->UpdateCurrentViewer();
} }
displayer.UpdateViewer();
} }

View File

@ -150,19 +150,22 @@ GEOM_Actor::GEOM_Actor():
myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false); myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
aProperty = myIsolatedEdgeActor->GetProperty(); aProperty = myIsolatedEdgeActor->GetProperty();
aProperty->SetRepresentation(VTK_WIREFRAME); aProperty->SetRepresentation(VTK_WIREFRAME);
aProperty->SetColor(1, 0, 0); myIsolatedEdgeColor[0] = 1; myIsolatedEdgeColor[1] = 0; myIsolatedEdgeColor[2] = 0;
aProperty->SetColor(myIsolatedEdgeColor[0], myIsolatedEdgeColor[1], myIsolatedEdgeColor[2]);
myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput()); myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false); myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
aProperty = myOneFaceEdgeActor->GetProperty(); aProperty = myOneFaceEdgeActor->GetProperty();
aProperty->SetRepresentation(VTK_WIREFRAME); aProperty->SetRepresentation(VTK_WIREFRAME);
aProperty->SetColor(0, 1, 0); myOneFaceEdgeColor[0] = 0; myOneFaceEdgeColor[1] = 1; myOneFaceEdgeColor[2] = 0;
aProperty->SetColor(myOneFaceEdgeColor[0], myOneFaceEdgeColor[1], myOneFaceEdgeColor[2]);
myAppendFilter->AddInput(mySharedEdgeSource->GetOutput()); myAppendFilter->AddInput(mySharedEdgeSource->GetOutput());
mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false); mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
aProperty = mySharedEdgeActor->GetProperty(); aProperty = mySharedEdgeActor->GetProperty();
aProperty->SetRepresentation(VTK_WIREFRAME); aProperty->SetRepresentation(VTK_WIREFRAME);
aProperty->SetColor(1, 1, 0); mySharedEdgeColor[0] = 1; mySharedEdgeColor[1] = 1; mySharedEdgeColor[2] = 0;
aProperty->SetColor(mySharedEdgeColor[0], mySharedEdgeColor[1], mySharedEdgeColor[2]);
myAppendFilter->AddInput(myWireframeFaceSource->GetOutput()); myAppendFilter->AddInput(myWireframeFaceSource->GetOutput());
myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false); myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
@ -183,8 +186,6 @@ GEOM_Actor::GEOM_Actor():
myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer()); myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
StoreBoundaryColors();
myNbIsos[0] = -1; myNbIsos[0] = -1;
myNbIsos[1] = -1; myNbIsos[1] = -1;
@ -296,40 +297,42 @@ setDisplayMode(int theMode)
MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode ); MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
#endif #endif
if ( theMode == (int)eWireframe ) { if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
RestoreIsoNumbers();
// Restore wireframe edges colors
RestoreBoundaryColors();
}
else if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
// Temporary store number of iso lines in order to recover its later // Temporary store number of iso lines in order to recover its later
// when display mode is achnged to 'Wirefame' or 'Shading'. // when display mode is changed to 'Wirefame'
// Iso lines are not displayed in 'Shading with edges' mode. // Iso lines are not displayed in 'Shading' and 'Shading with edges' modes.
StoreIsoNumbers(); StoreIsoNumbers();
// Reset number of iso lines to 0 // Reset number of iso lines to 0
ResetIsoNumbers(); ResetIsoNumbers();
}
if ( theMode == (int)eShadingWithEdges ) { if ( theMode == (int)eShadingWithEdges ) {
// Store wireframe edges colors // Coloring edges
StoreBoundaryColors(); myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
// Coloring edges
myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
myEdgesInShadingColor[1],
myEdgesInShadingColor[2]);
myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
myEdgesInShadingColor[1],
myEdgesInShadingColor[2]);
mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
myEdgesInShadingColor[1], myEdgesInShadingColor[1],
myEdgesInShadingColor[2]); myEdgesInShadingColor[2]);
//SetModified(); myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
} else { myEdgesInShadingColor[1],
myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0], myEdgesInShadingColor[2]);
myEdgesInWireframeColor[1], mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
myEdgesInWireframeColor[2]); myEdgesInShadingColor[1],
} myEdgesInShadingColor[2]);
}
else {
// Restore number of iso-lines
RestoreIsoNumbers();
// Coloring edges
myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
myIsolatedEdgeColor[1],
myIsolatedEdgeColor[2]);
mySharedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
myIsolatedEdgeColor[1],
myIsolatedEdgeColor[2]);
myOneFaceEdgeActor->GetProperty()->SetColor(myOneFaceEdgeColor[0],
myOneFaceEdgeColor[1],
myOneFaceEdgeColor[2]);
} }
VTKViewer_Actor::setDisplayMode(theMode); VTKViewer_Actor::setDisplayMode(theMode);
@ -502,6 +505,26 @@ vtkProperty* GEOM_Actor::GetWireframeProperty()
return myWireframeFaceActor->GetProperty(); return myWireframeFaceActor->GetProperty();
} }
vtkProperty* GEOM_Actor::GetIsolatedEdgeProperty()
{
return myIsolatedEdgeActor->GetProperty();
}
vtkProperty* GEOM_Actor::GetVertexProperty()
{
return myVertexActor->GetProperty();
}
vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
{
return mySharedEdgeActor->GetProperty();
}
vtkProperty* GEOM_Actor::GetFaceEdgeProperty()
{
return myOneFaceEdgeActor->GetProperty();
}
void GEOM_Actor::SetShadingProperty(vtkProperty* Prop) void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
{ {
#ifdef MYDEBUG #ifdef MYDEBUG
@ -691,22 +714,22 @@ vtkFloatingPointType GEOM_Actor::GetOpacity()
void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b) void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
{ {
// enk:tested OK // set the same color to all sub-actors:
myShadingFaceProp->SetColor(r,g,b); // shading color (Shading) // - points
myShadingBackFaceProp->SetColor(r,g,b); // back face shading color (Shading) // - standalone edges
myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe) // - shared edges
if ( myDisplayMode != (int)eShadingWithEdges ) { // - free edges
myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe) // - shading color (front and back faces)
myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe) SetPointColor(r, g, b);
mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe) SetIsolatedEdgeColor(r, g, b);
} SetSharedEdgeColor(r, g, b);
SetFreeEdgeColor(r, g, b);
StoreBoundaryColors(); myShadingFaceProp->SetColor(r,g,b); // shading color
myShadingBackFaceProp->SetColor(r,g,b); // back face shading color
} }
void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b) void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
{ {
// enk:tested OK
vtkFloatingPointType aRGB[3]; vtkFloatingPointType aRGB[3];
myShadingFaceProp->GetColor(aRGB); myShadingFaceProp->GetColor(aRGB);
r = aRGB[0]; r = aRGB[0];
@ -714,6 +737,60 @@ void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFlo
b = aRGB[2]; b = aRGB[2];
} }
/*!
\brief Set color of points
Points actor is shown in Wireframe mode only, see SetVisibility()
*/
void GEOM_Actor::SetPointColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b)
{
myVertexActor->GetProperty()->SetColor(r, g, b);
}
/*!
\brief Set color of standalone edges, wires, vectors
This actor is shown in all display mode, see SetVisibility()
TODO: check - this color seems to be used not only for standalone edges
*/
void GEOM_Actor::SetIsolatedEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b)
{
myIsolatedEdgeColor[0] = r; myIsolatedEdgeColor[1] = g; myIsolatedEdgeColor[2] = b;
if ( myDisplayMode != (int)eShadingWithEdges )
myIsolatedEdgeActor->GetProperty()->SetColor(r, g, b);
}
/*!
\brief Set color of shared edges
This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
TODO: check - this seems to be not working currently
*/
void GEOM_Actor::SetSharedEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b)
{
mySharedEdgeColor[0] = r; mySharedEdgeColor[1] = g; mySharedEdgeColor[2] = b;
if ( myDisplayMode != (int)eShadingWithEdges )
mySharedEdgeActor->GetProperty()->SetColor(r, g, b);
}
/*!
\brief Set color of edges for standalone faces
This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
TODO: this color should be used not only for faces
*/
void GEOM_Actor::SetFreeEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b)
{
myOneFaceEdgeColor[0] = r; myOneFaceEdgeColor[1] = g; myOneFaceEdgeColor[2] = b;
if ( myDisplayMode != (int)eShadingWithEdges )
myOneFaceEdgeActor->GetProperty()->SetColor(r, g, b);
}
/*!
\brief Set color of iso-lines
This actor is shown only in wireframe display mode, see SetVisibility()
*/
void GEOM_Actor::SetIsosColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b)
{
myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
}
void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps) void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
{ {
// we set material properties as back and front material // we set material properties as back and front material
@ -1040,22 +1117,3 @@ void GEOM_Actor::ResetIsoNumbers()
int aNb[2] = {0, 0}; int aNb[2] = {0, 0};
myWireframeFaceSource->SetNbIso(aNb); myWireframeFaceSource->SetNbIso(aNb);
} }
void GEOM_Actor::StoreBoundaryColors()
{
myShadingFaceProp->GetColor(myEdgesInWireframeColor);
}
void GEOM_Actor::RestoreBoundaryColors()
{
myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
myEdgesInWireframeColor[1],
myEdgesInWireframeColor[2]);
myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
myEdgesInWireframeColor[1],
myEdgesInWireframeColor[2]);
mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
myEdgesInWireframeColor[1],
myEdgesInWireframeColor[2]);
}

View File

@ -87,6 +87,10 @@ public:
vtkProperty* GetWireframeProperty(); vtkProperty* GetWireframeProperty();
vtkProperty* GetShadingProperty(); vtkProperty* GetShadingProperty();
vtkProperty* GetIsolatedEdgeProperty();
vtkProperty* GetVertexProperty();
vtkProperty* GetSharedEdgeProperty();
vtkProperty* GetFaceEdgeProperty();
void setDeflection(double adef); void setDeflection(double adef);
virtual void setDisplayMode(int thenewmode); virtual void setDisplayMode(int thenewmode);
@ -120,9 +124,22 @@ public:
void SetOpacity(vtkFloatingPointType opa); void SetOpacity(vtkFloatingPointType opa);
vtkFloatingPointType GetOpacity(); vtkFloatingPointType GetOpacity();
// Color // Color (same to all sub-actors/display modes)
void SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b); void SetColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
void GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b); void GetColor(vtkFloatingPointType& r, vtkFloatingPointType& g, vtkFloatingPointType& b);
// Color of points
void SetPointColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
// Color of standalone edges, wires, vectors
void SetIsolatedEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
// Color of shared edges
void SetSharedEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
// Color of free edges
void SetFreeEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
// Color of edges in shading+edges display mode
void SetEdgesInShadingColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
// Color of iso-lines
void SetIsosColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
// Material // Material
void SetMaterial(std::vector<vtkProperty*> theProps); void SetMaterial(std::vector<vtkProperty*> theProps);
@ -185,9 +202,6 @@ public:
bool bool
GetVectorMode(); GetVectorMode();
//! Edges in shading color management
void SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
void void
StoreIsoNumbers(); StoreIsoNumbers();
@ -202,9 +216,6 @@ protected:
void GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result); void GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result);
void StoreBoundaryColors();
void RestoreBoundaryColors();
GEOM_Actor(); GEOM_Actor();
~GEOM_Actor(); ~GEOM_Actor();
@ -254,6 +265,9 @@ private:
vtkFloatingPointType myEdgesInWireframeColor[3]; vtkFloatingPointType myEdgesInWireframeColor[3];
vtkFloatingPointType myEdgesInShadingColor[3]; vtkFloatingPointType myEdgesInShadingColor[3];
vtkFloatingPointType myIsolatedEdgeColor[3];
vtkFloatingPointType mySharedEdgeColor[3];
vtkFloatingPointType myOneFaceEdgeColor[3];
}; };
#endif //GEOM_ACTOR_H #endif //GEOM_ACTOR_H