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 )
{
QString theName;
if ( theParam.canConvert<QString>() ) theName = theParam.toString();
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
if ( !app )
return;
SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
if(!mod)
return;
GEOM_Displayer* disp = dynamic_cast<GEOM_Displayer*>(mod->displayer());
if(!disp)
return;
LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
if ( !aSelMgr || !study )
return;
SALOME_ListIO selected;
aSelMgr->selectedObjects( selected );
if ( selected.IsEmpty() )
return;
SUIT_ViewWindow* window = app->desktop()->activeWindow();
int mgrId = window ? window->getViewManager()->getGlobalId() : -1;
if ( !theParam.canConvert<QString>() ) return;
QString theName = theParam.toString();
SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
if ( !app ) return;
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
if ( !study ) return;
LightApp_SelectionMgr* selMgr = app->selectionMgr();
SALOME_ListIO selected;
selMgr->selectedObjects( selected );
if ( selected.IsEmpty() ) return;
GEOM_Displayer displayer( study );
SALOME_View* window = displayer.GetActiveView();
if ( !window ) return;
int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
// convert needed material properties to the string representation
Material_Model aModel;
aModel.fromResources( theName );
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();
// get VTK material properties from the current model
GEOM_VTKPropertyMaterial* vtkPropF = aModel.getMaterialVTKProperty();
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();
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
Handle(SALOME_InteractiveObject) io = It.Value();
study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
}
displayer.UpdateViewer();
}

View File

@ -150,19 +150,22 @@ GEOM_Actor::GEOM_Actor():
myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
aProperty = myIsolatedEdgeActor->GetProperty();
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());
myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
aProperty = myOneFaceEdgeActor->GetProperty();
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());
mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
aProperty = mySharedEdgeActor->GetProperty();
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());
myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
@ -183,8 +186,6 @@ GEOM_Actor::GEOM_Actor():
myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
StoreBoundaryColors();
myNbIsos[0] = -1;
myNbIsos[1] = -1;
@ -296,40 +297,42 @@ setDisplayMode(int theMode)
MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
#endif
if ( theMode == (int)eWireframe ) {
RestoreIsoNumbers();
// Restore wireframe edges colors
RestoreBoundaryColors();
}
else if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
// Temporary store number of iso lines in order to recover its later
// when display mode is achnged to 'Wirefame' or 'Shading'.
// Iso lines are not displayed in 'Shading with edges' mode.
// when display mode is changed to 'Wirefame'
// Iso lines are not displayed in 'Shading' and 'Shading with edges' modes.
StoreIsoNumbers();
// Reset number of iso lines to 0
ResetIsoNumbers();
}
if ( theMode == (int)eShadingWithEdges ) {
// Store wireframe edges colors
StoreBoundaryColors();
// 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],
if ( theMode == (int)eShadingWithEdges ) {
// Coloring edges
myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
myEdgesInShadingColor[1],
myEdgesInShadingColor[2]);
//SetModified();
} else {
myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
myEdgesInWireframeColor[1],
myEdgesInWireframeColor[2]);
}
myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
myEdgesInShadingColor[1],
myEdgesInShadingColor[2]);
mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
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);
@ -502,6 +505,26 @@ vtkProperty* GEOM_Actor::GetWireframeProperty()
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)
{
#ifdef MYDEBUG
@ -691,22 +714,22 @@ vtkFloatingPointType GEOM_Actor::GetOpacity()
void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
{
// enk:tested OK
myShadingFaceProp->SetColor(r,g,b); // shading color (Shading)
myShadingBackFaceProp->SetColor(r,g,b); // back face shading color (Shading)
myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe)
if ( myDisplayMode != (int)eShadingWithEdges ) {
myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe)
myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe)
mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe)
}
StoreBoundaryColors();
// set the same color to all sub-actors:
// - points
// - standalone edges
// - shared edges
// - free edges
// - shading color (front and back faces)
SetPointColor(r, g, b);
SetIsolatedEdgeColor(r, g, b);
SetSharedEdgeColor(r, g, b);
SetFreeEdgeColor(r, g, b);
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)
{
// enk:tested OK
vtkFloatingPointType aRGB[3];
myShadingFaceProp->GetColor(aRGB);
r = aRGB[0];
@ -714,6 +737,60 @@ void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFlo
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)
{
// we set material properties as back and front material
@ -1040,22 +1117,3 @@ void GEOM_Actor::ResetIsoNumbers()
int aNb[2] = {0, 0};
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* GetShadingProperty();
vtkProperty* GetIsolatedEdgeProperty();
vtkProperty* GetVertexProperty();
vtkProperty* GetSharedEdgeProperty();
vtkProperty* GetFaceEdgeProperty();
void setDeflection(double adef);
virtual void setDisplayMode(int thenewmode);
@ -120,9 +124,22 @@ public:
void SetOpacity(vtkFloatingPointType opa);
vtkFloatingPointType GetOpacity();
// Color
void SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
void GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
// Color (same to all sub-actors/display modes)
void SetColor(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
void SetMaterial(std::vector<vtkProperty*> theProps);
@ -185,9 +202,6 @@ public:
bool
GetVectorMode();
//! Edges in shading color management
void SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
void
StoreIsoNumbers();
@ -202,9 +216,6 @@ protected:
void GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result);
void StoreBoundaryColors();
void RestoreBoundaryColors();
GEOM_Actor();
~GEOM_Actor();
@ -254,6 +265,9 @@ private:
vtkFloatingPointType myEdgesInWireframeColor[3];
vtkFloatingPointType myEdgesInShadingColor[3];
vtkFloatingPointType myIsolatedEdgeColor[3];
vtkFloatingPointType mySharedEdgeColor[3];
vtkFloatingPointType myOneFaceEdgeColor[3];
};
#endif //GEOM_ACTOR_H