From: srn Date: Mon, 6 Feb 2006 10:21:14 +0000 (+0000) Subject: update of the package X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=07b8fb8bfaff3d29943a546b0bab1ccbb20a22de;p=modules%2Fvisu.git update of the package --- diff --git a/idl/VISU_Gen.idl b/idl/VISU_Gen.idl index 480ae6e3..5f7648d6 100644 --- a/idl/VISU_Gen.idl +++ b/idl/VISU_Gen.idl @@ -59,6 +59,8 @@ module VISU { TSCALARMAP, /*!< Scalarmap 3D presentation object */ TISOSURFACE, /*!< Iso surface 3D presentation object */ TDEFORMEDSHAPE, /*!< Deformed shape 3D presentation object */ + TSCALARMAPONDEFORMEDSHAPE, /*!< Scalar map on deformed shape 3D presentation object */ + TGAUSSPOINTS, /*!< Gauss Points 3D presentation object */ TPLOT3D, /*!< Plot3D 3D presentation object */ TCUTPLANES, /*!< Cut planes 3D presentation object */ TCUTLINES, /*!< Cut lines 3D presentation object */ @@ -70,6 +72,7 @@ module VISU { TXYPLOT, /*!< 2D XY plot consisting of one or several curve lines */ TTABLEVIEW, /*!< Table view is used for displaying data tables */ TVIEW3D, /*!< 3D view is used for displaying 3D graphical presentations */ + TGAUSSVIEW, /*!< 3D view is used for displaying Gauss Points graphical presentations */ TENTITY, /*!< An element composing a mesh: node, edge, face or cell */ TFAMILY, /*!< The whole mesh can be divided into one or several submeshes, called families, which are defined by the user. Each family in its turn is composed of entities of a definite type. */ TGROUP, /*!< A group of families */ @@ -364,8 +367,9 @@ module VISU { PresentationType GetPresentationType(); }; + //------------------------------------------------------- - /*! \brief Interface of the %Scalar Map + /*! \brief Basic Interface for the %Colored 3D Presentations * * This interface is responsable for coloring of 3D field presentations * according the scalar values applied to different cells. @@ -373,7 +377,7 @@ module VISU { * bar is displayed along with each colored field presentation and serves for * consulting the correspondance between colors and data values. */ - interface ScalarMap : Prs3d { + interface ColoredPrs3d : Prs3d { /*! Sets the method of coloring of the elements composing a 3D presentation. */ void SetScalarMode(in long theScalarMode); @@ -382,24 +386,6 @@ module VISU { */ long GetScalarMode(); - /*! - * Sets the type of scaling of the values reflected by the scalar bar. - * \param theScaling The value of this parameter is taken from the Scaling enumeration. - */ - void SetScaling(in Scaling theScaling); - - /*! - * Gets the type of scaling of the values reflected by this presentation. - */ - Scaling GetScaling(); - - /*! - * Sets scalar range - min and max boundaries of the scalar bar. - * \param theMin Min boundary of the scalar bar. - * \param theMax Max boundary of the scalar bar. - */ - void SetRange(in double theMin, in double theMax); - /*! * Gets the min boundary of the scalar bar. */ @@ -410,24 +396,6 @@ module VISU { */ double GetMax(); - /*! %Orientation of the scalar bar. */ - enum Orientation { - HORIZONTAL, /*!< Horizontal orientation of the scalar bar.*/ - VERTICAL /*!< Vertical orientation of the scalar bar.*/ - }; - - /*! - * Sets the type of orientation of the scalar bar. - * \param theOrientation This parameter defines the orientation of the scalar bar. - * It is taken from the Orientaton enumeration. - */ - void SetBarOrientation(in Orientation theOrientation); - - /*! - * Gets the type of orientation of the scalar bar. - */ - Orientation GetBarOrientation(); - /*! \brief Position of the scalar bar. * * Sets the position of the scalar bar origin on the screen. @@ -505,7 +473,63 @@ module VISU { string GetTitle(); }; + + //------------------------------------------------------- + /*! \brief Interface of the %Scalar Map + * + * This interface is responsable for coloring of 3D field presentations + * according the scalar values applied to different cells. + * As well it contains presentation parameters of the scalar bar. The scalar + * bar is displayed along with each colored field presentation and serves for + * consulting the correspondance between colors and data values. + */ + interface ScalarMap : ColoredPrs3d { + /*! + * Sets the type of scaling of the values reflected by the scalar bar. + * \param theScaling The value of this parameter is taken from the Scaling enumeration. + */ + void SetScaling(in Scaling theScaling); + + /*! + * Gets the type of scaling of the values reflected by this presentation. + */ + Scaling GetScaling(); + + /*! + * Sets scalar range - min and max boundaries of the scalar bar. + * \param theMin Min boundary of the scalar bar. + * \param theMax Max boundary of the scalar bar. + */ + void SetRange(in double theMin, in double theMax); + + /*! %Orientation of the scalar bar (to provide backward compatibility). */ + enum Orientation { + HORIZONTAL, /*!< Horizontal orientation of the scalar bar.*/ + VERTICAL /*!< Vertical orientation of the scalar bar.*/ + }; + + /*! + * Sets the type of orientation of the scalar bar (to provide backward compatibility). + * \param theOrientation This parameter defines the orientation of the scalar bar. + * It is taken from the Orientaton enumeration. + */ + void SetBarOrientation(in Orientation theOrientation); + + /*! + * Gets the type of orientation of the scalar bar (to provide backward compatibility). + */ + Orientation GetBarOrientation(); + }; + + //------------------------------------------------------- + /*! \brief Gauss Points presentation interface + * + * Presentation parameters of the Gauss Points presentation. + */ //------------------------------------------------------- + interface GaussPoints : ColoredPrs3d { + }; + /*! \brief Deformed shape presentation interface * * Presentation parameters of the deformed shape presentation. @@ -544,6 +568,38 @@ module VISU { void SetColor(in SALOMEDS::Color theColor); }; + //------------------------------------------------------- + /*! \brief Scalar Map on Deformed shape presentation interface + * + * Presentation parameters of the scalar map on deformed shape presentation. + */ + interface ScalarMapOnDeformedShape : ScalarMap { + + /*! + * Sets the source ranges of pipeline + */ + void SetSourceRange(in double theMinRange,in double theMaxRange); + /*! + * Gets the minimum source range of pipeline + */ + double GetSourceRangeMin(); + /*! + * Gets the maximum source range of pipeline + */ + double GetSourceRangeMax(); + + /*! + * Sets the scale of the presentatable object. + * \param theScale Double value defining the scale of this presentable object. + */ + void SetScale(in double theScale); + + /*! + * Gets the scale of the presentatable object. + */ + double GetScale(); + + }; //------------------------------------------------------- /*! * \brief Plot3D interface @@ -1127,7 +1183,7 @@ module VISU { /*! */ - ScalarMap getPresentation(in long theField, in long theFrame); + ColoredPrs3d getPresentation(in long theField, in long theFrame); /*! Sets the type of presentation (vectors, deformed shape etc.) * which will be generated by the method generatePresentations. @@ -1237,10 +1293,33 @@ module VISU { * for further construction of graphical presentations. */ interface Result : RemovableObject, SALOME::GenericObj { - //interface Result : Base{ /*! Reads all data from the corresponding sources. By default the data is loaded on demand. */ boolean BuildAll(); + + /*! Start to parse the source MED file and publish all its entities into the study*/ + boolean Build(in boolean theIsBuildAll, in boolean theIsAtOnce); + + /*! Allow to check is all requested MED entites already loaded or not */ + boolean IsDone(); + + /*! Allow to check is corresponding MED entites already loaded or not */ + boolean IsEntitiesDone(); + + /*! Choose to parse MED fields and perform global min / max on the MED timestamps.*/ + void SetBuildFields(in boolean theIsBuildFields, in boolean theIsCalculateMinMax); + + /*! Allow to check is corresponding MED fields already loaded or not */ + boolean IsFieldsDone(); + + /*! Choose to parse MED groups.*/ + void SetBuildGroups(in boolean theIsBuildGroups); + + /*! Allow to check is corresponding MED groups and families already loaded or not */ + boolean IsGroupsDone(); + + /*! Allow to check is min / max calculation over field's components already perfrormed or not */ + boolean IsMinMaxDone(); }; //------------------------------------------------------- @@ -1285,6 +1364,13 @@ module VISU { */ Result ImportFile(in string theFileName); + /*! + * Create result and initialize its with the file. The access to this file will be conserved outside of the application. + * \param theFileName String parameter defining the name of the file + * from which the data will be imported. + */ + Result CreateResult(in string theFileName); + /*! * Imports data from a file. The access to this file will closed. * \param theFileName String parameter defining the name of the file @@ -1340,6 +1426,18 @@ module VISU { in Entity theEntity, in string theFieldName, in double theIteration); + /*! + * Creates a Gauss Points presentation. + * \param theResult Data generated in other sources. (MED object or file) + * \param theMeshName One of the meshes presented in MED file + * \param theEntity Type of entity where the field is defined + * \param theFieldName Group of data attributed to the %MESH. The data can be scalar or vector. + * \param theIteration Number of iteration on the field + */ + GaussPoints GaussPointsOnField(in Result theResult, in string theMeshName, + in Entity theEntity, in string theFieldName, + in double theIteration); + /*! * Creates a deformed shape presentation. * \param theResult Data generated in other sources. (MED object or file) diff --git a/resources/VISU_en.xml b/resources/VISU_en.xml index 4e3aedae..d2c013d9 100644 --- a/resources/VISU_en.xml +++ b/resources/VISU_en.xml @@ -32,6 +32,7 @@ + @@ -91,6 +92,7 @@ + diff --git a/resources/VISU_fr.xml b/resources/VISU_fr.xml index b10a3084..7a3230b9 100644 --- a/resources/VISU_fr.xml +++ b/resources/VISU_fr.xml @@ -32,6 +32,7 @@ + @@ -89,6 +90,7 @@ + diff --git a/resources/Vertex_Program_ARB.txt b/resources/Vertex_Program_ARB.txt new file mode 100755 index 00000000..ce6147ff --- /dev/null +++ b/resources/Vertex_Program_ARB.txt @@ -0,0 +1,21 @@ +attribute float mode; +attribute float clampSize; +attribute float geomSize; +attribute float minSize; +attribute float maxSize; +attribute float magnification; + +void main() +{ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + + gl_FrontColor = gl_Color; + + float size; + if( mode == 0 ) // Results + size = minSize + ( maxSize - minSize ) * ( 1 - gl_Color.w / 241.0f ); + else // Geometry and Uniform colored outside cursor + size = geomSize; + + gl_PointSize = clamp( magnification * size * gl_ProjectionMatrix[1].y, 2.0, clampSize ); +} diff --git a/resources/Visu_PlaneSegmentation.png b/resources/Visu_PlaneSegmentation.png new file mode 100644 index 00000000..eb538d00 Binary files /dev/null and b/resources/Visu_PlaneSegmentation.png differ diff --git a/resources/Visu_SphereSegmentation.png b/resources/Visu_SphereSegmentation.png new file mode 100644 index 00000000..e27ca1ca Binary files /dev/null and b/resources/Visu_SphereSegmentation.png differ diff --git a/resources/Visu_gauss_points.png b/resources/Visu_gauss_points.png new file mode 100644 index 00000000..3410cce8 Binary files /dev/null and b/resources/Visu_gauss_points.png differ diff --git a/resources/Visu_load_texture.png b/resources/Visu_load_texture.png new file mode 100755 index 00000000..d9953b6a Binary files /dev/null and b/resources/Visu_load_texture.png differ diff --git a/resources/Visu_recording_pause.png b/resources/Visu_recording_pause.png new file mode 100644 index 00000000..6f37d3fe Binary files /dev/null and b/resources/Visu_recording_pause.png differ diff --git a/resources/Visu_recording_play.png b/resources/Visu_recording_play.png new file mode 100644 index 00000000..62b82247 Binary files /dev/null and b/resources/Visu_recording_play.png differ diff --git a/resources/Visu_recording_start.png b/resources/Visu_recording_start.png new file mode 100644 index 00000000..aef1bb2f Binary files /dev/null and b/resources/Visu_recording_start.png differ diff --git a/resources/Visu_recording_stop.png b/resources/Visu_recording_stop.png new file mode 100644 index 00000000..c6134cce Binary files /dev/null and b/resources/Visu_recording_stop.png differ diff --git a/resources/Visu_scalarmapondeformedshape.png b/resources/Visu_scalarmapondeformedshape.png new file mode 100644 index 00000000..29df0932 Binary files /dev/null and b/resources/Visu_scalarmapondeformedshape.png differ diff --git a/resources/Visu_vvtk_switch.png b/resources/Visu_vvtk_switch.png new file mode 100644 index 00000000..b0a9c807 Binary files /dev/null and b/resources/Visu_vvtk_switch.png differ diff --git a/resources/sprite_alpha.bmp b/resources/sprite_alpha.bmp new file mode 100644 index 00000000..30a0fde7 Binary files /dev/null and b/resources/sprite_alpha.bmp differ diff --git a/resources/sprite_texture.bmp b/resources/sprite_texture.bmp new file mode 100644 index 00000000..8ace2014 Binary files /dev/null and b/resources/sprite_texture.bmp differ diff --git a/src/CONVERTOR/Makefile.in b/src/CONVERTOR/Makefile.in index 8805f3d6..59057158 100644 --- a/src/CONVERTOR/Makefile.in +++ b/src/CONVERTOR/Makefile.in @@ -32,12 +32,25 @@ VPATH=.:@srcdir@ @COMMENCE@ -EXPORT_HEADERS = VISU_Convertor.hxx VISU_Convertor_impl.hxx VISU_ConvertorUtils.hxx VISU_ExtractUnstructuredGrid.hxx +EXPORT_HEADERS = \ + VISU_IDMapper.hxx \ + VISU_Convertor.hxx \ + VISU_ConvertorDef.hxx \ + VISU_Convertor_impl.hxx \ + VISU_ConvertorUtils.hxx \ + VISU_MergeFilter.hxx \ + VISU_ExtractUnstructuredGrid.hxx # Libraries targets LIB = libVisuConvertor.la -LIB_SRC = VISU_Convertor.cxx VISU_Convertor_impl.cxx VISU_ConvertorUtils.cxx VISU_ExtractUnstructuredGrid.cxx \ +LIB_SRC = \ + VISU_IDMapper.cxx \ + VISU_Convertor.cxx \ + VISU_Convertor_impl.cxx \ + VISU_ConvertorUtils.cxx \ + VISU_ExtractUnstructuredGrid.cxx \ + VISU_MergeFilter.cxx \ VISU_MedConvertor.cxx # Executables targets @@ -45,7 +58,16 @@ BIN = VISUConvertor BIN_SRC = CPPFLAGS+= -ftemplate-depth-32 $(VTK_INCLUDES) $(HDF5_INCLUDES) $(QT_INCLUDES) \ - -I${KERNEL_ROOT_DIR}/include/salome -I${MED_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) -LDFLAGS+= $(VTK_LIBS) $(QT_LIBS) -L${MED_ROOT_DIR}/lib/salome -lMEDWrapper -LDFLAGSFORBIN=$(LDFLAGS) $(HDF5_LIBS) -lMEDWrapper_V2_2 -lMEDWrapper_V2_1 -lMEDWrapperBase + -I${KERNEL_ROOT_DIR}/include/salome \ + -I${MED_ROOT_DIR}/include/salome \ + -I${GUI_ROOT_DIR}/include/salome \ + $(BOOST_CPPFLAGS) + +LDFLAGS+= $(VTK_LIBS) $(QT_LIBS) \ + $(BOOST_LIBS) -lboost_thread-mt \ + -L${MED_ROOT_DIR}/lib/salome -lMEDWrapper \ + -L${GUI_ROOT_DIR}/lib/salome -lVTKViewer + +LDFLAGSFORBIN=$(LDFLAGS) -lMEDWrapper_V2_2 -lMEDWrapper_V2_1 -lMEDWrapperBase -lmed_V2_1 -lVTKViewer -lsuit -lqtx + @CONCLUDE@ diff --git a/src/CONVERTOR/VISUConvertor.cxx b/src/CONVERTOR/VISUConvertor.cxx index c81e39e0..273b62a8 100644 --- a/src/CONVERTOR/VISUConvertor.cxx +++ b/src/CONVERTOR/VISUConvertor.cxx @@ -34,6 +34,9 @@ #include #include #include +#include "VISU_Convertor_impl.hxx" + +#include using namespace std; @@ -43,19 +46,33 @@ static int MYDEBUG = 1; static int MYDEBUG = 0; #endif -void parseFile(const char* theFileName) { - //try{ +//#define _DEXCEPT_ + +typedef vtkUnstructuredGrid TOutput; + +void parseFile(const char* theFileName) +{ +#ifndef _DEXCEPT_ + try{ +#endif MSG(MYDEBUG,"'"< aCon(CreateConvertor(theFileName)); //aCon->GetSize(); //return; + aCon->BuildEntities(); + aCon->BuildFields(); + aCon->BuildMinMax(); const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap(); + //return; VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + //continue; + const string& aMeshName = aMeshMapIter->first; const VISU::PMesh& aMesh = aMeshMapIter->second; const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; + //Import fields aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ @@ -70,12 +87,36 @@ void parseFile(const char* theFileName) { VISU::TValField::const_iterator aValFieldIter = aValField.begin(); for(; aValFieldIter != aValField.end(); aValFieldIter++){ int aTimeStamp = aValFieldIter->first; - aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); + + if(anEntity != VISU::NODE_ENTITY){ + VISU::PGaussPtsIDMapper aGaussMesh = + aCon->GetTimeStampOnGaussPts(aMeshName,anEntity,aFieldName,aTimeStamp); + VISU::TVTKOutput* aDataSet = aGaussMesh->GetVTKOutput(); + /* + int aNbCells = aDataSet->GetNumberOfCells(); + for(int anCellId = 0; anCellId < aNbCells; anCellId++){ + VISU::TGaussPointID anObjID = aGaussMesh->GetObjID(anCellId); + cout<GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); + VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); + /* + int aNbCells = aDataSet->GetNumberOfCells(); + for(int anCellId = 0; anCellId < aNbCells; anCellId++){ + int anObjID = anIDMapper->GetElemObjID(anCellId); + int aVTKID = anIDMapper->GetElemVTKID(anObjID); + cout<myGroupMap; VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); @@ -83,6 +124,28 @@ void parseFile(const char* theFileName) { const string& aGroupName = aGroupMapIter->first; aCon->GetMeshOnGroup(aMeshName,aGroupName); } + + //continue; + + //Import mesh on entity + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + VISU::PIDMapper anIDMapper = aCon->GetMeshOnEntity(aMeshName,anEntity); + VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); + { + /* + int aNbCells, anCellId, anObjID, aVTKID; + aNbCells = aDataSet->GetNumberOfCells(); + for(anCellId = 0; anCellId < aNbCells; anCellId++){ + anObjID = anIDMapper->GetElemObjID(anCellId); + aVTKID = anIDMapper->GetElemVTKID(anObjID); + cout<first; - aCon->GetMeshOnEntity(aMeshName,anEntity,aFamilyName); + aCon->GetFamilyOnEntity(aMeshName,anEntity,aFamilyName); } } - //Import mesh on entity - aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); - for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ - const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; - aCon->GetMeshOnEntity(aMeshName,anEntity); - } } + OK: MSG(MYDEBUG,"OK"); -// }catch(std::exception& exc){ -// MSG(MYDEBUG,"Follow exception was occured in file:"< 1){ - QFileInfo fi(argv[1]); - for(int i = 0; i < 1; i++){ - if(fi.exists()){ - if(fi.isDir()){ - QDir aDir(fi.absFilePath()); - QStringList aStringList = aDir.entryList("*.med",QDir::Files); - int jEnd = aStringList.count(); - for(int j = 0; j < jEnd; j++){ - parseFile(aDir.filePath(aStringList[j]).latin1()); - } - }else{ - parseFile(argv[1]); + if(argc > 1){ + QFileInfo fi(argv[1]); + for(int i = 0; i < 1; i++){ + if(fi.exists()){ + if(fi.isDir()){ + QDir aDir(fi.absFilePath()); + QStringList aStringList = aDir.entryList("*.med",QDir::Files); + int jEnd = aStringList.count(); + for(int j = 0; j < jEnd; j++){ + parseFile(aDir.filePath(aStringList[j]).latin1()); } + }else{ + parseFile(argv[1]); } } - return 0; } - //}catch(std::exception& exc){ - // MSG(MYDEBUG,"Follow exception was occured :\n"< TMeshOnEntity::GetCellsDims(const string& theFamilyName) const - { - if(theFamilyName == "") - return make_pair(myNbCells,myCellsSize); - TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName); - if(aFamilyMapIter == myFamilyMap.end()) - throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!"); - const PFamily& aFamily = aFamilyMapIter->second; - return make_pair(aFamily->myNbCells,aFamily->myCellsSize); - } - - const PField TMesh::GetField(const string& theFieldName) const { - TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = myMeshOnEntityMap.begin(); - for(; aMeshOnEntityMapIter != myMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ - const TFieldMap& aFieldMap = aMeshOnEntityMapIter->second->myFieldMap; - TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); - for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++) - if(theFieldName == aFieldMapIter->first) - return aFieldMapIter->second; - } - return PField(); - } - - - PFamily FindFamily(VISU::PMesh theMesh, const string& theFamilyName) - { - PFamily aFamily; - const TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap; - TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); - for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ - const PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second; - aFamily = GetFamily(aMeshOnEntity,theFamilyName); - if(aFamily) - break; - } - return aFamily; - } - - - PFamily GetFamily(VISU::PMeshOnEntity theMeshOnEntity, const string& theFamilyName) - { - PFamily aFamily; - if(theFamilyName != ""){ - TFamilyMap& aFamilyMap = theMeshOnEntity->myFamilyMap; - TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName); - if(aFamilyMapIter != aFamilyMap.end()) - aFamily = aFamilyMapIter->second; - } - return aFamily; - } } -const VISU::TMeshMap& VISU_Convertor::GetMeshMap() { - if(!myIsDone) { myIsDone = true; Build();} +const VISU::TMeshMap& +VISU_Convertor +::GetMeshMap() +{ return myMeshMap; } -string VISU_Convertor::GenerateName(const VISU::TTime& aTime){ +string +VISU_Convertor +::GenerateName(const VISU::TTime& aTime) +{ static QString aName; const string aUnits = aTime.second, tmp(aUnits.size(),' '); if(aUnits == "" || aUnits == tmp) @@ -117,7 +74,11 @@ string VISU_Convertor::GenerateName(const VISU::TTime& aTime){ return aName.latin1(); } -string VISU_Convertor::GenerateName(const string& theName, unsigned int theTimeId) { +string +VISU_Convertor +::GenerateName(const string& theName, + unsigned int theTimeId) +{ static QString aName; aName = QString(theName.c_str()).simplifyWhiteSpace(); int iEnd = strlen(aName); diff --git a/src/CONVERTOR/VISU_Convertor.hxx b/src/CONVERTOR/VISU_Convertor.hxx index bebb26f0..4a5ac993 100644 --- a/src/CONVERTOR/VISU_Convertor.hxx +++ b/src/CONVERTOR/VISU_Convertor.hxx @@ -27,228 +27,387 @@ #ifndef VISU_Convertor_HeaderFile #define VISU_Convertor_HeaderFile -#include +/*! + \file VISU_Convertor.hxx + \brief The file contains definitions for basic classes of the VISU CONVERTER package +*/ + +#include "VISU_IDMapper.hxx" +#include "VISU_ConvertorDef.hxx" + +#include "MED_Vector.hxx" -#include #include #include #include -#include #include #include -#include +namespace VISU +{ + using MED::TVector; -class vtkUnstructuredGrid; + //--------------------------------------------------------------- + typedef std::string TName; -namespace VISU{ + typedef TVector TNames; - template class shared_ptr: public boost::shared_ptr + //--------------------------------------------------------------- + //! Define a basic class for all MED entites which can be identified by its number + struct TIntId: virtual TBaseStructure { - public: - shared_ptr() {} - - template - explicit shared_ptr(Y * p) - { - reset(p); - } - - template - shared_ptr(shared_ptr const & r): - boost::shared_ptr(r,boost::detail::dynamic_cast_tag()) + vtkIdType myId; + + TIntId(): myId(0) {} + }; - template - shared_ptr & operator=(shared_ptr const & r) - { - shared_ptr(r).swap(*this); - return *this; - } - - template shared_ptr& operator()(Y * p) // Y must be complete - { - if(T* pt = dynamic_cast(p)) - boost::shared_ptr::reset(pt); - else - boost::throw_exception(std::bad_cast()); - return *this; - } + //--------------------------------------------------------------- + typedef std::map TMeshOnEntityMap; + typedef std::map TGroupMap; + + //! Define a basic class which corresponds to MED MESH entity + /*! + This class in its turn contains map of TMeshOnEntity and TGroup substructures, + also it keeps name and dimention of corresponding MED MESH entity. + */ + struct TMesh: virtual TBaseStructure + { + TMeshOnEntityMap myMeshOnEntityMap; //!< Contains corresponding meshes for MED ENTITIES + TGroupMap myGroupMap; //!< Contains map of bounded MED GROUPS + TName myName; //! Name of the corresponding MED MESH + int myDim; //! Dimension of the corresponding MED MESH + + TMesh(): myDim(0) + {} }; + typedef std::map TMeshMap; - enum TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY}; + //--------------------------------------------------------------- + //! Define a basic class which corresponds to MED PROFILE entity + struct TSubProfile: virtual TBaseStructure + {}; - typedef std::pair TFamilyAndEntity; - typedef std::set TFamilyAndEntitySet; - typedef std::set TBindGroups; - typedef std::pair TTime; + //--------------------------------------------------------------- + //! Define a containerfor MED PROFILE entities which belongs to the same MED ENTITY + struct TProfile: virtual TNamedIDMapper + {}; - struct TMesh; - typedef shared_ptr PMesh; - typedef std::map TMeshMap; - struct TMeshOnEntity; - typedef shared_ptr PMeshOnEntity; - typedef std::map TMeshOnEntityMap; + //--------------------------------------------------------------- + bool + operator<(const PSubProfile& theLeft, const PSubProfile& theRight); - struct TFamily; - typedef shared_ptr PFamily; - typedef std::map TFamilyMap; + typedef std::set TProfileKey; + typedef std::map TProfileMap; - struct TGroup; - typedef shared_ptr PGroup; - typedef std::map TGroupMap; - struct TField; - typedef shared_ptr PField; - typedef std::map TFieldMap; + //--------------------------------------------------------------- + //! Define a basic class for MED GAUSS entity + struct TGauss: virtual TBaseStructure + {}; - struct TValForTime; - typedef shared_ptr PValForTime; - typedef std::map TValField; - struct TBaseStructure{ - virtual ~TBaseStructure(){} + //--------------------------------------------------------------- + //! Define a container for mesh generated from MED GAUSS and corresponding MED PROFILE + struct TGaussSubMesh: virtual TBaseStructure + { + PSubProfile mySubProfile; //!< Keeps reference on what submesh the Gauss Points are located }; - typedef std::vector TNames; + + //--------------------------------------------------------------- + //! Define a container for all TGaussSubMesh that belongs to the same MED ENTITY + struct TGaussMesh: virtual TGaussPtsIDMapper + {}; - struct TMesh: TBaseStructure{ - int myDim, myNbPoints; - std::string myName; - TMeshOnEntityMap myMeshOnEntityMap; - TGroupMap myGroupMap; + //--------------------------------------------------------------- + bool + operator<(const PGaussSubMesh& theLeft, const PGaussSubMesh& theRight); - TMesh() : myDim(0), myNbPoints(0) {} - const PField GetField(const std::string& theFieldName) const; - }; + typedef std::set TGaussKey; + typedef std::map TGaussMeshMap; + + + //--------------------------------------------------------------- + + typedef std::map TFamilyMap; + typedef std::map TFieldMap; + + //! Define a basic class which corresponds to MED ENTITY + /*! + This class in its turn contains map of TGaussMesh and TProfile substructures, + also it keeps corresponding map of MED FAMILIES and FIELDS. + */ + struct TMeshOnEntity: virtual TNamedIDMapper + { + TGaussMeshMap myGaussMeshMap; //!< Contains map of Gauss mesh which exist on it + TProfileMap myProfileMap; //!< Contains map of Profile mesh which exist on it - struct TMeshOnEntity: TBaseStructure{ - std::string myMeshName; - TEntity myEntity; - int myNbCells, myCellsSize; - TFamilyMap myFamilyMap; - TFieldMap myFieldMap; - TMeshOnEntity() : myNbCells(0), myCellsSize(0) {} + TFamilyMap myFamilyMap; //!< Contains map of MED FAMILIES which belongs to it + TFieldMap myFieldMap; //!< Contains map of MED FIELDS which belongs to it - std::pair - GetCellsDims(const std::string& theFamilyName = "") const; + TName myMeshName; //!< Contains name of the MED MESH where the it belongs to. + TEntity myEntity; //!< Referes to MED ENTITY where the it belongs to. }; - struct TFamily: TBaseStructure{ - int myId; - std::string myName; - TEntity myEntity; - TBindGroups myGroups; - int myNbCells, myCellsSize; - TFamily() : myNbCells(0), myCellsSize(0) {} + + //--------------------------------------------------------------- + //! Define a basic class for MED FAMILY entity + struct TFamily: virtual TIntId, + virtual TIDMapper + { + TEntity myEntity; //!< Referes to MED ENTITY where the TFamily belongs to. + TName myName; //!< Contains name of the corresponding MED FAMILY }; - struct TGroup: TBaseStructure{ - std::string myName; - std::string myMeshName; - int myNbCells, myCellsSize; - TFamilyAndEntitySet myFamilyAndEntitySet; - TGroup() : myNbCells(0), myCellsSize(0) {} + + //--------------------------------------------------------------- + typedef std::set TFamilySet; + + //! Define a basic class for MED GROUP entity + struct TGroup: virtual TIDMapper + { + TFamilySet myFamilySet; }; - struct TField: TBaseStructure{ - int myId; - TEntity myEntity; - bool myIsTrimmed; - std::string myName; - std::string myMeshName; - int myNbComp, myDataSize; - TValField myValField; - TNames myCompNames; - TNames myUnitNames; - TField() : myNbComp(0), myDataSize(0), myIsTrimmed(0) {} + + //--------------------------------------------------------------- + typedef std::map TValField; + typedef std::pair TMinMax; + + //! Define a basic class for MED FIELD entity + struct TField: virtual TIntId + { + TEntity myEntity; //!< Referes to MED ENTITY where it belongs to. + TName myName; //!< Contains name of the corresponding MED FIELD + TName myMeshName; //!< Contains name of the MED MESH where it belongs to. + TValField myValField; //!< Contains sequence of values for corresponding MED TIMESTAMPS + TNames myCompNames; //!< Contains names of components of the MED FIELD + TNames myUnitNames; //!< Contains names of units of the MED FIELD + vtkIdType myNbComp; //!< Keeps number of components for the MED FIELD + + //! Calculate min/max values for each of the MED FIELD components among all its timestamps + /*! + Numeration of the components starts from 1. + Zero component contains min/max value for modulus of corresponding vector + */ + virtual + TMinMax + GetMinMax(vtkIdType theCompID) = 0; + + bool myIsMinMaxInitilized; //!< Is the min / max values are calculated + + TField(): + myNbComp(0), + myIsMinMaxInitilized(false) + {} }; - struct TValForTime: TBaseStructure{ - int myId; - TEntity myEntity; - std::string myMeshName; - std::string myFieldName; - int myNbComp; - TTime myTime; - TValForTime() : myNbComp(0) {} - }; + //--------------------------------------------------------------- + typedef std::pair TTime; - PFamily FindFamily(VISU::PMesh theMesh, - const std::string& theFamilyName); + //! Define a basic class for MED TIMESTAMP entity + struct TValForTime: virtual TIntId + { + TEntity myEntity; //!< Referes to MED ENTITY where it belongs to. + TName myMeshName; //!< Contains name of the MED MESH where it belongs to. + TName myFieldName; //!< Contains name of the MED FIELD where it belongs to. + TTime myTime; - PFamily GetFamily(VISU::PMeshOnEntity theMeshOnEntity, - const std::string& theFamilyName); + PProfile myProfile; //!< Contains corresponding MED PROFILE where the MED TIEMSTMAP attached to + PGaussMesh myGaussMesh; + }; - void WriteToFile(vtkUnstructuredGrid* theDataSet, - const std::string& theFileName); + //--------------------------------------------------------------- + //! The utility function allows to write vtkUnstructuredGrid to a file with defined name + void + WriteToFile(vtkUnstructuredGrid* theDataSet, + const std::string& theFileName); }; -class VISU_Convertor{ + +//--------------------------------------------------------------- +//! This class defines interface to read VTK interpretation of MED entities +/*! + It is the main class of the VISU CONVERTER package. + Following MED entities can be retrived from any MED file: + - mesh from corresponding MED ENTITIES; + - MED TIMESTAMPS; + - MED FAMILIES; + - MED GROUPS. + The class produce its work in two main steps: + 1. Perfrom parsing of MED file to get known what MED entities are pressent in it + 2. Get VTK representation for any existing MED entity + Also, it can perform some additional work to calculate expected amount of memory to build defined VTK representation + +*/ +class VISU_Convertor +{ protected: std::string myName; VISU::TMeshMap myMeshMap; int myIsDone; + public: - virtual ~VISU_Convertor(){}; - virtual const std::string& GetName() { return myName;} - virtual int IsDone() const { return myIsDone;} - typedef vtkUnstructuredGrid TOutput; - - virtual VISU_Convertor* Build() = 0; - virtual const VISU::TMeshMap& GetMeshMap() ; - virtual float GetSize() = 0; - - virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName = "") = 0; - - virtual float GetMeshOnEntitySize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName = "") = 0; + virtual + ~VISU_Convertor() + {}; - virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, - const std::string& theGroupName) = 0; - - virtual float GetMeshOnGroupSize(const std::string& theMeshName, - const std::string& theGroupName) = 0; - - virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) = 0; + //! Get brief name of the corresponding source MED file + virtual + const std::string& + GetName(){ return myName;} + + //! Let known whether the source MED file parsed or not + virtual + int + IsDone() const { return myIsDone; } + + //! Defines what subtype of vtkDataSet is used for MED to VTK mapping + typedef VISU::TVTKOutput TOutput; + + //! This method perform first parsing of MED file to get known what MED entities are pressent in it + virtual + VISU_Convertor* + Build() = 0; + + //! This method perform first parsing of MED file to get known what MED mesh entities are pressent in it + virtual + VISU_Convertor* + BuildEntities() = 0; + + //! This method perform first parsing of MED file to get known what MED fields are pressent in it + virtual + VISU_Convertor* + BuildFields() = 0; + + //! This min /max calculation over existing MED fields + virtual + VISU_Convertor* + BuildMinMax() = 0; + + //! This method perform first parsing of MED file to get known what MED groups are pressent in it + virtual + VISU_Convertor* + BuildGroups() = 0; + + //! This method allow to get known what MED entities are present is the MED file + virtual + const VISU::TMeshMap& + GetMeshMap(); + + //! Get amount of memory to build VTK representations for all existing MED entities + virtual + float + GetSize() = 0; + + //! Get mesh for corresponding MED ENTITY + virtual + VISU::PNamedIDMapper + GetMeshOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity) = 0; + + //! Get amount of memory to build mesh for corresponding MED ENTITY + virtual + float + GetMeshOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity) = 0; + + //! Get mesh for corresponding MED FAMILY + virtual + VISU::PIDMapper + GetFamilyOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName) = 0; + + //! Get amount of memory to build mesh for corresponding MED FAMILY + virtual + float + GetFamilyOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName) = 0; + + //! Get mesh for corresponding MED GROUP + virtual + VISU::PIDMapper + GetMeshOnGroup(const std::string& theMeshName, + const std::string& theGroupName) = 0; + + //! Get amount of memory to build mesh for corresponding MED GROUP + virtual + float + GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) = 0; + + //! Get mesh with attached values for corresponding MED TIMESTAMP + virtual + VISU::PIDMapper + GetTimeStampOnMesh(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) = 0; + + //! Get Gauss Points mesh with attached values for corresponding MED TIMESTAMP + virtual + VISU::PGaussPtsIDMapper + GetTimeStampOnGaussPts(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) = 0; - virtual float GetTimeStampSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) = 0; + //! Get amount of memory to build mesh for corresponding MED TIMESTAMP + virtual + float + GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) = 0; - virtual float GetFieldOnMeshSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName) = 0; - - virtual const VISU::PField GetField(const std::string& theMeshName, - VISU::TEntity theEntity, - const std::string& theFieldName) = 0; - - virtual const VISU::PValForTime GetTimeStamp(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) = 0; + //! Get amount of memory to build all MED TIMESTAMPS for corresponding MED FIELD + virtual + float + GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) = 0; + + //! Find MED FIELD container + virtual + const VISU::PField + GetField(const std::string& theMeshName, + VISU::TEntity theEntity, + const std::string& theFieldName) = 0; + + //! Find MED TIMESTAMP container + virtual + const VISU::PValForTime + GetTimeStamp(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) = 0; - static std::string GenerateName(const VISU::TTime& aTime); - static std::string GenerateName(const std::string& theName, unsigned int theTimeId); + //! Allow to generate pretty name for MED TIMESTAMP + static + std::string + GenerateName(const VISU::TTime& aTime); + + static + std::string + GenerateName(const std::string& theName, unsigned int theTimeId); }; -extern "C"{ - VISU_Convertor* CreateConvertor(const std::string& theFileName) ; +extern "C" +{ + //! Instatiate proper VISU_Convertor subclass + VISU_Convertor* + CreateConvertor(const std::string& theFileName); }; + #endif diff --git a/src/CONVERTOR/VISU_ConvertorDef.hxx b/src/CONVERTOR/VISU_ConvertorDef.hxx new file mode 100644 index 00000000..0fedadc5 --- /dev/null +++ b/src/CONVERTOR/VISU_ConvertorDef.hxx @@ -0,0 +1,78 @@ +// VISU CONVERTOR : +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : +// Author : +// Module : + +#ifndef VISU_ConvertorDef_HeaderFile +#define VISU_ConvertorDef_HeaderFile + +/*! + \file VISU_ConvertorDef.hxx + \brief The file contains predeclarations for basic classes of the VISU CONVERTER package +*/ + +#include "MED_SharedPtr.hxx" + +namespace VISU +{ + using MED::SharedPtr; + + //--------------------------------------------------------------- + enum TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY}; + + struct TMesh; + typedef SharedPtr PMesh; + + struct TGaussSubMesh; + typedef SharedPtr PGaussSubMesh; + + struct TGaussMesh; + typedef SharedPtr PGaussMesh; + + struct TSubProfile; + typedef SharedPtr PSubProfile; + + struct TProfile; + typedef SharedPtr PProfile; + + struct TMeshOnEntity; + typedef SharedPtr PMeshOnEntity; + + struct TFamily; + typedef SharedPtr PFamily; + + struct TGroup; + typedef SharedPtr PGroup; + + struct TField; + typedef SharedPtr PField; + + struct TGauss; + typedef SharedPtr PGauss; + + struct TValForTime; + typedef SharedPtr PValForTime; +} + +#endif diff --git a/src/CONVERTOR/VISU_ConvertorUtils.cxx b/src/CONVERTOR/VISU_ConvertorUtils.cxx index fcfb6f95..a4d0f3bb 100644 --- a/src/CONVERTOR/VISU_ConvertorUtils.cxx +++ b/src/CONVERTOR/VISU_ConvertorUtils.cxx @@ -25,9 +25,18 @@ // Module : VISU #include "VISU_ConvertorUtils.hxx" + #include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif -namespace VISU{ +namespace VISU +{ void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName) @@ -40,4 +49,32 @@ namespace VISU{ aWriter->Delete(); } + + TTimerLog + ::TTimerLog(int theIsDebug, + const std::string& theName): + myIsDebug(MYDEBUG + theIsDebug), + myTimerLog(vtkTimerLog::New()), + myPrefixPrinter(myIsDebug == 1), + myName(theName) + { + myCPUTime = myTimerLog->GetCPUTime(); + BEGMSG(myIsDebug > 1,"{\n"); + } + + TTimerLog + ::~TTimerLog() + { + myCPUTime = myTimerLog->GetCPUTime() - myCPUTime; + + if(myIsDebug > 1){ + BEGMSG(myIsDebug,"} = "<Delete(); + myTimerLog = NULL; + } + } diff --git a/src/CONVERTOR/VISU_ConvertorUtils.hxx b/src/CONVERTOR/VISU_ConvertorUtils.hxx index 1ef42e36..154589fc 100644 --- a/src/CONVERTOR/VISU_ConvertorUtils.hxx +++ b/src/CONVERTOR/VISU_ConvertorUtils.hxx @@ -34,11 +34,30 @@ #include "MED_Utilities.hxx" class vtkUnstructuredGrid; +class vtkTimerLog; + +namespace MED +{ + class PrefixPrinter; +} namespace VISU{ void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName); + + class TTimerLog + { + int myIsDebug; + double myCPUTime; + std::string myName; + vtkTimerLog* myTimerLog; + MED::PrefixPrinter myPrefixPrinter; + public: + TTimerLog(int theIsDebug, + const std::string& theName); + ~TTimerLog(); + }; } diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index 477abba7..ba2a8ad5 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -26,6 +26,11 @@ #include "VISU_Convertor_impl.hxx" #include "VISU_ConvertorUtils.hxx" +#include "VTKViewer_AppendFilter.h" +#include "VISU_MergeFilter.hxx" + +#include +#include #include #include @@ -37,7 +42,6 @@ #include #include -#include #include #include @@ -55,36 +59,970 @@ static int MYVTKDEBUG = 0; #ifdef _DEBUG_ static int MYDEBUG = 0; static int MYDEBUGWITHFILES = 0; +//#define _DEXCEPT_ #else static int MYDEBUG = 0; static int MYDEBUGWITHFILES = 0; #endif +namespace VISU +{ + //--------------------------------------------------------------- + TIsVTKDone::TIsVTKDone(): + myIsVTKDone(false), + myIsDone(false) + {} + + + //--------------------------------------------------------------- + TSizeCounter::TSizeCounter(): + myNbCells(0), + myCellsSize(0) + {} + + + //--------------------------------------------------------------- + TSource::TSource() + {} + + const TVTKSource& + TSource + ::GetSource() const + { + if(!mySource.GetPointer()){ + mySource = vtkUnstructuredGrid::New(); + mySource->Delete(); + } + return mySource; + } + + TVTKOutput* + TSource + ::GetVTKOutput() + { + return GetSource().GetPointer(); + } + + + //--------------------------------------------------------------- + TAppendFilter::TAppendFilter() + {} + + const TVTKAppendFilter& + TAppendFilter + ::GetFilter() const + { + if(!myFilter.GetPointer()){ + myFilter = VTKViewer_AppendFilter::New(); + myFilter->Delete(); + myFilter->SetDoMappingFlag(true); + } + return myFilter; + } + + TVTKOutput* + TAppendFilter + ::GetVTKOutput() + { + GetFilter()->Update(); + return GetFilter()->GetOutput(); + } + + + //--------------------------------------------------------------- + TMergeFilter::TMergeFilter() + {} + + const TVTKMergeFilter& + TMergeFilter + ::GetFilter() const + { + if(!myFilter.GetPointer()){ + myFilter = VISU_MergeFilter::New(); + myFilter->Delete(); + } + return myFilter; + } + + TVTKOutput* + TMergeFilter + ::GetVTKOutput() + { + GetFilter()->Update(); + return GetFilter()->GetUnstructuredGridOutput(); + } + + + //--------------------------------------------------------------- + TPointCoords + ::TPointCoords(): + myPoints(vtkPoints::New()) + { + myPoints->Delete(); + } + + void + TPointCoords + ::Init(vtkIdType theNbPoints, + vtkIdType theDim) + { + myDim = theDim; + myNbPoints = theNbPoints; + myCoord.resize(theNbPoints*theDim); + myPoints->SetNumberOfPoints(theNbPoints); + } + + TCCoordSlice + TPointCoords + ::GetCoordSlice(vtkIdType theNodeId) const + { + return TCCoordSlice(myCoord,std::slice(theNodeId*myDim,myDim,1)); + } + + TCoordSlice + TPointCoords + ::GetCoordSlice(vtkIdType theNodeId) + { + return TCoordSlice(myCoord,std::slice(theNodeId*myDim,myDim,1)); + } + + + //--------------------------------------------------------------- + void + TNamedPointCoords + ::Init(vtkIdType theNbPoints, + vtkIdType theDim, + const TVectorID& theVectorID) + { + TPointCoords::Init(theNbPoints,theDim); + myPointsDim.resize(theDim); + myVectorID = theVectorID; + + for(vtkIdType anID = 0, anEnd = theVectorID.size(); anID < anEnd; anID++) + myObj2VTKID[theVectorID[anID]] = anID; + } + + std::string& + TNamedPointCoords + ::GetName(vtkIdType theDim) + { + return myPointsDim[theDim]; + } + + const std::string& + TNamedPointCoords + ::GetName(vtkIdType theDim) const + { + return myPointsDim[theDim]; + } + + vtkIdType + TNamedPointCoords + ::GetObjID(vtkIdType theID) const + { + if(myVectorID.empty()) + return theID; + else + return myVectorID[theID]; + } + + + vtkIdType + TNamedPointCoords + ::GetVTKID(vtkIdType theID) const + { + if(myObj2VTKID.empty()) + return theID; + else{ + TObj2VTKID::const_iterator anIter = myObj2VTKID.find(theID); + if(anIter != myObj2VTKID.end()) + return anIter->second; + } + return -1; + } + + std::string + TNamedPointCoords + ::GetNodeName(vtkIdType theObjID) const + { + return ""; + } + + //--------------------------------------------------------------- + TMeshImpl::TMeshImpl(): + myPoints(vtkPoints::New()), + myNbPoints(0) + { + myPoints->Delete(); + } + + + //--------------------------------------------------------------- + TSubProfileImpl::TSubProfileImpl(): + myStatus(eNone), + myGeom(eNONE) + {} + + + vtkIdType + TSubProfileImpl + ::GetElemObjID(vtkIdType theID) const + { + return theID; + } + + + //--------------------------------------------------------------- + bool + operator<(const PSubProfile& theLeft, const PSubProfile& theRight) + { + PSubProfileImpl aLeft(theLeft), aRight(theRight); + + if(aLeft->myGeom != aRight->myGeom) + return aLeft->myGeom < aRight->myGeom; + + if(aLeft->myStatus != aRight->myStatus) + return aLeft->myStatus < aRight->myStatus; + + return aLeft->myName < aRight->myName; + } + + + //--------------------------------------------------------------- + TProfileImpl::TProfileImpl(): + myIsAll(true), + myMeshOnEntity(NULL) + {} + + vtkIdType + TProfileImpl + ::GetNodeObjID(vtkIdType theID) const + { + return myNamedPointCoords->GetObjID(theID); + } + + vtkIdType + TProfileImpl + ::GetNodeVTKID(vtkIdType theID) const + { + return myNamedPointCoords->GetVTKID(theID); + } + + float* + TProfileImpl + ::GetNodeCoord(vtkIdType theObjID) + { + if(myIsAll) + return myMeshOnEntity->GetNodeCoord(theObjID); + + vtkIdType aVtkID = GetNodeVTKID(theObjID); + return GetFilter()->GetOutput()->GetPoint(aVtkID); + } + + vtkIdType + TProfileImpl + ::GetElemObjID(vtkIdType theID) const + { + if(myIsAll) + return myMeshOnEntity->GetElemObjID(theID); + + vtkIdType anInputID; + const TVTKAppendFilter& anAppendFilter = GetFilter(); + vtkIdType aID = anAppendFilter->GetCellInputID(theID,anInputID); + PSubProfileImpl aSubProfileImpl = mySubProfileArr[anInputID]; + return aSubProfileImpl->GetElemObjID(aID); + } + + vtkIdType + TProfileImpl + ::GetElemVTKID(vtkIdType theID) const + { + if(myIsAll) + return myMeshOnEntity->GetElemVTKID(theID); + + if(myElemObj2VTKID.empty()) + return theID; + else{ + TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID); + if(anIter != myElemObj2VTKID.end()) + return anIter->second; + } + return -1; + } + + vtkCell* + TProfileImpl + ::GetElemCell(vtkIdType theObjID) + { + if(myIsAll) + return myMeshOnEntity->GetElemCell(theObjID); + + vtkIdType aVtkID = GetElemVTKID(theObjID); + return GetFilter()->GetOutput()->GetCell(aVtkID); + } + + TVTKOutput* + TProfileImpl + ::GetVTKOutput() + { + const TVTKAppendFilter& anAppendFilter = GetFilter(); + return anAppendFilter->GetOutput(); + } + + std::string + TProfileImpl + ::GetNodeName(vtkIdType theObjID) const + { + return myNamedPointCoords->GetNodeName(theObjID); + } + + std::string + TProfileImpl + ::GetElemName(vtkIdType theObjID) const + { + if(myIsAll) + return myMeshOnEntity->GetElemName(theObjID); + + vtkIdType anInputID; + vtkIdType aVTKId = GetElemVTKID(theObjID); + const TVTKAppendFilter& anAppendFilter = GetFilter(); + vtkIdType aSubID = anAppendFilter->GetCellInputID(aVTKId,anInputID); + PSubProfileImpl aSubProfileImpl = mySubProfileArr[anInputID]; + vtkIdType anEntityObjId = aSubProfileImpl->GetElemObjID(aSubID); + return myMeshOnEntity->GetElemName(anEntityObjId); + } + + + //--------------------------------------------------------------- + TVTKOutput* + TIDMapperFilter + ::GetVTKOutput() + { + if(!myFilter.GetPointer()){ + const TVTKAppendFilter& anAppendFilter = myIDMapper.GetFilter(); + TVTKOutput* aGeometry = anAppendFilter->GetOutput(); + + const TVTKSource& aSource = mySource.GetSource(); + TDataSet* aDataSet = aSource.GetPointer(); + aDataSet->ShallowCopy(aGeometry); + + const TVTKMergeFilter& aFilter = GetFilter(); + aFilter->SetGeometry(aGeometry); + aFilter->SetScalars(aDataSet); + aFilter->SetVectors(aDataSet); + aFilter->AddField("VISU_FIELD",aDataSet); + } + return myFilter->GetUnstructuredGridOutput(); + } + + vtkIdType + TIDMapperFilter + ::GetNodeObjID(vtkIdType theID) const + { + return myIDMapper.GetNodeObjID(theID); + } + + vtkIdType + TIDMapperFilter + ::GetNodeVTKID(vtkIdType theID) const + { + return myIDMapper.GetNodeVTKID(theID); + } + + float* + TIDMapperFilter + ::GetNodeCoord(vtkIdType theObjID) + { + return myIDMapper.GetNodeCoord(theObjID); + } + + vtkIdType + TIDMapperFilter + ::GetElemObjID(vtkIdType theID) const + { + return myIDMapper.GetElemObjID(theID); + } + + vtkIdType + TIDMapperFilter + ::GetElemVTKID(vtkIdType theID) const + { + return myIDMapper.GetElemVTKID(theID); + } + + vtkCell* + TIDMapperFilter + ::GetElemCell(vtkIdType theObjID) + { + return myIDMapper.GetElemCell(theObjID); + } + + + //--------------------------------------------------------------- + void + TGaussImpl + ::LessThan(const PGaussImpl& theGauss, + bool& theResult) const + { + theResult = false; + } + + + //--------------------------------------------------------------- + TGaussSubMeshImpl::TGaussSubMeshImpl(): + myStatus(eNone) + {} + + TGaussPointID + TGaussSubMeshImpl + ::GetObjID(vtkIdType theID) const + { + TCellID aCellID = theID / myGauss->myNbPoints; + TLocalPntID aLocalPntID = theID % myGauss->myNbPoints; + + return TGaussPointID(aCellID,aLocalPntID); + } + + //--------------------------------------------------------------- + bool + operator<(const PGaussSubMesh& theLeft, const PGaussSubMesh& theRight) + { + PGaussSubMeshImpl aLeft(theLeft), aRight(theRight); + const PGaussImpl& aGaussLeft = aLeft->myGauss; + const PGaussImpl& aGaussRight = aRight->myGauss; + + if(aGaussLeft->myGeom != aGaussRight->myGeom) + return aGaussLeft->myGeom < aGaussRight->myGeom; + + if(aLeft->mySubProfile != aRight->mySubProfile) + return aLeft->mySubProfile < aRight->mySubProfile; + + bool aResult; + aGaussLeft->LessThan(aGaussRight,aResult); + + return aResult; + } + + + //--------------------------------------------------------------- + TGaussMeshImpl + ::TGaussMeshImpl(): + myParent(NULL) + {} + + TGaussPointID + TGaussMeshImpl + ::GetObjID(vtkIdType theID) const + { + const TVTKAppendFilter& anAppendFilter = GetFilter(); + vtkIdType anInputDataSetID; + vtkIdType anInputID = anAppendFilter->GetCellInputID(theID,anInputDataSetID); + const TGaussSubMeshImpl& aSubMeshImpl = myGaussSubMeshArr[anInputDataSetID]; + + return aSubMeshImpl.GetObjID(anInputID); + } + + TVTKOutput* + TGaussMeshImpl + ::GetVTKOutput() + { + return mySource.GetVTKOutput(); + } + + TNamedIDMapper* + TGaussMeshImpl:: + GetParent() + { + return myParent; + } + + + //--------------------------------------------------------------- + TGaussPointID + TGaussPtsIDFilter + ::GetObjID(vtkIdType theID) const + { + return myGaussPtsIDMapper->GetObjID(theID); + } + + TNamedIDMapper* + TGaussPtsIDFilter:: + GetParent() + { + return myGaussPtsIDMapper->GetParent(); + } + + + //--------------------------------------------------------------- + vtkIdType + TSubMeshImpl + ::GetElemObjID(vtkIdType theID) const + { + return myStartID + theID; + } + + std::string + TSubMeshImpl + ::GetElemName(vtkIdType theObjID) const + { + return ""; + } + + //--------------------------------------------------------------- + vtkIdType + TMeshOnEntityImpl + ::GetNodeVTKID(vtkIdType theID) const + { + return myNamedPointCoords->GetVTKID(theID); + } + + vtkIdType + TMeshOnEntityImpl + ::GetNodeObjID(vtkIdType theID) const + { + return myNamedPointCoords->GetObjID(theID); + } + + vtkIdType + TMeshOnEntityImpl + ::GetElemVTKID(vtkIdType theID) const + { + if(myElemObj2VTKID.empty()) + return theID; + else{ + TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID); + if(anIter != myElemObj2VTKID.end()) + return anIter->second; + } + return -1; + } + + vtkIdType + TMeshOnEntityImpl + ::GetElemObjID(vtkIdType theID) const + { + vtkIdType anInputID; + const TVTKAppendFilter& anAppendFilter = GetFilter(); + vtkIdType aID = anAppendFilter->GetCellInputID(theID,anInputID); + const PSubMeshImpl& aSubMesh = mySubMeshArr[anInputID]; + return aSubMesh->GetElemObjID(aID); + } + + std::string + TMeshOnEntityImpl + ::GetNodeName(vtkIdType theObjID) const + { + return myNamedPointCoords->GetNodeName(theObjID); + } + + std::string + TMeshOnEntityImpl + ::GetElemName(vtkIdType theObjID) const + { + vtkIdType aVTKId = GetElemVTKID(theObjID); + vtkIdType anInputID; + const TVTKAppendFilter& anAppendFilter = GetFilter(); + vtkIdType aSubID = anAppendFilter->GetCellInputID(aVTKId,anInputID); + const PSubMeshImpl& aSubMesh = mySubMeshArr[anInputID]; + return aSubMesh->GetElemName(aSubID); + } + + //--------------------------------------------------------------- + vtkIdType + TFamilyImpl + ::GetElemVTKID(vtkIdType theID) const + { + if(myElemObj2VTKID.empty()) + return theID; + else{ + TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID); + if(anIter != myElemObj2VTKID.end()) + return anIter->second; + } + return -1; + } + + vtkIdType + TFamilyImpl + ::GetElemObjID(vtkIdType theID) const + { + return myMeshID[theID]; + } + + vtkIdType + TFamilyImpl + ::GetNodeObjID(vtkIdType theID) const + { + return myNamedPointCoords->GetObjID(theID); + } + + vtkIdType + TFamilyImpl + ::GetNodeVTKID(vtkIdType theID) const + { + return myNamedPointCoords->GetVTKID(theID); + } + + TVTKOutput* + TFamilyImpl + ::GetVTKOutput() + { + return TSource::GetVTKOutput(); + } + + + //--------------------------------------------------------------- + TNbASizeCells + TGroupImpl + ::GetNbASizeCells() const + { + vtkIdType aNbCells = 0, aCellsSize = 0; + TFamilySet::const_iterator anIter = myFamilySet.begin(); + for(; anIter != myFamilySet.end(); anIter++){ + PFamilyImpl aFamily = *anIter; + aNbCells += aFamily->myNbCells; + aCellsSize += aFamily->myCellsSize; + } + return make_pair(aNbCells,aCellsSize); + } + + vtkIdType + TGroupImpl + ::GetElemVTKID(vtkIdType theID) const + { + if(myElemObj2VTKID.empty()) + return theID; + else{ + TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID); + if(anIter != myElemObj2VTKID.end()) + return anIter->second; + } + return -1; + } + + vtkIdType + TGroupImpl + ::GetElemObjID(vtkIdType theID) const + { + vtkIdType anInputID; + const TVTKAppendFilter& anAppendFilter = GetFilter(); + vtkIdType anID = anAppendFilter->GetCellInputID(theID,anInputID); + const PFamilyImpl& aFamily = myFamilyArr[anInputID]; + return aFamily->GetElemObjID(anID); + } + + vtkIdType + TGroupImpl + ::GetNodeObjID(vtkIdType theID) const + { + return myNamedPointCoords->GetObjID(theID); + } + + vtkIdType + TGroupImpl + ::GetNodeVTKID(vtkIdType theID) const + { + return myNamedPointCoords->GetVTKID(theID); + } + + + //--------------------------------------------------------------- + TFieldImpl + ::TFieldImpl(): + myDataSize(0) + {} + + void + TFieldImpl + ::InitArrays(vtkIdType theNbComp) + { + myNbComp = theNbComp; + myCompNames.resize(theNbComp); + myUnitNames.resize(theNbComp); + myMinMaxArr.resize(theNbComp + 1); + for(vtkIdType iComp = 0; iComp <= theNbComp; iComp++){ + TMinMax& aMinMax = myMinMaxArr[iComp]; + aMinMax.first = VTK_LARGE_FLOAT; + aMinMax.second = -VTK_LARGE_FLOAT; + } + } + + TMinMax + TFieldImpl + ::GetMinMax(vtkIdType theCompID) + { + return myMinMaxArr[theCompID]; + } + + + //--------------------------------------------------------------- + void + TMeshValue + ::Init(vtkIdType theNbElem, + vtkIdType theNbGauss, + vtkIdType theNbComp) + { + myNbElem = theNbElem; + myNbGauss = theNbGauss; + myNbComp = theNbComp; + + myStep = theNbComp*theNbGauss; + + myValue.resize(theNbElem*myStep); + } + + TCValueSliceArr + TMeshValue + ::GetGaussValueSliceArr(vtkIdType theElemId) const + { + TCValueSliceArr aValueSliceArr(myNbGauss); + vtkIdType anId = theElemId*myStep; + for(vtkIdType aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TCValueSlice(myValue,std::slice(anId,myNbComp,1)); + anId += myNbComp; + } + return aValueSliceArr; + } + + TValueSliceArr + TMeshValue + ::GetGaussValueSliceArr(vtkIdType theElemId) + { + TValueSliceArr aValueSliceArr(myNbGauss); + vtkIdType anId = theElemId*myStep; + for(vtkIdType aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TValueSlice(myValue,std::slice(anId,myNbComp,1)); + anId += myNbComp; + } + return aValueSliceArr; + } + + TCValueSliceArr + TMeshValue + ::GetCompValueSliceArr(vtkIdType theElemId) const + { + TCValueSliceArr aValueSliceArr(myNbComp); + vtkIdType anId = theElemId*myStep; + for(vtkIdType aCompId = 0; aCompId < myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TCValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp)); + anId += 1; + } + return aValueSliceArr; + } + + TValueSliceArr + TMeshValue + ::GetCompValueSliceArr(vtkIdType theElemId) + { + TValueSliceArr aValueSliceArr(myNbComp); + vtkIdType anId = theElemId*myStep; + for(vtkIdType aCompId = 0; aCompId < myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp)); + anId += 1; + } + return aValueSliceArr; + } + + + //--------------------------------------------------------------- + TValForTimeImpl + ::TValForTimeImpl(): + myGaussPtsIDFilter(new TGaussPtsIDFilter()), + myIDMapperFilter(new TIDMapperFilter()) + {} + + const TMeshValue& + TValForTimeImpl + ::GetMeshValue(EGeometry theGeom) const + { + TGeom2Value::const_iterator anIter = myGeom2Value.find(theGeom); + if(anIter == myGeom2Value.end()) + EXCEPTION(runtime_error,"TValForTimeImpl::GetMeshValue - myGeom2Value.find(theGeom) fails"); + return anIter->second; + } + + TMeshValue& + TValForTimeImpl + ::GetMeshValue(EGeometry theGeom) + { + return myGeom2Value[theGeom]; + } + + int + TValForTimeImpl + ::GetNbGauss(EGeometry theGeom) const + { + TGeom2NbGauss::const_iterator anIter = myGeom2NbGauss.find(theGeom); + if(anIter == myGeom2NbGauss.end()){ + //EXCEPTION(runtime_error,"TValForTimeImpl::GetNbGauss - myGeom2NbGauss.find(theGeom) fails"); + return 1; + } + return anIter->second; + } + + + //--------------------------------------------------------------- + vtkIdType + VISUGeom2NbNodes(EGeometry theGeom) + { + switch(theGeom){ +#ifndef VISU_ENABLE_QUADRATIC + case VISU::eSEG3: + return 2; + case VISU::eTRIA6: + return 3; + case VISU::eQUAD8: + return 4; + case VISU::eTETRA10: + return 4; + case VISU::eHEXA20: + return 8; + case VISU::ePENTA15: + return 6; + case VISU::ePYRA13: + return 5; +#endif + case VISU::ePOLYGONE: + case VISU::ePOLYEDRE: + return -1; + default: + return theGeom % 100; + } + } + + vtkIdType + VISUGeom2VTK(EGeometry theGeom) + { + switch(theGeom){ + case VISU::ePOINT1: + return VTK_VERTEX; + case VISU::eSEG2: + return VTK_LINE; + case VISU::eTRIA3: + return VTK_TRIANGLE; + case VISU::eQUAD4: + return VTK_QUAD; + case VISU::eTETRA4: + return VTK_TETRA; + case VISU::eHEXA8: + return VTK_HEXAHEDRON; + case VISU::ePENTA6: + return VTK_WEDGE; + case VISU::ePYRA5: + return VTK_PYRAMID; + + case VISU::ePOLYGONE: + return VTK_POLYGON; + case VISU::ePOLYEDRE: + return VTK_CONVEX_POINT_SET; + +#ifndef VISU_ENABLE_QUADRATIC + case VISU::eSEG3: + return VTK_LINE; + case VISU::eTRIA6: + return VTK_TRIANGLE; + case VISU::eQUAD8: + return VTK_QUAD; + case VISU::eTETRA10: + return VTK_TETRA; + case VISU::eHEXA20: + return VTK_HEXAHEDRON; + case VISU::ePENTA15: + return VTK_WEDGE; + case VISU::ePYRA13: + return VTK_PYRAMID; + +#else + + case VISU::eSEG3: +#if defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC) + return VTK_QUADRATIC_EDGE; +#else + return VTK_POLY_LINE; +#endif + + case VISU::eTRIA6: +#if defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC) + return VTK_QUADRATIC_TRIANGLE; +#else + return VTK_POLYGON; +#endif + + case VISU::eQUAD8: +#if defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC) + return VTK_QUADRATIC_QUAD; +#else + return VTK_POLYGON; +#endif + + case VISU::eTETRA10: +#if defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC) + return VTK_QUADRATIC_TETRA; +#else + return VTK_CONVEX_POINT_SET; +#endif + + case VISU::eHEXA20: +#if defined(VTK_QUADRATIC_HEXAHEDRON) && defined(VISU_USE_VTK_QUADRATIC) + return VTK_QUADRATIC_HEXAHEDRON; +#else + return VTK_CONVEX_POINT_SET; +#endif + + case VISU::ePENTA15: +#if defined(VTK_QUADRATIC_WEDGE) && defined(VISU_USE_VTK_QUADRATIC) + return VTK_QUADRATIC_WEDGE; +#else + return VTK_CONVEX_POINT_SET; +#endif + + case VISU::ePYRA13: +#if defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC) + return VTK_QUADRATIC_PYRAMID; +#else + return VTK_CONVEX_POINT_SET; +#endif + +#endif //VISU_ENABLE_QUADRATIC -namespace{ + default: + return -1; + } + } +} + +namespace +{ + //--------------------------------------------------------------- template - std::string dtos(const std::string& fmt, T val){ + std::string + dtos(const std::string& fmt, T val) + { static QString aString; aString.sprintf(fmt.c_str(),val); return aString.latin1(); } + + //--------------------------------------------------------------- enum ECoordName{eX, eY, eZ, eNone}; - typedef VISU::TCoord (*TGetCoord)(const VISU::TMeshImpl::TPointsCoord&, int); + typedef VISU::TCoord (*TGetCoord)(const VISU::TCCoordSlice& theCoordSlice); - template + template VISU::TCoord - GetCoord(const VISU::TMeshImpl::TPointsCoord& thePointsCoord, - int theStartPos) + GetCoord(const VISU::TCCoordSlice& theCoordSlice) { - return thePointsCoord[theStartPos+TheCoordId]; + return theCoordSlice[TCoordId]; } template<> VISU::TCoord - GetCoord(const VISU::TMeshImpl::TPointsCoord& thePointsCoord, - int theStartPos) + GetCoord(const VISU::TCCoordSlice& theCoordSlice) { return 0.0; } @@ -136,86 +1074,100 @@ namespace{ class TCoordHelper{ - const VISU::TMeshImpl::TPointsCoord& myPointsCoord; TGetCoord* myGetCoord; public: - TCoordHelper(const VISU::TMeshImpl::TPointsCoord& thePointsCoord, - TGetCoord* theGetCoord): - myPointsCoord(thePointsCoord), + TCoordHelper(TGetCoord* theGetCoord): myGetCoord(theGetCoord) {} - virtual ~TCoordHelper(){} + + virtual + ~TCoordHelper() + {} + VISU::TCoord - GetCoord(int theStartPos, int theCoodId) + GetCoord(VISU::TCCoordSlice& theCoordSlice, + int theCoordId) { - return (*myGetCoord[theCoodId])(myPointsCoord,theStartPos); + return (*myGetCoord[theCoordId])(theCoordSlice); } }; typedef std::auto_ptr TCoordHelperPtr; - void GetPoints(VISU::TVTKSource& theStorage, VISU::PMeshImpl theMesh) + + //--------------------------------------------------------------- + vtkPoints* + GetPoints(const PMeshImpl& theMesh) { - vtkPoints* aPoints = theMesh->myPoints.GetPointer(); - if(!aPoints){ - aPoints = vtkPoints::New(); + TVTKPoints& aPoints = theMesh->myPoints; + const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; + + if(!theMesh->myIsVTKDone){ TCoordHelperPtr aCoordHelperPtr; - const VISU::TMeshImpl::TPointsCoord& anArray = theMesh->myPointsCoord; { int aMeshDimension = theMesh->myDim; bool anIsDimPresent[3] = {false, false, false}; for(int iDim = 0; iDim < aMeshDimension; iDim++){ - string aDimName = theMesh->myPointsDim[iDim]; - if(aDimName == "x" || aDimName == "X") + const std::string& aName = aCoords.GetName(iDim); + if(aName == "x" || aName == "X") anIsDimPresent[eX] = true; - else if(aDimName == "y" || aDimName == "Y") + else if(aName == "y" || aName == "Y") anIsDimPresent[eY] = true; - else if(aDimName == "z" || aDimName == "Z") + else if(aName == "z" || aName == "Z") anIsDimPresent[eZ] = true; } switch(aMeshDimension){ case 3: - aCoordHelperPtr.reset(new TCoordHelper(anArray,aXYZGetCoord)); + aCoordHelperPtr.reset(new TCoordHelper(aXYZGetCoord)); break; case 2: if(anIsDimPresent[eY] && anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(anArray,aYZGetCoord)); + aCoordHelperPtr.reset(new TCoordHelper(aYZGetCoord)); else if(anIsDimPresent[eX] && anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(anArray,aXZGetCoord)); + aCoordHelperPtr.reset(new TCoordHelper(aXZGetCoord)); else - aCoordHelperPtr.reset(new TCoordHelper(anArray,aXYGetCoord)); + aCoordHelperPtr.reset(new TCoordHelper(aXYGetCoord)); break; case 1: if(anIsDimPresent[eY]) - aCoordHelperPtr.reset(new TCoordHelper(anArray,aYGetCoord)); + aCoordHelperPtr.reset(new TCoordHelper(aYGetCoord)); else if(anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(anArray,aZGetCoord)); + aCoordHelperPtr.reset(new TCoordHelper(aZGetCoord)); else - aCoordHelperPtr.reset(new TCoordHelper(anArray,aXGetCoord)); + aCoordHelperPtr.reset(new TCoordHelper(aXGetCoord)); break; } } - if(MYVTKDEBUG) aPoints->DebugOn(); - vtkIdType iEnd = theMesh->myPointsCoord.size(); - vtkIdType aNbPoints = iEnd / theMesh->myDim; + vtkIdType aNbPoints = aCoords.GetNbPoints(); aPoints->SetNumberOfPoints(aNbPoints); - MSG(MYDEBUG,"GetPoints - aNbPoints = "<myNbCells; + vtkIdType aCellsSize = theFamily->myCellsSize; + + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate(aCellsSize,0); + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents(1); + aCellTypesArray->SetNumberOfTuples(aNbCells); + + TSubMeshID& aMeshID = theFamily->myMeshID; + aMeshID.resize(aNbCells); + + VISU::TID2ID& anElemObj2VTKID = theFamily->myElemObj2VTKID; + + const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh; + VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin(); + for(vtkIdType i = 0, j = 0; anIter != aGeom2SubMesh.end(); anIter++){ + VISU::EGeometry aEGeom = anIter->first; + vtkIdType aVGeom = VISUGeom2VTK(aEGeom); + + const VISU::TSubMeshImpl& aSubMesh = anIter->second; + const VISU::TCell2Connect& anArray = aSubMesh.myCell2Connect; + + const VISU::TGeom2SubMeshID& aGeom2SubMeshID = theFamily->myGeom2SubMeshID; + if(aGeom2SubMeshID.empty()) + EXCEPTION(runtime_error,"GetCells >> There is no elements on the family !!!"); + + VISU::TGeom2SubMeshID::const_iterator aGeom2SubMeshIDIter = aGeom2SubMeshID.find(aEGeom); + if(aGeom2SubMeshIDIter == aGeom2SubMeshID.end()) + continue; + + const VISU::TSubMeshID& aSubMeshID = aGeom2SubMeshIDIter->second; + + INITMSG(MYDEBUG, + " - aEGeom = "<myName + ": " + + VISU_Convertor::GenerateName(aTime); + return aFieldName; + } + + + //--------------------------------------------------------------- + void + GetTimeStampOnProfile(const TVTKSource& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime, + const VISU::TEntity& theEntity) + { + int aNbTuples = theField->myDataSize/theField->myNbComp; + std::string aFieldName = GenerateFieldName(theField,theValForTime); + + vtkDataSetAttributes* aDataSetAttributes; + switch(theEntity){ + case VISU::NODE_ENTITY : + aDataSetAttributes = theSource->GetPointData(); + break; + default: + aDataSetAttributes = theSource->GetCellData(); + } + + int aNbComp = theField->myNbComp; + vtkFloatArray *aFloatArray = vtkFloatArray::New(); + + switch(aNbComp) { + case 1: + aFloatArray->SetNumberOfComponents(1); + aDataSetAttributes->SetScalars(aFloatArray); + break; + default: + aFloatArray->SetNumberOfComponents(3); + aDataSetAttributes->SetVectors(aFloatArray); + } + aFloatArray->SetNumberOfTuples(aNbTuples); + aFloatArray->SetName(aFieldName.c_str()); + + vtkFloatArray *aDataArray = vtkFloatArray::New(); + aDataArray->SetNumberOfComponents(aNbComp); + aDataArray->SetNumberOfTuples(aNbTuples); + aDataArray->SetName("VISU_FIELD"); + aDataSetAttributes->AddArray(aDataArray); + + INITMSG(MYDEBUG,"GetTimeStampOnProfile "<< + "- theEntity = "<> There is no elements for the GEOM("<second; + const TCell2Connect& aCell2Connect = aSubMesh.myCell2Connect; + + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate(aCellsSize,0); + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents(1); + aCellTypesArray->SetNumberOfTuples(aNbCells); + + if(theSubProfile->myStatus == eAddAll){ + VISU::TCell2Connect::const_iterator anIter = aCell2Connect.begin(); + for(vtkIdType anId = 0, aConnId = 0; anIter != aCell2Connect.end(); anIter++){ + const TConnect& anArray = aCell2Connect[anId]; + PrintCells(aConnId,aConnectivity,anArray); + aCellTypesArray->SetValue(anId,(unsigned char)aVGeom); + aConnId += aNbNodes; + anId++; + } + }else{ + VISU::TSubMeshID::const_iterator anIter = aSubMeshID.begin(); + for(vtkIdType anId = 0, aConnId = 0; anIter != aSubMeshID.end(); anIter++){ + vtkIdType aSubId = *anIter; + const TConnect& anArray = aCell2Connect[aSubId]; + PrintCells(aConnId,aConnectivity,anArray); + aCellTypesArray->SetValue(anId,(unsigned char)aVGeom); + aConnId += aNbNodes; + anId++; + } + } + + vtkIdType *pts = 0, npts = 0; + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + + aCellLocationsArray->SetNumberOfComponents(1); + aCellLocationsArray->SetNumberOfTuples(aNbCells); + aConnectivity->InitTraversal(); + for(int i=0; aConnectivity->GetNextCell(npts,pts); i++) + aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); + theSource->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); + + aCellLocationsArray->Delete(); + aCellTypesArray->Delete(); + aConnectivity->Delete(); + } + + + //--------------------------------------------------------------- + void + GetMeshOnSubProfile(const PMeshImpl& theMesh, + const PMeshOnEntityImpl& theMeshOnEntity, + const PProfileImpl& theProfile, + const PSubProfileImpl& theSubProfile) + { + INITMSG(MYDEBUG,"GetMeshOnSubProfile - aEGeom = "<myGeom<GetSource(); + if(theSubProfile->myIsVTKDone) + return; + + aSource->SetPoints(GetPoints(theMesh)); + INITMSGA(MYDEBUG,0,"GetNumberOfPoints - "<GetNumberOfPoints()<GetNumberOfCells()<myIsVTKDone = true; + } + + + //--------------------------------------------------------------- + void + GetMeshOnProfile(const PMeshImpl& theMesh, + const PMeshOnEntityImpl& theMeshOnEntity, + const PProfileImpl& theProfile) + { + INITMSG(MYDEBUG,"GetMeshOnProfile - anEntity = "<myEntity<myIsVTKDone) + return; + + theProfile->myMeshOnEntity = theMeshOnEntity.get(); + const TVTKAppendFilter& anAppendFilter = theProfile->GetFilter(); + anAppendFilter->SetPoints(GetPoints(theMesh)); + + if(theProfile->myIsAll){ + TVTKOutput* aDataSet = theMeshOnEntity->GetVTKOutput(); + anAppendFilter->AddInput(aDataSet); + }else{ + const TGeom2SubProfile& aGeom2SubProfile = theProfile->myGeom2SubProfile; + + TID2ID& anElemObj2VTKID = theProfile->myElemObj2VTKID; + + TSubProfileArr& aSubProfileArr = theProfile->mySubProfileArr; + aSubProfileArr.resize(aGeom2SubProfile.size()); + + TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin(); + for(vtkIdType anInputID = 0, aCellID = 0; anIter != aGeom2SubProfile.end(); anIter++){ + PSubProfileImpl aSubProfile = anIter->second; + if(aSubProfile->myStatus == eRemoveAll) + continue; + + GetMeshOnSubProfile(theMesh, + theMeshOnEntity, + theProfile, + aSubProfile); + + const TVTKSource& aSource = aSubProfile->GetSource(); + anAppendFilter->AddInput(aSource.GetPointer()); + + vtkIdType aNbCells = aSource->GetNumberOfCells(); + for(vtkIdType aCell = 0; aCell < aNbCells; aCell++, aCellID++){ + anElemObj2VTKID[aSubProfile->GetElemObjID(aCell)] = aCellID; + } + + aSubProfileArr[anInputID++] = aSubProfile; + } + } + anAppendFilter->Update(); // Fix on VTK + theProfile->myNamedPointCoords = theMesh->myNamedPointCoords; + + theProfile->myIsVTKDone = true; + } + + + //--------------------------------------------------------------- + void + GetTimeStampOnGaussMesh(const TVTKSource& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime) + { + int aNbTuples = theSource->GetNumberOfPoints(); + std::string aFieldName = GenerateFieldName(theField,theValForTime); + + vtkDataSetAttributes* aDataSetAttributes; + switch(theField->myEntity){ + case VISU::NODE_ENTITY : + aDataSetAttributes = theSource->GetPointData(); + break; + default: + aDataSetAttributes = theSource->GetCellData(); + } + + int aNbComp = theField->myNbComp; + vtkFloatArray *aFloatArray = vtkFloatArray::New(); + switch(aNbComp){ + case 1: + aFloatArray->SetNumberOfComponents(1); + aDataSetAttributes->SetScalars(aFloatArray); + break; + default: + aFloatArray->SetNumberOfComponents(3); + aDataSetAttributes->SetVectors(aFloatArray); + } + aFloatArray->SetNumberOfTuples(aNbTuples); + aFloatArray->SetName(aFieldName.c_str()); + + vtkFloatArray *aDataArray = vtkFloatArray::New(); + aDataArray->SetNumberOfComponents(aNbComp); + aDataArray->SetNumberOfTuples(aNbTuples); + aDataArray->SetName("VISU_FIELD"); + aDataSetAttributes->AddArray(aDataArray); + + INITMSG(MYDEBUG,"GetTimeStampOnGaussMesh "<< + "- aNbTuples = "<> Can't find values for corresponding Gauss Points SubMesh"); + } + const TMeshValue& aMeshValue = anIter2->second; + int aNbGauss = aMeshValue.myNbGauss; + int aNbElem = aMeshValue.myNbElem; + + if(aNbGauss < 1) + continue; + + const TPointCoords& aCoords = aGaussSubMesh->myPointCoords; + + INITMSG(MYDEBUG, + "- aEGeom = "<> There is no elements on the family !!!"); - VISU::TFamilyImpl::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); - if(aSubMeshIter == aSubMesh.end()) continue; - const VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; - MSG(MYDEBUG,"GetCellsOnEntity - aSubMeshOnCellType.size() = "<SetValue(j++,(unsigned char)aVtkType); + }else{ + for(int iElem = 0; iElem < aNbElem; iElem++, aTupleId++){ + TCValueSliceArr aValueSliceArr = aMeshValue.GetCompValueSliceArr(iElem); + for(int iComp = 0; iComp < aNbComp; iComp++){ + const TCValueSlice& aValueSlice = aValueSliceArr[iComp]; + aDataValues[iComp] = 0.0; + for(int iGauss = 0; iGauss < aNbGauss; iGauss++){ + aDataValues[iComp] += aValueSlice[iGauss]; + } + aDataValues[iComp] /= aNbGauss; + } + aFloatArray->SetTuple(aTupleId,&aDataValues[0]); + aDataArray->SetTuple(aTupleId,&aDataValues[0]); } } } - vtkIdType *pts = 0, npts = 0; - vtkIntArray* aCellLocationsArray = vtkIntArray::New(); - aCellLocationsArray->SetNumberOfComponents(1); - aCellLocationsArray->SetNumberOfTuples(aNbCells); - aConnectivity->InitTraversal(); - for(int i=0; aConnectivity->GetNextCell(npts,pts); i++) - aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); - theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); - if(MYVTKDEBUG) aConnectivity->DebugOn(); - aCellLocationsArray->Delete(); - aCellTypesArray->Delete(); - aConnectivity->Delete(); - } - - - void GetCellsOnGroup(VISU::TVTKSource& theStorage, - VISU::PMeshImpl theMesh, - const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) + aFloatArray->Delete(); + aDataArray->Delete(); + } + + + //--------------------------------------------------------------- + void + GetSource(const TVTKSource& theSource, + const PGaussSubMeshImpl& theGaussSubMesh, + const PMeshOnEntityImpl& theMeshOnEntity) { - //Calculate dimentions of the group - int aNbCells = 0, aCellsSize = 0; - VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); - for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ - const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; - const string& aFamilyName = aFamilyAndEntity.first; - const VISU::TEntity& anEntity = aFamilyAndEntity.second; - const VISU::PMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity]; - pair aCellsDim = aMeshOnEntity->GetCellsDims(aFamilyName); - aNbCells += aCellsDim.first; - aCellsSize += aCellsDim.second; - } + const TPointCoords& aCoords = theGaussSubMesh->myPointCoords; + vtkIdType aNbPoints = aCoords.GetNbPoints(); + vtkIdType aDim = aCoords.GetDim(); + + vtkIdType aNbCells = theGaussSubMesh->myNbCells; + vtkIdType aCellsSize = theGaussSubMesh->myCellsSize; + vtkCellArray* aConnectivity = vtkCellArray::New(); aConnectivity->Allocate(aCellsSize,0); vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); aCellTypesArray->SetNumberOfComponents(1); aCellTypesArray->SetNumberOfTuples(aNbCells); - aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); - for(int i = 0, j = 0; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ - const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; - const string& aFamilyName = aFamilyAndEntity.first; - const VISU::TEntity& anEntity = aFamilyAndEntity.second; - PMeshOnEntityImpl aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity]; - PFamilyImpl aFamily = GetFamily(aMeshOnEntity,aFamilyName); - const VISU::TMeshOnEntityImpl::TCellsConn &aCellsConn = aMeshOnEntity->myCellsConn; - VISU::TMeshOnEntityImpl::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin(); - for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){ - const VISU::TMeshOnEntityImpl::TConnForCellType& anArray = aCellsConnIter->second; - int aVtkType = aCellsConnIter->first; - MSG(MYDEBUG,"GetCellsOnGroup - aVtkType = "<> There is no elements on the family !!!"); - VISU::TFamilyImpl::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); - if(aSubMeshIter == aSubMesh.end()) continue; - const VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; - MSG(MYDEBUG,"GetCellsOnGroup - aSubMeshOnCellType.size() = "<SetValue(j++,(unsigned char)aVtkType); - } - } + + const TVTKPoints& aPoints = aCoords.GetPoints(); + vtkIdList *anIdList = vtkIdList::New(); + anIdList->SetNumberOfIds(1); + for(vtkIdType aPointId = 0; aPointId < aNbPoints; aPointId++){ + TCCoordSlice aSlice = aCoords.GetCoordSlice(aPointId); + + float aCoords[3] = {0.0, 0.0, 0.0}; + for(vtkIdType aDimId = 0; aDimId < aDim; aDimId++) + aCoords[aDimId] = aSlice[aDimId]; + + aPoints->SetPoint(aPointId,aCoords); + + anIdList->SetId(0,aPointId); + aConnectivity->InsertNextCell(anIdList); + aCellTypesArray->SetValue(aPointId,(unsigned char)VTK_VERTEX); } - vtkIdType *pts = 0, npts = 0; + anIdList->Delete(); + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); aCellLocationsArray->SetNumberOfComponents(1); aCellLocationsArray->SetNumberOfTuples(aNbCells); + + vtkIdType *pts = 0, npts = 0; aConnectivity->InitTraversal(); for(int i = 0; aConnectivity->GetNextCell(npts,pts); i++) aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); - theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); + + const TVTKSource& aSource = theGaussSubMesh->GetSource(); + aSource->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); + aSource->SetPoints(aPoints.GetPointer()); + aCellLocationsArray->Delete(); aCellTypesArray->Delete(); aConnectivity->Delete(); - } + } - void InitProfile(VISU::TVTKExtractFilter& theFilter, - PMeshOnEntityImpl theMeshOnEntity, - PValForTimeImpl theValForTime) - { - const VISU::TValForTimeImpl::TValForCells& aValForCells = theValForTime->myValForCells; - const VISU::TMeshOnEntityImpl::TCellsConn &aCellsConn = theMeshOnEntity->myCellsConn; - VISU::TMeshOnEntityImpl::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin(); - for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){ - const vtkIdType& aCellType = aCellsConnIter->first; - if(aValForCells.find(aCellType) == aValForCells.end()) - theFilter->RemoveCellsWithType(aCellType); - } - } - - - void GetValsOnTimeStamp(vtkFloatArray *theFloatArray, - const vtkIdType& theNumberOfTuples, - const std::string& theFieldName, - VISU::PFieldImpl theField, - VISU::PValForTimeImpl theValForTime) - { - //theFloatArray->DebugOn(); - theFloatArray->SetNumberOfTuples(theNumberOfTuples); - theFloatArray->SetName(theFieldName.c_str()); - MSG(MYDEBUG,"GetValsOnTimeStamp - theNumberOfTuples = "<myValForCells; - VISU::TValForTimeImpl::TValForCells::const_iterator aValForCellsIter = aValForCells.begin(); - for(int k = 0; aValForCellsIter != aValForCells.end(); aValForCellsIter++) { - const VISU::TValForTimeImpl::TValForCellsWithType& anArray = aValForCellsIter->second; - int iEnd = anArray.size()/theField->myNbComp; - int aVtkType = aValForCellsIter->first; - MSG(MYDEBUG,"GetValsOnTimeStamp - iEnd = "<myTime; - string aFieldName = theField->myMeshName + ", " + theField->myName + ": " + - VISU_Convertor::GenerateName(aTime); - return aFieldName; + PGaussImpl aGauss = theGaussSubMesh->myGauss; + INITMSG(MYDEBUG,"GetGaussSubMesh - aVGeom = "<myGeom<myIsDone) + return; + + if(theGaussSubMesh->myIsVTKDone) + return; + + const TVTKSource& aSource = theGaussSubMesh->GetSource(); + GetSource(aSource,theGaussSubMesh,theMeshOnEntity); + INITMSGA(MYDEBUG,0,"GetNumberOfPoints - "<GetNumberOfPoints()<GetNumberOfCells()<myIsVTKDone = true; } + - void GetTimeStamp(VISU::TVTKSource& theStorage, - const VISU::PFieldImpl theField, - const VISU::PValForTimeImpl theValForTime) + //--------------------------------------------------------------- + void + BuildGaussMesh(const PMeshImpl& theMesh, + const PMeshOnEntityImpl& theMeshOnEntity, + const PGaussMeshImpl& theGaussMesh) { - int aNumberOfTuples = theField->myDataSize/theField->myNbComp; - string aFieldName = GenerateFieldName(theField,theValForTime); - MSG(MYDEBUG,"GetTimeStamp(TVTKSource) - aFieldName = "<GetFilter(); + const TGeom2GaussSubMesh& aGeom2GaussSubMesh = theGaussMesh->myGeom2GaussSubMesh; + TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin(); + for(; anIter != aGeom2GaussSubMesh.end(); anIter++){ + PGaussSubMeshImpl aGaussSubMesh = anIter->second; + if(aGaussSubMesh->myStatus == eRemoveAll) + continue; + + GetGaussSubMesh(theMesh, + theMeshOnEntity, + theGaussMesh, + aGaussSubMesh); + + const TVTKSource& aSource = aGaussSubMesh->GetSource(); + + anAppendFilter->AddInput(aSource.GetPointer()); } + anAppendFilter->Update(); // Fix on VTK - vtkFloatArray *aFloatArray = vtkFloatArray::New(); - switch(theField->myNbComp) { - case 1: - aFloatArray->SetNumberOfComponents(1); - aDataSetAttributes->SetScalars(aFloatArray); - break; - default: - aFloatArray->SetNumberOfComponents(3); - aDataSetAttributes->SetVectors(aFloatArray); - } + theMeshOnEntity->GetVTKOutput()->Update(); - GetValsOnTimeStamp(aFloatArray,aNumberOfTuples,aFieldName,theField,theValForTime); + vtkDataSet* aSource = anAppendFilter->GetOutput(); + INITMSGA(MYDEBUG,0,"aNbPoints - "<GetNumberOfPoints()<GetNumberOfCells()<myIsVTKDone = true; } - void GetTimeStamp(VISU::TVTKAttribyteFilter& theAttribyteFilter, - VISU::TVTKMergetFilter& theMergeFilter, - VISU::TVTKExtractFilter& theExtractFilter, - const VISU::PFieldImpl theField, - const VISU::PValForTimeImpl theValForTime) + + //--------------------------------------------------------------- + void + PrintMemorySize(vtkUnstructuredGrid* theDataSet) { - int aNumberOfTuples = theField->myDataSize/theField->myNbComp; - string aFieldName = GenerateFieldName(theField,theValForTime); - MSG(MYDEBUG,"GetTimeStamp(TVTKAttribyteFilter) - aFieldName = "<GetOutput(),aFileName); + } + + if(MYVTKDEBUG){ + GetMeshOnEntitySize(theMeshName,theEntity); + PrintMemorySize(anAppendFilter->GetOutput()); + } + } + +#ifndef _DEXCEPT_ + }catch(...){ + throw; + } +#endif + + return aMeshOnEntity; +} + + +//--------------------------------------------------------------- +VISU::PIDMapper +VISU_Convertor_impl +::GetFamilyOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName) +{ + INITMSG(MYDEBUG,"GetFamilyOnEntity"<< + "; theMeshName = '"<(aFindFamilyOnEntity);; + PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindFamilyOnEntity); + PFamilyImpl aFamily = boost::get<2>(aFindFamilyOnEntity); + //Main part of code +#ifndef _DEXCEPT_ try{ - if(aSource.GetPointer() == NULL){ - aSource = TOutput::New(); - aSource->Delete(); +#endif + if(!aFamily->myIsVTKDone){ + const TVTKSource& aSource = aFamily->GetSource(); if(MYVTKDEBUG) aSource->DebugOn(); - LoadMeshOnEntity(aMeshOnEntity,theFamilyName); - GetPoints(aSource,aMesh); - GetCellsOnEntity(aSource,aMeshOnEntity,theFamilyName); + + GetMeshOnEntity(theMeshName,theEntity); + + LoadFamilyOnEntity(aMesh,aMeshOnEntity,aFamily); + aSource->SetPoints(GetPoints(aMesh)); + GetCellsOnFamily(aSource,aMeshOnEntity,aFamily); + + aFamily->myNamedPointCoords = aMesh->myNamedPointCoords; + + aFamily->myIsVTKDone = true; + if(MYDEBUGWITHFILES){ - string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); - string aFamilyName = QString(theFamilyName.c_str()).simplifyWhiteSpace().latin1(); - string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + std::string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + std::string aFamilyName = QString(theFamilyName.c_str()).simplifyWhiteSpace().latin1(); + std::string aFileName = string(getenv("HOME"))+"/"+getenv("USER")+"-"; aFileName += aMeshName + dtos("-%d-",int(theEntity)) + aFamilyName + "-Conv.vtk"; VISU::WriteToFile(aSource.GetPointer(),aFileName); } + + if(MYVTKDEBUG){ + GetFamilyOnEntitySize(theMeshName,theEntity,theFamilyName); + PrintMemorySize(aSource.GetPointer()); + } } - if(MYVTKDEBUG){ - GetMeshOnEntitySize(theMeshName,theEntity,theFamilyName); - vtkUnstructuredGrid* aDataSet = aSource.GetPointer(); - aDataSet->Update(); - MSG(MYVTKDEBUG,"GetMeshOnEntity - GetPoints() = "<GetPoints()->GetActualMemorySize()*1000)); - MSG(MYVTKDEBUG,"GetMeshOnEntity - GetCells() = "<GetCells()->GetActualMemorySize()*1000)); - MSG(MYVTKDEBUG,"GetMeshOnEntity - GetCellTypesArray() = "<GetCellTypesArray()->GetActualMemorySize()*1000)); - MSG(MYVTKDEBUG,"GetMeshOnEntity - GetCellLocationsArray() = "<GetCellLocationsArray()->GetActualMemorySize()*1000)); - aDataSet->BuildLinks(); - MSG(MYVTKDEBUG,"GetMeshOnEntity - GetCellLinks() = "<GetCellLinks()->GetActualMemorySize()*1000)); - MSG(MYVTKDEBUG,"GetMeshOnEntity - GetActualMemorySize() = "<GetActualMemorySize()*1000)); - } + +#ifndef _DEXCEPT_ }catch(...){ - aSource = vtkSmartPointerBase(); throw; } - return aSource.GetPointer(); +#endif + + return aFamily; } -VISU_Convertor::TOutput* -VISU_Convertor_impl::GetMeshOnGroup(const string& theMeshName, - const string& theGroupName) + +//--------------------------------------------------------------- +VISU::PIDMapper +VISU_Convertor_impl +::GetMeshOnGroup(const string& theMeshName, + const string& theGroupName) { - MSG(MYDEBUG,"GetMeshOnGroup - theMeshName = '"<(aFindMeshOnGroup); PGroupImpl aGroup = boost::get<1>(aFindMeshOnGroup); - const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet; - VISU::TVTKSource& aSource = aGroup->myStorage; + //Main part of code +#ifndef _DEXCEPT_ try{ - if(aSource.GetPointer() == NULL){ - aSource = TOutput::New(); - aSource->Delete(); - LoadMeshOnGroup(aMesh,aFamilyAndEntitySet); - GetPoints(aSource,aMesh); - GetCellsOnGroup(aSource,aMesh,aFamilyAndEntitySet); +#endif + if(!aGroup->myIsVTKDone){ + const TVTKAppendFilter& anAppendFilter = aGroup->GetFilter(); + const VISU::TFamilySet& aFamilySet = aGroup->myFamilySet; + + LoadMeshOnGroup(aMesh,aFamilySet); + anAppendFilter->SetPoints(GetPoints(aMesh)); + + TFamilySet::const_iterator anIter = aFamilySet.begin(); + + TID2ID& anElemObj2VTKID = aGroup->myElemObj2VTKID; + TFamilyArr& aFamilyArr = aGroup->myFamilyArr; + aFamilyArr.resize(aFamilySet.size()); + + for(vtkIdType anID = 0; anIter != aFamilySet.end(); anIter++){ + PFamilyImpl aFamily = *anIter; + const std::string& aFamilyName = aFamily->myName; + const VISU::TEntity& anEntity = aFamily->myEntity; + + VISU::PIDMapper anIDMapper = GetFamilyOnEntity(theMeshName,anEntity,aFamilyName); + VISU::TVTKOutput* anOutput = anIDMapper->GetVTKOutput(); + anAppendFilter->AddInput(anOutput); + + vtkIdType aNbCells = anOutput->GetNumberOfCells(); + for(vtkIdType aCellID = 0; aCellID < aNbCells; aCellID++){ + anElemObj2VTKID[aFamily->GetElemObjID(aCellID)] = aCellID; + } + aFamilyArr[anID] = aFamily; + } + aGroup->myNamedPointCoords = aMesh->myNamedPointCoords; + + aGroup->myIsVTKDone = true; + if(MYDEBUGWITHFILES){ - string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); - string aGroupName = QString(theGroupName.c_str()).simplifyWhiteSpace().latin1(); - string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + std::string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + std::string aGroupName = QString(theGroupName.c_str()).simplifyWhiteSpace().latin1(); + std::string aFileName = string(getenv("HOME"))+"/"+getenv("USER")+"-"; aFileName += aMeshName + "-" + aGroupName + "-Conv.vtk"; - VISU::WriteToFile(aSource.GetPointer(),aFileName); + VISU::WriteToFile(anAppendFilter->GetOutput(),aFileName); } } +#ifndef _DEXCEPT_ }catch(...){ - aSource = vtkSmartPointerBase(); throw; } - return aSource.GetPointer(); +#endif + + return aGroup; } -VISU_Convertor::TOutput* -VISU_Convertor_impl::GetTimeStampOnMesh(const string& theMeshName, - const VISU::TEntity& theEntity, - const string& theFieldName, - int theStampsNum) + +//--------------------------------------------------------------- +VISU::TVTKOutput* +VISU_Convertor_impl +::GetTimeStampOnProfile(const VISU::PMeshImpl& theMesh, + const VISU::PMeshOnEntityImpl& theMeshOnEntity, + const VISU::PFieldImpl& theField, + const VISU::PValForTimeImpl& theValForTime, + const VISU::PIDMapperFilter& theIDMapperFilter, + const VISU::PProfileImpl& theProfile, + const VISU::TEntity& theEntity) +{ + LoadMeshOnEntity(theMesh,theMeshOnEntity); + GetMeshOnEntity(theMeshOnEntity->myMeshName,theMeshOnEntity->myEntity); + GetMeshOnProfile(theMesh,theMeshOnEntity,theProfile); + + theIDMapperFilter->myIDMapper = theProfile; + TVTKOutput* anOutput = theIDMapperFilter->GetVTKOutput(); + const TVTKSource& aSource = theIDMapperFilter->mySource.GetSource(); + ::GetTimeStampOnProfile(aSource,theField,theValForTime,theEntity); + + return anOutput; +} + + +//--------------------------------------------------------------- +VISU::PIDMapper +VISU_Convertor_impl +::GetTimeStampOnMesh(const string& theMeshName, + const VISU::TEntity& theEntity, + const string& theFieldName, + int theStampsNum) { - MSG(MYDEBUG,"GetTimeStampOnMesh - theMeshName = '"<myMeshName,aVTKMeshOnEntity->myEntity); - - anExtractFilter->SetInput(aVTKMeshOnEntity->myStorage.GetPointer()); - ::InitProfile(anExtractFilter,aMeshOnEntity,aValForTime); - } - if(!anExtractFilter->IsRemoving()){ - aSource = TOutput::New(); - aSource->Delete(); - aSource->ShallowCopy(aVTKMeshOnEntity->myStorage.GetPointer()); - ::GetTimeStamp(aSource,aField,aValForTime); - anOutput = aSource.GetPointer(); - }else{ - anAttribyteFilter = vtkFieldDataToAttributeDataFilter::New(); - anAttribyteFilter->Delete(); - //anAttribyteFilter->DebugOn(); - - VISU::TVTKMergetFilter& aMergeFilter = aValForTime->myMergeFilter; - aMergeFilter = vtkMergeDataObjectFilter::New(); - aMergeFilter->Delete(); - //aMergeFilter->DebugOn(); - - ::GetTimeStamp(anAttribyteFilter,aMergeFilter,anExtractFilter, - aField,aValForTime); - anOutput = anAttribyteFilter->GetUnstructuredGridOutput(); +#endif + if(!anIDMapperFilter->myIsVTKDone){ + LoadValForTimeOnMesh(aMesh,aMeshOnEntity,aField,aValForTime); + + TVTKOutput* anOutput; + try{ + anOutput = GetTimeStampOnProfile(aMesh, + aVTKMeshOnEntity, + aField, + aValForTime, + anIDMapperFilter, + aValForTime->myProfile, + aMeshOnEntity->myEntity); + }catch(std::exception& exc){ + MSG(MYDEBUG,"Follow exception was occured :\n"<myProfile, + aVTKMeshOnEntity->myEntity); } + + anIDMapperFilter->myIsVTKDone = true; + if(MYDEBUGWITHFILES){ string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); string aFieldName = QString(theFieldName.c_str()).simplifyWhiteSpace().latin1(); - string aPrefix = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + string aPrefix = string(getenv("HOME"))+"/"+getenv("USER")+"-"; string aFileName = aPrefix + aMeshName + dtos("-%d-",int(theEntity)) + aFieldName + dtos("-%d",theStampsNum) + "-Conv.vtk"; VISU::WriteToFile(anOutput,aFileName); } if(MYVTKDEBUG){ GetTimeStampSize(theMeshName,theEntity,theFieldName,theStampsNum); - vtkUnstructuredGrid *aDataSet = anAttribyteFilter->GetUnstructuredGridOutput(); - aDataSet->Update(); + anOutput->Update(); if(theEntity == VISU::NODE_ENTITY) - MSG(MYVTKDEBUG,"GetTimeStampOnMesh - GetData() = "<GetPointData()->GetActualMemorySize()*1000)); + BEGMSG(MYVTKDEBUG,"GetPointData() = "<GetPointData()->GetActualMemorySize()*1000)<Update(); + if(theEntity == VISU::NODE_ENTITY) + BEGMSG(MYVTKDEBUG,"GetPointData() = "<GetPointData()->GetActualMemorySize()*1000)<> There is no mesh on the entity - "<second; - + return TFindMeshOnEntity(aMesh, - aMeshOnEntityMap[theEntity], - GetFamily(aMeshOnEntity,theFamilyName)); + aMeshOnEntity); +} + + +//--------------------------------------------------------------- +VISU_Convertor_impl::TFindFamilyOnEntity +VISU_Convertor_impl +::FindFamilyOnEntity(const string& theMeshName, + const VISU::TEntity& theEntity, + const string& theFamilyName) +{ + if(theFamilyName != ""){ + PMeshImpl aMesh = FindMesh(theMeshName); + VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(theEntity); + if(aMeshOnEntityMapIter == aMeshOnEntityMap.end()) + EXCEPTION(runtime_error,"FindFamilyOnEntity >> There is no mesh on the entity - "<second; + + TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; + TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName); + if(aFamilyMapIter != aFamilyMap.end()){ + const PFamily& aFamily = aFamilyMapIter->second; + return TFindFamilyOnEntity(aMesh, + aMeshOnEntity, + aFamily); + } + } + return TFindFamilyOnEntity(); } -float VISU_Convertor_impl::GetSize() { +//--------------------------------------------------------------- +float +VISU_Convertor_impl +::GetSize() +{ float aResult = 0.0; const VISU::TMeshMap& aMeshMap = GetMeshMap(); VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); @@ -757,7 +2359,7 @@ float VISU_Convertor_impl::GetSize() { VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ const string& aFamilyName = aFamilyMapIter->first; - aResult += GetMeshOnEntitySize(aMeshName,anEntity,aFamilyName); + aResult += GetFamilyOnEntitySize(aMeshName,anEntity,aFamilyName); } //Import mesh on entity aResult += GetMeshOnEntitySize(aMeshName,anEntity); @@ -768,27 +2370,65 @@ float VISU_Convertor_impl::GetSize() { } -float VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName) +//--------------------------------------------------------------- +float +VISU_Convertor_impl +::GetMeshOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity) { TFindMeshOnEntity aFindMeshOnEntity = - FindMeshOnEntity(theMeshName,theEntity,theFamilyName); + FindMeshOnEntity(theMeshName,theEntity); + PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity); - PFamilyImpl aFamily = boost::get<2>(aFindMeshOnEntity); PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity); vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord); - vtkIdType aNbCells, aCellsSize; + vtkIdType aNbCells = aMeshOnEntity->myNbCells; + vtkIdType aCellsSize = aMeshOnEntity->myCellsSize; + + vtkIdType aConnectivitySize = aCellsSize*sizeof(vtkIdType); + vtkIdType aTypesSize = aNbCells*sizeof(char); + vtkIdType aLocationsSize = aNbCells*sizeof(int); + float aNbCellsPerPoint = aCellsSize / aNbCells - 1; + vtkIdType aLinksSize = aMesh->myNbPoints * + (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link)); + aLinksSize = 0; + vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; - if(!aFamily){ - aNbCells = aMeshOnEntity->myNbCells; - aCellsSize = aMeshOnEntity->myCellsSize; - }else{ - aNbCells = aFamily->myNbCells; - aCellsSize = aFamily->myCellsSize; + MSG(MYDEBUG,"GetMeshOnEntitySize "<< + "- aResult = "<(aFindFamilyOnEntity); + PFamilyImpl aFamily = boost::get<2>(aFindFamilyOnEntity); + PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindFamilyOnEntity); + + vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord); + vtkIdType aNbCells = aFamily->myNbCells; + vtkIdType aCellsSize = aFamily->myCellsSize; + vtkIdType aConnectivitySize = aCellsSize*sizeof(vtkIdType); vtkIdType aTypesSize = aNbCells*sizeof(char); vtkIdType aLocationsSize = aNbCells*sizeof(int); @@ -797,24 +2437,30 @@ float VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshName, (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link)); aLinksSize = 0; vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; + + MSG(MYDEBUG,"GetFamilyOnEntitySize "<< + "- aResult = "<myGroupMap; @@ -827,15 +2473,19 @@ VISU_Convertor_impl::FindMeshOnGroup(const std::string& theMeshName, } -float VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName, - const std::string& theGroupName) +float +VISU_Convertor_impl +::GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) { TFindMeshOnGroup aFindMeshOnGroup = FindMeshOnGroup(theMeshName,theGroupName); PMeshImpl aMesh = boost::get<0>(aFindMeshOnGroup); PGroupImpl aGroup = boost::get<1>(aFindMeshOnGroup); vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord); - vtkIdType aNbCells = aGroup->myNbCells, aCellsSize = aGroup->myCellsSize; + TNbASizeCells aNbASizeCells = aGroup->GetNbASizeCells(); + vtkIdType aNbCells = aNbASizeCells.first; + vtkIdType aCellsSize = aNbASizeCells.second; vtkIdType aConnectivityAndTypesSize = aCellsSize*sizeof(vtkIdType); vtkIdType aLocationsSize = aNbCells*sizeof(int); float aNbCellsPerPoint = aCellsSize / aNbCells - 1; @@ -856,14 +2506,17 @@ float VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName, return aResult; } + VISU_Convertor_impl::TFindField -VISU_Convertor_impl::FindField(const string& theMeshName, - const VISU::TEntity& theEntity, - const string& theFieldName) +VISU_Convertor_impl +::FindField(const string& theMeshName, + const VISU::TEntity& theEntity, + const string& theFieldName) { - TFindMeshOnEntity aFindMeshOnEntity = FindMeshOnEntity(theMeshName,theEntity,""); + TFindMeshOnEntity aFindMeshOnEntity = + FindMeshOnEntity(theMeshName,theEntity); + PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity);; - PFamilyImpl aFamily = boost::get<2>(aFindMeshOnEntity); PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity); VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; @@ -892,13 +2545,15 @@ VISU_Convertor_impl::FindField(const string& theMeshName, } -float VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName) +float +VISU_Convertor_impl +::GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) { TFindField aFindField = FindField(theMeshName,theEntity,theFieldName); PMeshOnEntityImpl aVTKMeshOnEntity = boost::get<2>(aFindField); - PField aField = boost::get<3>(aFindField); + PFieldImpl aField = boost::get<3>(aFindField); float aMeshSize = GetMeshOnEntitySize(theMeshName,aVTKMeshOnEntity->myEntity); float aFieldOnMeshSize = float(aField->myDataSize*sizeof(float)*aField->myValField.size()*ERR_SIZE_CALC); @@ -913,10 +2568,11 @@ float VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName, VISU_Convertor_impl::TFindTimeStamp -VISU_Convertor_impl::FindTimeStamp(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) +VISU_Convertor_impl +::FindTimeStamp(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) { TFindField aFindField = FindField(theMeshName,theEntity,theFieldName); PField aField = boost::get<3>(aFindField); @@ -939,15 +2595,17 @@ VISU_Convertor_impl::FindTimeStamp(const std::string& theMeshName, } -float VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) +float +VISU_Convertor_impl +::GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) { TFindTimeStamp aFindTimeStamp = FindTimeStamp(theMeshName,theEntity,theFieldName,theStampsNum); PMeshOnEntityImpl aVTKMeshOnEntity = boost::get<2>(aFindTimeStamp); - PField aField = boost::get<3>(aFindTimeStamp); + PFieldImpl aField = boost::get<3>(aFindTimeStamp); float aMeshSize = GetMeshOnEntitySize(theMeshName,aVTKMeshOnEntity->myEntity); float aTimeStampSize = float(aField->myDataSize*sizeof(float) * ERR_SIZE_CALC); @@ -963,9 +2621,10 @@ float VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName, const VISU::PField -VISU_Convertor_impl::GetField(const string& theMeshName, - VISU::TEntity theEntity, - const string& theFieldName) +VISU_Convertor_impl +::GetField(const string& theMeshName, + VISU::TEntity theEntity, + const string& theFieldName) { TFindField aFindField = FindField(theMeshName,theEntity,theFieldName); PField aField = boost::get<3>(aFindField); @@ -974,10 +2633,11 @@ VISU_Convertor_impl::GetField(const string& theMeshName, const VISU::PValForTime -VISU_Convertor_impl::GetTimeStamp(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) +VISU_Convertor_impl +::GetTimeStamp(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) { TFindTimeStamp aFindTimeStamp = FindTimeStamp(theMeshName,theEntity,theFieldName,theStampsNum); diff --git a/src/CONVERTOR/VISU_Convertor_impl.hxx b/src/CONVERTOR/VISU_Convertor_impl.hxx index 46284cba..c4efc7d2 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.hxx +++ b/src/CONVERTOR/VISU_Convertor_impl.hxx @@ -1,121 +1,868 @@ -// Copyright (C) 2003 CEA/DEN, EDF R&D +// SALOME VTKViewer : build VTK viewer into Salome desktop // +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // -// File : VISU_Convertor_impl.hxx -// Author : Alexey PETROV -// Module : VISU +// +// File : +// Author : +// Module : SALOME +// $Header$ #ifndef VISU_Convertor_impl_HeaderFile #define VISU_Convertor_impl_HeaderFile +#include + +#include + +class vtkCell; +class vtkPoints; +class vtkUnstructuredGrid; +class VTKViewer_AppendFilter; +class VISU_MergeFilter; + #include "VISU_Convertor.hxx" +#include "MED_SliceArray.hxx" -#include +#ifndef VISU_ENABLE_QUADRATIC +#define VISU_ENABLE_QUADRATIC +#define VISU_USE_VTK_QUADRATIC +#endif -#include -#include -#include -#include -#include "VISU_ExtractUnstructuredGrid.hxx" +namespace VISU +{ + //! Defines VISU enumeration of geometrical types + enum EGeometry {ePOINT1=1, eSEG2=102, eSEG3=103, eTRIA3=203, + eQUAD4=204, eTRIA6=206,eQUAD8=208, eTETRA4=304, + ePYRA5=305, ePENTA6=306, eHEXA8=308, eTETRA10=310, + ePYRA13=313, ePENTA15=315, eHEXA20=320, + ePOLYGONE=400, ePOLYEDRE=500, eNONE=-1}; -#include -#include + //! Get number of nodes for defined geometrical type + vtkIdType + VISUGeom2NbNodes(EGeometry theGeom); -#include + //! Maps VISU geometrical type to VTK one + vtkIdType + VISUGeom2VTK(EGeometry theGeom); -#include + //--------------------------------------------------------------- + using MED::TCSlice; + using MED::TSlice; -namespace VISU{ + typedef vtkUnstructuredGrid TDataSet; + typedef vtkSmartPointer TVTKSource; typedef vtkSmartPointer TVTKPoints; - typedef vtkSmartPointer TVTKSource; - typedef vtkSmartPointer TVTKMergetFilter; - typedef vtkSmartPointer TVTKExtractFilter; - typedef vtkSmartPointer TVTKAttribyteFilter; + typedef vtkSmartPointer TVTKMergeFilter; + + typedef vtkSmartPointer TVTKAppendFilter; typedef float TCoord; - struct TMeshImpl: TMesh{ - TVTKPoints myPoints; + //--------------------------------------------------------------- + //! Define an utility base class which is repsonsible for preventing repetion + struct TIsVTKDone: virtual TBaseStructure + { + TIsVTKDone(); + bool myIsDone; //!< Say, is the corresponding MED entity already loaded into intermediate data structure + bool myIsVTKDone; //!< Say, is the corresponding intermediate data structure already mapped into VTK representation + }; + + + //--------------------------------------------------------------- + //! Define an utility base class which allow to keep calculated number of cells and their size + struct TSizeCounter: virtual TIsVTKDone + { + TSizeCounter(); + vtkIdType myNbCells; //!< Number of cells contained into corresponding sublclass + vtkIdType myCellsSize; //!< Size of cells contained into corresponding sublclass + }; + + + //--------------------------------------------------------------- + //! Define a container for VTK representation + class TSource: public virtual TSizeCounter + { + protected: + mutable TVTKSource mySource; + public: + TSource(); + + //! This method allow to create corresponding VTK data set by demand (not at once) + const TVTKSource& + GetSource() const; + + //! Reimplement the TIDMapper::GetVTKOutput + virtual + TVTKOutput* + GetVTKOutput(); + }; + + + //--------------------------------------------------------------- + //! Define a container for VTK representation + /*! + This container allow to combine other VTK representation into single one. + */ + class TAppendFilter: public virtual TIsVTKDone, + public virtual TIDMapper + { + protected: + mutable TVTKAppendFilter myFilter; + public: + TAppendFilter(); + + //! This method allow to create corresponding VTK filter by demand (not at once) + const TVTKAppendFilter& + GetFilter() const; + + //! Reimplement the TIDMapper::GetVTKOutput + virtual + TVTKOutput* + GetVTKOutput(); + }; + + + //--------------------------------------------------------------- + //! Define a container for VTK representation + /*! + This container allow to assign data to mesh and represent them into single VTK representation + */ + class TMergeFilter: public virtual TIsVTKDone, + public virtual TIDMapper + { + protected: + mutable TVTKMergeFilter myFilter; + public: + TMergeFilter(); + + //! This method allow to create corresponding VTK filter by demand (not at once) + const TVTKMergeFilter& + GetFilter() const; + + //! Reimplement the TIDMapper::GetVTKOutput + virtual + TVTKOutput* + GetVTKOutput(); + }; + + + //--------------------------------------------------------------- + typedef TVector TCoordArray; + typedef TSlice TCoordSlice; + typedef TCSlice TCCoordSlice; + + //! This class is responsible for representation of mesh nodes + class TPointCoords: public virtual TBaseStructure + { + protected: + vtkIdType myDim; //!< Dimension of the nodal coordinates + vtkIdType myNbPoints; //!< Number of nodes in corresponding mesh + + //! An container for coordinates of the nodes + /*! + Usage of slices allow to minimize amount of memory to store the nodal coordinates and + provide unifirm way of conversation with this coordinates (independant from mesh dimension) + */ + TCoordArray myCoord; + TVTKPoints myPoints; //!< VTK representation for the mesh nodes + + public: + TPointCoords(); + + //! To initilize the class + void + Init(vtkIdType theNbPoints, + vtkIdType theDim); + + //! Get slice of coordinates for defined node (const version) + TCCoordSlice + GetCoordSlice(vtkIdType theNodeId) const; + + //! Get slice of coordinates for defined node + TCoordSlice + GetCoordSlice(vtkIdType theNodeId); + + vtkIdType + GetNbPoints() const { return myNbPoints; } + + vtkIdType + GetDim() const { return myDim; } + + vtkIdType + size() const { return GetNbPoints(); } + + const TVTKPoints& + GetPoints() const { return myPoints;} + }; + typedef SharedPtr PPointCoords; + + + //--------------------------------------------------------------- + typedef TVector TVectorID; + typedef std::map TObj2VTKID; + + //! This class is responsible for representation of mesh nodes + /*! + In additition to its base functionlity it support mapping of VTK to object numeration and + keeps names for each of nodes. + */ + class TNamedPointCoords: public virtual TPointCoords + { + protected: + typedef TVector TPointsDim; + TPointsDim myPointsDim; //!< Keeps name of each dimension + TVectorID myVectorID; //!< Keeps object¶ numeration + TObj2VTKID myObj2VTKID; //!< Keeps mapping from object number to VTK one + + public: + + //! To initilize the class (numeration of the nodes can be missed) + void + Init(vtkIdType theNbPoints, + vtkIdType theDim, + const TVectorID& theVectorID = TVectorID()); + + //! Get name for defined dimension + std::string& + GetName(vtkIdType theDim); + + //! Get name for defined dimension (const version) + const std::string& + GetName(vtkIdType theDim) const; + + //! Get object number for node by its VTK one + virtual + vtkIdType + GetObjID(vtkIdType theID) const; + + //! Get VTK number for node by its object one + virtual + vtkIdType + GetVTKID(vtkIdType theID) const; + + //! Get name of node by its object number + virtual + std::string + GetNodeName(vtkIdType theObjID) const; + }; + typedef SharedPtr PNamedPointCoords; + - typedef std::vector TPointsCoord; - TPointsCoord myPointsCoord; + //--------------------------------------------------------------- + //! Specialize TMesh to provide VTK mapping for nodes + struct TMeshImpl: virtual TMesh, + virtual TIsVTKDone + { + PNamedPointCoords myNamedPointCoords; //!< Keeps intermediate representation of the nodes - typedef std::vector TPointsDim; - TPointsDim myPointsDim; + TVTKPoints myPoints; //!< Keeps VTK representation of the nodes + vtkIdType myNbPoints; //!< Keeps number of the nodes + + TMeshImpl(); + }; + typedef SharedPtr PMeshImpl; + + + //--------------------------------------------------------------- + typedef TVector TSubMeshID; + typedef enum {eRemoveAll, eAddAll, eAddPart, eNone} ESubMeshStatus; + + //! Specialize TSubProfile to provide VTK mapping + struct TSubProfileImpl: virtual TSubProfile, + virtual TSource + { + TSubProfileImpl(); + + EGeometry myGeom; //!< Defines to what geometrical type the MED PROFILE belong to + std::string myName; //!< Keeps its name + + //! Get object number of mesh cell by its VTK one + virtual + vtkIdType + GetElemObjID(int theVtkI) const; + + //! Keeps status of the structure + /*! + In some cases MED file does not use MED PROFILES, but at VISU creates corresponding data strucutre + in order to construct mesh for MED TIEMSTAMPS in uniform way. + */ + ESubMeshStatus myStatus; + TSubMeshID mySubMeshID; //!< Keeps numbers of mesh cell which contain the MED PROFILE }; - typedef shared_ptr PMeshImpl; + typedef SharedPtr PSubProfileImpl; + + + //--------------------------------------------------------------- + struct TMeshOnEntityImpl; + + typedef std::map TID2ID; + typedef TVector TSubProfileArr; + typedef std::map TGeom2SubProfile; + + //! Specialize TProfile to provide VTK mapping for MED TIMESTAMP mesh + struct TProfileImpl: virtual TProfile, + virtual TAppendFilter + { + TProfileImpl(); + bool myIsAll; //!< Say, whether the MED TIMESTAMP defined on all MED ENTITY or not + + //! Reimplement the TIDMapper::GetNodeObjID + virtual + vtkIdType + GetNodeObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetNodeVTKID + virtual + vtkIdType + GetNodeVTKID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetNodeCoord + virtual + float* + GetNodeCoord(vtkIdType theObjID); + + //! Reimplement the TIDMapper::GetElemObjID + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetElemVTKID + virtual + vtkIdType + GetElemVTKID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetElemCell + virtual + vtkCell* + GetElemCell(vtkIdType theObjID); + + //! Reimplement the TIDMapper::GetVTKOutput + virtual + TVTKOutput* + GetVTKOutput(); + + //! Reimplement the TNamedIDMapper::GetNodeName + virtual + std::string + GetNodeName(vtkIdType theObjID) const; + + //! Reimplement the TNamedIDMapper::GetElemName + virtual + std::string + GetElemName(vtkIdType theObjID) const; + + TID2ID myElemObj2VTKID; //!< Keeps object to VTK numeration mapping + TSubProfileArr mySubProfileArr; //!< Keeps sequence of TSubProfiles as they were added into TAppendFilter + PNamedPointCoords myNamedPointCoords; //!< Keeps reference on the same TNamedPointCoords as TMesh + TMeshOnEntityImpl* myMeshOnEntity; // PProfileImpl; + + + //--------------------------------------------------------------- + //! Specialize TIDMapper to provide VTK mapping for MED TIMESTAMP mesh + struct TIDMapperFilter: virtual TMergeFilter + { + TAppendFilter myIDMapper; //!< Responsible for numbering + TSource mySource; //!< Keeps assigned data + + //! Reimplement the TIDMapper::GetNodeObjID + virtual + vtkIdType + GetNodeObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetNodeVTKID + virtual + vtkIdType + GetNodeVTKID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetNodeCoord + virtual + float* + GetNodeCoord(vtkIdType theObjID); + + //! Reimplement the TIDMapper::GetElemObjID + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetElemVTKID + virtual + vtkIdType + GetElemVTKID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetElemCell + virtual + vtkCell* + GetElemCell(vtkIdType theObjID); + + //! Reimplement the TIDMapper::GetVTKOutput + virtual + TVTKOutput* + GetVTKOutput(); + }; + typedef SharedPtr PIDMapperFilter; + + + //--------------------------------------------------------------- + struct TGaussImpl; + typedef SharedPtr PGaussImpl; + + //! Specialize TGauss to provide more detail information of the MED GAUSS entity for VTK mapping + struct TGaussImpl: virtual TGauss + { + EGeometry myGeom; //!< Define, to which geometrical type the MED GAUSS entity belongs + std::string myName; //!< Keeps name of the MED GAUSS entity + vtkIdType myNbPoints; // TConnect; - typedef std::vector TConnForCellType; - typedef std::map TCellsConn; - TCellsConn myCellsConn; + //! To define a way to implement more detail comparision of the TGaussSubMesh instances + virtual + void + LessThan(const PGaussImpl& theGauss, + bool& theResult) const; }; - typedef shared_ptr PMeshOnEntityImpl; - struct TFamilyImpl: TFamily{ - TVTKSource myStorage; - typedef std::set TSubMeshOnCellType; - typedef std::map TSubMesh; - TSubMesh mySubMesh; + //--------------------------------------------------------------- + //! Specialize TGaussSubMesh to provide VTK mapping for the entity + struct TGaussSubMeshImpl: virtual TGaussSubMesh, + virtual TSource + { + TGaussSubMeshImpl(); + + //! To implement the TGaussPtsIDMapper::GetObjID + virtual + TGaussPointID + GetObjID(vtkIdType theID) const; + + PGaussImpl myGauss; // PFamilyImpl; + typedef SharedPtr PGaussSubMeshImpl; + + + //--------------------------------------------------------------- + typedef TVector TGaussSubMeshArr; + typedef std::map TGeom2GaussSubMesh; + + //! Specialize TGaussMesh to provide VTK mapping for the entity + struct TGaussMeshImpl: virtual TGaussMesh, + virtual TAppendFilter + { + TGaussMeshImpl(); + + //! Reimplement the TGaussPtsIDMapper::GetObjID + virtual + TGaussPointID + GetObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetVTKOutput + virtual + TVTKOutput* + GetVTKOutput(); + + //! Reimplement the TGaussPtsIDMapper::GetParent + virtual + TNamedIDMapper* + GetParent(); + + TSource mySource; //!< Keeps VTK representation of the Gauss Points + TNamedIDMapper* myParent; //!< Refer to parent mesh + TGaussSubMeshArr myGaussSubMeshArr; //!< Keeps sequence of TGaussSubMesh as they were added into TAppendFilter + TGeom2GaussSubMesh myGeom2GaussSubMesh; //!< Keeps TGaussSubMesh according to their geometrical type + }; + typedef SharedPtr PGaussMeshImpl; + + + //--------------------------------------------------------------- + //! Specialize TGaussPtsIDMapper to provide VTK mapping for MED TIMESTAMP mesh + struct TGaussPtsIDFilter: virtual TIDMapperFilter, + virtual TGaussPtsIDMapper + { + PGaussPtsIDMapper myGaussPtsIDMapper; - struct TGroupImpl: TGroup{ - TVTKSource myStorage; + //! Reimplement the TGaussPtsIDMapper::GetObjID + virtual + TGaussPointID + GetObjID(vtkIdType theID) const; + + //! Reimplement the TGaussPtsIDMapper::GetParent + virtual + TNamedIDMapper* + GetParent(); }; - typedef shared_ptr PGroupImpl; + typedef SharedPtr PGaussPtsIDFilter; + + + //--------------------------------------------------------------- + typedef TVector TConnect; + typedef TVector TCell2Connect; + + //! The class is responsible for mapping of cells of defined geometrical type + struct TSubMeshImpl: virtual TSource + { + + //! To implement the TIDMapper::GetElemObjID + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; + + //! To implement the TNamedIDMapper::GetElemName + virtual + std::string + GetElemName(vtkIdType theObjID) const; + + vtkIdType myStartID; + TCell2Connect myCell2Connect; //!< Contains connectivity for the cells + }; + typedef SharedPtr PSubMeshImpl; + + + //--------------------------------------------------------------- + typedef std::map TGeom2SubMesh; + typedef TVector TSubMeshArr; + + //! Specialize TMeshOnEntity to provide VTK mapping for the entity + struct TMeshOnEntityImpl: virtual TMeshOnEntity, + virtual TAppendFilter, + virtual TSizeCounter + { + //! Reimplement the TIDMapper::GetNodeVTKID + virtual + vtkIdType + GetNodeVTKID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetNodeObjID + virtual + vtkIdType + GetNodeObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetElemVTKID + virtual + vtkIdType + GetElemVTKID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetElemObjID + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; + + //! Reimplement the TNamedIDMapper::GetNodeName + virtual + std::string + GetNodeName(vtkIdType theObjID) const; + + //! Reimplement the TNamedIDMapper::GetElemName + virtual + std::string + GetElemName(vtkIdType theObjID) const; + + TID2ID myElemObj2VTKID; //!< To support object to VTK number mapping + TSubMeshArr mySubMeshArr; //!< Keeps sequence of TSubMeshImpl as they were added into TAppendFilter + PNamedPointCoords myNamedPointCoords; //!< Share the same instance with TMesh to implement nodal mapping + + TGeom2SubMesh myGeom2SubMesh; //!< Keeps TSubMeshImpl according to their geometrical type + }; + typedef SharedPtr PMeshOnEntityImpl; + + + //--------------------------------------------------------------- + typedef std::map TGeom2SubMeshID; + + //! Specialize TFamily to provide VTK mapping for the entity + struct TFamilyImpl: virtual TFamily, + virtual TSource + { + //! Reimplement the TIDMapper::GetNodeObjID + vtkIdType + GetNodeObjID(vtkIdType theID) const ; + + //! Reimplement the TIDMapper::GetNodeVTKID + virtual + vtkIdType + GetNodeVTKID(vtkIdType theID) const ; + + //! Reimplement the TIDMapper::GetElemVTKID + virtual + vtkIdType + GetElemVTKID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetElemObjID + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetVTKOutput + virtual + TVTKOutput* + GetVTKOutput(); + + PNamedPointCoords myNamedPointCoords; //!< Share the same instance with TMesh to implement nodal mapping + TID2ID myElemObj2VTKID; //!< To support object to VTK number mapping + TSubMeshID myMeshID; //!< Keeps numbers of mesh elements that belongs to the MED FAMILY + + TGeom2SubMeshID myGeom2SubMeshID; //!< Keeps TSubMeshID according to their geometrical type + }; + typedef SharedPtr PFamilyImpl; + + + //--------------------------------------------------------------- + typedef std::pair TNbASizeCells; + typedef TVector TFamilyArr; + + //! Specialize TGroup to provide VTK mapping for the entity + struct TGroupImpl: virtual TGroup, + virtual TAppendFilter + { + //! Calculate pair of values - number of cells and its size + TNbASizeCells + GetNbASizeCells() const; + + //! Reimplement the TIDMapper::GetElemVTKID + virtual + vtkIdType + GetElemVTKID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetElemObjID + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetNodeObjID + virtual + vtkIdType + GetNodeObjID(vtkIdType theID) const; + + //! Reimplement the TIDMapper::GetNodeVTKID + virtual + vtkIdType + GetNodeVTKID(vtkIdType theID) const; + + TID2ID myElemObj2VTKID; //!< To support object to VTK number mapping + TFamilyArr myFamilyArr; //!< Keeps sequence of TFamily as they were added into TAppendFilter + PNamedPointCoords myNamedPointCoords; //!< Share the same instance with TMesh to implement nodal mapping + }; + typedef SharedPtr PGroupImpl; + + + //--------------------------------------------------------------- + typedef TVector TMinMaxArr; + + //! Specialize TField to provide VTK mapping for the entity + struct TFieldImpl: virtual TField + { + vtkIdType myDataSize; //!< Keeps size of the assigned data + + TMinMaxArr myMinMaxArr; //!< Keeps min/max values for each component of the MED FIELD + + //! Implement the TField::GetMinMax + virtual + TMinMax + GetMinMax(vtkIdType theCompID); - struct TFieldImpl: TField{ - TVTKExtractFilter myExtractFilter; - ~TFieldImpl() - { - if(myExtractFilter.GetPointer()) - myExtractFilter->UnRegisterAllOutputs(); - } + //! To initialize the data structure + void + InitArrays(vtkIdType theNbComp); + + TFieldImpl(); }; - typedef shared_ptr PFieldImpl; + typedef SharedPtr PFieldImpl; + + + //--------------------------------------------------------------- + typedef TVector TValue; + typedef TSlice TValueSlice; + typedef TCSlice TCValueSlice; + + typedef TVector TCValueSliceArr; + typedef TVector TValueSliceArr; + + //! Define a container to get access to data assigned to mesh + struct TMeshValue + { + TValue myValue; //!< Keeps all values as one dimensional sequence - struct TValForTimeImpl: TValForTime{ - TVTKAttribyteFilter myAttribyteFilter; - TVTKMergetFilter myMergeFilter; - TVTKSource myStorage; + vtkIdType myNbElem; //!< Defines number of mesh elements where the data assigned to + vtkIdType myNbComp; //!< Keeps number of components of corresponding MED FIELD + vtkIdType myNbGauss; //!< Defines number of Gauss Points + vtkIdType myStep; //! Internal variable - typedef std::vector TValForCellsWithType; - typedef std::map TValForCells; - TValForCells myValForCells; + //! To intitilize the data strucutre + void + Init(vtkIdType theNbElem, + vtkIdType theNbGauss, + vtkIdType theNbComp); - ~TValForTimeImpl() - { - if(myMergeFilter.GetPointer()) - myMergeFilter->UnRegisterAllOutputs(); - if(myAttribyteFilter.GetPointer()) - myAttribyteFilter->UnRegisterAllOutputs(); - } + //! To get assigned values first by Gauss Points and then by components (constant version) + TCValueSliceArr + GetGaussValueSliceArr(vtkIdType theElemId) const; + + //! To get assigned values first by Gauss Points and then by components + TValueSliceArr + GetGaussValueSliceArr(vtkIdType theElemId); + + //! To get assigned values first by components and then by Gauss Points (constant version) + TCValueSliceArr + GetCompValueSliceArr(vtkIdType theElemId) const; + + //! To get assigned values first by components and then by Gauss Points + TValueSliceArr + GetCompValueSliceArr(vtkIdType theElemId); }; - typedef shared_ptr PValForTimeImpl; + + //--------------------------------------------------------------- + typedef std::map TGeom2Value; + typedef std::map TGeom2NbGauss; + + //! Specialize TValForTime to provide VTK mapping for the entity + struct TValForTimeImpl: virtual TValForTime + { + PGaussPtsIDFilter myGaussPtsIDFilter; //!< Keep VTK representation for mesh and data on Gauss Points + PIDMapperFilter myIDMapperFilter; //!< Keep VTK representation for ordinary mesh and data + TGeom2Value myGeom2Value; //!< Keep value that is assigned to the mesh + TGeom2NbGauss myGeom2NbGauss; //!< Keep number of Gauss Points + + TValForTimeImpl(); + + //! Get mesh data for defined geometrical type (constant version) + const TMeshValue& + GetMeshValue(EGeometry theGeom) const; + + //! Get mesh data for defined geometrical type + TMeshValue& + GetMeshValue(EGeometry theGeom); + + //! Get number of Gauss Points for defined geometrical type + virtual + int + GetNbGauss(EGeometry theGeom) const; + }; + typedef SharedPtr PValForTimeImpl; } -class VISU_Convertor_impl: public VISU_Convertor{ + +//! This class perfroms mapping of intermediate data strucutres into corresponding VTK representation +/*! + It implements VISU_Convertor public interface and declare new pure virtual functions + to fill its intermediate data structure from a MED source +*/ +class VISU_Convertor_impl: public VISU_Convertor +{ public: - virtual float GetSize() ; + VISU_Convertor_impl(); + virtual + ~VISU_Convertor_impl(); + + //! Just to define default behaviour + virtual + VISU_Convertor* + Build(); + + //! Just to define default behaviour + virtual + VISU_Convertor* + BuildEntities(); + + //! Just to define default behaviour + virtual + VISU_Convertor* + BuildFields(); + + //! Just to define default behaviour + virtual + VISU_Convertor* + BuildMinMax(); + + //! Just to define default behaviour + virtual + VISU_Convertor* + BuildGroups(); + + //! Implemention of the VISU_Convertor::GetSize + virtual + float + GetSize(); + + //! Implemention of the VISU_Convertor::GetMeshOnEntity + virtual + VISU::PNamedIDMapper + GetMeshOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity); + + //! Implemention of the VISU_Convertor::GetMeshOnEntitySize virtual float GetMeshOnEntitySize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName = ""); + const VISU::TEntity& theEntity); + + //! Implemention of the VISU_Convertor::GetFamilyOnEntity + virtual + VISU::PIDMapper + GetFamilyOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName); + //! Implemention of the VISU_Convertor::GetFamilyOnEntitySize + virtual + float + GetFamilyOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName); + + //! Implemention of the VISU_Convertor::GetMeshOnGroup + virtual + VISU::PIDMapper + GetMeshOnGroup(const std::string& theMeshName, + const std::string& theGroupName); + + //! Implemention of the VISU_Convertor::GetMeshOnGroupSize virtual float GetMeshOnGroupSize(const std::string& theMeshName, const std::string& theGroupName); + //! Implemention of the VISU_Convertor::GetTimeStampOnMesh + virtual + VISU::PIDMapper + GetTimeStampOnMesh(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum); + + //! Implemention of the VISU_Convertor::GetTimeStampSize virtual float GetTimeStampSize(const std::string& theMeshName, @@ -123,18 +870,29 @@ public: const std::string& theFieldName, int theStampsNum); + //! Implemention of the VISU_Convertor::GetTimeStampOnGaussPts + virtual + VISU::PGaussPtsIDMapper + GetTimeStampOnGaussPts(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum); + + //! Implemention of the VISU_Convertor::GetFieldOnMeshSize virtual float GetFieldOnMeshSize(const std::string& theMeshName, const VISU::TEntity& theEntity, const std::string& theFieldName); + //! Implemention of the VISU_Convertor::GetField virtual const VISU::PField GetField(const std::string& theMeshName, VISU::TEntity theEntity, const std::string& theFieldName); + //! Implemention of the VISU_Convertor::GetTimeStamp virtual const VISU::PValForTime GetTimeStamp(const std::string& theMeshName, @@ -142,46 +900,31 @@ public: const std::string& theFieldName, int theStampsNum); -public: - VISU_Convertor_impl(); - - virtual ~VISU_Convertor_impl(); - - virtual VISU_Convertor* Build() { return this;}; - - virtual - TOutput* - GetMeshOnEntity(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName = ""); - - virtual - TOutput* - GetMeshOnGroup(const std::string& theMeshName, - const std::string& theGroupName); - - virtual - TOutput* - GetTimeStampOnMesh(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum); - protected: + //! An utility method to find TMesh by its name VISU::PMeshImpl FindMesh(const std::string& theMeshName); - typedef boost::tuple TFindMeshOnEntity; + //! An utility method to find TMeshOnEntity by name of its parent mesh and entity + typedef boost::tuple TFindMeshOnEntity; TFindMeshOnEntity FindMeshOnEntity(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName); + const VISU::TEntity& theEntity); + //! An utility method to find TFamily by name of its parent mesh, corresponding entity and its name + typedef boost::tuple TFindFamilyOnEntity; + TFindFamilyOnEntity + FindFamilyOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName); + + //! An utility method to find Group by name of its parent mesh and its name typedef boost::tuple TFindMeshOnGroup; TFindMeshOnGroup FindMeshOnGroup(const std::string& theMeshName, const std::string& theGroupName); + //! An utility method to find TField by name of its parent mesh, corresponding entity and its name typedef boost::tuple + +namespace VISU +{ + //--------------------------------------------------------------- + float* + TIDMapper + ::GetNodeCoord(vtkIdType theObjID) + { + vtkIdType aVTKID = GetNodeVTKID(theObjID); + return GetVTKOutput()->GetPoint(aVTKID); + } + + vtkIdType + TIDMapper + ::GetNodeVTKID(vtkIdType theID) const + { + return theID; + } + + vtkIdType + TIDMapper + ::GetNodeObjID(vtkIdType theID) const + { + return theID; + } + + vtkCell* + TIDMapper + ::GetElemCell(int theObjID) + { + vtkIdType aVtkID = GetElemVTKID(theObjID); + return GetVTKOutput()->GetCell(aVtkID); + } + + vtkIdType + TIDMapper + ::GetElemVTKID(vtkIdType theID) const + { + return theID; + } + + vtkIdType + TIDMapper + ::GetElemObjID(vtkIdType theID) const + { + return theID; + } +} diff --git a/src/CONVERTOR/VISU_IDMapper.hxx b/src/CONVERTOR/VISU_IDMapper.hxx new file mode 100644 index 00000000..57cf9ee7 --- /dev/null +++ b/src/CONVERTOR/VISU_IDMapper.hxx @@ -0,0 +1,150 @@ +// VISU CONVERTOR : +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_Convertor.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_IDMapper_HeaderFile +#define VISU_IDMapper_HeaderFile + +/*! + \file VISU_IDMapper.hxx + \brief The file contains declarations for basic interfaces that defines mapping of mesh elements +*/ + +#include "MED_SharedPtr.hxx" + +#include +#include + +class vtkUnstructuredGrid; +class vtkCell; + +namespace VISU +{ + using MED::SharedPtr; + + //--------------------------------------------------------------- + //! Defines a basic class for intemediate data structures + struct TBaseStructure + { + //! Just to provide possibility of dynamic navigation through the class hierarchy + virtual ~TBaseStructure() + {} + + std::string myEntry; //!< To simplify publication of the object tree + }; + typedef SharedPtr PBaseStructure; + + //--------------------------------------------------------------- + typedef vtkUnstructuredGrid TVTKOutput; + + //! Defines a basic abstract interface for VTK to object ID's and backward mapping + /*! + Where object ID means ID which attached to corresponding MED entity. + For example, each MED node can have its own ID as well as any other mesh cell + */ + struct TIDMapper: virtual TBaseStructure + { + //! Get node object ID for corresponding VTK ID + virtual + vtkIdType + GetNodeObjID(vtkIdType theID) const; + + //! Get node VTK ID for corresponding object ID + virtual + vtkIdType + GetNodeVTKID(vtkIdType theID) const; + + //! Get coordinates of node for corresponding object ID + virtual + float* + GetNodeCoord(vtkIdType theObjID); + + //! Get cell object ID for corresponding VTK ID + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; + + //! Get cell VTK ID for corresponding object ID + virtual + vtkIdType + GetElemVTKID(vtkIdType theID) const; + + //! Get VTK representation of mesh cell for corresponding object ID + virtual + vtkCell* + GetElemCell(vtkIdType theObjID); + + //! Get VTK representation of mesh for corresponding MED entity + virtual + TVTKOutput* + GetVTKOutput() = 0; + }; + typedef SharedPtr PIDMapper; + + + //--------------------------------------------------------------- + //! Defines an abstract interface for VTK to object ID's and backward mapping + /*! + This class defines some additional methods that allow get names for corresponding mesh elements + */ + struct TNamedIDMapper: virtual TIDMapper + { + //! Get name of mesh node for corresponding object ID + virtual + std::string + GetNodeName(vtkIdType theObjID) const = 0; + + //! Get name of mesh cell for corresponding object ID + virtual + std::string + GetElemName(vtkIdType theObjID) const = 0; + }; + typedef SharedPtr PNamedIDMapper; + + + //--------------------------------------------------------------- + typedef vtkIdType TCellID; + typedef vtkIdType TLocalPntID; + //! Defines a type that represent complex ID for defined Gauss Point + typedef std::pair TGaussPointID; + + struct TGaussPtsIDMapper: virtual TIDMapper + { + //! Gets complex Gauss Point ID by its VTK ID + virtual + TGaussPointID + GetObjID(vtkIdType theID) const = 0; + + //! Gets parent TNamedIDMapper, which contains reference mesh cells + virtual + TNamedIDMapper* + GetParent() = 0; + }; + typedef SharedPtr PGaussPtsIDMapper; + + //--------------------------------------------------------------- +} + +#endif diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx index 5c47189b..2eaddcfe 100644 --- a/src/CONVERTOR/VISU_MedConvertor.cxx +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -31,606 +31,1592 @@ #include "MED_Factory.hxx" #include "MED_Algorithm.hxx" +#include "MED_GaussUtils.hxx" #include "MED_Utilities.hxx" -#include +#include +#include -#define _EDF_NODE_IDS_ +#include using namespace std; -using namespace MED; using namespace VISU; +using MED::TInt; +using MED::TFloat; +using MED::EBooleen; + #ifdef _DEBUG_ static int MYDEBUG = 0; +static int MYVALUEDEBUG = 0; +static int MY_FAMILY_DEBUG = 0; +static int MY_GROUP_DEBUG = 0; +//#define _DEXCEPT_ #else static int MYDEBUG = 0; +static int MYVALUEDEBUG = 0; +static int MY_FAMILY_DEBUG = 0; +static int MY_GROUP_DEBUG = 0; #endif +#define _LOAD_FAMILIES_ +#define _EDF_NODE_IDS_ -namespace{ - - using namespace MED; - using namespace VISU; - - int MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType) +namespace +{ + //--------------------------------------------------------------- + vtkIdType + MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType) { return theMEDGeomType % 100; } - int MEDGeomToVTK(MED::EGeometrieElement theMEDGeomType) - { - switch(theMEDGeomType){ - case ePOINT1: return VTK_VERTEX; - case eSEG2: return VTK_LINE; - case eSEG3: return VTK_LINE; - case eTRIA3: return VTK_TRIANGLE; - case eTRIA6: return VTK_TRIANGLE; - case eQUAD4: return VTK_QUAD; - case eQUAD8: return VTK_QUAD; - case eTETRA4: return VTK_TETRA; - case eTETRA10: return VTK_TETRA; - case eHEXA8: return VTK_HEXAHEDRON; - case eHEXA20: return VTK_HEXAHEDRON; - case ePENTA6: return VTK_WEDGE; - case ePENTA15: return VTK_WEDGE; - case ePYRA5: return VTK_PYRAMID; - case ePYRA13: return VTK_PYRAMID; - case ePOLYGONE: return VTK_POLYGON; - case ePOLYEDRE: return VTK_CONVEX_POINT_SET; - } - return -1; - } - int VTKGeom2NbNodes(int theVTKGeomType) + //--------------------------------------------------------------- + VISU::EGeometry + MEDGeom2VISU(MED::EGeometrieElement theGeom) { - switch(theVTKGeomType){ - case VTK_VERTEX: return 1; - case VTK_LINE: return 2; - case VTK_TRIANGLE: return 3; - case VTK_QUAD: return 4; - case VTK_TETRA: return 4; - case VTK_HEXAHEDRON: return 8; - case VTK_WEDGE: return 6; - case VTK_PYRAMID: return 5; + switch(theGeom){ + case MED::ePOINT1: return VISU::ePOINT1; + case MED::eSEG2: return VISU::eSEG2; + case MED::eTRIA3: return VISU::eTRIA3; + case MED::eQUAD4: return VISU::eQUAD4; + case MED::eTETRA4: return VISU::eTETRA4; + case MED::eHEXA8: return VISU::eHEXA8; + case MED::ePENTA6: return VISU::ePENTA6; + case MED::ePYRA5: return VISU::ePYRA5; + + case MED::eSEG3: return VISU::eSEG3; + case MED::eTRIA6: return VISU::eTRIA6; + case MED::eQUAD8: return VISU::eQUAD8; + case MED::eTETRA10: return VISU::eTETRA10; + case MED::eHEXA20: return VISU::eHEXA20; + case MED::ePENTA15: return VISU::ePENTA15; + case MED::ePYRA13: return VISU::ePYRA13; + + case MED::ePOLYGONE: return VISU::ePOLYGONE; + case MED::ePOLYEDRE: return VISU::ePOLYEDRE; } - return -1; + return VISU::eNONE; } - MED::EGeometrieElement VTKGeomToMED(int theVTKGeomType) + + //--------------------------------------------------------------- + MED::EGeometrieElement + VISUGeom2MED(int theGeom) { - switch(theVTKGeomType){ - case VTK_VERTEX: return ePOINT1; - case VTK_LINE: return eSEG2; - case VTK_TRIANGLE: return eTRIA3; - case VTK_QUAD: return eQUAD4; - case VTK_TETRA: return eTETRA4; - case VTK_HEXAHEDRON: return eHEXA8; - case VTK_WEDGE: return ePENTA6; - case VTK_PYRAMID: return ePYRA5; - case VTK_POLYGON: return ePOLYGONE; - case VTK_CONVEX_POINT_SET: return ePOLYEDRE; + switch(theGeom){ + case VISU::ePOINT1: return MED::ePOINT1; + case VISU::eSEG2: return MED::eSEG2; + case VISU::eTRIA3: return MED::eTRIA3; + case VISU::eQUAD4: return MED::eQUAD4; + case VISU::eTETRA4: return MED::eTETRA4; + case VISU::eHEXA8: return MED::eHEXA8; + case VISU::ePENTA6: return MED::ePENTA6; + case VISU::ePYRA5: return MED::ePYRA5; + + case VISU::eSEG3: return MED::eSEG3; + case VISU::eTRIA6: return MED::eTRIA6; + case VISU::eQUAD8: return MED::eQUAD8; + case VISU::eTETRA10: return MED::eTETRA10; + case VISU::eHEXA20: return MED::eHEXA20; + case VISU::ePENTA15: return MED::ePENTA15; + case VISU::ePYRA13: return MED::ePYRA13; + + case VISU::ePOLYGONE: return MED::ePOLYGONE; + case VISU::ePOLYEDRE: return MED::ePOLYEDRE; } - return EGeometrieElement(-1); + return MED::EGeometrieElement(-1); } - TEntity MEDEntityToVTK(MED::EEntiteMaillage theMEDEntity) + + //--------------------------------------------------------------- + VISU::TEntity + MEDEntityToVTK(MED::EEntiteMaillage theMEDEntity) { switch(theMEDEntity){ - case eNOEUD: return NODE_ENTITY; - case eARETE: return EDGE_ENTITY; - case eFACE: return FACE_ENTITY; - case eMAILLE: return CELL_ENTITY; + case MED::eNOEUD: return NODE_ENTITY; + case MED::eARETE: return EDGE_ENTITY; + case MED::eFACE: return FACE_ENTITY; + case MED::eMAILLE: return CELL_ENTITY; } - return TEntity(-1); + return VISU::TEntity(-1); } - MED::EEntiteMaillage VTKEntityToMED(TEntity theVTKEntity) + + //--------------------------------------------------------------- + MED::EEntiteMaillage + VTKEntityToMED(TEntity theVTKEntity) { switch(theVTKEntity){ - case NODE_ENTITY: return eNOEUD; - case EDGE_ENTITY: return eARETE; - case FACE_ENTITY: return eFACE; - case CELL_ENTITY: return eMAILLE; + case NODE_ENTITY: return MED::eNOEUD; + case EDGE_ENTITY: return MED::eARETE; + case FACE_ENTITY: return MED::eFACE; + case CELL_ENTITY: return MED::eMAILLE; } return MED::EEntiteMaillage(-1); } -} - -extern "C" -VISU_Convertor* CreateConvertor(const string& theFileName) -{ - return new VISU_MedConvertor(theFileName); -} - -VISU_MedConvertor::VISU_MedConvertor(const string& theFileName) { - myFileInfo.setFile(QString(theFileName.c_str())); - myName = myFileInfo.baseName().latin1(); -} -VISU_Convertor* VISU_MedConvertor::Build() { - PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1()); - TInt aNbMeshes = aMed->GetNbMeshes(); - TMeshMap& aMeshMap = myMeshMap; + //--------------------------------------------------------------- + PMEDSubProfile + CrSubProfile(const MED::PWrapper& theMEDWrapper, + const MED::PMeshInfo& theMeshInfo, + MED::EEntiteMaillage theMEntity, + MED::EGeometrieElement theMGeom, + const MED::TGeom2Size& theGeom2Size, + const MED::TGeom2Profile& theGeom2Profile) + { + VISU::EGeometry aEGeom = MEDGeom2VISU(theMGeom); + vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom); + + PMEDSubProfile aSubProfile(new TMEDSubProfile()); + aSubProfile->myGeom = aEGeom; + aSubProfile->myMGeom = theMGeom; + aSubProfile->myStatus = eAddAll; + + MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(theMGeom); + if(aTimeStampIter == theGeom2Size.end()) + aSubProfile->myStatus = eRemoveAll; + else{ + MED::TGeom2Profile::const_iterator aProfileIter = theGeom2Profile.find(theMGeom); + if(aProfileIter != theGeom2Profile.end()){ + MED::PProfileInfo aProfileInfo = aProfileIter->second; + + aSubProfile->myName = aProfileInfo->GetName(); + aSubProfile->myStatus = eAddPart; + + const MED::TElemNum& anElemNum = aProfileInfo->myElemNum; + TInt aNbElem = anElemNum.size(); + aSubProfile->myNbCells = aNbElem; + switch(theMGeom){ + case MED::ePOLYGONE: { + MED::PPolygoneInfo aPolygoneInfo = + theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom); + for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){ + TInt aNbConn = aPolygoneInfo->GetNbConn(anElemNum[anElemId]); + aSubProfile->myCellsSize += aNbConn; + } + break; + } + case MED::ePOLYEDRE: { + MED::PPolyedreInfo aPolyedreInfo = + theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom); + for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){ + MED::TCConnSliceArr aConnSliceArr = + aPolyedreInfo->GetConnSliceArr(anElemNum[anElemId]); + TInt aNbFaces = aConnSliceArr.size(); + TInt aCellSize = 0; + for(TInt iFace = 0; iFace < aNbFaces; iFace++){ + MED::TCConnSlice aConnSlice = aConnSliceArr[iFace]; + TInt aNbConn = aConnSlice.size(); + aCellSize += aNbConn; + } + aSubProfile->myCellsSize += aCellSize; + } + break; + } + default: { + aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes; + }} + }else{ + TInt aNbElem = aTimeStampIter->second; + aSubProfile->myNbCells = aNbElem; + switch(theMGeom){ + case MED::ePOLYGONE: { + MED::PPolygoneInfo aPolygoneInfo = + theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom); + for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){ + TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId); + aSubProfile->myCellsSize += aNbConn; + } + break; + } + case MED::ePOLYEDRE: { + MED::PPolyedreInfo aPolyedreInfo = + theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom); + for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){ + MED::TCConnSliceArr aConnSliceArr = + aPolyedreInfo->GetConnSliceArr(anElemId); + TInt aNbFaces = aConnSliceArr.size(); + TInt aCellSize = 0; + for(TInt iFace = 0; iFace < aNbFaces; iFace++){ + MED::TCConnSlice aConnSlice = aConnSliceArr[iFace]; + TInt aNbConn = aConnSlice.size(); + aCellSize += aNbConn; + } + aSubProfile->myCellsSize += aCellSize; + } + break; + } + default: { + aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes; + }} + } + } + INITMSG(MYDEBUG, + "- aMGeom = "<GetPMeshInfo(iMesh); + //--------------------------------------------------------------- + TProfileKey + GetProfileKey(const MED::PWrapper& theMEDWrapper, + const MED::PMeshInfo& theMeshInfo, + const MED::TTimeStampVal& theTimeStampVal, + const VISU::TMEDMeshOnEntity& theMeshOnEntity, + MED::EEntiteMaillage theMEntity, + const MED::TGeom2Size& theGeom2Size) + { + INITMSG(MYDEBUG,"GetProfileKey"<first; + PSubProfile aSubProfile = CrSubProfile(theMEDWrapper, + theMeshInfo, + theMEntity, + aMGeom, + theGeom2Size, + aGeom2Profile); + aProfileKey.insert(aSubProfile); + } + + return aProfileKey; + } + - PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo); + //--------------------------------------------------------------- + void + InitProfile(const MED::PWrapper& theMEDWrapper, + const MED::PMeshInfo& theMeshInfo, + MED::TTimeStampVal& theTimeStampVal, + VISU::TMEDMeshOnEntity& theMeshOnEntity, + MED::EEntiteMaillage theMEntity, + const MED::TGeom2Size& theGeom2Size, + VISU::TMEDValForTime& theValForTime) + { + TTimerLog aTimerLog(MYDEBUG,"InitProfile"); + INITMSG(MYDEBUG,"InitProfile"<GetEntityInfo(aMeshInfo); + TProfileMap& aProfileMap = theMeshOnEntity.myProfileMap; - TElemGroup aElemGroup = GetElemsByEntity(aMed,aMeshInfo,aEntityInfo); + TProfileKey aProfileKey = GetProfileKey(theMEDWrapper, + theMeshInfo, + theTimeStampVal, + theMeshOnEntity, + theMEntity, + theGeom2Size); + + TProfileMap::const_iterator anIter = aProfileMap.find(aProfileKey); + if(anIter != aProfileMap.end()){ + theValForTime.myProfile = anIter->second; + INITMSG(MYDEBUG,"aProfileMap.find(aProfileKey)"<myGeom2SubProfile; + + TProfileKey::const_iterator anIter = aProfileKey.begin(); + for(; anIter != aProfileKey.end(); anIter++){ + PMEDSubProfile aSubProfile(*anIter); + + if(aProfile->myIsAll && aSubProfile->myStatus != eAddAll) + aProfile->myIsAll = false; - TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo); + VISU::EGeometry aEGeom = aSubProfile->myGeom; + aGeom2SubProfile[aEGeom] = aSubProfile; + } + + aProfileMap[aProfileKey] = aProfile; + theValForTime.myProfile = aProfile; + } + } - TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,aElemGroup,aFamilyGroup); - TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup); + //--------------------------------------------------------------- + TGaussKey + GetGaussKey(const MED::TTimeStampVal& theTimeStampVal, + const VISU::TMEDMeshOnEntity& theMeshOnEntity, + const MED::TGeom2Size& theGeom2Size, + VISU::TMEDValForTime& theValForTime) + { + TTimerLog aTimerLog(MYDEBUG,"GetGaussKey"); + INITMSG(MYDEBUG,"GetGaussKey"< TFamilyCounterMap; - TFamilyCounterMap aFamilyNbCellsCounterMap, aFamilyCellsSizeCounterMap; + TGaussKey aGaussKey; + PMEDProfile aProfile = theValForTime.myProfile; + TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile; - TInt aDim = aMeshInfo->GetDim(); - const string& aMeshName = aMeshInfo->GetName(); - - PMEDMesh aMesh = aMeshMap[aMeshName](new TMEDMesh()); - aMesh->myDim = aDim; - aMesh->myName = aMeshName; - aMesh->myNbPoints = aNodeInfo->GetNbElem(); - aMesh->myMeshInfo = aMeshInfo; - aMesh->myEntityInfo = aEntityInfo; - - INITMSG(MYDEBUG,"aMeshName = '"<first; + VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom); + + TGeom2SubProfile::iterator anIter2 = aGeom2SubProfile.find(aEGeom); + if(anIter2 == aGeom2SubProfile.end()){ + INITMSG(MYDEBUG,"anIter2 == aGeom2SubProfile.end!!"<second; + + MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(aMGeom); + if(aTimeStampIter != theGeom2Size.end()){ + TInt aNbCells = aTimeStampIter->second; + if(aSubProfile->myStatus == eAddPart) + aNbCells = aSubProfile->myNbCells; + + PMEDGaussSubMesh aGaussSubMesh(new TMEDGaussSubMesh()); + aGaussSubMesh->mySubProfile = aSubProfile; + aGaussSubMesh->myStatus = aSubProfile->myStatus; + + PMEDGauss aGauss(new TMEDGauss()); + aGaussSubMesh->myGauss = aGauss; + aGauss->myGeom = aEGeom; + aGauss->myNbPoints = 1; + + MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom); + if(aGaussIter != aGeom2Gauss.end()){ + MED::PGaussInfo aGaussInfo = aGaussIter->second; + aGauss->myGaussInfo = aGaussInfo; + aGauss->myName = aGaussInfo->GetName(); + aGauss->myNbPoints = aGaussInfo->GetNbGauss(); + } + + aGaussSubMesh->myNbCells = aNbCells*aGauss->myNbPoints; + aGaussSubMesh->myCellsSize = aGaussSubMesh->myNbCells*2; + + aGaussKey.insert(aGaussSubMesh); + + INITMSGA(MYDEBUG,0, + "- aEGeom = "<myGeom<< + "; aName = '"<myName<<"'"<< + "; aNbGauss = "<myNbPoints<< + "; aStatus = "<myStatus<< + "; aNbCells = "<myNbCells<< + "; aCellsSize = "<myCellsSize<< + endl); + } + } + + return aGaussKey; + } + + + //--------------------------------------------------------------- + void + InitGaussMesh(MED::TTimeStampVal& theTimeStampVal, + VISU::TMEDMeshOnEntity& theMeshOnEntity, + const MED::TGeom2Size& theGeom2Size, + VISU::TMEDValForTime& theValForTime) + { + TTimerLog aTimerLog(MYDEBUG,"InitGaussMesh"); + INITMSG(MYDEBUG,"InitGaussMesh"<second; + INITMSG(MYDEBUG,"aGaussMeshMap.find(aGaussKey)"<myGeom2GaussSubMesh; + { + TGaussKey::const_iterator anIter = aGaussKey.begin(); + for(; anIter != aGaussKey.end(); anIter++){ + PMEDGaussSubMesh aGaussSubMesh(*anIter); + PMEDGauss aGauss = aGaussSubMesh->myGauss; + VISU::EGeometry aEGeom = aGauss->myGeom; + aGeom2GaussSubMesh[aEGeom] = aGaussSubMesh; + } + } + { + TGaussSubMeshArr& aGaussSubMeshArr = aGaussMesh->myGaussSubMeshArr; + aGaussSubMeshArr.resize(aGeom2GaussSubMesh.size()); + TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin(); + for(TInt anID = 0; anIter != aGeom2GaussSubMesh.end(); anIter++, anID++){ + const PGaussSubMeshImpl& aGaussSubMesh = anIter->second; + aGaussSubMeshArr[anID] = aGaussSubMesh; + } + } + INITMSG(MYDEBUG,"aGaussMeshMap[aGaussKey] = aGaussMesh"<myMeshOnEntityMap; - MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin(); - for(; anEntityIter != aEntityInfo.end(); anEntityIter++){ - const EEntiteMaillage& aMEntity = anEntityIter->first; - const MED::TGeom& aTGeom = anEntityIter->second; + //--------------------------------------------------------------- + void + InitGaussProfile(const MED::PWrapper& theMEDWrapper, + const MED::PMeshInfo& theMeshInfo, + MED::TTimeStampVal& theTimeStampVal, + VISU::TMEDMeshOnEntity& theMeshOnEntity, + MED::EEntiteMaillage theMEntity, + const MED::TGeom2Size& theGeom2Size, + VISU::TMEDValForTime& theValForTime) + { + TTimerLog aTimerLog(MYDEBUG,"InitGaussProfile"); + INITMSG(MYDEBUG,"InitGaussProfile"<myMeshInfo; + const std::string& aMeshName = theMesh->myName; + TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap; + MED::TEntityInfo::const_iterator anEntityIter = theEntityInfo.begin(); + for(; anEntityIter != theEntityInfo.end(); anEntityIter++){ + const MED::EEntiteMaillage& aMEntity = anEntityIter->first; + const MED::TGeom2Size& aGeom2Size = anEntityIter->second; + TEntity aVEntity = MEDEntityToVTK(aMEntity); PMEDMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TMEDMeshOnEntity()); aMeshOnEntity->myEntity = aVEntity; aMeshOnEntity->myMeshName = aMeshName; - aMeshOnEntity->myGeom = aTGeom; - - INITMSG(MYDEBUG,"aMEntity = "<myGeom2Size = aGeom2Size; + TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize; - if(aMEntity == eNOEUD){ - aMeshOnEntity->myNbCells = aMesh->myNbPoints; - aMeshOnEntity->myCellsSize = 2*aMesh->myNbPoints; + INITMSG(MYDEBUG, + "- aMEntity = "<GetFamNum(iElem); - if(aFamId != 0){ - aFamilyNbCellsCounterMap[aFamId] += 1; - ADDMSG(MYDEBUG,"aFamId="<GetNbConn(iElem) + 1; - } - } - ADDMSG(MYDEBUG,endl); - break; - } - case ePOLYEDRE: - { - PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aGeom); - TInt aNbElem = aPolyedreInfo->GetNbElem(); - TElemNum aConn = aPolyedreInfo->GetConnectivite(); - TElemNum aIndex = aPolyedreInfo->GetIndex(); - TInt aNbIndex = aIndex.size(); - TInt aNbConn = aConn.size(); - - aMeshOnEntity->myNbCells += aNbElem; - - for (int ii = 0; iiGetNbConn(ii); - aMeshOnEntity->myCellsSize += aNbConnii; - } - INITMSG(MYDEBUG,"aGeom = "<GetFamNum(iElem); - std::string aName = aPolyedreInfo->GetElemName(iElem); - if(aFamId != 0){ - aFamilyNbCellsCounterMap[aFamId] += 1; - ADDMSG(MYDEBUG,"(aFamId="<GetNbConn(iElem) + 1; - } - } - ADDMSG(MYDEBUG,endl); - break; + for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){ + const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first; + + switch(aMGeom){ + case MED::ePOLYGONE: { + MED::PPolygoneInfo aPolygoneInfo = theMEDWrapper->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom); + TInt aNbElem = aPolygoneInfo->GetNbElem(); + + INITMSG(MYDEBUG, + "- aMGeom = "<GetFamNum(iElem); - if(aFamId != 0){ - aFamilyNbCellsCounterMap[aFamId] += 1; - ADDMSG(MYDEBUG,"aFamId = "<GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom); + TInt aNbElem = aPolyedreInfo->GetNbElem(); + + INITMSG(MYDEBUG, + "- aMGeom = "<first; - const TFamilyGroup& aFamilyGroup = aFamilyByEntityIter->second; + } - TEntity aVEntity = MEDEntityToVTK(aMEntity); - VISU::PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity]; - VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; + + //--------------------------------------------------------------- + void + BuildFieldMap(PMEDMesh theMesh, + const MED::TEntityInfo& theEntityInfo, + MED::PWrapper theMEDWrapper) + { + TTimerLog aTimerLog(MYDEBUG,"BuildFieldMap"); + TInt aNbFields = theMEDWrapper->GetNbFields(); + MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo; + const std::string& aMeshName = theMesh->myName; + INITMSG(MYDEBUG,"BuildFieldMap: aNbFields = "<GetPFieldInfo(aMeshInfo,iField); + TInt aNbComp = aFieldInfo->GetNbComp(); + std::string aFieldName = aFieldInfo->GetName(); - if(aFamilyGroup.empty()) + MED::TGeom2Size aGeom2Size; + MED::EEntiteMaillage aMEntity; + TInt aNbTimeStamps = theMEDWrapper->GetNbTimeStamps(aFieldInfo, + theEntityInfo, + aMEntity, + aGeom2Size); + if(aNbTimeStamps < 1) continue; + + TEntity aVEntity = MEDEntityToVTK(aMEntity); + PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity]; + TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; + PMEDField aField = aFieldMap[aFieldName](new TMEDField()); + aField->myId = iField; + aField->InitArrays(aNbComp); + aField->myEntity = aVEntity; + aField->myName = aFieldName; + aField->myMeshName = aMeshName; + aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp; + + INITMSG(MYDEBUG,"myName = '"<myName<<"'"<< + "; myId = "<myId<< + "; myEntity = "<myEntity<< + "; myDataSize = "<myDataSize<< + "; myNbComp = "<myNbComp<<"\n"); + + for(TInt iComp = 0; iComp < aNbComp; iComp++){ + aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp); + aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp); + } + + for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){ + TTimerLog aTimerLog(MYDEBUG,"GetPTimeStampInfo"); + MED::PTimeStampInfo aTimeStampInfo = theMEDWrapper->GetPTimeStampInfo(aFieldInfo, + aMEntity, + aGeom2Size, + iTimeStamp); + TFloat aDt = aTimeStampInfo->GetDt(); + std::string anUnitDt = aTimeStampInfo->GetUnitDt(); + + TValField& aValField = aField->myValField; + PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime()); + aValForTime->myId = iTimeStamp; + aValForTime->myFieldName = aField->myName; + aValForTime->myEntity = aField->myEntity; + aValForTime->myMeshName = aField->myMeshName; + aValForTime->myTime = VISU::TTime(aDt,anUnitDt); + INITMSG(MYDEBUG,"aDt = '"<myGeom2NbGauss; + const MED::TGeom2NbGauss& aMGeom2NbGauss = aTimeStampInfo->myGeom2NbGauss; + MED::TGeom2NbGauss::const_iterator anIter = aMGeom2NbGauss.begin(); + for(; anIter != aMGeom2NbGauss.end(); anIter++){ + const MED::EGeometrieElement& aMGeom = anIter->first; + EGeometry aEGeom = MEDGeom2VISU(aMGeom); + TInt aNbGauss = anIter->second; + aVGeom2NbGauss[aEGeom] = aNbGauss; + } + } + } + } - INITMSG(MYDEBUG,"aMEntity = "<GetId() == 0) + + //--------------------------------------------------------------- + void + BuildFamilyMap(PMEDMesh theMesh, + const MED::TEntityInfo& theEntityInfo, + const MED::TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo, + const MED::TFamilyInfoSet& theFamilyInfoSet, + MED::PWrapper theMEDWrapper) + { + TTimerLog aTimerLog(MYDEBUG,"BuildFamilyMap"); + INITMSG(MYDEBUG,"BuildFamilyMap\n"); + + MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo; + MED::TEntity2FamilySet aEntity2FamilySet = MED::GetEntity2FamilySet(theMEDWrapper,theEntity2TGeom2ElemInfo,theFamilyInfoSet); + MED::TEntity2FamilySet::const_iterator aEntity2FamilySetIter = aEntity2FamilySet.begin(); + for(; aEntity2FamilySetIter != aEntity2FamilySet.end(); aEntity2FamilySetIter++){ + const MED::EEntiteMaillage& aMEntity = aEntity2FamilySetIter->first; + const MED::TFamilyTSizeSet& aFamilyTSizeSet = aEntity2FamilySetIter->second; + + TEntity aVEntity = MEDEntityToVTK(aMEntity); + PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity]; + const TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize; + TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; + + if(aFamilyTSizeSet.empty()) + continue; + + INITMSG(MY_FAMILY_DEBUG, + "- aMEntity = "<myGroups; + "; myCellsSize = "<myCellsSize<< + endl); +#ifdef _DEBUG_ const TInt aNbGroup = aFamilyInfo->GetNbGroup(); for(TInt i = 0; i < aNbGroup; i++){ - const string& aGroupName = aFamilyInfo->GetGroupName(i); - aBindGroups.insert(aGroupName); - INITMSG(MYDEBUG,"aGroupName = '"<GetGroupName(i); + INITMSG(MY_FAMILY_DEBUG,"- aGroupName = '"<myGroupMap; - TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin(); - for(;aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){ - const string& aGroupName = aGroupInfoIter->first; - const TFamilyGroup& aFamilyGroup = aGroupInfoIter->second; - PMEDGroup aGroup(new TMEDGroup()); - aGroup->myName = aGroupName; - aGroup->myMeshName = aMesh->myName; - INITMSG(MYDEBUG,"aGroup->myName = '"<myName<<"'\n"); + //--------------------------------------------------------------- + void + BuildGroupMap(PMEDMesh theMesh, + const MED::TFamilyInfoSet& theFamilyInfoSet) + { + TTimerLog aTimerLog(MYDEBUG,"BuildGroupMap"); + INITMSG(MYDEBUG,"BuildGroupMap\n"); - TFamilyGroup::const_iterator aFamilyIter = aFamilyGroup.begin(); - for(; aFamilyIter != aFamilyGroup.end(); aFamilyIter++){ - const PFamilyInfo& aFamilyInfo = *aFamilyIter; - const string& aFamilyName = aFamilyInfo->GetName(); + TGroupMap& aGroupMap = theMesh->myGroupMap; + MED::TGroupInfo aGroupInfo = MED::GetGroupInfo(theFamilyInfoSet); + MED::TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin(); + for(; aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){ + const std::string& aGroupName = aGroupInfoIter->first; + INITMSG(MY_GROUP_DEBUG,"aGroupName = '"<myFamilySet; + const MED::TFamilyInfoSet& aFamilyInfoSet = aGroupInfoIter->second; + MED::TFamilyInfoSet::const_iterator aFamilyIter = aFamilyInfoSet.begin(); + for(; aFamilyIter != aFamilyInfoSet.end(); aFamilyIter++){ + const MED::PFamilyInfo& aFamilyInfo = *aFamilyIter; + std::string aFamilyName = aFamilyInfo->GetName(); + + TEntity aVEntity = TEntity(-1); + PMEDFamily aFamily; + // Find aVisuEntity - const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + const TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap; TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin(); for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){ const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second; const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); - for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ - const string& aName = aFamilyMapIter->first; + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const std::string& aName = aFamilyMapIter->first; aFamily = aFamilyMapIter->second; if(aName == aFamilyName){ aVEntity = aFamily->myEntity; goto exit_lable; } } - } + } exit_lable: if(aFamily && aVEntity >= 0){ - aGroup->myFamilyAndEntitySet.insert(TFamilyAndEntity(aFamilyName,aVEntity)); - INITMSG(MYDEBUG,"aFamilyName = '"<myName<<"'; aVEntity = "<myNbCells += aFamily->myNbCells; - aGroup->myCellsSize += aFamily->myCellsSize; + aFamilySet.insert(aFamily); + INITMSG(MY_GROUP_DEBUG, + "- aFamilyName = '"<myFamilyAndEntitySet.empty() && aGroup->myNbCells > 0){ - BEGMSG(MYDEBUG,"myNbCells = "<myNbCells<< - "; myCellsSize = "<myCellsSize<<"\n\n"); + if(!aFamilySet.empty()) aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup)); - } } - - TInt aNbFields = aMed->GetNbFields(); - BEGMSG(MYDEBUG,"VISU::TField: NbFields="<GetPFieldInfo(aMeshInfo,iField); - TInt aNbComp = aFieldInfo->GetNbComp(); - const string& aFieldName = aFieldInfo->GetName(); + } - MED::TErr anErr; - MED::TGeom aTGeom; - EEntiteMaillage aMEntity; - TInt aNbTimeStamps = aMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,aMEntity,aTGeom,&anErr); - if (anErr < 0 || aNbTimeStamps < 1) - continue; - TEntity aVEntity = MEDEntityToVTK(aMEntity); - VISU::PMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity]; - TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; - PMEDField aField = aFieldMap[aFieldName](new TMEDField()); - aField->myId = iField; - aField->myNbComp = aNbComp; - aField->myEntity = aVEntity; - aField->myName = aFieldName; - aField->myMeshName = aMeshName; - aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp; - aField->myCompNames.resize(aNbComp); - aField->myUnitNames.resize(aNbComp); + //--------------------------------------------------------------- + void + TMEDNamedPointCoords + ::Init(vtkIdType theNbPoints, + vtkIdType theDim, + const MED::PNodeInfo& theNodeInfo) + { + if(theNodeInfo->IsElemNum()) + TNamedPointCoords::Init(theNbPoints,theDim,theNodeInfo->myElemNum); + else + TNamedPointCoords::Init(theNbPoints,theDim); + if(theNodeInfo->IsElemNames()) + myNodeInfo = theNodeInfo; + } - INITMSG(MYDEBUG,"myName = '"<myName<< - "'; myId = "<myId<< - "; myEntity = "<myEntity<< - "; myDataSize = "<myDataSize<< - "; myNbComp = "<myNbComp<<"\n"); + std::string + TMEDNamedPointCoords + ::GetNodeName(vtkIdType theObjID) const + { + if(myNodeInfo) + return myNodeInfo->GetElemName(theObjID); + return TNamedPointCoords::GetNodeName(theObjID); + } - for(TInt iComp = 0; iComp < aNbComp; iComp++){ - aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp); - aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp); - } - for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){ - PTimeStampInfo aTimeStamp = aMed->GetPTimeStampInfo(aFieldInfo, - aMEntity, - aTGeom, - iTimeStamp, - &anErr); - if (anErr < 0) - continue; - - TFloat aDt = aTimeStamp->GetDt(); - const string& anUnitDt = aTimeStamp->GetUnitDt(); - PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStamp,&anErr); - TValField& aValField = aField->myValField; - PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime()); - aValForTime->myId = iTimeStamp; - aValForTime->myFieldName = aField->myName; - aValForTime->myEntity = aField->myEntity; - aValForTime->myMeshName = aField->myMeshName; - aValForTime->myNbComp = aField->myNbComp; - aValForTime->myTime = VISU::TTime(aDt,anUnitDt); - INITMSG(MYDEBUG,"aDt = "<myGaussInfo; + theResult = MED::TGaussInfo::TLess()(aLeft,aReight); } } - } catch (std::runtime_error& exc){ - MSG(MYDEBUG,"Follow exception wqs occured in:\n"<myNbPoints; + TCellID aCellID = theID / aNbPoints; + if(myIsElemNum) + aCellID = myElemNum[aCellID]; + + TLocalPntID aLocalPntID = theID % aNbPoints; + + return TGaussPointID(aCellID,aLocalPntID); + } + + + //--------------------------------------------------------------- + void + TMEDSubMesh + ::Init(const MED::PElemInfo& theElemInfo) + { + myIsElemNum = theElemInfo->IsElemNum(); + myElemNum = theElemInfo->myElemNum; + if(theElemInfo->IsElemNames()) + myElemInfo = theElemInfo; } - return this; -} + vtkIdType + TMEDSubMesh + ::GetElemObjID(vtkIdType theID) const + { + if(myIsElemNum) + return myElemNum[theID]; + else + return TSubMeshImpl::GetElemObjID(theID); + } -int VISU_MedConvertor::LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity, - const string& theFamilyName) -{ - PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1()); - const string& aMeshName = theMeshOnEntity->myMeshName; - const VISU::TEntity& anEntity = theMeshOnEntity->myEntity; - PMeshImpl aMesh = myMeshMap[aMeshName]; - int isPointsUpdated; - if(anEntity == VISU::NODE_ENTITY) - isPointsUpdated = LoadPoints(aMed,aMesh,theFamilyName); - else - isPointsUpdated = LoadPoints(aMed,aMesh); - int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,aMesh,theMeshOnEntity,theFamilyName); + std::string + TMEDSubMesh + ::GetElemName(vtkIdType theObjID) const + { + if(myElemInfo) + return myElemInfo->GetElemName(theObjID); + return TSubMeshImpl::GetElemName(theObjID); + } - return (isPointsUpdated || isCellsOnEntityUpdated); + struct TSetIsDone + { + bool& myIsDone; + TSetIsDone(bool& theIsDone): + myIsDone(theIsDone) + {} + + ~TSetIsDone() + { + myIsDone = true; + } + + }; } -int VISU_MedConvertor::LoadMeshOnGroup(VISU::PMeshImpl theMesh, - const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) -{ - PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1()); - int isPointsUpdated = 0, isCellsOnEntityUpdated = 0; - VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); - for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ - const string& aFamilyName = aFamilyAndEntitySetIter->first; - const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second; - const VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity]; - if(anEntity == VISU::NODE_ENTITY){ - isPointsUpdated += LoadPoints(aMed,theMesh,aFamilyName); - isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity); - }else{ - isPointsUpdated += LoadPoints(aMed,theMesh); - isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity,aFamilyName); - } - } - return (isPointsUpdated || isCellsOnEntityUpdated); +//--------------------------------------------------------------- +extern "C" +VISU_Convertor* +CreateConvertor(const string& theFileName) +{ + if(MED::PWrapper aMed = MED::CrWrapper(theFileName)) + return new VISU_MedConvertor(theFileName); + return NULL; } -int VISU_MedConvertor::LoadFieldOnMesh(VISU::PMeshImpl theMesh, - VISU::PMeshOnEntityImpl theMeshOnEntity, - VISU::PFieldImpl theField, - VISU::PValForTimeImpl theValForTime) +VISU_MedConvertor +::VISU_MedConvertor(const string& theFileName): + myIsEntitiesDone(false), + myIsFieldsDone(false), + myIsGroupsDone(false), + myIsMinMaxDone(false) { - PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1()); - int isPointsUpdated = LoadPoints(aMed,theMesh); - int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity); - int isFieldUpdated = LoadField(aMed,theMesh,theMeshOnEntity,theField,theValForTime); - - return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated); + myFileInfo.setFile(QString(theFileName.c_str())); + myName = myFileInfo.baseName().latin1(); } -int -VISU_MedConvertor::LoadPoints(const MED::PWrapper& theMed, - VISU::PMEDMesh theMesh, - const string& theFamilyName) +//--------------------------------------------------------------- +VISU_Convertor* +VISU_MedConvertor +::BuildEntities() { + if(myIsEntitiesDone) + return this; + + TSetIsDone aSetIsDone(myIsEntitiesDone); + TTimerLog aTimerLog(MYDEBUG,"BuildEntities"); + MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1()); + + TInt aNbMeshes = aMed->GetNbMeshes(); + TMeshMap& aMeshMap = myMeshMap; + + INITMSG(MYDEBUG,"BuildEntities aNbMeshes = "<GetPMeshInfo(iMesh); + std::string aMeshName = aMeshInfo->GetName(); + TInt aDim = aMeshInfo->GetDim(); + + MED::PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo); + + MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo); + + // creating TMesh structure and TMeshOnEntityMap + PMEDMesh aMesh = aMeshMap[aMeshName](new TMEDMesh()); + aMesh->myDim = aDim; + aMesh->myName = aMeshName; + aMesh->myNbPoints = aNodeInfo->GetNbElem(); + aMesh->myMeshInfo = aMeshInfo; + aMesh->myEntityInfo = anEntityInfo; + aMesh->myNamedPointCoords(new TMEDNamedPointCoords()); + + INITMSG(MYDEBUG,"aMeshName = '"<GetNbMeshes(); + TMeshMap& aMeshMap = myMeshMap; + + INITMSG(MYDEBUG,"BuildFields - aNbMeshes = "<GetPMeshInfo(iMesh); + std::string aMeshName = aMeshInfo->GetName(); + + TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName); + if(anIter == aMeshMap.end()) + continue; + PMEDMesh aMesh = anIter->second; + + INITMSG(MYDEBUG,"aMeshName = '"<GetEntityInfo(aMeshInfo); + + BuildFieldMap(aMesh, + anEntityInfo, + aMed); +#ifndef _DEXCEPT_ + }catch(std::exception& exc){ + MSG(MYDEBUG,"Follow exception was occured in:\n"<GetNbMeshes(); + TMeshMap& aMeshMap = myMeshMap; + + INITMSG(MYDEBUG,"BuildMinMax - aNbMeshes = "<GetPMeshInfo(iMesh); + std::string aMeshName = aMeshInfo->GetName(); + + TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName); + if(anIter == aMeshMap.end()) + continue; + PMEDMesh aMesh = anIter->second; + +#ifndef _DEXCEPT_ + try{ +#endif + TInt aNbFields = aMed->GetNbFields(); + + INITMSG(MYDEBUG, + "- aMeshName = '"<GetEntityInfo(aMeshInfo); + + for(TInt iField = 1; iField <= aNbFields; iField++){ + TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPFieldInfo()"); + MED::PFieldInfo aFieldInfo = aMed->GetPFieldInfo(aMeshInfo,iField); + std::string aFieldName = aFieldInfo->GetName(); + INITMSG(MYDEBUG,"- aFieldName = '"<GetNbTimeStamps(aFieldInfo, + anEntityInfo, + aMEntity, + aGeom2Size); + if(aNbTimeStamps < 1) + continue; + + TEntity aVEntity = MEDEntityToVTK(aMEntity); + PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity]; + TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; + PMEDField aField = aFieldMap[aFieldName]; + + TInt aNbComp = aField->myNbComp; + int aNbComp2 = aNbComp; + if(aNbComp == 2 || aNbComp == 4) + aNbComp2 = 2; + else if(aNbComp > 4) + aNbComp2 = 3; + + TMinMaxArr& aMinMaxArr = aField->myMinMaxArr; + TSetIsDone aSetIsDone(aField->myIsMinMaxInitilized); + for(TInt iTimeStamp = aNbTimeStamps; iTimeStamp >= 1; iTimeStamp--){ + TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPTimeStampInfo()"); + INITMSG(MYDEBUG,"- iTimeStamp = "<GetPTimeStampInfo(aFieldInfo, + aMEntity, + aGeom2Size, + iTimeStamp); + + MED::PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStampInfo, + aMKey2Profile, + aKey2Gauss); + + const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->GetGeom2Gauss(); + + const MED::TTimeStampVal& aTimeStampValRef = aTimeStampVal; + + const MED::TGeom2Value& aGeom2Value = aTimeStampValRef.myGeom2Value; + MED::TGeom2Value::const_iterator anIter = aGeom2Value.begin(); + for(; anIter != aGeom2Value.end(); anIter++){ + const MED::TMeshValue& aMMeshValue = anIter->second; + MED::EGeometrieElement aMGeom = anIter->first; + + TInt aNbElem = aMMeshValue.myNbElem; + TInt aNbGauss = aMMeshValue.myNbGauss; + + MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom); + if(aGaussIter == aGeom2Gauss.end()) + aNbGauss = 1; + + INITMSG(MYDEBUG, + "- aMGeom = "<GetMinMax(iComp); + INITMSG(MYDEBUG,"- "<GetNbMeshes(); + TMeshMap& aMeshMap = myMeshMap; + + INITMSG(MYDEBUG,"BuildGroups - aNbMeshes = "<GetPMeshInfo(iMesh); + std::string aMeshName = aMeshInfo->GetName(); + + TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName); + if(anIter == aMeshMap.end()) + continue; + PMEDMesh aMesh = anIter->second; + + INITMSG(MYDEBUG,"aMeshName = '"<GetEntityInfo(aMeshInfo); + + MED::TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo = + MED::GetEntity2TGeom2ElemInfo(aMed,aMeshInfo,anEntityInfo); + +#ifndef _DEXCEPT_ + try{ +#endif + MED::TFamilyInfoSet aFamilyInfoSet = MED::GetFamilyInfoSet(aMed,aMeshInfo); + + BuildFamilyMap(aMesh, + anEntityInfo, + anEntity2TGeom2ElemInfo, + aFamilyInfoSet, + aMed); + + BuildGroupMap(aMesh, + aFamilyInfoSet); +#ifndef _DEXCEPT_ + }catch(std::exception& exc){ + MSG(MYDEBUG,"Follow exception was occured in:\n"<myEntity; + + int isPointsUpdated = 0, isCellsOnEntityUpdated = 0; + if(anEntity == NODE_ENTITY){ + isPointsUpdated += LoadPoints(aMed,theMesh); + }else{ + isPointsUpdated += LoadPoints(aMed,theMesh); + isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity); + } + + return (isPointsUpdated || isCellsOnEntityUpdated); +} + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadFamilyOnEntity(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFamilyImpl theFamily) +{ + TTimerLog aTimerLog(MYDEBUG,"LoadFamilyOnEntity"); + INITMSG(MYDEBUG,"LoadFamilyOnEntity"<myEntity; + + int isPointsUpdated = 0, isCellsOnEntityUpdated = 0; + if(anEntity == NODE_ENTITY){ + isPointsUpdated += LoadPointsOnFamily(aMed,theMesh,theFamily); + }else{ + isPointsUpdated += LoadPoints(aMed,theMesh); + isCellsOnEntityUpdated += LoadCellsOnFamily(aMed,theMesh,theMeshOnEntity,theFamily); + } + + return (isPointsUpdated || isCellsOnEntityUpdated); +} + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadMeshOnGroup(VISU::PMeshImpl theMesh, + const VISU::TFamilySet& theFamilySet) +{ + TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnGroup"); + INITMSG(MYDEBUG,"LoadMeshOnGroup"<myEntity; + const PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity]; + if(anEntity == NODE_ENTITY){ + isPointsUpdated += LoadPointsOnFamily(aMed,theMesh,aFamily); + }else{ + isPointsUpdated += LoadPoints(aMed,theMesh); + isCellsOnEntityUpdated += LoadCellsOnFamily(aMed,theMesh,aMeshOnEntity,aFamily); + } + } + + return (isPointsUpdated || isCellsOnEntityUpdated); +} + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFieldImpl theField, + VISU::PValForTimeImpl theValForTime) +{ + TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnMesh"); + INITMSG(MYDEBUG,"LoadValForTimeOnMesh"<myEntity; + int isPointsUpdated = 0, isCellsOnEntityUpdated = 0; + isPointsUpdated += LoadPoints(aMed,theMesh); + if(anEntity != NODE_ENTITY) + isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity); + int isFieldUpdated = LoadValForTimeOnMesh(aMed,theMesh,theMeshOnEntity,theField,theValForTime); + + return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated); +} + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFieldImpl theField, + VISU::PValForTimeImpl theValForTime) +{ + TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnGaussPts"); + INITMSG(MYDEBUG,"LoadValForTimeOnGaussPts"<myEntity; + int isPointsUpdated = 0, isCellsOnEntityUpdated = 0; + if(anEntity != NODE_ENTITY) + isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity); + int isFieldUpdated = LoadValForTimeOnGaussPts(aMed,theMesh,theMeshOnEntity,theField,theValForTime); + + return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated); +} + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadPoints(const MED::PWrapper& theMed, + VISU::PMEDMesh theMesh) +{ + TTimerLog aTimerLog(MYDEBUG,"LoadPoints"); try{ //Check on existing family - VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY]; - aMeshOnEntity->myEntity = VISU::NODE_ENTITY; + PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY]; aMeshOnEntity->myMeshName = theMesh->myName; - PFamilyImpl aFamily = GetFamily(aMeshOnEntity,theFamilyName); - //Check on loading already done - bool isPointsLoaded = !theMesh->myPointsCoord.empty(); - if(isPointsLoaded) - if(!aFamily) - return 0; - else if(!aFamily->mySubMesh.empty()) - return 0; + aMeshOnEntity->myEntity = NODE_ENTITY; + + INITMSG(MYDEBUG,"LoadPoints - theMesh->myIsDone = "<myIsDone<<"'\n"); - INITMSG(MYDEBUG,"LoadPoints - isPointsLoaded = "<myIsDone) + return 0; //Main part of code - PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo); + MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo); TInt aNbElem = aNodeInfo->GetNbElem(); + TInt aDim = theMesh->myDim; - if(!isPointsLoaded){ - VISU::TMeshImpl::TPointsDim& aPointsDim = theMesh->myPointsDim; - aPointsDim.resize(theMesh->myDim); - for(int iDim = 0; iDim < theMesh->myDim; iDim++) - aPointsDim[iDim] = aNodeInfo->GetCoordName(iDim); - - VISU::TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord; - aPointsCoord.resize(aNbElem*theMesh->myDim); - for (int iElem = 0; iElem < aNbElem; iElem++) - for(int iDim = 0, iElem2Dim = iElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iElem2Dim++) - aPointsCoord[iElem2Dim] = aNodeInfo->GetNodeCoord(iElem,iDim); - - VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX]; - aConnForCellType.resize(aNbElem); - for (int iElem = 0; iElem < aNbElem; iElem++) - aConnForCellType[iElem] = VISU::TMeshOnEntityImpl::TConnect(1,iElem); + PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords; + TMEDNamedPointCoords& aCoords = aNamedPointCoords; + aCoords.Init(aNbElem,aDim,aNodeInfo); + + for(int iDim = 0; iDim < aDim; iDim++) + aCoords.GetName(iDim) = aNodeInfo->GetCoordName(iDim); + + for(int iElem = 0; iElem < aNbElem; iElem++){ + TCoordSlice aVCoordSlice = aCoords.GetCoordSlice(iElem); + MED::TCCoordSlice aMCoordSlice = aNodeInfo->GetCoordSlice(iElem); + for(int iDim = 0; iDim < aDim; iDim++) + aVCoordSlice[iDim] = aMCoordSlice[iDim]; } - if(aFamily && aNbElem > 0){ - VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX]; - for (int iElem = 0; iElem < aNbElem; iElem++) - if(aNodeInfo->GetFamNum(iElem) == aFamily->myId) - aSubMeshOnCellType.insert(iElem); + + TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh; + PMEDSubMesh aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new TMEDSubMesh()); + + aSubMesh->Init(aNodeInfo); + aSubMesh->myNbCells = theMesh->myNbPoints; + aSubMesh->myCellsSize = 2*theMesh->myNbPoints; + + TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect; + aCell2Connect.resize(aNbElem); + for (int iElem = 0; iElem < aNbElem; iElem++) + aCell2Connect[iElem] = VISU::TConnect(1,iElem); + + theMesh->myIsDone = true; + + return 1; + + }catch(std::exception& exc){ + throw; + }catch(...){ + EXCEPTION(runtime_error,"Unknown exception !!!"); + } + + return 0; +} + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadPointsOnFamily(const MED::PWrapper& theMed, + const VISU::PMEDMesh theMesh, + const VISU::PMEDFamily theFamily) +{ + TTimerLog aTimerLog(MYDEBUG,"LoadPointsOnFamily"); + try{ + if(theFamily->myIsDone) + return 0; + + //Main part of code + MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo); + TInt aNbElem = aNodeInfo->GetNbElem(); + + if(aNbElem > 0){ + TInt anId = theFamily->myId; + TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1]; + for(TInt iElem = 0; iElem < aNbElem; iElem++) + if(aNodeInfo->GetFamNum(iElem) == anId) + aSubMeshID.push_back(iElem); } + + theFamily->myIsDone = true; + return 1; - }catch(std::runtime_error& exc){ - theMesh->myPointsCoord.clear(); + + }catch(std::exception& exc){ throw; }catch(...){ - theMesh->myPointsCoord.clear(); EXCEPTION(runtime_error,"Unknown exception !!!"); } + return 0; } +//--------------------------------------------------------------- int -VISU_MedConvertor::LoadCellsOnEntity(const MED::PWrapper& theMed, - VISU::PMEDMesh theMesh, - VISU::PMEDMeshOnEntity theMeshOnEntity, - const string& theFamilyName) +VISU_MedConvertor +::LoadCellsOnEntity(const MED::PWrapper& theMed, + const VISU::PMEDMesh theMesh, + const VISU::PMEDMeshOnEntity theMeshOnEntity) { + TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnEntity"); +#ifndef _DEXCEPT_ try{ - //Check on existing family - PFamilyImpl aFamily = GetFamily(theMeshOnEntity,theFamilyName); - //Check on loading already done - bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty(); - if(isCellsLoaded) - if(!aFamily) - return 0; - else if(!aFamily->mySubMesh.empty()) - return 0; +#endif + const TEntity& aVEntity = theMeshOnEntity->myEntity; + const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity); - INITMSG(MYDEBUG,"LoadCellsOnEntity - theFamilyName = '"<myEntity; - const EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity); + if(theMeshOnEntity->myIsDone) + return 0; - const PMeshInfo& aMeshInfo = theMesh->myMeshInfo; - PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo); + const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo; + MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo); TInt aNbPoints = aNodeInfo->GetNbElem(); std::map aNodeIdMap; #ifdef _EDF_NODE_IDS_ - EBooleen anIsNodeNum = eFAUX; + EBooleen anIsNodeNum = MED::eFAUX; #else EBooleen anIsNodeNum = aNodeInfo->IsElemNum(); if(anIsNodeNum){ @@ -640,235 +1626,715 @@ VISU_MedConvertor::LoadCellsOnEntity(const MED::PWrapper& theMed, } #endif - const MED::TGeom& aTGeom = theMeshOnEntity->myGeom; - MED::TGeom::const_iterator anTGeomIter = aTGeom.begin(); - TMeshOnEntityImpl::TCellsConn& aCellsConn = theMeshOnEntity->myCellsConn; - - for(; anTGeomIter != aTGeom.end(); anTGeomIter++){ - const EGeometrieElement& aGeom = anTGeomIter->first; - int aVTKGeomType = MEDGeomToVTK(aGeom); - ADDMSG(MYDEBUG,"LoadCellsOnEntity aGeom="<GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom); - TInt aNbElem = aPolygoneInfo->GetNbElem(); + const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size; + MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin(); + TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh; + + for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){ + const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first; + VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom); + INITMSG(MYDEBUG,"aMGeom = "<GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom); + TInt aNbElem = aPolygoneInfo->GetNbElem(); + if(aNbElem > 0){ + PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh()); - if(!isCellsLoaded){ - VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolygoneType = aCellsConn[aVTKGeomType]; - aConnForPolygoneType.resize(aNbElem); - - int aMNbNodes = aPolygoneInfo->GetConnDim(); - - vector aConnect(aMNbNodes); - vector aIndex = aPolygoneInfo->GetIndex(); + aSubMesh->Init(aPolygoneInfo); + aSubMesh->myNbCells = aNbElem; - for (int iElem = 0; iElem < aNbElem; iElem++) { - VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolygoneType[iElem]; - int aNbConn = aPolygoneInfo->GetNbConn(iElem); - - anArray.resize(aNbConn); - - aConnect = aPolygoneInfo->GetConnectivite(); - - for (int i=0;imySubMesh[aVTKGeomType]; - for(int iElem = 0; iElem < aNbElem; iElem++) - if(aPolygoneInfo->GetFamNum(iElem) == aFamily->myId) - aSubMeshOnCellType.insert(iElem); + TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect; + aCell2Connect.resize(aNbElem); + + for(TInt iElem = 0; iElem < aNbElem; iElem++) { + MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem); + TInt aNbConn = aPolygoneInfo->GetNbConn(iElem); + aSubMesh->myCellsSize += aNbConn; + TConnect& anArray = aCell2Connect[iElem]; + anArray.resize(aNbConn); + for(TInt iConn = 0; iConn < aNbConn; iConn++) + anArray[iConn] = aConnSlice[iConn] - 1; } - break; } - case ePOLYEDRE: - { - PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aGeom); - TInt aNbElem = aPolyedreInfo->GetNbElem(); - - int aMNbNodes = aPolyedreInfo->GetNbConn(); - vector aConnect(aMNbNodes); - aConnect = aPolyedreInfo->GetConnectivite(); + break; + } + case MED::ePOLYEDRE: { + MED::PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom); + TInt aNbElem = aPolyedreInfo->GetNbElem(); + + if(aNbElem > 0){ + PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh()); - if(!isCellsLoaded){ - VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolyedreType = aCellsConn[aVTKGeomType]; - aConnForPolyedreType.resize(aNbElem); - - vector aFacesIndex = aPolyedreInfo->GetFacesIndex(); - vector aIndex = aPolyedreInfo->GetIndex(); - - for (int iElem = 0; iElem < aNbElem; iElem++) { - set aArrayNew; - VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolyedreType[iElem]; - - int aInd1 = aIndex[iElem]-1; - int aInd2 = aIndex[iElem+1]-2; - - for (int i=aInd1;i<=aInd2;i++){ - for (int j=aFacesIndex[i]-1;j::iterator aIter = aArrayNew.begin(); - for (int i=0; aIter!=aArrayNew.end();aIter++, i++) - anArray[i] = (*aIter)-1; + aSubMesh->Init(aPolyedreInfo); + aSubMesh->myNbCells = aNbElem; + TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect; + aCell2Connect.resize(aNbElem); + + for(TInt iElem = 0; iElem < aNbElem; iElem++){ + MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem); + TConnect& anArray = aCell2Connect[iElem]; + typedef std::set TConnectSet; + TConnectSet aConnectSet; + TInt aNbFaces = aConnSliceArr.size(); + for(TInt iFace = 0; iFace < aNbFaces; iFace++){ + MED::TCConnSlice aConnSlice = aConnSliceArr[iFace]; + TInt aNbConn = aConnSlice.size(); + aSubMesh->myCellsSize += aNbConn; + for(TInt iConn = 0; iConn < aNbConn; iConn++){ + aConnectSet.insert(aConnSlice[iConn]); + } + } + + int aNbConn = aConnectSet.size(); + anArray.resize(aNbConn); + TConnectSet::iterator anIter = aConnectSet.begin(); + for(int i = 0; anIter != aConnectSet.end(); anIter++, i++){ + TInt anId = *anIter; + anArray[i] = anId - 1; } } - if(aFamily){ - VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType]; - for(int iElem = 0; iElem < aNbElem; iElem++) - if(aPolyedreInfo->GetFamNum(iElem) == aFamily->myId) - aSubMeshOnCellType.insert(iElem); - } - break; } - default: - { - int aVNbNodes = VTKGeom2NbNodes(aVTKGeomType); - - PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom); - TInt aNbElem = aCellInfo->GetNbElem(); + + break; + } + default: { + vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom); + INITMSG(MYDEBUG,"aVNbNodes = "<GetPCellInfo(aMeshInfo,aMEntity,aMGeom); + TInt aNbElem = aCellInfo->GetNbElem(); + + if(aNbElem > 0){ + PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh()); - if(!isCellsLoaded){ - VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aCellsConn[aVTKGeomType]; - aConnForCellType.resize(aNbElem); + aSubMesh->Init(aCellInfo); + aSubMesh->myNbCells = aNbElem; + aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1); + + TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect; + aCell2Connect.resize(aNbElem); + + TInt aMNbNodes = MEDGeom2NbNodes(aMGeom); + TVector aConnect(aMNbNodes); + + for(TInt iElem = 0; iElem < aNbElem; iElem++) { + MED::TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem); + TConnect& anArray = aCell2Connect[iElem]; + anArray.resize(aVNbNodes); - int aMNbNodes = MEDGeom2NbNodes(aGeom); - vector aConnect(aMNbNodes); - - for (int iElem = 0; iElem < aNbElem; iElem++) { - VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForCellType[iElem]; - anArray.resize(aVNbNodes); - - if(anIsNodeNum){ - for(int i = 0; i < aMNbNodes; i++){ - aConnect[i] = aNodeIdMap[aCellInfo->GetConn(iElem,i)-1]; - } - }else{ - for(int i = 0; i < aMNbNodes; i++){ - aConnect[i] = aCellInfo->GetConn(iElem,i)-1; - } + if(anIsNodeNum){ + for(TInt iConn = 0; iConn < aMNbNodes; iConn++){ + aConnect[iConn] = aNodeIdMap[aConnSlice[iConn] - 1]; } - - switch(aGeom){ - case eTETRA4: - case eTETRA10: - anArray[0] = aConnect[0]; - anArray[1] = aConnect[1]; - anArray[2] = aConnect[3]; - anArray[3] = aConnect[2]; - break; - case ePYRA5: - case ePYRA13: - anArray[0] = aConnect[0]; - anArray[1] = aConnect[3]; - anArray[2] = aConnect[2]; - anArray[3] = aConnect[1]; - anArray[4] = aConnect[4]; - break; - default: - for(int iNode = 0; iNode < aVNbNodes; iNode++) - anArray[iNode] = aConnect[iNode]; + }else{ + for(int iConn = 0; iConn < aMNbNodes; iConn++){ + aConnect[iConn] = aConnSlice[iConn] - 1; } + } + + switch(aMGeom){ +#if !(defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC) + case MED::eSEG3: + anArray[0] = aConnect[0]; + anArray[2] = aConnect[1]; + + anArray[1] = aConnect[2]; + break; +#endif +#if !(defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC) + case MED::eTRIA6: + anArray[0] = aConnect[0]; + anArray[2] = aConnect[1]; + anArray[4] = aConnect[2]; + + anArray[1] = aConnect[3]; + anArray[3] = aConnect[4]; + anArray[5] = aConnect[5]; + break; +#endif +#if !(defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC) + case MED::eQUAD8: + anArray[0] = aConnect[0]; + anArray[2] = aConnect[1]; + anArray[4] = aConnect[2]; + anArray[6] = aConnect[3]; + + anArray[1] = aConnect[4]; + anArray[3] = aConnect[5]; + anArray[5] = aConnect[6]; + anArray[7] = aConnect[7]; + break; +#endif +#if (defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC) + case MED::eTETRA10: + anArray[0] = aConnect[0]; + anArray[1] = aConnect[2]; + anArray[2] = aConnect[1]; + anArray[3] = aConnect[3]; + + anArray[4] = aConnect[6]; + anArray[5] = aConnect[5]; + anArray[6] = aConnect[4]; + + anArray[7] = aConnect[7]; + anArray[8] = aConnect[9]; + anArray[9] = aConnect[8]; + break; +#endif + case MED::eTETRA4: + anArray[0] = aConnect[0]; + anArray[1] = aConnect[2]; + anArray[2] = aConnect[1]; + anArray[3] = aConnect[3]; + break; +#if (defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC) + case MED::ePYRA13: + anArray[0] = aConnect[0]; + anArray[1] = aConnect[3]; + anArray[2] = aConnect[2]; + anArray[3] = aConnect[1]; + anArray[4] = aConnect[4]; + + anArray[5] = aConnect[5]; + anArray[6] = aConnect[8]; + anArray[7] = aConnect[7]; + anArray[8] = aConnect[6]; + + anArray[9] = aConnect[9]; + anArray[10] = aConnect[12]; + anArray[11] = aConnect[11]; + anArray[12] = aConnect[10]; + break; +#endif + case MED::ePYRA5: + anArray[0] = aConnect[0]; + anArray[1] = aConnect[3]; + anArray[2] = aConnect[2]; + anArray[3] = aConnect[1]; + anArray[4] = aConnect[4]; + break; + default: for(int iNode = 0; iNode < aVNbNodes; iNode++) - if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode]) - EXCEPTION(runtime_error,"ImportCells >> aNbPoints("<mySubMesh[aVTKGeomType]; - for(int iElem = 0; iElem < aNbElem; iElem++) - if(aCellInfo->GetFamNum(iElem) == aFamily->myId) - aSubMeshOnCellType.insert(iElem); + } + }} + } + + theMeshOnEntity->myIsDone = true; + + return 1; + +#ifndef _DEXCEPT_ + }catch(std::exception& exc){ + throw; + }catch(...){ + EXCEPTION(runtime_error,"Unknown exception !!!"); + } +#endif + + return 0; +} + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadCellsOnFamily(const MED::PWrapper& theMed, + const VISU::PMEDMesh theMesh, + const VISU::PMEDMeshOnEntity theMeshOnEntity, + const VISU::PMEDFamily theFamily) +{ + TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnFamily"); +#ifndef _DEXCEPT_ + try{ +#endif + const TEntity& aVEntity = theMeshOnEntity->myEntity; + const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity); + + INITMSG(MYDEBUG,"LoadCellsOnFamily - aVEntity = "<myIsDone) + return 0; + + TInt anId = theFamily->myId; + + const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo; + TGeom2SubMeshID& aGeom2SubMeshID = theFamily->myGeom2SubMeshID; + + const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size; + MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin(); + for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){ + const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first; + MED::PElemInfo anElemInfo; + switch(aMGeom){ + case MED::ePOLYGONE: { + anElemInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom); + break; + } + case MED::ePOLYEDRE: { + anElemInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom); + break; + } + default: { + anElemInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom); + break; + }} + if(anElemInfo){ + if(TInt aNbElem = anElemInfo->GetNbElem()){ + TSubMeshID aSubMeshID; + for(TInt iElem = 0; iElem < aNbElem; iElem++) + if(anElemInfo->GetFamNum(iElem) == anId) + aSubMeshID.push_back(iElem); + if(!aSubMeshID.empty()){ + VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom); + INITMSG(MYDEBUG,"aMGeom = "<myIsDone = true; + return 1; - }catch(std::runtime_error& exc){ - theMeshOnEntity->myCellsConn.clear(); + +#ifndef _DEXCEPT_ + }catch(std::exception& exc){ throw; }catch(...){ - theMeshOnEntity->myCellsConn.clear(); EXCEPTION(runtime_error,"Unknown exception !!!"); } +#endif + return 0; } +//--------------------------------------------------------------- +void +LoadProfile(const MED::PWrapper& theMed, + VISU::PMEDMesh theMesh, + MED::TTimeStampVal& theTimeStampVal, + VISU::TMEDValForTime& theValForTime, + VISU::TMEDMeshOnEntity& theMeshOnEntity) +{ + TTimerLog aTimerLog(MYDEBUG,"LoadProfile"); + INITMSG(MYDEBUG,"LoadProfile"<myIsDone) + return; + + const TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile; + const MED::TGeom2Profile& aGeom2Profile = theTimeStampVal.GetGeom2Profile(); + MED::TGeom2Profile::const_iterator anIter = aGeom2Profile.begin(); + for(; anIter != aGeom2Profile.end(); anIter++){ + MED::PProfileInfo aProfileInfo = anIter->second; + MED::EGeometrieElement aMGeom = anIter->first; + VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom); + + TGeom2SubProfile::const_iterator anIter2 = aGeom2SubProfile.find(aEGeom); + if(anIter2 != aGeom2SubProfile.end()){ + PMEDSubProfile aSubProfile = anIter2->second; + + MED::TElemNum& anElemNum = aProfileInfo->myElemNum; + if(!anElemNum.empty()){ + TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID; + TInt aSize = anElemNum.size(); + aSubMeshID.resize(aSize); + for(TInt anId = 0; anId < aSize; anId++) + aSubMeshID[anId] = anElemNum[anId] - 1; + } + + INITMSG(MYDEBUG, + "- aEGeom = "<myIsDone) + return; + + const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo; + MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo); + + TEntity aVEntity = theMeshOnEntity.myEntity; + MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity); + + const TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh; + const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampVal.GetTimeStampInfo(); + const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss(); + + TGeom2GaussSubMesh::const_iterator aSubMeshIter = aGeom2GaussSubMesh.begin(); + for(; aSubMeshIter != aGeom2GaussSubMesh.end(); aSubMeshIter++){ + PMEDGaussSubMesh aGaussSubMesh = aSubMeshIter->second; + VISU::EGeometry aEGeom = aSubMeshIter->first; + + if(aGaussSubMesh->myIsDone) + continue; + + PMEDSubProfile aSubProfile = aGaussSubMesh->mySubProfile; + const TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID; + MED::EGeometrieElement aMGeom = aSubProfile->myMGeom; + + MED::PPolygoneInfo aPolygoneInfo; + MED::PPolyedreInfo aPolyedreInfo; + MED::PCellInfo aCellInfo; + MED::PElemInfo anElemInfo; + + switch(aMGeom){ + case MED::ePOLYGONE: + aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo, + aMEntity, + aMGeom); + anElemInfo = aPolygoneInfo; + break; + case MED::ePOLYEDRE: + aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo, + aMEntity, + aMGeom); + anElemInfo = aPolyedreInfo; + break; + default: + aCellInfo = theMed->GetPCellInfo(aMeshInfo, + aMEntity, + aMGeom); + anElemInfo = aCellInfo; + } + aGaussSubMesh->myIsElemNum = anElemInfo->IsElemNum(); + aGaussSubMesh->myElemNum = anElemInfo->myElemNum; + + std::string aName; + MED::TGaussCoord aGaussCoord; + bool anIsGaussCoord3D = false; + + MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom); + if(aGaussIter != aGeom2Gauss.end()){ + PMEDGauss aGauss = aGaussSubMesh->myGauss; + MED::PGaussInfo aGaussInfo = aGauss->myGaussInfo; + if(aGaussInfo){ + aName = aGaussInfo->GetName(); + if(!aSubMeshID.empty()){ + const std::string& aProfileName = aSubProfile->myName; + MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed, + aProfileName); + if(aProfileInfo){ + const MED::TElemNum& anElemNum = aProfileInfo->myElemNum; + anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo, + aCellInfo, + aNodeInfo, + aGaussCoord, + anElemNum); + } + }else + anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo, + aCellInfo, + aNodeInfo, + aGaussCoord); + } + }else{ + if(!aSubMeshID.empty()){ + const std::string& aProfileName = aSubProfile->myName; + MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed, + aProfileName); + if(aProfileInfo){ + const MED::TElemNum& anElemNum = aProfileInfo->myElemNum; + switch(aMGeom){ + case MED::ePOLYGONE: + anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo, + aNodeInfo, + aGaussCoord, + anElemNum); + break; + case MED::ePOLYEDRE: + anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo, + aNodeInfo, + aGaussCoord, + anElemNum); + break; + default: + anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo, + aNodeInfo, + aGaussCoord, + anElemNum); + } + } + }else + switch(aMGeom){ + case MED::ePOLYGONE: + anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo, + aNodeInfo, + aGaussCoord); + break; + case MED::ePOLYEDRE: + anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo, + aNodeInfo, + aGaussCoord); + break; + default: + anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo, + aNodeInfo, + aGaussCoord); + } + } + + if(anIsGaussCoord3D){ + TPointCoords& aCoords = aGaussSubMesh->myPointCoords; + TInt aNbGauss = aGaussCoord.GetNbGauss(); + TInt aNbElem = aGaussCoord.GetNbElem(); + TInt aDim = aGaussCoord.GetDim(); + vtkIdType aNbCells = aNbElem*aNbGauss; + aCoords.Init(aNbCells,aDim); + for(TInt anElemId = 0, aNodeId = 0; anElemId < aNbElem; anElemId++){ + MED::TCoordSliceArr aCoordSliceArr = aGaussCoord.GetCoordSliceArr(anElemId); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++, aNodeId++){ + MED::TCoordSlice aCoordSlice = aCoordSliceArr[aGaussId]; + TCoordSlice aSlice = aCoords.GetCoordSlice(aNodeId); + for(TInt aDimId = 0; aDimId < aDim; aDimId++) + aSlice[aDimId] = aCoordSlice[aDimId]; + } + } + + aGaussSubMesh->myIsDone = true;; + + INITMSG(MYDEBUG, + "- aEGeom = "<myIsTrimmed = anIsTrimmed; + + theIsDone = true; + return 1; } + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadValForTimeOnMesh(const MED::PWrapper& theMed, + VISU::PMEDMesh theMesh, + VISU::PMEDMeshOnEntity theMeshOnEntity, + VISU::PMEDField theField, + VISU::PMEDValForTime theValForTime) +{ + PIDMapperFilter anIDMapperFilter = theValForTime->myIDMapperFilter; + return LoadValForTime(theMed, + theMesh, + theMeshOnEntity, + theField, + theValForTime, + false, + anIDMapperFilter->myIsVTKDone); +} + + +//--------------------------------------------------------------- +int +VISU_MedConvertor +::LoadValForTimeOnGaussPts(const MED::PWrapper& theMed, + VISU::PMEDMesh theMesh, + VISU::PMEDMeshOnEntity theMeshOnEntity, + VISU::PMEDField theField, + VISU::PMEDValForTime theValForTime) +{ + PGaussPtsIDFilter aGaussPtsIDFilter = theValForTime->myGaussPtsIDFilter; + return LoadValForTime(theMed, + theMesh, + theMeshOnEntity, + theField, + theValForTime, + true, + aGaussPtsIDFilter->myIsVTKDone); +} diff --git a/src/CONVERTOR/VISU_MedConvertor.hxx b/src/CONVERTOR/VISU_MedConvertor.hxx index c93ac341..abcb6ad7 100644 --- a/src/CONVERTOR/VISU_MedConvertor.hxx +++ b/src/CONVERTOR/VISU_MedConvertor.hxx @@ -12,73 +12,260 @@ #include "VISU_Convertor_impl.hxx" #include "MED_Common.hxx" +#include "MED_Structures.hxx" -namespace VISU{ +#include +#include - struct TMEDMesh: TMeshImpl{ +namespace VISU +{ + typedef TVector TNames; + + //--------------------------------------------------------------- + class TMEDNamedPointCoords: public virtual TNamedPointCoords + { + MED::PNodeInfo myNodeInfo; + TNames myPointNames; + public: + void + Init(vtkIdType theNbPoints, + vtkIdType theDim, + const MED::PNodeInfo& theNodeInfo); + + virtual + std::string + GetNodeName(vtkIdType theObjID) const; + }; + typedef SharedPtr PMEDNamedPointCoords; + + + //--------------------------------------------------------------- + struct TMEDMesh: virtual TMeshImpl + { MED::PMeshInfo myMeshInfo; MED::TEntityInfo myEntityInfo; }; - typedef shared_ptr PMEDMesh; + typedef SharedPtr PMEDMesh; + - struct TMEDMeshOnEntity: TMeshOnEntityImpl{ - MED::TGeom myGeom; + //--------------------------------------------------------------- + struct TMEDSubProfile: virtual TSubProfileImpl + { + MED::EGeometrieElement myMGeom; + + TMEDSubProfile(): + myIsElemNum(MED::eFAUX) + {} + + MED::EBooleen myIsElemNum; + MED::TElemNum myElemNum; + + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; }; - typedef shared_ptr PMEDMeshOnEntity; + typedef SharedPtr PMEDSubProfile; + + + //--------------------------------------------------------------- + struct TMEDProfile: virtual TProfileImpl + {}; + typedef SharedPtr PMEDProfile; + - struct TMEDFamily: TFamilyImpl{ + //--------------------------------------------------------------- + struct TMEDGauss: virtual TGaussImpl + { + MED::PGaussInfo myGaussInfo; + + //! To define a way to implement more detail comparision of the TGaussSubMesh instances + virtual + void + LessThan(const PGaussImpl& theGauss, + bool& theResult) const; }; - typedef shared_ptr PMEDFamily; - - struct TMEDGroup: TGroupImpl{ + typedef SharedPtr PMEDGauss; + + + //--------------------------------------------------------------- + struct TMEDGaussSubMesh: virtual TGaussSubMeshImpl + { + TMEDGaussSubMesh(): + myIsElemNum(MED::eFAUX) + {} + + MED::EBooleen myIsElemNum; + MED::TElemNum myElemNum; + + virtual + TGaussPointID + GetObjID(vtkIdType theID) const; }; - typedef shared_ptr PMEDGroup; + typedef SharedPtr PMEDGaussSubMesh; + + + //--------------------------------------------------------------- + struct TMEDGaussMesh: virtual TGaussMeshImpl + {}; + typedef SharedPtr PMEDGaussMesh; + + + //--------------------------------------------------------------- + struct TMEDSubMesh: virtual TSubMeshImpl + { + TMEDSubMesh(): + myIsElemNum(MED::eFAUX) + {} + + MED::EBooleen myIsElemNum; + MED::TElemNum myElemNum; + MED::PElemInfo myElemInfo; + + void + Init(const MED::PElemInfo& theElemInfo); - struct TMEDField: TFieldImpl{ + virtual + vtkIdType + GetElemObjID(vtkIdType theID) const; + + virtual + std::string + GetElemName(vtkIdType theObjID) const; }; - typedef shared_ptr PMEDField; + typedef SharedPtr PMEDSubMesh; + + + //--------------------------------------------------------------- + typedef std::map TFamilyID2CellsSize; - struct TMEDValForTime: TValForTimeImpl{ + struct TMEDMeshOnEntity: virtual TMeshOnEntityImpl + { + TFamilyID2CellsSize myFamilyID2CellsSize; + MED::TGeom2Size myGeom2Size; }; - typedef shared_ptr PMEDValForTime; + typedef SharedPtr PMEDMeshOnEntity; + + + //--------------------------------------------------------------- + struct TMEDFamily: virtual TFamilyImpl + {}; + typedef SharedPtr PMEDFamily; + + + //--------------------------------------------------------------- + struct TMEDGroup: virtual TGroupImpl + {}; + typedef SharedPtr PMEDGroup; + + + //--------------------------------------------------------------- + struct TMEDField: virtual TFieldImpl + {}; + typedef SharedPtr PMEDField; + + + //--------------------------------------------------------------- + struct TMEDValForTime: virtual TValForTimeImpl + {}; + typedef SharedPtr PMEDValForTime; } -class VISU_MedConvertor: public VISU_Convertor_impl{ +class VISU_MedConvertor: public VISU_Convertor_impl +{ VISU_MedConvertor(); VISU_MedConvertor(const VISU_MedConvertor&); + + bool myIsEntitiesDone; + bool myIsFieldsDone; + bool myIsGroupsDone; + bool myIsMinMaxDone; + public: - VISU_MedConvertor(const std::string& theFileName) ; - virtual VISU_Convertor* Build() ; + VISU_MedConvertor(const std::string& theFileName); + + virtual + VISU_Convertor* + BuildEntities(); + + virtual + VISU_Convertor* + BuildFields(); + + virtual + VISU_Convertor* + BuildMinMax(); + + virtual + VISU_Convertor* + BuildGroups(); + protected: QFileInfo myFileInfo; - virtual int LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity, - const std::string& theFamilyName = ""); + virtual + int + LoadMeshOnEntity(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity); + + virtual + int + LoadFamilyOnEntity(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFamilyImpl theFamily); - virtual int LoadMeshOnGroup(VISU::PMeshImpl theMesh, - const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet); + virtual + int + LoadMeshOnGroup(VISU::PMeshImpl theMesh, + const VISU::TFamilySet& theFamilySet); + + virtual + int + LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFieldImpl theField, + VISU::PValForTimeImpl theValForTime); + + virtual + int + LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFieldImpl theField, + VISU::PValForTimeImpl theValForTime); - virtual int LoadFieldOnMesh(VISU::PMeshImpl theMesh, - VISU::PMeshOnEntityImpl theMeshOnEntity, - VISU::PFieldImpl theField, - VISU::PValForTimeImpl theValForTime); + int + LoadPoints(const MED::PWrapper& theMed, + const VISU::PMEDMesh theMesh); + + int + LoadPointsOnFamily(const MED::PWrapper& theMed, + const VISU::PMEDMesh theMesh, + const VISU::PMEDFamily theFamily); + + int + LoadCellsOnEntity(const MED::PWrapper& theMed, + const VISU::PMEDMesh theMesh, + const VISU::PMEDMeshOnEntity theMeshOnEntity); - int LoadPoints(const MED::PWrapper& theMed, - VISU::PMEDMesh theMesh, - const std::string& theFamilyName = ""); - - int LoadCellsOnEntity(const MED::PWrapper& theMed, - VISU::PMEDMesh theMesh, - VISU::PMEDMeshOnEntity theMeshOnEntity, - const std::string& theFamilyName = ""); + int + LoadCellsOnFamily(const MED::PWrapper& theMed, + const VISU::PMEDMesh theMesh, + const VISU::PMEDMeshOnEntity theMeshOnEntity, + const VISU::PMEDFamily theFamily); - int LoadField(const MED::PWrapper& theMed, - VISU::PMEDMesh theMesh, - VISU::PMEDMeshOnEntity theMeshOnEntity, - VISU::PMEDField theField, - VISU::PMEDValForTime theValForTime); + int + LoadValForTimeOnMesh(const MED::PWrapper& theMed, + VISU::PMEDMesh theMesh, + VISU::PMEDMeshOnEntity theMeshOnEntity, + VISU::PMEDField theField, + VISU::PMEDValForTime theValForTime); + int + LoadValForTimeOnGaussPts(const MED::PWrapper& theMed, + VISU::PMEDMesh theMesh, + VISU::PMEDMeshOnEntity theMeshOnEntity, + VISU::PMEDField theField, + VISU::PMEDValForTime theValForTime); }; #endif diff --git a/src/CONVERTOR/VISU_MergeFilter.cxx b/src/CONVERTOR/VISU_MergeFilter.cxx new file mode 100644 index 00000000..aa48a46a --- /dev/null +++ b/src/CONVERTOR/VISU_MergeFilter.cxx @@ -0,0 +1,418 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "VISU_MergeFilter.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace VISU +{ + + class TFieldNode + { + public: + TFieldNode(const char* name, vtkDataSet* ptr=0) + { + int length = static_cast(strlen(name)); + if (length > 0) { + this->Name = new char[length+1]; + strcpy(this->Name, name); + } else { + this->Name = 0; + } + this->Ptr = ptr; + this->Next = 0; + } + ~TFieldNode() + { + delete[] this->Name; + } + + const char* GetName() + { + return Name; + } + vtkDataSet* Ptr; + TFieldNode* Next; + private: + TFieldNode(const TFieldNode&) {} + void operator=(const TFieldNode&) {} + char* Name; + }; + + class TFieldList + { + public: + TFieldList() + { + this->First = 0; + this->Last = 0; + } + ~TFieldList() + { + TFieldNode* node = this->First; + TFieldNode* next; + while(node){ + next = node->Next; + delete node; + node = next; + } + } + + + void Add(const char* name, vtkDataSet* ptr) + { + TFieldNode* newNode = new TFieldNode(name, ptr); + if (!this->First) { + this->First = newNode; + this->Last = newNode; + } else { + this->Last->Next = newNode; + this->Last = newNode; + } + } + + friend class TFieldListIterator; + + private: + TFieldNode* First; + TFieldNode* Last; + }; + + class TFieldListIterator + { + public: + TFieldListIterator(TFieldList* list) + { + this->List = list; + this->Position = 0; + } + void Begin() + { + this->Position = this->List->First; + } + void Next() + { + if (this->Position) { + this->Position = this->Position->Next; + } + } + int End() + { + return this->Position ? 0 : 1; + } + TFieldNode* Get() + { + return this->Position; + } + + private: + TFieldNode* Position; + TFieldList* List; + }; + +} + +//------------------------------------------------------------------------------ +vtkStandardNewMacro(VISU_MergeFilter); + +//------------------------------------------------------------------------------ + +// Create object with no input or output. +VISU_MergeFilter::VISU_MergeFilter() +{ + this->FieldList = new VISU::TFieldList; +} + +VISU_MergeFilter::~VISU_MergeFilter() +{ + delete this->FieldList; +} + +void VISU_MergeFilter::SetScalars(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(1, input); +} +vtkDataSet *VISU_MergeFilter::GetScalars() +{ + if (this->NumberOfInputs < 2) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[1]); +} + +void VISU_MergeFilter::SetVectors(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(2, input); +} +vtkDataSet *VISU_MergeFilter::GetVectors() +{ + if (this->NumberOfInputs < 3) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[2]); +} + +void VISU_MergeFilter::SetNormals(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(3, input); +} +vtkDataSet *VISU_MergeFilter::GetNormals() +{ + if (this->NumberOfInputs < 4) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[3]); +} + +void VISU_MergeFilter::SetTCoords(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(4, input); +} +vtkDataSet *VISU_MergeFilter::GetTCoords() +{ + if (this->NumberOfInputs < 5) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[4]); +} + +void VISU_MergeFilter::SetTensors(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(5, input); +} +vtkDataSet *VISU_MergeFilter::GetTensors() +{ + if (this->NumberOfInputs < 6) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[5]); +} + +void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input) +{ + this->FieldList->Add(name, input); +} + +void VISU_MergeFilter::Execute() +{ + vtkIdType numPts, numScalars=0, numVectors=0, numNormals=0, numTCoords=0; + vtkIdType numTensors=0; + vtkIdType numCells, numCellScalars=0, numCellVectors=0, numCellNormals=0; + vtkIdType numCellTCoords=0, numCellTensors=0; + vtkPointData *pd; + vtkDataArray *scalars = NULL; + vtkDataArray *vectors = NULL; + vtkDataArray *normals = NULL; + vtkDataArray *tcoords = NULL; + vtkDataArray *tensors = NULL; + vtkCellData *cd; + vtkDataArray *cellScalars = NULL; + vtkDataArray *cellVectors = NULL; + vtkDataArray *cellNormals = NULL; + vtkDataArray *cellTCoords = NULL; + vtkDataArray *cellTensors = NULL; + vtkDataSet *output = this->GetOutput(); + vtkPointData *outputPD = output->GetPointData(); + vtkCellData *outputCD = output->GetCellData(); + + vtkDebugMacro(<<"Merging data!"); + + // geometry needs to be copied + output->CopyStructure(this->GetInput()); + if ( (numPts = this->GetInput()->GetNumberOfPoints()) < 1 ) + { + vtkWarningMacro(<<"Nothing to merge!"); + } + numCells = this->GetInput()->GetNumberOfCells(); + + if ( this->GetScalars() ) + { + pd = this->GetScalars()->GetPointData(); + scalars = pd->GetScalars(); + if ( scalars != NULL ) + { + numScalars = scalars->GetNumberOfTuples(); + } + cd = this->GetScalars()->GetCellData(); + cellScalars = cd->GetScalars(); + if ( cellScalars != NULL ) + { + numCellScalars = cellScalars->GetNumberOfTuples(); + } + } + + if ( this->GetVectors() ) + { + pd = this->GetVectors()->GetPointData(); + vectors = pd->GetVectors(); + if ( vectors != NULL ) + { + numVectors= vectors->GetNumberOfTuples(); + } + cd = this->GetVectors()->GetCellData(); + cellVectors = cd->GetVectors(); + if ( cellVectors != NULL ) + { + numCellVectors = cellVectors->GetNumberOfTuples(); + } + } + + if ( this->GetNormals() ) + { + pd = this->GetNormals()->GetPointData(); + normals = pd->GetNormals(); + if ( normals != NULL ) + { + numNormals= normals->GetNumberOfTuples(); + } + cd = this->GetNormals()->GetCellData(); + cellNormals = cd->GetNormals(); + if ( cellNormals != NULL ) + { + numCellNormals = cellNormals->GetNumberOfTuples(); + } + } + + if ( this->GetTCoords() ) + { + pd = this->GetTCoords()->GetPointData(); + tcoords = pd->GetTCoords(); + if ( tcoords != NULL ) + { + numTCoords= tcoords->GetNumberOfTuples(); + } + cd = this->GetTCoords()->GetCellData(); + cellTCoords = cd->GetTCoords(); + if ( cellTCoords != NULL ) + { + numCellTCoords = cellTCoords->GetNumberOfTuples(); + } + } + + if ( this->GetTensors() ) + { + pd = this->GetTensors()->GetPointData(); + tensors = pd->GetTensors(); + if ( tensors != NULL ) + { + numTensors = tensors->GetNumberOfTuples(); + } + cd = this->GetTensors()->GetCellData(); + cellTensors = cd->GetTensors(); + if ( cellTensors != NULL ) + { + numCellTensors = cellTensors->GetNumberOfTuples(); + } + } + + // merge data only if it is consistent + if ( numPts == numScalars ) + { + outputPD->SetScalars(scalars); + } + if ( numCells == numCellScalars ) + { + outputCD->SetScalars(cellScalars); + } + + if ( numPts == numVectors ) + { + outputPD->SetVectors(vectors); + } + if ( numCells == numCellVectors ) + { + outputCD->SetVectors(cellVectors); + } + + if ( numPts == numNormals ) + { + outputPD->SetNormals(normals); + } + if ( numCells == numCellNormals ) + { + outputCD->SetNormals(cellNormals); + } + + if ( numPts == numTCoords ) + { + outputPD->SetTCoords(tcoords); + } + if ( numCells == numCellTCoords ) + { + outputCD->SetTCoords(cellTCoords); + } + + if ( numPts == numTensors ) + { + outputPD->SetTensors(tensors); + } + if ( numCells == numCellTensors ) + { + outputCD->SetTensors(cellTensors); + } + + VISU::TFieldListIterator it(this->FieldList); + vtkDataArray* da; + const char* name; + vtkIdType num; + for(it.Begin(); !it.End() ; it.Next()) + { + pd = it.Get()->Ptr->GetPointData(); + cd = it.Get()->Ptr->GetCellData(); + name = it.Get()->GetName(); + if ( (da=pd->GetArray(name)) ) + { + num = da->GetNumberOfTuples(); + if (num == numPts) + { + outputPD->AddArray(da); + } + } + if ( (da=cd->GetArray(name)) ) + { + num = da->GetNumberOfTuples(); + if (num == numCells) // To fix a VTK bug + { + outputCD->AddArray(da); + } + } + } +} diff --git a/src/CONVERTOR/VISU_MergeFilter.hxx b/src/CONVERTOR/VISU_MergeFilter.hxx new file mode 100644 index 00000000..1d15cd3b --- /dev/null +++ b/src/CONVERTOR/VISU_MergeFilter.hxx @@ -0,0 +1,99 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef VISU_MergeFilter_H +#define VISU_MergeFilter_H + +#include + +namespace VISU +{ + class TFieldList; +} + +// Following class was redefined in order to fix VTK bug +// (see code for more details) + +class VISU_MergeFilter : public vtkDataSetToDataSetFilter +{ +public: + static VISU_MergeFilter *New(); + vtkTypeMacro(VISU_MergeFilter,vtkDataSetToDataSetFilter); + + // Description: + // Specify object from which to extract geometry information. + void SetGeometry(vtkDataSet *input) {this->SetInput(input);}; + vtkDataSet *GetGeometry() {return this->GetInput();}; + + // Description: + // Specify object from which to extract scalar information. + void SetScalars(vtkDataSet *); + vtkDataSet *GetScalars(); + + // Description: + // Set / get the object from which to extract vector information. + void SetVectors(vtkDataSet *); + vtkDataSet *GetVectors(); + + // Description: + // Set / get the object from which to extract normal information. + void SetNormals(vtkDataSet *); + vtkDataSet *GetNormals(); + + // Description: + // Set / get the object from which to extract texture coordinates + // information. + void SetTCoords(vtkDataSet *); + vtkDataSet *GetTCoords(); + + // Description: + // Set / get the object from which to extract tensor data. + void SetTensors(vtkDataSet *); + vtkDataSet *GetTensors(); + + // Description: + // Set the object from which to extract a field and the name + // of the field + void AddField(const char* name, vtkDataSet* input); + +protected: + VISU_MergeFilter(); + ~VISU_MergeFilter(); + + // Usual data generation method + void Execute(); + + VISU::TFieldList* FieldList; +private: + VISU_MergeFilter(const VISU_MergeFilter&); // Not implemented. + void operator=(const VISU_MergeFilter&); // Not implemented. +}; + +#endif + + diff --git a/src/ENGINE/VISU_Engine_i.cc b/src/ENGINE/VISU_Engine_i.cc index 63ccfd1f..45dc68bc 100644 --- a/src/ENGINE/VISU_Engine_i.cc +++ b/src/ENGINE/VISU_Engine_i.cc @@ -162,6 +162,11 @@ namespace VISU{ } + Result_ptr VISU_Gen_i::CreateResult(const char* theFileName){ + return myVisuGen->CreateResult(theFileName); + } + + Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){ return myVisuGen->CopyAndImportFile(theFileName); } @@ -212,6 +217,16 @@ namespace VISU{ } + GaussPoints_ptr VISU_Gen_i::GaussPointsOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return myVisuGen->GaussPointsOnField(theResult,theMeshName,theEntity,theFieldName,theIteration); + } + + DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, diff --git a/src/ENGINE/VISU_Engine_i.hh b/src/ENGINE/VISU_Engine_i.hh index 841c0198..d9c665ac 100644 --- a/src/ENGINE/VISU_Engine_i.hh +++ b/src/ENGINE/VISU_Engine_i.hh @@ -57,6 +57,7 @@ namespace VISU{ //Create Result virtual Result_ptr ImportFile(const char* theFileName); + virtual Result_ptr CreateResult(const char* theFileName); virtual Result_ptr CopyAndImportFile(const char* theFileName); virtual Result_ptr ImportMed(SALOMEDS::SObject_ptr theMedSObject); virtual Result_ptr ImportMedField(SALOME_MED::FIELD_ptr theField); @@ -69,6 +70,8 @@ namespace VISU{ virtual ScalarMap_ptr ScalarMapOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, const char* theFieldName, CORBA::Double theIteration); + virtual GaussPoints_ptr GaussPointsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); virtual DeformedShape_ptr DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, const char* theFieldName, CORBA::Double theIteration); virtual Vectors_ptr VectorsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, diff --git a/src/Makefile.in b/src/Makefile.in index b8b86f6e..7e207ca1 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -32,6 +32,6 @@ VPATH=.:@srcdir@ @COMMENCE@ -SUBDIRS = CONVERTOR PIPELINE OBJECT ENGINE GUITOOLS VISU_I VISUGUI VISU_SWIG +SUBDIRS = CONVERTOR PIPELINE OBJECT VVTK GUITOOLS VISU_I VISUGUI VISU_SWIG ENGINE @MODULE@ diff --git a/src/OBJECT/Makefile.in b/src/OBJECT/Makefile.in index 6c2ba23c..e73a5816 100644 --- a/src/OBJECT/Makefile.in +++ b/src/OBJECT/Makefile.in @@ -32,12 +32,28 @@ VPATH=.:@srcdir@:@top_srcdir@/idl @COMMENCE@ -EXPORT_HEADERS = VISU_Actor.h VISU_MeshAct.h VISU_ScalarMapAct.h VISU_VectorsAct.h +EXPORT_HEADERS = \ + VISU_ActorFactory.h \ + VISU_GaussPtsSettings.h \ + VISU_GaussPtsActorFactory.h \ + VISU_Event.h \ + VISU_Actor.h \ + VISU_MeshAct.h \ + VISU_ScalarMapAct.h \ + VISU_GaussPtsAct.h \ + VISU_VectorsAct.h # Libraries targets LIB = libVisuObject.la -LIB_SRC = VISU_Actor.cxx VISU_MeshAct.cxx VISU_ScalarMapAct.cxx VISU_VectorsAct.cxx +LIB_SRC = \ + VISU_Actor.cxx \ + VISU_MeshAct.cxx \ + VISU_ScalarMapAct.cxx \ + VISU_GaussPtsDeviceActor.cxx \ + VISU_GaussPtsSettings.cxx \ + VISU_GaussPtsAct.cxx \ + VISU_VectorsAct.cxx LIB_CLIENT_IDL = @@ -45,9 +61,24 @@ LIB_CLIENT_IDL = BIN = BIN_SRC = -CPPFLAGS+= $(OCC_INCLUDES) $(VTK_INCLUDES) $(QT_INCLUDES) \ - -I${KERNEL_ROOT_DIR}/include/salome -I${GUI_ROOT_DIR}/include/salome -LDFLAGS+= $(VTK_LIBS) -lSalomeObject -lVisuPipeLine \ - -L${KERNEL_ROOT_DIR}/lib/salome -L${GUI_ROOT_DIR}/lib/salome +CPPFLAGS+= \ + $(OCC_INCLUDES) \ + $(VTK_INCLUDES) \ + $(BOOST_CPPFLAGS) \ + -I${MED_ROOT_DIR}/include/salome \ + -I${GUI_ROOT_DIR}/include/salome \ + -I${KERNEL_ROOT_DIR}/include/salome + +LDFLAGS+= \ + $(VTK_LIBS) \ + $(BOOST_LIBS) \ + -L${GUI_ROOT_DIR}/lib/salome \ + -L${KERNEL_ROOT_DIR}/lib/salome + +LIBS+= \ + -lboost_signals-mt \ + -lSalomeObject \ + -lVisuPipeLine \ + -lSVTK @CONCLUDE@ diff --git a/src/OBJECT/VISU_Actor.cxx b/src/OBJECT/VISU_Actor.cxx index e38b8cd3..42591ab3 100644 --- a/src/OBJECT/VISU_Actor.cxx +++ b/src/OBJECT/VISU_Actor.cxx @@ -21,8 +21,8 @@ // // // -// File : VISU_Actor.cxx -// Author : Laurent CORNABE with help of Nicolas REJNERI +// File : +// Author : // Module : VISU // $Header$ @@ -33,10 +33,20 @@ #include "VTKViewer_PassThroughFilter.h" #include +#include // VTK Includes #include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -48,6 +58,8 @@ #include #include +#include + #include "utilities.h" using namespace std; @@ -60,103 +72,199 @@ static int MYDEBUG = 1; static int MYDEBUG = 0; #endif -//======================================================================= +//#define ENABLE_ANNOTATION +//---------------------------------------------------------------------------- vtkStandardNewMacro(VISU_Actor); -VISU_Actor::VISU_Actor(){ - SetDebug(MYVTKDEBUG); - myParent = this; - myPipeLine = NULL; - myPrs3d = NULL; +//---------------------------------------------------------------------------- +VISU_Actor +::VISU_Actor(): + myIsVTKMapping(false), + myPrs3d(NULL), + myActorFactory(NULL), + myMapper(vtkDataSetMapper::New()), + myIsShrunk(false), + myIsShrinkable(false), + myShrinkFilter(VTKViewer_ShrinkFilter::New()), + myAnnotationMapper(vtkTextMapper::New()), + myAnnotationActor(vtkTextActor::New()) +{ + if(MYDEBUG) MESSAGE("VISU_Actor::VISU_Actor - this = "<Delete(); + myShrinkFilter->Delete(); myStoreMapping = true; - myIsShrunk = false; - myIsShrinkable = false; - myShrinkFilter = VTKViewer_ShrinkFilter::New(); myShrinkFilter->SetStoreMapping(true); - SetShrinkFactor(); - - myMapper = vtkDataSetMapper::New(); - myIO = NULL; - myName = ""; + myAnnotationMapper->Delete(); + myAnnotationActor->SetMapper(myAnnotationMapper.GetPointer()); + + myAnnotationActor->Delete(); + myAnnotationActor->SetVisibility(0); } -VISU_Actor::~VISU_Actor(){ - SALOME_Actor::SetProperty(NULL); +//---------------------------------------------------------------------------- +void +VISU_Actor +::ShallowCopy(vtkProp *prop) +{ + VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop); + if(anActor != NULL){ + setName(anActor->getName()); + if(anActor->hasIO()) setIO(anActor->getIO()); + } + Superclass::ShallowCopy(prop); +} - myMapper->RemoveAllInputs(); - myMapper->Delete(); +void +VISU_Actor +::ShallowCopyPL(VISU_PipeLine* thePipeLine) +{ + myPipeLine->ShallowCopy(thePipeLine); - if(myPipeLine) - myPipeLine->UnRegister(this); + vtkDataSet* aDatsSet = myMapper->GetInput(); + GetMapper()->ShallowCopy(thePipeLine->GetMapper()); - myShrinkFilter->UnRegisterAllOutputs(); - myShrinkFilter->Delete(); + // To restore mapper input from pipeline + myMapper->SetInput(aDatsSet); } -void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){ - SALOME_Actor::setIO(theIO); +//---------------------------------------------------------------------------- +VISU_Actor +::~VISU_Actor() +{ + if(MYDEBUG) MESSAGE("~VISU_Actor() - this = "<getName(); } -void VISU_Actor::SetPrs3d(VISU::Prs3d_i* thePrs3d){ +//---------------------------------------------------------------------------- +void +VISU_Actor +::SetPrs3d(VISU::Prs3d_i* thePrs3d) +{ myPrs3d = thePrs3d; } -void VISU_Actor::SetPipeLine(VISU_PipeLine* thePipeLine) { - if (myPipeLine != thePipeLine){ - if (myPipeLine != NULL) myPipeLine->UnRegister(this); - myPipeLine = thePipeLine; - if (myPipeLine != NULL) myPipeLine->Register(this); - this->Modified(); - vtkMapper *aMapper = myPipeLine->GetMapper(); - vtkDataSet *aDataSet = aMapper->GetInput(); - - //This code has been moved into VISU::Prs3d_i::UpdateActor() for bug 9808 - //if(!aDataSet) - // throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no input data !!!"); - //aDataSet->Update(); - //static float eps = VTK_LARGE_FLOAT * 0.1 ; - //if(aDataSet->GetLength() > eps) - // throw std::runtime_error("VISU_Actor::SetPipeLine >> Diagonal of the actor is too large !!!"); - //if(!aDataSet->GetNumberOfCells()) - // throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no visible elements"); - - //Bug SAL4221: Mesh with less than 10 cells : shrink mode disable - //SetShrinkable(aDataSet->GetNumberOfCells() > 10); - SetShrinkable(thePipeLine->IsShrinkable()); - //Now, we use vtkShrinkPolyData (not vtkShrinkFilter), - //and the class there is no such limitation. - - myMapper->SetInput(aDataSet); - SetMapper(myMapper); - } +VISU::Prs3d_i* +VISU_Actor +::GetPrs3d() +{ + return myPrs3d; } -void VISU_Actor::SetParent(VISU_Actor* theParent){ - myParent = theParent; +//---------------------------------------------------------------------------- +VISU::TActorFactory* +VISU_Actor +::GetFactory() +{ + return myActorFactory; } -void VISU_Actor::SetRepresentation(int theMode) { - SALOME_Actor::SetRepresentation(theMode); - if(myRepresentation == VTK_POINTS) - UnShrink(); +void +VISU_Actor +::SetFactory(VISU::TActorFactory* theActorFactory) +{ + using namespace VISU; + + if(myActorFactory == theActorFactory) + return; + + if(theActorFactory) + myDestroySignal.connect(boost::bind(&TActorFactory::RemoveActor, + theActorFactory, + _1)); + + myActorFactory = theActorFactory; } -void VISU_Actor::SetOpacity(float theValue){ - GetProperty()->SetOpacity(theValue); +//---------------------------------------------------------------------------- +void +VISU_Actor +::UpdateFromFactory() +{ + myActorFactory->UpdateActor(this); + Update(); } -float VISU_Actor::GetOpacity(){ - return GetProperty()->GetOpacity(); +void +VISU_Actor +::RemoveFromRender() +{ + RemoveFromRender(GetRenderer()); +} + +//---------------------------------------------------------------------------- +void +VISU_Actor +::SetMapperInput(vtkDataSet* theDataSet) +{ + myMapper->SetInput(theDataSet); + SetMapper(myMapper.GetPointer()); +} + +void +VISU_Actor +::SetPipeLine(VISU_PipeLine* thePipeLine) +{ + myPipeLine = thePipeLine; + if(thePipeLine){ + if(vtkMapper *aMapper = myPipeLine->GetMapper()){ + if(vtkDataSet *aDataSet = aMapper->GetInput()){ + SetShrinkable(thePipeLine->IsShrinkable()); + + SetMapperInput(aDataSet); + } + } + } + this->Modified(); +} + +VISU_PipeLine* +VISU_Actor +::GetPipeLine() +{ + return myPipeLine.GetPointer(); +} + +VISU_PipeLine* +VISU_Actor +::GetCurrentPL() +{ + return GetPipeLine(); +} + + +//---------------------------------------------------------------------------- +void +VISU_Actor +::SetRepresentation(int theMode) +{ + Superclass::SetRepresentation(theMode); + if(myRepresentation == VTK_POINTS) + UnShrink(); } -void VISU_Actor::SetShrink(){ - if(!myIsShrinkable) return; +//---------------------------------------------------------------------------- +void +VISU_Actor +::SetShrink() +{ + if(!myIsShrinkable) + return; if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){ myShrinkFilter->SetInput(aDataSet); myPassFilter[1]->SetInput(myShrinkFilter->GetOutput()); @@ -164,8 +272,12 @@ void VISU_Actor::SetShrink(){ } } -void VISU_Actor::UnShrink(){ - if(!myIsShrunk) return; +void +VISU_Actor +::UnShrink() +{ + if(!myIsShrunk) + return; if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){ myPassFilter[1]->SetInput(aDataSet); myPassFilter[1]->Modified(); @@ -174,54 +286,298 @@ void VISU_Actor::UnShrink(){ } } -void VISU_Actor::SetShrinkable(bool theIsShrinkable){ +bool +VISU_Actor +::IsShrunk() +{ + return myIsShrunk; +} + +void +VISU_Actor +::SetShrinkable(bool theIsShrinkable) +{ myIsShrinkable = theIsShrinkable; } -void VISU_Actor::SetShrinkFactor(float theValue){ +bool +VISU_Actor +::IsShrunkable() +{ + return myIsShrinkable; +} + +void +VISU_Actor +::SetShrinkFactor(float theValue) +{ myShrinkFilter->SetShrinkFactor(theValue); Modified(); } -float VISU_Actor::GetShrinkFactor(){ +float +VISU_Actor +::GetShrinkFactor() +{ return myShrinkFilter->GetShrinkFactor(); } //---------------------------------------------------------------------------- -void VISU_Actor::SetVisibility(int theMode){ - SALOME_Actor::SetVisibility(theMode); +void +VISU_Actor +::SetOpacity(float theValue) +{ + GetProperty()->SetOpacity(theValue); } -int VISU_Actor::GetVisibility(){ - return SALOME_Actor::GetVisibility(); +float +VISU_Actor +::GetOpacity() +{ + return GetProperty()->GetOpacity(); } -void VISU_Actor::SetLineWidth(float theLineWidth){ +void +VISU_Actor +::SetLineWidth(float theLineWidth) +{ GetProperty()->SetLineWidth(theLineWidth); } -float VISU_Actor::GetLineWidth(){ +float +VISU_Actor +::GetLineWidth() +{ return GetProperty()->GetLineWidth(); } +//================================================================== +// function: AddToRender +// purpose : +//================================================================== +void +VISU_Actor +::AddToRender(vtkRenderer* theRenderer) +{ + Superclass::AddToRender(theRenderer); + theRenderer->AddActor(myAnnotationActor.GetPointer()); +} + +//================================================================== +// function: RemoveFromRender +// purpose : +//================================================================== +void +VISU_Actor +::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(myAnnotationActor.GetPointer()); + Superclass::RemoveFromRender(theRenderer); + myDestroySignal(this); +} + //---------------------------------------------------------------------------- -void VISU_Actor::ShallowCopy(vtkProp *prop){ - VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop); - if(anActor != NULL){ - setName(anActor->getName()); - if(anActor->hasIO()) setIO(anActor->getIO()); - } - SALOME_Actor::ShallowCopy(prop); +void +VISU_Actor +::SetVTKMapping(bool theIsVTKMapping) +{ + myIsVTKMapping = theIsVTKMapping; +} + +bool +VISU_Actor +::IsVTKMapping() const +{ + return myIsVTKMapping; } //---------------------------------------------------------------------------- -int VISU_Actor::GetNodeObjId(int theVtkID){ - if ( myIsShrunk ) - return myShrinkFilter->GetNodeObjId(theVtkID); - return theVtkID; +vtkDataSet* +VISU_Actor +::GetInput() +{ + if(myIsVTKMapping) + return Superclass::GetInput(); + + return GetCurrentPL()->GetOutput(); } -int VISU_Actor::GetElemObjId(int theVtkID){ - return myGeomFilter->GetElemObjId(theVtkID); +//---------------------------------------------------------------------------- +vtkIdType +VISU_Actor +::GetNodeObjId(vtkIdType theID) +{ + if(myIsVTKMapping) + return Superclass::GetNodeObjId(theID); + + vtkIdType anID = myGeomFilter->GetNodeObjId(theID); + + if(myIsShrunk) + anID = myShrinkFilter->GetNodeObjId(anID); + + return GetCurrentPL()->GetNodeObjID(anID); +} + +vtkIdType +VISU_Actor +::GetNodeVTKID(vtkIdType theID) +{ + if(myIsVTKMapping) + return theID; + + return GetCurrentPL()->GetNodeVTKID(theID); +} + +float* +VISU_Actor +::GetNodeCoord(int theObjID) +{ + if(myIsVTKMapping) + return Superclass::GetNodeCoord(theObjID); + + return GetCurrentPL()->GetNodeCoord(theObjID); +} + + +//---------------------------------------------------------------------------- +vtkIdType +VISU_Actor +::GetElemObjId(vtkIdType theID) +{ + if(myIsVTKMapping) + return Superclass::GetElemObjId(theID); + + vtkIdType anID = myGeomFilter->GetElemObjId(theID); + + if(myIsShrunk) + anID = myShrinkFilter->GetElemObjId(anID); + + return GetCurrentPL()->GetElemObjID(anID); +} + +vtkIdType +VISU_Actor +::GetElemVTKID(vtkIdType theID) +{ + if(myIsVTKMapping) + return theID; + + return GetCurrentPL()->GetElemVTKID(theID); +} + +vtkCell* +VISU_Actor +::GetElemCell(vtkIdType theObjID) +{ + if(myIsVTKMapping) + return Superclass::GetElemCell(theObjID); + + return GetCurrentPL()->GetElemCell(theObjID); +} + + +//---------------------------------------------------------------------------- +bool +VISU_Actor +::PreHighlight(vtkInteractorStyle* theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight) +{ + bool aRet = Superclass::PreHighlight(theInteractorStyle, + theSelectionEvent, + theIsHighlight); +#ifndef ENABLE_ANNOTATION + return aRet; +#endif + // + myAnnotationActor->SetVisibility(0); + if(theIsHighlight){ + switch(mySelectionMode){ + case CellSelection:{ + vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer(); + myCellPicker->Pick(theSelectionEvent->myX, + theSelectionEvent->myY, + 0.0, + aRenderer); + + if(myCellPicker->GetActor() != this) + return false; + + vtkIdType aVTKId = myCellPicker->GetCellId(); + if(aVTKId >= 0 && mySelector->IsValid(this,aVTKId,true) && hasIO()){ + vtkIdType anObjId = GetElemObjId(aVTKId); + if(vtkCell* aCell = GetElemCell(anObjId)){ + vtkPoints* aPts = aCell->GetPoints(); + if(int aNbPts = aCell->GetNumberOfPoints()){ + float aCoord[3] = {0.0, 0.0, 0.0}; + for(int i = 0; i < aNbPts; i++){ + float *aPntCoord = aPts->GetPoint(i); + aCoord[0] += aPntCoord[0]; + aCoord[1] += aPntCoord[1]; + aCoord[2] += aPntCoord[2]; + } + // Display coordinates + float aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0}; + aRenderer->SetWorldPoint(aWorldCoord); + aRenderer->WorldToDisplay(); + float aSelectionPoint[3]; + aRenderer->GetDisplayPoint(aSelectionPoint); + myAnnotationActor->SetPosition(aSelectionPoint); + // + // To prepare the annotation text + std::ostringstream aStr; + aStr<<"Cell ID: "<< anObjId; + std::string aString = aStr.str(); + myAnnotationMapper->SetInput(aString.c_str()); + + myAnnotationActor->SetVisibility(1); + return true; + } + } + } + break; + } + case NodeSelection:{ + vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer(); + myPointPicker->Pick(theSelectionEvent->myX, + theSelectionEvent->myY, + 0.0, + aRenderer); + + if(myPointPicker->GetActor() != this) + return false; + + vtkIdType aVtkId = myPointPicker->GetPointId(); + if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){ + vtkIdType anObjId = GetNodeObjId( aVtkId ); + if(float* aCoord = GetNodeCoord(anObjId)){ + // Display coordinates + float aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0}; + aRenderer->SetWorldPoint(aWorldCoord); + aRenderer->WorldToDisplay(); + float aSelectionPoint[3]; + aRenderer->GetDisplayPoint(aSelectionPoint); + myAnnotationActor->SetPosition(aSelectionPoint); + // + // To prepare the annotation text + std::ostringstream aStr; + aStr<<"Node ID: "<< anObjId; + std::string aString = aStr.str(); + myAnnotationMapper->SetInput(aString.c_str()); + + myAnnotationActor->SetVisibility(1); + return true; + } + } + break; + } + case EdgeOfCellSelection: + break; + default: + break; + } + } + + return aRet; } diff --git a/src/OBJECT/VISU_Actor.h b/src/OBJECT/VISU_Actor.h index 01cf5c67..ffeab72e 100644 --- a/src/OBJECT/VISU_Actor.h +++ b/src/OBJECT/VISU_Actor.h @@ -21,8 +21,8 @@ // // // -// File : VISU_Actor.h -// Author : Laurent CORNABE with the help of Nicolas REJNERI +// File : +// Author : // Module : VISU // $Header$ @@ -30,78 +30,225 @@ #define VISU_ACTOR_H #include "SALOME_Actor.h" +#include "VISU_ActorFactory.h" #include +#include +#include +#include class vtkProp; class vtkProperty; class vtkDataSetMapper; - +class vtkTextMapper; +class vtkTextActor; +class vtkInteractorStyle; class VTKViewer_ShrinkFilter; class VISU_PipeLine; -namespace VISU { - class Prs3d_i; -} - #ifdef _WIN_32 #define VTKOCC_EXPORT __declspec (dllexport) #else #define VTKOCC_EXPORT VTK_EXPORT #endif -class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor { +namespace VISU +{ + class Prs3d_i; +} + +//---------------------------------------------------------------------------- +class VTKOCC_EXPORT VISU_Actor : + public SALOME_Actor, + public boost::bsignals::trackable +{ public: vtkTypeMacro(VISU_Actor,SALOME_Actor); - void ShallowCopy(vtkProp *prop); - static VISU_Actor* New(); - virtual ~VISU_Actor(); - - virtual void setIO(const Handle(SALOME_InteractiveObject)& theIO); - - VISU::Prs3d_i* GetPrs3d(){ return myPrs3d;} - virtual void SetPrs3d(VISU::Prs3d_i* thePrs3d); - - virtual VISU_PipeLine* GetPipeLine() { return myPipeLine;} - virtual void SetPipeLine(VISU_PipeLine* thePipeLine) ; - - VISU_Actor* GetParent(){ return myParent;} - virtual void SetParent(VISU_Actor* theParent); - virtual void SetOpacity(float theValue); - virtual float GetOpacity(); - - virtual void SetRepresentation(int theMode); - - virtual bool IsShrunkable() { return myIsShrinkable;} - virtual bool IsShrunk() { return myIsShrunk;} - virtual void SetShrink(); - virtual void UnShrink(); - - virtual void SetShrinkable(bool theIsShrinkable); - virtual void SetShrinkFactor(float theFactor = 0.8); - virtual float GetShrinkFactor(); - - virtual void SetVisibility(int theMode); - virtual int GetVisibility(); - - virtual void SetLineWidth(float theLineWidth); - virtual float GetLineWidth(); + static + VISU_Actor* + New(); + + void + ShallowCopy(vtkProp *prop); + + virtual + void + ShallowCopyPL(VISU_PipeLine* thePipeLine); + + //---------------------------------------------------------------------------- + virtual + void + setIO(const Handle(SALOME_InteractiveObject)& theIO); + + //---------------------------------------------------------------------------- + VISU::Prs3d_i* + GetPrs3d(); + + virtual + void + SetPrs3d(VISU::Prs3d_i* thePrs3d); + + //---------------------------------------------------------------------------- + VISU::TActorFactory* + GetFactory(); + + virtual + void + SetFactory(VISU::TActorFactory* theActorFactory); + + //---------------------------------------------------------------------------- + virtual + void + UpdateFromFactory(); + + virtual + void + RemoveFromRender(); + + //---------------------------------------------------------------------------- + virtual + VISU_PipeLine* + GetPipeLine(); + + virtual + void + SetPipeLine(VISU_PipeLine* thePipeLine); + + //---------------------------------------------------------------------------- + virtual + void + SetRepresentation(int theMode); + + //---------------------------------------------------------------------------- + virtual + bool + IsShrunkable(); + + virtual + bool + IsShrunk(); + + virtual + void + SetShrink(); + + virtual + void + UnShrink(); + + virtual + void + SetShrinkable(bool theIsShrinkable); + + virtual + void + SetShrinkFactor(float theFactor = 0.8); + + virtual + float + GetShrinkFactor(); + + //---------------------------------------------------------------------------- + virtual + void + SetOpacity(float theValue); + + virtual + float + GetOpacity(); + + virtual + void + SetLineWidth(float theLineWidth); + + virtual + float + GetLineWidth(); - virtual int GetNodeObjId(int theVtkID); - virtual int GetElemObjId(int theVtkID); - + //---------------------------------------------------------------------------- + virtual + void + AddToRender( vtkRenderer* ); + + virtual + void + RemoveFromRender( vtkRenderer* ); + + //---------------------------------------------------------------------------- + virtual + bool + PreHighlight(vtkInteractorStyle* theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight); + + virtual + void + SetVTKMapping(bool theIsVTKMapping); + + virtual + bool + IsVTKMapping() const; + + virtual + vtkDataSet* + GetInput(); + + //---------------------------------------------------------------------------- + virtual + vtkIdType + GetNodeObjId(vtkIdType theID); + + virtual + vtkIdType + GetNodeVTKID(vtkIdType theID); + + virtual + float* + GetNodeCoord(vtkIdType theObjID); + + virtual + vtkIdType + GetElemObjId(vtkIdType theID); + + virtual + vtkIdType + GetElemVTKID(vtkIdType theID); + + virtual + vtkCell* + GetElemCell(vtkIdType theObjID); + + //---------------------------------------------------------------------------- protected: VISU_Actor(); + + virtual + ~VISU_Actor(); - VISU_Actor* myParent; + virtual + void + SetMapperInput(vtkDataSet* theDataSet); + + virtual + VISU_PipeLine* + GetCurrentPL(); + + //---------------------------------------------------------------------------- + bool myIsVTKMapping; VISU::Prs3d_i* myPrs3d; - VISU_PipeLine* myPipeLine; - vtkDataSetMapper* myMapper; + vtkSmartPointer myPipeLine; + vtkSmartPointer myMapper; - VTKViewer_ShrinkFilter* myShrinkFilter; + VISU::TActorFactory* myActorFactory; + boost::signal1 myDestroySignal; + + vtkSmartPointer myShrinkFilter; bool myIsShrinkable; bool myIsShrunk; + + vtkSmartPointer myAnnotationMapper; + vtkSmartPointer myAnnotationActor; }; #endif //VISU_ACTOR_H diff --git a/src/OBJECT/VISU_ActorFactory.h b/src/OBJECT/VISU_ActorFactory.h new file mode 100644 index 00000000..97cee603 --- /dev/null +++ b/src/OBJECT/VISU_ActorFactory.h @@ -0,0 +1,68 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : VISU +// $Header$ + +#ifndef VISU_ACTOR_FACTORY_H +#define VISU_ACTOR_FACTORY_H + +#include + +class VISU_Actor; + +//---------------------------------------------------------------------------- +namespace VISU +{ + //! This class defines an abstaract interface to manage actors + /*! + Actors are created by corresponding presentations and published in the defined view. + Each actor can be published only into one view but one presentation can have many actors. + Due to the complexity of the actor presentation interaction the new interface defines common + and simply way to manage them properly. + @note + This interface inherits from boost::bsignals::trackable in order to provide automatic + diconnection from defined signals if the object is destroyed. + */ + struct TActorFactory: public virtual boost::bsignals::trackable + { + //! Just to make this class virtual + virtual + ~TActorFactory() + {} + + //! To update the actor + virtual + void + UpdateActor(VISU_Actor* theActor) = 0; + + //! To unregister the actor + virtual + void + RemoveActor(VISU_Actor* theActor) = 0; + }; +} + +#endif //VISU_ACTOR_FACTORY_H diff --git a/src/OBJECT/VISU_Event.h b/src/OBJECT/VISU_Event.h new file mode 100644 index 00000000..7c613cf2 --- /dev/null +++ b/src/OBJECT/VISU_Event.h @@ -0,0 +1,47 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef VISU_Event_h +#define VISU_Event_h + +#include "SVTK_Event.h" +#include "SVTK_Selection.h" + +namespace VISU +{ + enum Event + { + SetSMDecreaseMagnificationEvent = SVTK::LastEvent + 100, + SetSMIncreaseMagnificationEvent, + LastEvent + }; +} + +const Selection_Mode GaussPointSelection = 100; + +#endif diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx new file mode 100644 index 00000000..e7758b85 --- /dev/null +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -0,0 +1,1511 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VISU_MeshAct.hxx +// Author : Laurent CORNABE with the help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#include "VISU_GaussPtsAct.h" +#include "VISU_GaussPointsPL.hxx" +#include "VISU_GaussPtsSettings.h" +#include "VISU_GaussPtsDeviceActor.h" +#include "VISU_WidgetCtrl.hxx" +#include "VISU_SphereWidget.hxx" +#include "VISU_OpenGLPointSpriteMapper.hxx" +#include "VISU_ScalarBarCtrl.hxx" +#include "VISU_ScalarBarActor.hxx" + +#include "SALOME_ExtractGeometry.h" + +#include "VISU_Event.h" +#include "SVTK_Actor.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUG1 = 0; +static int MYDEBUG2 = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUG1 = 0; +static int MYDEBUG2 = 0; +#endif + + +//============================================================================ +vtkStandardNewMacro(VISU_GaussPtsAct); + +//---------------------------------------------------------------------------- +VISU_GaussPtsAct +::VISU_GaussPtsAct(): + myEventCallbackCommand(vtkCallbackCommand::New()), + myPriority(0.0), + myDeviceActor(VISU_GaussPtsDeviceActor::New()), + myWidgetCtrl(NULL), + myGaussPointsPL(NULL), + myLastObjPointID(-1), + myTextActor(VISU_FramedTextActor::New()), + myCursorPyramid(VISU_CursorPyramid::New()), + myCursorPyramidSelected(VISU_CursorPyramid::New()), + myCellSource(vtkUnstructuredGrid::New()), + myCellActor(SVTK_Actor::New()), + myScalarBarCtrl(VISU_ScalarBarCtrl::New()), + myBarVisibility(true), + myPickingSettings(NULL), + myInsideCursorSettings(NULL), + myCurrentPL(NULL) +{ + if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<Delete(); + myDeviceActor->Delete(); + myTextActor->Delete(); + + myCursorPyramid->Delete(); + myCursorPyramid->SetPickable(0); + myCursorPyramid->SetVisibility(0); + + myCursorPyramidSelected->Delete(); + myCursorPyramidSelected->SetPickable(0); + myCursorPyramidSelected->SetVisibility(0); + + myCellSource->Delete(); + myCellActor->Delete(); + + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents); + + myDeviceActor->SetProperty(GetProperty()); + myDeviceActor->SetVisibility(true); + myDeviceActor->SetPickable(false); + + myTextActor->SetVisibility(false); + myTextActor->SetPickable(false); + + myCellSource->Allocate(); + myCellActor->Initialize(); + myCellActor->SetRepresentation(VTK_WIREFRAME); + myCellActor->SetSource(myCellSource.GetPointer()); + + myCellActor->SetVisibility(0); + myCellActor->SetPickable(0); + myCellActor->GetProperty()->SetAmbient(1.0); + myCellActor->GetProperty()->SetDiffuse(0.0); + + myScalarBarCtrl->Delete(); +} + +VISU_GaussPtsAct +::~VISU_GaussPtsAct() +{ + if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<= 0){ + float *aNodeCoord = GetNodeCoord(anObjId); + float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.}; + // + vtkDataSet* aDataSet = GetInput(); + vtkCellData* aDataSetAttributes = aDataSet->GetCellData(); + // + if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){ + float aVal = aScalarArray->GetTuple1(aVtkId); + // + GetScalarBarCtrl()->SetIsMarked(true); + GetScalarBarCtrl()->SetMarkValue(aVal); + GetScalarBarCtrl()->Update(); + // + float aPyramidHeight = myPickingSettings->GetPyramidHeight(); + aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize(); + myCursorPyramidSelected->Init(aPyramidHeight, + myPickingSettings->GetCursorSize(), + GetRadius(anObjId,aVtkId,aScalarArray), + GetMagnification(anObjId), + GetClamp(anObjId), + aNodeCoord, + myHighlightActor->GetProperty()->GetColor()); + myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight); + // + const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = + myGaussPointsPL->GetGaussPtsIDMapper(); + VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent(); + + VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId); + VISU::TCellID aCellID = aGaussPointID.first; + VISU::TLocalPntID aLocalPntID = aGaussPointID.second; + aStr<<"\nParentCellID: "<GetElemName(aCellID); + if(aParentName != "") { + aStr<<"\nParentCellName: '"<GetArray("VISU_FIELD")){ + if(vtkFloatArray *aFloatArray = dynamic_cast(aFieldArray)){ + int aNbComp = aFloatArray->GetNumberOfComponents(); + aStr<<"\nData: {"; + int anId = 0; + while(anId < aNbComp){ + float aComp = aFloatArray->GetComponent(aVtkId,anId++); + aStr<SetModePosition(myPickingSettings->GetInfoWindowPosition()); + myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency()); + myTextActor->SetWorldPoint(aWorldCoord); + myTextActor->SetText(aString.c_str()); + myTextActor->SetVisibility(anIsVisible && theIsHighlight); + // + // myCellActor + if(myPickingSettings->GetDisplayParentMesh()){ + const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = + myGaussPointsPL->GetGaussPtsIDMapper(); + VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent(); + + myCellSource->Reset(); + myCellSource->Modified(); // a VTK bug + myCellSource->SetPoints(aParent->GetVTKOutput()->GetPoints()); + + VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId); + vtkIdType aCellID = aGaussPointID.first; + vtkCell* aCell = aParent->GetElemCell(aCellID); + myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); + myCellActor->SetVisibility(anIsVisible && theIsHighlight); + myCellActor->SetRepresentation(VTK_WIREFRAME); + } + } +} + + +//---------------------------------------------------------------- +void +VISU_GaussPtsAct +::SetPickingSettings(VISU_PickingSettings* thePickingSettings) +{ + if(myPickingSettings == thePickingSettings) + return; + + if(myPickingSettings) + myPickingSettings->RemoveObserver(myEventCallbackCommand.GetPointer()); + + myPickingSettings = thePickingSettings; + + if(thePickingSettings) + { + thePickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + this->UpdatePickingSettings(); + } +} + +void +VISU_GaussPtsAct +::UpdatePickingSettings() +{ + if(!myPickingSettings || myPickingSettings->GetInitial()) + return; + + myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition()); + myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency()); + + float aHeight = myGaussPointsPL->GetMaxPointSize()*myPickingSettings->GetPyramidHeight(); + float aCursorSize = myPickingSettings->GetCursorSize(); + myCursorPyramid->SetPreferences(aHeight,aCursorSize); + myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize); + + myHighlightActor->GetProperty()->SetColor( myPickingSettings->GetColor() ); + myPointPicker->SetTolerance( myPickingSettings->GetPointTolerance() ); + + Highlight(isHighlighted()); + + Update(); +} + +//---------------------------------------------------------------- +void +VISU_GaussPtsAct +::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings) +{ + if(myInsideCursorSettings == theInsideCursorSettings) + return; + + if(myInsideCursorSettings) + myInsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer()); + + myInsideCursorSettings = theInsideCursorSettings; + + if(theInsideCursorSettings){ + theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + UpdateInsideCursorSettings(); + } +} + +void +VISU_GaussPtsAct +::UpdateInsideCursorSettings() +{ + UpdateInsideCursorSettings( myDeviceActor ); +} + +void +VISU_GaussPtsAct +::UpdateInsideCursorSettings( PDeviceActor theActor ) +{ + if(!myInsideCursorSettings || myInsideCursorSettings->GetInitial()) + return; + + if(!IsSegmentationEnabled()) + return; + + VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine(); + + SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter(); + vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction(); + + aPipeline->ShallowCopy(GetGaussPointsPL()); + + aPipeline->SetImplicitFunction(anImplicitFunction); // To restore + + aPipeline->SetPrimitiveType( myInsideCursorSettings->GetPrimitiveType() ); + aPipeline->SetClamp( myInsideCursorSettings->GetClamp() ); + aPipeline->SetImageData( myInsideCursorSettings->GetTexture() ); + aPipeline->SetAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() ); + aPipeline->SetResolution( myInsideCursorSettings->GetResolution() ); + aPipeline->SetMinSize( myInsideCursorSettings->GetMinSize() ); + aPipeline->SetMaxSize( myInsideCursorSettings->GetMaxSize() ); + aPipeline->SetMagnification( myInsideCursorSettings->GetMagnification() ); + aPipeline->SetMagnificationIncrement( myInsideCursorSettings->GetIncrement() ); + + if( myInsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere ) + theActor->GetProperty()->SetRepresentation( VTK_POINTS ); + else + theActor->GetProperty()->SetRepresentation( VTK_SURFACE ); + + aPipeline->Update(); + + Highlight(isHighlighted()); + + Update(); +} + +//============================================================================== +vtkStandardNewMacro(VISU_GaussPtsAct1); + + +//---------------------------------------------------------------------------- +VISU_GaussPtsAct1 +::VISU_GaussPtsAct1(): + myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()), + myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()), + myOutsideCursorSettings(NULL) +{ + if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<SetCallback(VISU_GaussPtsAct1::ProcessEvents); + + myInsideDeviceActor->SetVisibility(false); + myInsideDeviceActor->SetPickable(false); + myInsideDeviceActor->Delete(); + + myOutsideDeviceActor->SetVisibility(false); + myOutsideDeviceActor->SetPickable(false); + myOutsideDeviceActor->Delete(); +} + +VISU_GaussPtsAct1 +::~VISU_GaussPtsAct1() +{ + if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "< +#include + +class VISU_GaussPointsPL; +class VISU_WidgetCtrl; +class VISU_OpenGLPointSpriteMapper; + +class vtkTextMapper; +class vtkTextActor; + +class vtkSphereSource; +class vtkPolyDataMapper; +class vtkActor; +class vtkImageData; +class vtkInteractorStyle; + +class VISU_GaussPtsDeviceActor; +class VISU_CursorPyramid; +class VISU_FramedTextActor; + +class vtkUnstructuredGrid; +class vtkDataSetMapper; +class vtkDataArray; + +class vtkInteractorObserver; +class vtkCallbackCommand; + +class VISU_ScalarBarCtrl; +class VISU_PickingSettings; +class VISU_InsideCursorSettings; +class VISU_OutsideCursorSettings; + + +//============================================================================ +//! Base class for Gauss Points Actors. +/*! + The actor is responsible for representation of Gauss Points. + It render corresponding presentation by usage of corresponding VISU_GaussPtsDeviceActor. + Usage of such technic of rendering gives addititional flexibility to change its behaviour in run-time. + Also, the base class implements the following functionality: + - implements a highlight and prehighlight functionality; + - defining a way to handle VISU_ImplicitFunctionWidget; + - global / local scalar bar mamangement. +*/ +class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_Actor +{ + public: + vtkTypeMacro(VISU_GaussPtsAct,VISU_Actor); + typedef vtkSmartPointer PDeviceActor; + + static + VISU_GaussPtsAct* + New(); + + //---------------------------------------------------------------------------- + virtual + void + SetPipeLine(VISU_PipeLine* thePipeLine) ; + + VISU_GaussPointsPL* + GetGaussPointsPL(); + + virtual + void + ShallowCopyPL(VISU_PipeLine* thePipeLine); + + //---------------------------------------------------------------------------- + //! Redefined method of getting a native mapper of the actor. + virtual + vtkMapper* + GetMapper(); + + //! Redefined method of getting an actor bounds. + virtual + float* + GetBounds(); + + //! Redefined method of getting an actor input. + virtual + vtkDataSet* + GetInput(); + + //---------------------------------------------------------------------------- + virtual + void + SetFactory(VISU::TActorFactory* theActorFactory); + + VISU::TGaussPtsActorFactory* + GetGaussPtsFactory(); + + //---------------------------------------------------------------------------- + //! Add actor to the renderer. + virtual + void + AddToRender(vtkRenderer* theRenderer); + + //! Remove actor from the renderer. + virtual + void + RemoveFromRender(vtkRenderer* theRenderer); + + //! Set the Render Window Interactor to the actor. + virtual + void + SetInteractor(vtkRenderWindowInteractor* theInteractor); + + //! Apply the transform on the actor. + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + //! Redefined method of rendering the Opaque Geometry. + virtual + int + RenderOpaqueGeometry(vtkViewport *viewport); + + //! Redefined method of rendering the Translucent Geometry. + virtual + int + RenderTranslucentGeometry(vtkViewport *viewport); + + //---------------------------------------------------------------------------- + //! Set actor visibility. + virtual + void + SetVisibility(int theMode); + + //! Get segmentation visibility. + virtual + int + IsSegmentationEnabled(); + + //! Set Scalar Bar Control to the actor. + VISU_ScalarBarCtrl* + GetScalarBarCtrl(); + + //! Set the Scalar Bar Control visibility. + void + SetBarVisibility(bool theMode); + + //! Get the Scalar Bar Control visibility. + bool + GetBarVisibility(); + + virtual void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl); + + //! Return the information about pipeline magnification changing. + /*! True indicates that magnification is increased, false - decreased. */ + bool + GetChangeMagnification(); + + //! Change the pipeline magnification. + virtual + void + ChangeMagnification( bool ); + + //---------------------------------------------------------------------------- + //! Internal highlight. + virtual + void + Highlight(bool theIsHighlight); + + //! Redefined method of the actor's prehighlighting + virtual + bool + PreHighlight(vtkInteractorStyle* theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight); + + //! Redefined method of the actor's highlighting + virtual + bool + Highlight(vtkInteractorStyle* theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight); + + //---------------------------------------------------------------------------- + //! Set the picking settings to the actor. + void + SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings); + + virtual void + UpdateInsideCursorSettings(); + + virtual void + UpdateInsideCursorSettings( PDeviceActor ); + + //---------------------------------------------------------------------------- + void + SetPickingSettings(VISU_PickingSettings* thePickingSettings); + + //! Apply the picking settings on the actor. + void + UpdatePickingSettings(); + + virtual + bool + IsInfinitive(); + + protected: + //---------------------------------------------------------------------------- + VISU_GaussPtsAct(); + + virtual + ~VISU_GaussPtsAct(); + + // Redefined method of setting mapper input. + virtual + void + SetMapperInput(vtkDataSet* theDataSet); + + virtual + VISU_PipeLine* + GetCurrentPL(); + + //! To get current value of the radius of the Point Sprite + virtual + float + GetRadius(vtkIdType theObjID, + vtkIdType theVTKID, + vtkDataArray *theScalarArray); + + //! To get current value of the magnification + virtual + float + GetMagnification(vtkIdType theObjID); + + //! To get current value of the clamp + virtual + float + GetClamp(vtkIdType theObjID); + + //---------------------------------------------------------------------------- + vtkSmartPointer myEventCallbackCommand; + + //! Main process VTK event method + static + void + ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + + // To process VTK event method + virtual + void + OnInteractorEvent(unsigned long theEvent); + + float myPriority; + bool myChangeMagnification; + VISU::TGaussPtsActorFactory* myGaussPtsActorFactory; + boost::signal1 myUpdatePrs3dSignal; + + //---------------------------------------------------------------------------- + PDeviceActor myDeviceActor; + + VISU_WidgetCtrl* myWidgetCtrl; + + VISU_GaussPointsPL* myCurrentPL; + vtkSmartPointer myGaussPointsPL; + + vtkIdType myLastObjPointID; + + vtkSmartPointer myTextActor; + + vtkSmartPointer myCursorPyramid; + vtkSmartPointer myCursorPyramidSelected; + + vtkSmartPointer myCellSource; + vtkSmartPointer myCellActor; + + bool myBarVisibility; + vtkSmartPointer myScalarBarCtrl; + + VISU_InsideCursorSettings* myInsideCursorSettings; + VISU_PickingSettings* myPickingSettings; +}; + + +//============================================================================ +class VISU_GaussPtsAct2; + +//! Gauss Points Actor, displayed in the Base View. +/*! + * Contains device actor (VISU_GaussPtsDeviceActor), + * which has two representation modes - outside and + * inside segmentation cursor. + */ +class VTKOCC_EXPORT VISU_GaussPtsAct1 : public VISU_GaussPtsAct +{ + public: + vtkTypeMacro(VISU_GaussPtsAct1,VISU_GaussPtsAct); + + static + VISU_GaussPtsAct1* + New(); + + virtual + void + ShallowCopyPL(VISU_PipeLine* thePipeLine); + + //---------------------------------------------------------------------------- + //! Set actor visibility. + virtual + void + SetVisibility(int theMode); + + virtual + void + Connect(VISU_GaussPtsAct2* theActor); + + //---------------------------------------------------------------------------- + virtual void + UpdateInsideCursorSettings(); + + //---------------------------------------------------------------------------- + //! Set the Outside Cursor Gauss Points settings to the actor. + void + SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings); + + //! Apply the Outside Cursor Gauss Points settings on the actor. + void + UpdateOutsideCursorSettings(); + + //---------------------------------------------------------------------------- + //! Add actor to the renderer. + virtual + void + AddToRender(vtkRenderer* theRenderer); + + //! Remove actor from the renderer. + virtual + void + RemoveFromRender(vtkRenderer* theRenderer); + + //! Apply the transform on the actor. + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + virtual void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl); + + protected: + //---------------------------------------------------------------------------- + VISU_GaussPtsAct1(); + + virtual + ~VISU_GaussPtsAct1(); + + // Redefined method of setting mapper input. + virtual + void + SetMapperInput(vtkDataSet* theDataSet); + + //! To get current value of the radius of the Point Sprite + virtual + float + GetRadius(vtkIdType theObjID, + vtkIdType theVTKID, + vtkDataArray *theScalarArray); + + //! To get current value of the magnification + virtual + float + GetMagnification(vtkIdType theObjID); + + //! To get current value of the clamp + virtual + float + GetClamp(vtkIdType theObjID); + + //---------------------------------------------------------------------------- + // Main process VTK event method + static + void + ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + + // To process VTK event method + virtual + void + OnInteractorEvent(unsigned long theEvent); + + boost::signal1 mySetVisibilitySignal; + VISU_OutsideCursorSettings* myOutsideCursorSettings; + + //---------------------------------------------------------------------------- + PDeviceActor myInsideDeviceActor; + PDeviceActor myOutsideDeviceActor; +}; + + +//! Gauss Points Actor, displayed in the Segmented View. +class VTKOCC_EXPORT VISU_GaussPtsAct2 : public VISU_GaussPtsAct +{ + public: + vtkTypeMacro(VISU_GaussPtsAct2,VISU_GaussPtsAct); + + static + VISU_GaussPtsAct2* + New(); + + // Redefined method of setting mapper input. + virtual + void + SetMapperInput(vtkDataSet* theDataSet); + + virtual + void + ShallowCopyPL(VISU_PipeLine* thePipeLine); + + //---------------------------------------------------------------------------- + //! Set actor visibility. + virtual + void + SetVisibility(int theMode); + + virtual void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl); + + protected: + //---------------------------------------------------------------------------- + VISU_GaussPtsAct2(); + + virtual + ~VISU_GaussPtsAct2(); + + //---------------------------------------------------------------------------- + // To process VTK event method + virtual + void + OnInteractorEvent(unsigned long theEvent); +}; + + +#endif diff --git a/src/OBJECT/VISU_GaussPtsActorFactory.h b/src/OBJECT/VISU_GaussPtsActorFactory.h new file mode 100644 index 00000000..ba785efc --- /dev/null +++ b/src/OBJECT/VISU_GaussPtsActorFactory.h @@ -0,0 +1,57 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VISU_ScalarMapAct.h +// Author : Laurent CORNABE with help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#ifndef VISU_GAUSSPTS_ACTOR_FACTORY_H +#define VISU_GAUSSPTS_ACTOR_FACTORY_H + +#include "VISU_ActorFactory.h" + +class VISU_GaussPtsAct; +class VISU_GaussPtsAct1; +class VISU_GaussPtsAct2; + +//---------------------------------------------------------------------------- +namespace VISU +{ + //! Extend an abstaract interface to manage Gauss points actors + struct TGaussPtsActorFactory: virtual TActorFactory + { + //! To create VISU_GaussPtsAct2 actor (segemented representation) from VISU_GaussPtsAct1 (basic representation) + virtual + VISU_GaussPtsAct2* + CloneActor(VISU_GaussPtsAct1* theActor) = 0; + + //! The VISU_GaussPtsAct can update its presentation + virtual + void + UpdateFromActor(VISU_GaussPtsAct* theActor) = 0; + }; +} + + +#endif diff --git a/src/OBJECT/VISU_GaussPtsDeviceActor.cxx b/src/OBJECT/VISU_GaussPtsDeviceActor.cxx new file mode 100644 index 00000000..a59f4f20 --- /dev/null +++ b/src/OBJECT/VISU_GaussPtsDeviceActor.cxx @@ -0,0 +1,686 @@ +// SMESH OBJECT : interactive object for SMESH visualization +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + + +#include "VISU_GaussPtsDeviceActor.h" + +#include "VISU_GaussPointsPL.hxx" +#include "VISU_OpenGLPointSpriteMapper.hxx" + +#include "VTKViewer_Transform.h" +#include "VTKViewer_TransformFilter.h" +#include "VTKViewer_PassThroughFilter.h" + +#include +#include +#include +#include +#include +#include + +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +using namespace std; + + +//---------------------------------------------------------------- +vtkStandardNewMacro(VISU_GaussPtsDeviceActor); + + +VISU_GaussPtsDeviceActor +::VISU_GaussPtsDeviceActor(): + myGeomFilter(VTKViewer_GeometryFilter::New()), + myTransformFilter(VTKViewer_TransformFilter::New()) +{ + if(MYDEBUG) MESSAGE("VISU_GaussPtsDeviceActor - "<Delete(); + myTransformFilter->Delete(); + + for(int i = 0; i < 3; i++){ + PPassThroughFilter aFilter(VTKViewer_PassThroughFilter::New()); + myPassFilter.push_back(aFilter); + aFilter->Delete(); + } +} + + +VISU_GaussPtsDeviceActor +::~VISU_GaussPtsDeviceActor() +{ + if(MYDEBUG) MESSAGE("~VISU_GaussPtsDeviceActor - "<Mapper == NULL) + { + vtkErrorMacro("No mapper for actor."); + return; + } + + // render the property + if (!this->Property) + { + // force creation of a property + this->GetProperty(); + } + this->Property->Render(this, ren); + if (this->BackfaceProperty) + { + this->BackfaceProperty->BackfaceRender(this, ren); + this->Device->SetBackfaceProperty(this->BackfaceProperty); + } + this->Device->SetProperty(this->Property); + + // render the texture + if (this->Texture) + { + this->Texture->Render(ren); + } + + // make sure the device has the same matrix + vtkMatrix4x4 *matrix = this->Device->GetUserMatrix(); + this->GetMatrix(matrix); + + this->Device->Render(ren,Mapper); + this->EstimatedRenderTime = Mapper->GetTimeToDraw(); +} + + +//---------------------------------------------------------------- +void +VISU_GaussPtsDeviceActor +::AddToRender(vtkRenderer* theRenderer) +{ + theRenderer->AddActor(this); +} + +void +VISU_GaussPtsDeviceActor +::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(this); +} + +void +VISU_GaussPtsDeviceActor +::SetTransform(VTKViewer_Transform* theTransform) +{ + myTransformFilter->SetTransform(theTransform); +} + +VISU_OpenGLPointSpriteMapper* +VISU_GaussPtsDeviceActor +::GetPSMapper() +{ + return myMapper.GetPointer(); +} + + +//---------------------------------------------------------------------------- +void +VISU_GaussPtsDeviceActor +::SetPipeLine(VISU_GaussPointsPL* thePipeLine) +{ + myPipeLine = thePipeLine; + myMapper = thePipeLine->GetPSMapper(); + vtkPolyData* aDataSet = myMapper->GetInput(); + + int anId = 0; + myPassFilter[ anId ]->SetInput( aDataSet ); + myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; + myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + + anId++; + myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); + + myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + + Superclass::SetMapper( myMapper.GetPointer() ); +} + +VISU_GaussPointsPL* +VISU_GaussPtsDeviceActor +::GetPipeLine() +{ + return myPipeLine.GetPointer(); +} + +void +VISU_GaussPtsDeviceActor +::ShallowCopyPL(VISU_GaussPointsPL* thePipeLine) +{ + myPipeLine->ShallowCopy(thePipeLine); +} + + +//============================================================================ +#include +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(VISU_CursorPyramid); + +//---------------------------------------------------------------------------- +VISU_CursorPyramid +::VISU_CursorPyramid(): + myHeight(10.0), + myRadius(5.0), + myMagnification(1.0), + myClamp(256.0), + myNbCones(6), + myAppendFilter(vtkAppendPolyData::New()), + myMapper(vtkPolyDataMapper::New()) +{ + myAppendFilter->Delete(); + myMapper->Delete(); + + myMapper->SetInput(myAppendFilter->GetOutput()); + + for(int i = 0; i < myNbCones; i++){ + vtkConeSource* aConeSource = vtkConeSource::New(); + myAppendFilter->AddInput(aConeSource->GetOutput()); + aConeSource->SetResolution(4); + mySources[i] = aConeSource; + aConeSource->Delete(); + } +} + + +//---------------------------------------------------------------------------- +void +VISU_CursorPyramid +::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m)) +{ + if (ren == NULL) + { + vtkErrorMacro("No mapper for actor."); + return; + } + + this->SetScale(1.0); + float aMRadius = myRadius*myMagnification; + Init(myHeight,aMRadius*myCursorSize); + + if(myClamp > 0.0f){ + float aPoint1[3] = {0.0, 0.0, 0.0}; + ren->SetDisplayPoint(aPoint1); + ren->DisplayToWorld(); + ren->GetWorldPoint(aPoint1); + + float aPoint2[3] = {0.0, myClamp, 0.0}; + ren->SetDisplayPoint(aPoint2); + ren->DisplayToWorld(); + ren->GetWorldPoint(aPoint2); + + float aWorldClamp = + (aPoint2[0] - aPoint1[0])*(aPoint2[0] - aPoint1[0]) + + (aPoint2[1] - aPoint1[1])*(aPoint2[1] - aPoint1[1]) + + (aPoint2[2] - aPoint1[2])*(aPoint2[2] - aPoint1[2]); + + aWorldClamp = sqrt(aWorldClamp); + float aMDiameter = 2.0 * aMRadius; + float aCoeff = aWorldClamp / aMDiameter; + + if(aCoeff < 1.0){ + this->SetScale(aCoeff); + //Init(myHeight/aCoeff,aMRadius*aCoeff); + } + } + + if (this->Mapper == NULL) + { + vtkErrorMacro("No mapper for actor."); + return; + } + + // render the property + if (!this->Property) + { + // force creation of a property + this->GetProperty(); + } + this->Property->Render(this, ren); + if (this->BackfaceProperty) + { + this->BackfaceProperty->BackfaceRender(this, ren); + this->Device->SetBackfaceProperty(this->BackfaceProperty); + } + this->Device->SetProperty(this->Property); + + // render the texture + if (this->Texture) + { + this->Texture->Render(ren); + } + + // make sure the device has the same matrix + vtkMatrix4x4 *matrix = this->Device->GetUserMatrix(); + this->GetMatrix(matrix); + + this->Device->Render(ren,Mapper); + this->EstimatedRenderTime = Mapper->GetTimeToDraw(); +} + + +//---------------------------------------------------------------------------- +void +VISU_CursorPyramid +::AddToRender(vtkRenderer* theRenderer) +{ + theRenderer->AddActor(this); +} + +void +VISU_CursorPyramid +::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(this); +} + +//---------------------------------------------------------------------------- +void +VISU_CursorPyramid +::SetPreferences(float theHeight, + float theCursorSize) +{ + Init(theHeight, theCursorSize, myRadius, myMagnification, myClamp, GetPosition(), GetProperty()->GetColor()); +} + +//---------------------------------------------------------------------------- +void +VISU_CursorPyramid +::Init(float theHeight, + float theCursorSize, + float theRadius, + float theMagnification, + float theClamp, + float thePos[3], + float theColor[3]) +{ + Init(theHeight,theRadius*theMagnification*theCursorSize); + SetPosition(thePos[0],thePos[1],thePos[2]); + GetProperty()->SetColor(theColor); + SetMapper(myMapper.GetPointer()); + + myHeight = theHeight; + myCursorSize = theCursorSize; + + myRadius = theRadius; + myMagnification = theMagnification; + + myClamp = theClamp; +} + + +void +VISU_CursorPyramid +::Init(float theHeight, + float theRadius) +{ + for(int i = 0; i < myNbCones; ++i){ + vtkConeSource* aSource = mySources[i].GetPointer(); + aSource->SetHeight(theHeight); + // Set the angle of the cone. As a side effect, the angle plus height sets + // the base radius of the cone. + aSource->SetAngle(20.0); + } + + float aDisplacement = -0.5*theHeight - theRadius; + + // X + mySources[0]->SetDirection(1.0, 0.0, 0.0); + mySources[0]->SetCenter(aDisplacement, 0.0, 0.0); + + // It is impossible to inverse direction around X axis (VTK bug) + mySources[1]->SetDirection(-VTK_LARGE_FLOAT, 1.0, 0.0); // A workaround + mySources[1]->SetCenter(-aDisplacement, 0.0, 0.0); + + // Y + mySources[2]->SetDirection(0.0, 1.0, 0.0); + mySources[2]->SetCenter(0.0, aDisplacement, 0.0); + + mySources[3]->SetDirection(0.0, -1.0, 0.0); + mySources[3]->SetCenter(0.0, -aDisplacement, 0.0); + + // Z + mySources[4]->SetDirection(0.0, 0.0, 1.0); + mySources[4]->SetCenter(0.0, 0.0, aDisplacement); + + mySources[5]->SetDirection(0.0, 0.0, -1.0); + mySources[5]->SetCenter(0.0, 0.0, -aDisplacement); +} + + +//---------------------------------------------------------------------------- +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//================================================================== +vtkCxxRevisionMacro(VISU_FramedTextActor, "$Revision$"); +vtkStandardNewMacro(VISU_FramedTextActor); + +//================================================================== +// function : VISU_FramedTextActor +// purpose : +//================================================================== +VISU_FramedTextActor::VISU_FramedTextActor() +{ + PositionCoordinate->SetCoordinateSystemToNormalizedViewport(); + + myTransparency=0.; + myBar = vtkPolyData::New(); + myBarMapper = vtkPolyDataMapper2D::New(); + myBarMapper->SetInput(myBar); + myBarActor = vtkActor2D::New(); + myBarActor->SetMapper(myBarMapper); + myBarActor->GetProperty()->SetOpacity(1.-myTransparency); + myBarActor->GetProperty()->SetColor(.5, .5, .5); + // + myTextProperty = vtkTextProperty::New(); + myTextProperty->SetFontSize(12); + myTextProperty->SetBold(0); + myTextProperty->SetItalic(0); + myTextProperty->SetShadow(1); + myTextProperty->SetFontFamilyToArial(); + // + myTextMapper=vtkTextMapper::New(); + myTextMapper->SetInput("some text"); + myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); + myTextActor=vtkActor2D::New(); + myTextActor->SetMapper(myTextMapper); + // + myBarActor->SetVisibility(1); + myTextActor->SetVisibility(1); + myBarActor->SetPickable(0); + myTextActor->SetPickable(0); + //---------------------------------------------------------- + myModePosition=0;// 0 -centered below the point + // 1 -top left corner of the 3D view window + // + for(int i=0; i<4; i++) { + myWorldPoint[i] = 0.; + } + myDistance=10.; + // +} +//================================================================== +// function : ~ +// purpose : +//================================================================== +VISU_FramedTextActor::~VISU_FramedTextActor() +{ + myTextActor->Delete(); + myTextMapper->Delete(); + myTextProperty->Delete(); + myBarActor->Delete(); + myBarMapper->Delete(); + myBar->Delete(); +} +//================================================================== +// function : SetVisibility +// purpose : +//================================================================== +void VISU_FramedTextActor::SetVisibility (int theVisibility) +{ + myBarActor->SetVisibility(theVisibility); + myTextActor->SetVisibility(theVisibility); +} +//================================================================== +// function : GetVisibility +// purpose : +//================================================================== +int VISU_FramedTextActor::GetVisibility() +{ + return myBarActor->GetVisibility(); +} +//================================================================== +// function : SetPickable +// purpose : +//================================================================== +void VISU_FramedTextActor::SetPickable (int thePickability) +{ + myBarActor->SetPickable(thePickability); + myTextActor->SetPickable(thePickability); +} +//================================================================== +// function : GetPickable +// purpose : +//================================================================== +int VISU_FramedTextActor::GetPickable() +{ + return myBarActor->GetPickable(); +} +//================================================================== +// function : SetTransparency +// purpose : +//================================================================== +void VISU_FramedTextActor::SetTransparency(const float theTransparency) +{ + if (theTransparency>=0. && theTransparency<=1.){ + myTransparency=theTransparency; + myBarActor->GetProperty()->SetOpacity(1.-myTransparency); + Modified(); + } +} +//================================================================== +// function : GetTransparency +// purpose : +//================================================================== +float VISU_FramedTextActor::GetTransparency()const +{ + return myTransparency; +} +//================================================================== +// function : SetText +// purpose : +//================================================================== +void VISU_FramedTextActor::SetText(const char* theText) +{ + myTextMapper->SetInput(theText); + Modified(); +} +//================================================================== +// function : GetText +// purpose : +//================================================================== +char* VISU_FramedTextActor::GetText() +{ + return myTextMapper->GetInput(); +} +//================================================================== +// function : SetModePosition +// purpose : +//================================================================== +void VISU_FramedTextActor::SetModePosition(const int theMode) +{ + myModePosition=theMode; + Modified(); +} +//================================================================== +// function : GetModePosition +// purpose : +//================================================================== +int VISU_FramedTextActor::GetModePosition()const +{ + return myModePosition; +} +//================================================================== +// function : SetWorldPoint +// purpose : +//================================================================== +void VISU_FramedTextActor::SetWorldPoint(const float theWorldPoint[4]) +{ + for(int i = 0; i<4; ++i) { + myWorldPoint[i] = theWorldPoint[i]; + } + Modified(); +} +//================================================================== +// function : GetWorldPoint +// purpose : +//================================================================== +const float* VISU_FramedTextActor::GetWorldPoint()const +{ + return myWorldPoint; +} +//================================================================== +// function : SetDistance +// purpose : +//================================================================== +void VISU_FramedTextActor::SetDistance(const float theDistance) +{ + myDistance=theDistance; +} +//================================================================== +// function : GetDistance +// purpose : +//================================================================== +float VISU_FramedTextActor::GetDistance()const +{ + return myDistance; +} +//================================================================== +// function : ReleaseGraphicsResources +// purpose : +//================================================================== +void VISU_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win) +{ + myTextActor->ReleaseGraphicsResources(win); + myBarActor->ReleaseGraphicsResources(win); +} +//================================================================== +// function : RenderOverlay +// purpose : +//================================================================== +int VISU_FramedTextActor::RenderOverlay(vtkViewport *viewport) +{ + int renderedSomething = 0; + myBarActor->RenderOverlay(viewport); + renderedSomething +=myTextActor->RenderOverlay(viewport); + return renderedSomething; +} +//================================================================== +// function : RenderOpaqueGeometry +// purpose : +//================================================================== +int +VISU_FramedTextActor +::RenderOpaqueGeometry(vtkViewport *theViewport) +{ + int anIsRenderedSomething = 0; + int* aViewportSize = theViewport->GetSize(); + if(aViewportSize[0] == 1 || aViewportSize[1] == 1) + return anIsRenderedSomething; + + myBar->Initialize(); + + int aNbPoints = 4; + vtkPoints *aPoints = vtkPoints::New(); + aPoints->SetNumberOfPoints(aNbPoints); + myBar->SetPoints(aPoints); + aPoints->Delete(); + + vtkCellArray *aPolys = vtkCellArray::New(); + aPolys->Allocate(aPolys->EstimateSize(1,4)); + vtkIdType aPointsIds[4] = {0, 1, 3, 2}; + aPolys->InsertNextCell(4,aPointsIds); + myBar->SetPolys(aPolys); + aPolys->Delete(); + + int aTextSize[2]; + myTextMapper->GetSize(theViewport, aTextSize); + int aBarWidth = aTextSize[0]; + int aBarHeight = aTextSize[1]; + + if (myModePosition==0) { + theViewport->SetWorldPoint(myWorldPoint); + theViewport->WorldToDisplay(); + + float aSelectionPoint[3]; + theViewport->GetDisplayPoint(aSelectionPoint); + float u = aSelectionPoint[0]; + float v = aSelectionPoint[1] - myDistance; + theViewport->ViewportToNormalizedViewport(u, v); + PositionCoordinate->SetValue(u, v); + // + myTextProperty->SetJustificationToCentered(); + myTextProperty->SetVerticalJustificationToTop(); + // + aBarWidth /= 2; + aPoints->SetPoint(0, -aBarWidth, 0.0, 0.0); + aPoints->SetPoint(1, -aBarWidth, -aBarHeight, 0.0); + aPoints->SetPoint(2, aBarWidth, 0.0, 0.0); + aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0); + } + else {//if (myModePosition==1) { + PositionCoordinate->SetValue(0.0, 1.0); + myTextProperty->SetJustificationToLeft(); + myTextProperty->SetVerticalJustificationToTop(); + // + aPoints->SetPoint(0, 0.0, 0.0, 0.0); + aPoints->SetPoint(1, 0.0, -aBarHeight, 0.0); + aPoints->SetPoint(2, aBarWidth, 0.0, 0.0); + aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0); + } + // + myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); + myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate); + myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate); + // + myBuildTime.Modified(); + // + return anIsRenderedSomething; +} diff --git a/src/OBJECT/VISU_GaussPtsDeviceActor.h b/src/OBJECT/VISU_GaussPtsDeviceActor.h new file mode 100644 index 00000000..e25e9256 --- /dev/null +++ b/src/OBJECT/VISU_GaussPtsDeviceActor.h @@ -0,0 +1,236 @@ +// SMESH OBJECT : interactive object for SMESH visualization +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#ifndef VISU_GAUSS_PTS_DEVICE_ACTOR_H +#define VISU_GAUSS_PTS_DEVICE_ACTOR_H + +#include "VTKViewer_GeometryFilter.h" + +#include +#include + +class VTKViewer_Transform; +class VTKViewer_TransformFilter; +class VTKViewer_PassThroughFilter; + +class VISU_OpenGLPointSpriteMapper; +class VISU_GaussPointsPL; + + +//============================================================================ +class VISU_GaussPtsDeviceActor: public vtkLODActor +{ + public: + vtkTypeMacro(VISU_GaussPtsDeviceActor,vtkLODActor); + + static + VISU_GaussPtsDeviceActor* + New(); + + virtual + void + Render(vtkRenderer *, vtkMapper *); + + //---------------------------------------------------------------------------- + void + AddToRender(vtkRenderer* theRenderer); + + void + RemoveFromRender(vtkRenderer* theRenderer); + + void + SetTransform(VTKViewer_Transform* theTransform); + + //---------------------------------------------------------------------------- + VISU_GaussPointsPL* + GetPipeLine(); + + void + SetPipeLine(VISU_GaussPointsPL* thePipeLine) ; + + void + ShallowCopyPL(VISU_GaussPointsPL* thePipeLine); + + VISU_OpenGLPointSpriteMapper* + GetPSMapper(); + + protected: + //---------------------------------------------------------------------------- + vtkSmartPointer myPipeLine; + vtkSmartPointer myMapper; + vtkSmartPointer myGeomFilter; + vtkSmartPointer myTransformFilter; + + typedef vtkSmartPointer PPassThroughFilter; + std::vector myPassFilter; + + VISU_GaussPtsDeviceActor(); + ~VISU_GaussPtsDeviceActor(); + + private: + VISU_GaussPtsDeviceActor(const VISU_GaussPtsDeviceActor&); // Not implemented + void operator=(const VISU_GaussPtsDeviceActor&); // Not implemented +}; + + +//============================================================================ +class vtkActor; +class vtkConeSource; +class vtkAppendPolyData; +class vtkPolyDataMapper; + +#include + +class VISU_CursorPyramid : public vtkLODActor +{ +public: + vtkTypeMacro(VISU_CursorPyramid, vtkObject); + + static + VISU_CursorPyramid* + New(); + + virtual + void + Render(vtkRenderer *, vtkMapper *); + + void + AddToRender(vtkRenderer* theRenderer); + + void + RemoveFromRender(vtkRenderer* theRenderer); + + void + Init(float theHeight, + float theCursorSize, + float theRadius, + float theMagnification, + float theClamp, + float thePos[3], + float theColor[3]); + + void SetPreferences(float theHeight, + float theCursorSize); + +protected: + VISU_CursorPyramid(); + + void + Init(float theHeight, + float theRadius); + + int myNbCones; + vtkSmartPointer mySources[6]; + vtkSmartPointer myAppendFilter; + vtkSmartPointer myMapper; + // + float myHeight; + float myCursorSize; + float myRadius; + float myMagnification; + float myClamp; + + private: + VISU_CursorPyramid(const VISU_CursorPyramid&); // Not implemented + void operator=(const VISU_CursorPyramid&); // Not implemented +}; + + +//================================================================== +// class VISU_FramedTextActor +// +#include +// +class vtkViewport; +class vtkProp; +class vtkWindow; +class vtkPolyData; +class vtkPolyDataMapper2D; +class vtkActor2D; +class vtkTimeStamp; +class vtkTextProperty; +class vtkTextMapper; + +class VISU_FramedTextActor : public vtkActor2D +{ +public: + // vtks + vtkTypeRevisionMacro(VISU_FramedTextActor,vtkActor2D); + static VISU_FramedTextActor *New(); + // + virtual int RenderOpaqueGeometry(vtkViewport* viewport); + virtual int RenderTranslucentGeometry(vtkViewport*) { return 0; }; + virtual int RenderOverlay(vtkViewport* viewport); + virtual void ReleaseGraphicsResources(vtkWindow *); + virtual void SetVisibility (int ); + virtual int GetVisibility() ; + virtual void SetPickable (int ) ; + virtual int GetPickable(); + // + // selectors + void SetText(const char* theText); + char* GetText(); + // + void SetModePosition(const int theMode); + int GetModePosition()const; + // + void SetWorldPoint(const float theWorldPoint[4]); + const float* GetWorldPoint()const; + // + void SetDistance(const float theDistance); + float GetDistance()const; + // + void SetTransparency(const float theTransparency); + float GetTransparency()const; + // +protected: + VISU_FramedTextActor(); + ~VISU_FramedTextActor(); + +protected: + vtkPolyData *myBar; + vtkPolyDataMapper2D *myBarMapper; + vtkActor2D *myBarActor; + // + vtkTextProperty *myTextProperty; + vtkTextMapper *myTextMapper; + vtkActor2D *myTextActor; + // + vtkTimeStamp myBuildTime; + // + int myModePosition; + float myWorldPoint[4]; + float myDistance; + float myTransparency; + +private: + VISU_FramedTextActor(const VISU_FramedTextActor&); // Not implemented. + void operator=(const VISU_FramedTextActor&); // Not implemented. +}; + +#endif //VISU_GAUSS_PTS_DEVICE_ACTOR_H diff --git a/src/OBJECT/VISU_GaussPtsSettings.cxx b/src/OBJECT/VISU_GaussPtsSettings.cxx new file mode 100644 index 00000000..b95b1627 --- /dev/null +++ b/src/OBJECT/VISU_GaussPtsSettings.cxx @@ -0,0 +1,106 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : VISU +// $Header$ + +#include "VISU_GaussPtsSettings.h" + +#include +#include + +//---------------------------------------------------------------- +vtkStandardNewMacro( VISU_GaussPtsSettings ); +vtkStandardNewMacro( VISU_InsideCursorSettings ); +vtkStandardNewMacro( VISU_OutsideCursorSettings ); +vtkStandardNewMacro( VISU_PickingSettings ); + +//---------------------------------------------------------------- +VISU_GaussPtsSettings::VISU_GaussPtsSettings() +{ + this->Initial = true; + + this->PrimitiveType = -1; + this->Clamp = -1; + this->Texture = NULL; + this->AlphaThreshold = -1; + this->Resolution = -1; + this->Magnification = -1; + this->Increment = -1; +} + +VISU_GaussPtsSettings::~VISU_GaussPtsSettings() +{ + this->SetTexture( NULL ); +} + +//---------------------------------------------------------------- +VISU_InsideCursorSettings::VISU_InsideCursorSettings() : + VISU_GaussPtsSettings() +{ + this->MinSize = -1; + this->MaxSize = -1; +} + +VISU_InsideCursorSettings::~VISU_InsideCursorSettings() +{ +} + +//---------------------------------------------------------------- +VISU_OutsideCursorSettings::VISU_OutsideCursorSettings() : + VISU_GaussPtsSettings() +{ + this->Size = -1; + this->Uniform = false; + this->Color[0] = -1; + this->Color[1] = -1; + this->Color[2] = -1; +} + +VISU_OutsideCursorSettings::~VISU_OutsideCursorSettings() +{ +} + +//---------------------------------------------------------------- +VISU_PickingSettings::VISU_PickingSettings() +{ + this->Initial = true; + + this->PyramidHeight = -1; + this->CursorSize = -1; + this->PointTolerance = -1; + this->Color[0] = -1; + this->Color[1] = -1; + this->Color[2] = -1; + this->InfoWindowTransparency = -1; + this->InfoWindowPosition = -1; + this->ZoomFactor = -1; + this->StepNumber = -1; + this->DisplayParentMesh = false; +} + +VISU_PickingSettings::~VISU_PickingSettings() +{ +} diff --git a/src/OBJECT/VISU_GaussPtsSettings.h b/src/OBJECT/VISU_GaussPtsSettings.h new file mode 100644 index 00000000..1778521d --- /dev/null +++ b/src/OBJECT/VISU_GaussPtsSettings.h @@ -0,0 +1,231 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : VISU +// $Header$ + +#ifndef VISU_GaussPtsSettings_HeaderFile +#define VISU_GaussPtsSettings_HeaderFile + +#include +#include + +class vtkImageData; + + +//============================================================================ +namespace VISU +{ + const vtkIdType UpdateFromSettingsEvent = vtkCommand::UserEvent + 100; + const vtkIdType UpdateInsideSettingsEvent = vtkCommand::UserEvent + 101; + const vtkIdType UpdateOutsideSettingsEvent = vtkCommand::UserEvent + 102; + const vtkIdType UpdatePickingSettingsEvent = vtkCommand::UserEvent + 103; +} + + +//! Base class of Gauss Points settings. +class VISU_GaussPtsSettings : public vtkObject +{ + public: + vtkTypeMacro( VISU_GaussPtsSettings, vtkObject ); + + VISU_GaussPtsSettings(); + virtual ~VISU_GaussPtsSettings(); + + static + VISU_GaussPtsSettings* + New(); + + vtkSetMacro( Initial, bool ); + vtkGetMacro( Initial, bool ); + + vtkSetMacro( PrimitiveType, int ); + vtkGetMacro( PrimitiveType, int ); + + vtkSetMacro( Clamp, float ); + vtkGetMacro( Clamp, float ); + + vtkSetMacro( Texture, vtkImageData* ); + vtkGetMacro( Texture, vtkImageData* ); + + vtkSetMacro( AlphaThreshold, float ); + vtkGetMacro( AlphaThreshold, float ); + + vtkSetMacro( Resolution, int ); + vtkGetMacro( Resolution, int ); + + vtkSetMacro( Magnification, float ); + vtkGetMacro( Magnification, float ); + + vtkSetMacro( Increment, float ); + vtkGetMacro( Increment, float ); + + protected: + bool Initial; + + int PrimitiveType; + float Clamp; + vtkImageData* Texture; + float AlphaThreshold; + int Resolution; + float Magnification; + float Increment; +}; + + +//! Class of Inside Cursor Gauss Points settings. +/*! + * Contains information about the point sprite parameters: + * Clamp, Texture, Alpha threshold, Const size and Color. + * Used by Gauss Points Actor. + */ +class VISU_InsideCursorSettings : public VISU_GaussPtsSettings +{ + public: + vtkTypeMacro( VISU_InsideCursorSettings, vtkObject ); + + VISU_InsideCursorSettings(); + virtual ~VISU_InsideCursorSettings(); + + static + VISU_InsideCursorSettings* + New(); + + vtkSetMacro( MinSize, float ); + vtkGetMacro( MinSize, float ); + + vtkSetMacro( MaxSize, float ); + vtkGetMacro( MaxSize, float ); + + protected: + float MinSize; + float MaxSize; +}; + + +//============================================================================ +//! Class of Outside Cursor Gauss Points settings. +/*! + * Contains information about the point sprite parameters: + * Clamp, Texture, Alpha threshold, Const size and Color. + * Used by Gauss Points Actor. + */ +class VISU_OutsideCursorSettings : public VISU_GaussPtsSettings +{ + public: + vtkTypeMacro( VISU_OutsideCursorSettings, vtkObject ); + + VISU_OutsideCursorSettings(); + virtual ~VISU_OutsideCursorSettings(); + + static + VISU_OutsideCursorSettings* + New(); + + vtkSetMacro( Size, float ); + vtkGetMacro( Size, float ); + + vtkSetMacro( Uniform, bool ); + vtkGetMacro( Uniform, bool ); + + vtkSetVector3Macro( Color, float ); + vtkGetVector3Macro( Color, float ); + + protected: + float Size; + bool Uniform; + float Color[3]; +}; + + +//! Class of Picking settings. +/*! + * Contains information about the following parameters: + * Cursor Pyramid height, Info Window transparency, + * Info Window position, Zoom factor on first selected point, + * Camera movement steps number and Display parent mesh. + * Used by Gauss Points Actor. + */ +class VISU_PickingSettings : public vtkObject +{ + public: + enum { BelowPoint = 0, TopLeftCorner }; + + public: + vtkTypeMacro( VISU_PickingSettings, vtkObject ); + + VISU_PickingSettings(); + virtual ~VISU_PickingSettings(); + + static + VISU_PickingSettings* + New(); + + vtkSetMacro( Initial, bool ); + vtkGetMacro( Initial, bool ); + + vtkSetMacro( PyramidHeight, float ); + vtkGetMacro( PyramidHeight, float ); + + vtkSetMacro( CursorSize, float ); + vtkGetMacro( CursorSize, float ); + + vtkSetVector3Macro( Color, float ); + vtkGetVector3Macro( Color, float ); + + vtkSetMacro( PointTolerance, float ); + vtkGetMacro( PointTolerance, float ); + + vtkSetMacro( InfoWindowTransparency, float ); + vtkGetMacro( InfoWindowTransparency, float ); + + vtkSetMacro( InfoWindowPosition, int ); + vtkGetMacro( InfoWindowPosition, int ); + + vtkSetMacro( ZoomFactor, float ); + vtkGetMacro( ZoomFactor, float ); + + vtkSetMacro( StepNumber, int ); + vtkGetMacro( StepNumber, int ); + + vtkSetMacro( DisplayParentMesh, bool ); + vtkGetMacro( DisplayParentMesh, bool ); + +private: + bool Initial; + + float PyramidHeight; + float CursorSize; + float PointTolerance; + float Color[3]; + float InfoWindowTransparency; + int InfoWindowPosition; + float ZoomFactor; + int StepNumber; + bool DisplayParentMesh; +}; + + +#endif diff --git a/src/OBJECT/VISU_MeshAct.cxx b/src/OBJECT/VISU_MeshAct.cxx index 68f7446a..b6b812d9 100644 --- a/src/OBJECT/VISU_MeshAct.cxx +++ b/src/OBJECT/VISU_MeshAct.cxx @@ -22,12 +22,12 @@ // // // File : VISU_MeshAct.cxx -// Author : Laurent CORNABE with the help of Nicolas REJNERI +// Author : // Module : VISU // $Header$ #include "VISU_MeshAct.h" -#include "VTKViewer_PassThroughFilter.h" +#include "SVTK_DeviceActor.h" #include #include @@ -39,351 +39,233 @@ #include #include + +//---------------------------------------------------------------------------- vtkStandardNewMacro(VISU_MeshAct); -VISU_MeshAct::VISU_MeshAct(){ +//---------------------------------------------------------------------------- +VISU_MeshAct +::VISU_MeshAct() +{ vtkMatrix4x4 *m; m = vtkMatrix4x4::New(); - mySurfaceActor = VISU_Actor::New(); - mySurfaceActor->SetParent(this); - mySurfaceActor->GetProperty()->FrontfaceCullingOff(); - mySurfaceActor->GetProperty()->BackfaceCullingOff(); + mySurfaceActor = SVTK_DeviceActor::New(); + mySurfaceActor->SetRepresentation(SVTK::Representation::Surface); mySurfaceActor->SetUserMatrix(m); - mySurfaceActor->SetRepresentation(2); //SURFACE - myEdgeActor = VISU_Actor::New(); - myEdgeActor->SetParent(this); - myEdgeActor->PickableOff(); - myEdgeActor->GetProperty()->FrontfaceCullingOff(); - myEdgeActor->GetProperty()->BackfaceCullingOff(); + myEdgeActor = SVTK_DeviceActor::New(); + myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe); myEdgeActor->SetUserMatrix(m); - myEdgeActor->SetRepresentation(1); //WIREFRAME - - myNodeActor = VISU_Actor::New(); - myNodeActor->SetParent(this); - myNodeActor->PickableOff(); - myNodeActor->GetProperty()->SetPointSize(SALOME_POINT_SIZE); - myNodeActor->GetProperty()->FrontfaceCullingOff(); - myNodeActor->GetProperty()->BackfaceCullingOff(); + + myNodeActor = SVTK_DeviceActor::New(); + myNodeActor->SetRepresentation(SVTK::Representation::Points); myNodeActor->SetUserMatrix(m); - myNodeActor->SetRepresentation(0); //POINT m->Delete(); - SetRepresentation(2); //SURFACE + SetRepresentation(SVTK::Representation::Surface); } -VISU_MeshAct::~VISU_MeshAct(){ +VISU_MeshAct +::~VISU_MeshAct() +{ mySurfaceActor->Delete(); myEdgeActor->Delete(); myNodeActor->Delete(); } -void VISU_MeshAct::setIO(const Handle(SALOME_InteractiveObject)& theIO){ - VISU_Actor::setIO(theIO); - mySurfaceActor->setIO(theIO); - myEdgeActor->setIO(theIO); - myNodeActor->setIO(theIO); -} -void VISU_MeshAct::SetPrs3d(VISU::Prs3d_i* thePrs3d){ - if(thePrs3d){ - VISU_Actor::SetPrs3d(thePrs3d); - mySurfaceActor->SetPrs3d(thePrs3d); - myEdgeActor->SetPrs3d(thePrs3d); - myNodeActor->SetPrs3d(thePrs3d); - } -} +//---------------------------------------------------------------------------- +void +VISU_MeshAct +::SetMapperInput(vtkDataSet* theDataSet) +{ + Superclass::SetMapperInput(theDataSet); -void VISU_MeshAct::AddToRender(vtkRenderer* theRenderer){ - VISU_Actor::AddToRender(theRenderer); - theRenderer->AddActor(myEdgeActor); + mySurfaceActor->SetInput(theDataSet); + myEdgeActor->SetInput(theDataSet); + myNodeActor->SetInput(theDataSet); } -void VISU_MeshAct::RemoveFromRender(vtkRenderer* theRenderer){ - VISU_Actor::RemoveFromRender(theRenderer); - theRenderer->RemoveActor(myEdgeActor); -} -void VISU_MeshAct::SetPipeLine(VISU_PipeLine* thePipeLine) { - VISU_Actor::SetPipeLine(thePipeLine); - mySurfaceActor->SetPipeLine(thePipeLine); - myEdgeActor->SetPipeLine(thePipeLine); - myNodeActor->SetPipeLine(thePipeLine); -} +//---------------------------------------------------------------------------- +void +VISU_MeshAct +::SetTransform(VTKViewer_Transform* theTransform) +{ + Superclass::SetTransform(theTransform); -void VISU_MeshAct::SetTransform(VTKViewer_Transform* theTransform){ - VISU_Actor::SetTransform(theTransform); mySurfaceActor->SetTransform(theTransform); myEdgeActor->SetTransform(theTransform); myNodeActor->SetTransform(theTransform); } -void VISU_MeshAct::SetShrinkable(bool theIsShrinkable){ - VISU_Actor::SetShrinkable(theIsShrinkable); + +//---------------------------------------------------------------------------- +void +VISU_MeshAct +::SetShrinkable(bool theIsShrinkable) +{ + Superclass::SetShrinkable(theIsShrinkable); + mySurfaceActor->SetShrinkable(theIsShrinkable); myEdgeActor->SetShrinkable(theIsShrinkable); - myNodeActor->SetShrinkable(theIsShrinkable); } -void VISU_MeshAct::SetShrinkFactor(float theValue){ - VISU_Actor::SetShrinkFactor(theValue); +void +VISU_MeshAct +::SetShrinkFactor(float theValue) +{ + Superclass::SetShrinkFactor(theValue); + mySurfaceActor->SetShrinkFactor(theValue); myEdgeActor->SetShrinkFactor(theValue); } -vtkProperty* VISU_MeshAct::GetSurfaceProperty(){ - return mySurfaceActor->GetProperty(); -} -void VISU_MeshAct::SetSurfaceProperty(vtkProperty* theProperty){ - mySurfaceActor->SetProperty(theProperty); +//---------------------------------------------------------------------------- +vtkProperty* +VISU_MeshAct +::GetSurfaceProperty() +{ + return mySurfaceActor->GetProperty(); } -vtkProperty* VISU_MeshAct::GetEdgeProperty(){ +vtkProperty* +VISU_MeshAct +::GetEdgeProperty() +{ return myEdgeActor->GetProperty(); } -void VISU_MeshAct::SetEdgeProperty(vtkProperty* theProperty){ - myEdgeActor->SetProperty(theProperty); -} - -vtkProperty* VISU_MeshAct::GetNodeProperty(){ +vtkProperty* +VISU_MeshAct +::GetNodeProperty() +{ return myNodeActor->GetProperty(); } -void VISU_MeshAct::SetNodeProperty(vtkProperty* theProperty){ - myNodeActor->SetProperty(theProperty); -} - -void VISU_MeshAct::SetOpacity(float theValue){ +//---------------------------------------------------------------------------- +void +VISU_MeshAct +::SetOpacity(float theValue) +{ GetSurfaceProperty()->SetOpacity(theValue); } -float VISU_MeshAct::GetOpacity(){ +float +VISU_MeshAct +::GetOpacity() +{ return GetSurfaceProperty()->GetOpacity(); } -void VISU_MeshAct::SetLineWidth(float theLineWidth){ +//---------------------------------------------------------------------------- +void +VISU_MeshAct +::SetLineWidth(float theLineWidth) +{ GetEdgeProperty()->SetLineWidth(theLineWidth); } -float VISU_MeshAct::GetLineWidth(){ +float +VISU_MeshAct::GetLineWidth() +{ return GetEdgeProperty()->GetLineWidth(); } -void VISU_MeshAct::SetShrink(){ +//---------------------------------------------------------------------------- +void +VISU_MeshAct +::SetShrink() +{ if(myRepresentation == VTK_POINTS) return; - VISU_Actor::SetShrink(); + + Superclass::SetShrink(); + mySurfaceActor->SetShrink(); myEdgeActor->SetShrink(); - //SetRepresentation(GetRepresentation()); } -void VISU_MeshAct::UnShrink(){ - VISU_Actor::UnShrink(); +void +VISU_MeshAct +::UnShrink() +{ + Superclass::UnShrink(); + mySurfaceActor->UnShrink(); myEdgeActor->UnShrink(); - //SetRepresentation(GetRepresentation()); } -void VISU_MeshAct::SetRepresentation(int theMode) + +//---------------------------------------------------------------------------- +void +VISU_MeshAct +::SetRepresentation(int theMode) { - SALOME_Actor::SetRepresentation(theMode); - - if (!GetVisibility()) return; // Fix IPAL9555 - - mySurfaceActor->VisibilityOff(); - myEdgeActor->VisibilityOff(); - myNodeActor->VisibilityOff(); - myEdgeActor->PickableOff(); - myNodeActor->PickableOff(); - switch (theMode) { - case VTK_POINTS: - myNodeActor->VisibilityOn(); - myNodeActor->PickableOn(); - break; - case VTK_WIREFRAME: - myEdgeActor->VisibilityOn(); - myEdgeActor->SetRepresentation(1); - myEdgeActor->PickableOn(); - break; - case VTK_SURFACE: - mySurfaceActor->VisibilityOn(); - break; - case 3: //INSIDEFRAME - myEdgeActor->VisibilityOn(); - myEdgeActor->SetRepresentation(3); - myEdgeActor->PickableOn(); - break; - case 4: //SURFACEFRAME - myEdgeActor->VisibilityOn(); - myEdgeActor->SetRepresentation(1); - mySurfaceActor->VisibilityOn(); - break; - } - if (myRepresentation == VTK_POINTS) - UnShrink(); -} + Superclass::SetRepresentation(theMode); -void VISU_MeshAct::SetVisibility(int theMode){ - VISU_Actor::SetVisibility(theMode); - if(GetVisibility()) - SetRepresentation(GetRepresentation()); - else{ - myNodeActor->VisibilityOff(); - myEdgeActor->VisibilityOff(); - mySurfaceActor->VisibilityOff(); - } + if(theMode == SVTK::Representation::Insideframe) + myEdgeActor->SetRepresentation(SVTK::Representation::Insideframe); + else + myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe); } -// From vtkLODActor -void VISU_MeshAct::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m)) +//---------------------------------------------------------------------------- +int +VISU_MeshAct +::RenderOpaqueGeometry(vtkViewport *ren) { - float myTime, bestTime, tempTime; - vtkMatrix4x4 *matrix; - vtkMapper *mapper, *bestMapper; - - if (this->Mapper == NULL) - { - vtkErrorMacro("No mapper for actor."); - return; - } - - // first time through create lods if non have been added - if (this->LODMappers->GetNumberOfItems() == 0) - { - this->CreateOwnLODs(); - } - - // If the actor has changed or the primary mapper has changed ... - // Is this the correct test? - if (this->MediumMapper) - { - if (this->GetMTime() > this->BuildTime || - this->Mapper->GetMTime() > this->BuildTime) - { - this->UpdateOwnLODs(); - } - } - - // figure out how much time we have to render - myTime = this->AllocatedRenderTime; - - // Figure out which resolution to use - // none is a valid resolution. Do we want to have a lowest: - // bbox, single point, ... - // There is no order to the list, so it is assumed that mappers that take - // longer to render are better quality. - // Timings might become out of date, but we rely on - - bestMapper = this->Mapper; - bestTime = bestMapper->GetTimeToDraw(); - if (bestTime > myTime) - { - this->LODMappers->InitTraversal(); - while ((mapper = this->LODMappers->GetNextItem()) != NULL && - bestTime != 0.0) - { - tempTime = mapper->GetTimeToDraw(); - - // If the LOD has never been rendered, select it! - if (tempTime == 0.0) - { - bestMapper = mapper; - bestTime = 0.0; - } - else - { - if (bestTime > myTime && tempTime < bestTime) - { - bestMapper = mapper; - bestTime = tempTime; - } - if (tempTime > bestTime && tempTime < myTime) - { - bestMapper = mapper; - bestTime = tempTime; - } - } - } - } + GetMatrix(myNodeActor->GetUserMatrix()); + GetMatrix(myEdgeActor->GetUserMatrix()); + GetMatrix(mySurfaceActor->GetUserMatrix()); + using namespace SVTK::Representation; switch(GetRepresentation()){ - case 0: //POINTS - myNodeActor->GetProperty()->Render(this, ren); - break; - case 1: //WIREFRAME - //PAL5268: myEdgeActor->GetProperty()->Render(this, ren); + case Points : + myNodeActor->RenderOpaqueGeometry(ren); break; - case 2: //SURFACE - mySurfaceActor->GetProperty()->Render(this, ren); + case Wireframe : + case Insideframe : + myEdgeActor->RenderOpaqueGeometry(ren); break; - case 3: //INSIDEFRAME - //PAL5268: myEdgeActor->GetProperty()->Render(this, ren); + case Surface : + mySurfaceActor->RenderOpaqueGeometry(ren); break; - case 4: //SURFACEFRAME - //PAL5268: myEdgeActor->GetProperty()->Render(this, ren); - mySurfaceActor->GetProperty()->Render(this, ren); + case Surfaceframe : + mySurfaceActor->RenderOpaqueGeometry(ren); + myEdgeActor->RenderOpaqueGeometry(ren); break; } + return 1; +} - // render the texture - if (this->Texture) - { - this->Texture->Render(ren); - } - - switch(GetRepresentation()){ - case 0: //POINTS - matrix = myNodeActor->GetUserMatrix(); - break; - case 1: //WIREFRAME - matrix = myEdgeActor->GetUserMatrix(); - break; - case 2: //SURFACE - matrix = mySurfaceActor->GetUserMatrix(); - break; - case 3: //INSIDEFRAME - matrix = myEdgeActor->GetUserMatrix(); - break; - case 4: //SURFACEFRAME - matrix = myEdgeActor->GetUserMatrix(); - this->GetMatrix(matrix); - matrix = mySurfaceActor->GetUserMatrix(); - break; - } - this->GetMatrix(matrix); +int +VISU_MeshAct +::RenderTranslucentGeometry(vtkViewport *ren) +{ + GetMatrix(myNodeActor->GetUserMatrix()); + GetMatrix(myEdgeActor->GetUserMatrix()); + GetMatrix(mySurfaceActor->GetUserMatrix()); + using namespace SVTK::Representation; switch(GetRepresentation()){ - case 0: //POINTS - myNodeActor->Render(ren,bestMapper); + case Points : + myNodeActor->RenderTranslucentGeometry(ren); break; - case 1: //WIREFRAME - //PAL5268: myEdgeActor->Render(ren,bestMapper); + case Wireframe : + case Insideframe : + myEdgeActor->RenderTranslucentGeometry(ren); break; - case 2: //SURFACE - mySurfaceActor->Render(ren,bestMapper); + case Surface : + mySurfaceActor->RenderTranslucentGeometry(ren); break; - case 3: //INSIDEFRAME - //PAL5268: myEdgeActor->Render(ren,bestMapper); - break; - case 4: //SURFACEFRAME - //PAL5268: myEdgeActor->Render(ren,bestMapper); - mySurfaceActor->Render(ren,bestMapper); + case Surfaceframe : + mySurfaceActor->RenderTranslucentGeometry(ren); + myEdgeActor->RenderTranslucentGeometry(ren); break; } - - this->EstimatedRenderTime = bestMapper->GetTimeToDraw(); -} - -// From vtkLODActor -void VISU_MeshAct::Modified() -{ - myNodeActor->Modified(); - //PAL5268: myEdgeActor->Modified(); - mySurfaceActor->Modified(); - this->vtkActor::Modified(); + return 1; } diff --git a/src/OBJECT/VISU_MeshAct.h b/src/OBJECT/VISU_MeshAct.h index bacc15c3..9dafb348 100644 --- a/src/OBJECT/VISU_MeshAct.h +++ b/src/OBJECT/VISU_MeshAct.h @@ -30,54 +30,94 @@ #define VISU_MeshAct_HeaderFile #include "VISU_Actor.h" -class vtkDataSetMapper; - -class VTKOCC_EXPORT VISU_MeshAct : public VISU_Actor { +#include "SVTK_DeviceActor.h" + +namespace SVTK +{ + namespace Representation + { + const Type Surfaceframe = Insideframe + 1; + } +} + +class VTKOCC_EXPORT VISU_MeshAct : public VISU_Actor +{ public: vtkTypeMacro(VISU_MeshAct,VISU_Actor); static VISU_MeshAct* New(); - ~VISU_MeshAct(); - virtual void setIO(const Handle(SALOME_InteractiveObject)& theIO); - virtual void SetPrs3d(VISU::Prs3d_i* thePrs3d); + //! Apply view transformation + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + virtual + vtkProperty* + GetSurfaceProperty(); + + virtual + vtkProperty* + GetEdgeProperty(); - virtual void AddToRender(vtkRenderer* theRenderer); - virtual void RemoveFromRender(vtkRenderer* theRenderer); + virtual + vtkProperty* + GetNodeProperty(); - virtual void SetPipeLine(VISU_PipeLine* thePipeLine) ; - virtual void SetTransform(VTKViewer_Transform* theTransform); + virtual + void + SetOpacity(float theValue); - virtual vtkProperty* GetSurfaceProperty(); - virtual void SetSurfaceProperty(vtkProperty* theProperty); + virtual + float + GetOpacity(); - virtual vtkProperty* GetEdgeProperty(); - virtual void SetEdgeProperty(vtkProperty* theProperty); + virtual + void + SetLineWidth(float theLineWidth); - virtual vtkProperty* GetNodeProperty(); - virtual void SetNodeProperty(vtkProperty* theProperty); + virtual + float + GetLineWidth(); - virtual void SetOpacity(float theValue); - virtual float GetOpacity(); + virtual + void + SetRepresentation(int theMode); - virtual void SetLineWidth(float theLineWidth); - virtual float GetLineWidth(); + virtual + void + SetShrinkable(bool theIsShrinkable); - virtual void SetRepresentation(int theMode); + virtual + void + SetShrinkFactor(float theFactor = 0.8); - virtual void SetVisibility(int theMode); + virtual + void + SetShrink(); - virtual void SetShrinkable(bool theIsShrinkable); - virtual void SetShrinkFactor(float theFactor = 0.8); + virtual + void + UnShrink(); - virtual void SetShrink(); - virtual void UnShrink(); + virtual + int + RenderOpaqueGeometry(vtkViewport *ren); - virtual void Render(vtkRenderer *, vtkMapper *); - void Modified(); + virtual + int + RenderTranslucentGeometry(vtkViewport *ren); protected: VISU_MeshAct(); - VISU_Actor *mySurfaceActor, *myEdgeActor, *myNodeActor; + ~VISU_MeshAct(); + + virtual + void + SetMapperInput(vtkDataSet* theDataSet); + + SVTK_DeviceActor *mySurfaceActor; + SVTK_DeviceActor *myEdgeActor; + SVTK_DeviceActor *myNodeActor; }; #endif diff --git a/src/OBJECT/VISU_ScalarMapAct.cxx b/src/OBJECT/VISU_ScalarMapAct.cxx index c34a8e7f..93445e00 100644 --- a/src/OBJECT/VISU_ScalarMapAct.cxx +++ b/src/OBJECT/VISU_ScalarMapAct.cxx @@ -32,10 +32,13 @@ #include #include +#include vtkStandardNewMacro(VISU_ScalarMapAct); -VISU_ScalarMapAct::VISU_ScalarMapAct(){ +VISU_ScalarMapAct +::VISU_ScalarMapAct() +{ myScalarBar = VISU_ScalarBarActor::New(); vtkProperty* aProperty = GetProperty(); @@ -49,32 +52,53 @@ VISU_ScalarMapAct::VISU_ScalarMapAct(){ myProperty->DeepCopy(aProperty); } -VISU_ScalarMapAct::~VISU_ScalarMapAct(){ +VISU_ScalarMapAct +::~VISU_ScalarMapAct() +{ myScalarBar->Delete(); } -void VISU_ScalarMapAct::AddToRender(vtkRenderer* theRenderer){ - SALOME_Actor::AddToRender(theRenderer); +void +VISU_ScalarMapAct +::AddToRender(vtkRenderer* theRenderer) +{ + Superclass::AddToRender(theRenderer); + if(myScalarBar) theRenderer->AddActor2D(myScalarBar); } -void VISU_ScalarMapAct::RemoveFromRender(vtkRenderer* theRenderer){ - SALOME_Actor::RemoveFromRender(theRenderer); +void +VISU_ScalarMapAct +::RemoveFromRender(vtkRenderer* theRenderer) +{ if(myScalarBar) theRenderer->RemoveActor(myScalarBar); + + Superclass::RemoveFromRender(theRenderer); } -void VISU_ScalarMapAct::SetVisibility(int theMode){ - SALOME_Actor::SetVisibility(theMode); - if(myScalarBar) myScalarBar->SetVisibility(myBarVisibility && theMode); +void +VISU_ScalarMapAct +::SetVisibility(int theMode) +{ + Superclass::SetVisibility(theMode); + + if(myScalarBar) + myScalarBar->SetVisibility(myBarVisibility && theMode); } -int VISU_ScalarMapAct::GetVisibility(){ - return SALOME_Actor::GetVisibility(); +int +VISU_ScalarMapAct +::GetVisibility() +{ + return Superclass::GetVisibility(); } -void VISU_ScalarMapAct::SetBarVisibility(bool theMode){ +void +VISU_ScalarMapAct +::SetBarVisibility(bool theMode) +{ myBarVisibility = theMode; if(myScalarBar) myScalarBar->SetVisibility(myBarVisibility); } diff --git a/src/OBJECT/VISU_VectorsAct.cxx b/src/OBJECT/VISU_VectorsAct.cxx index 4cb16c27..e568a9d4 100644 --- a/src/OBJECT/VISU_VectorsAct.cxx +++ b/src/OBJECT/VISU_VectorsAct.cxx @@ -36,43 +36,68 @@ #include #include -using namespace std; - -//======================================================================= +//---------------------------------------------------------------------------- vtkStandardNewMacro(VISU_VectorsAct); -VISU_VectorsAct::VISU_VectorsAct(){} +//---------------------------------------------------------------------------- +VISU_VectorsAct +::VISU_VectorsAct(): + myVectorsPL(NULL) +{} -VISU_VectorsAct::~VISU_VectorsAct(){} +//---------------------------------------------------------------------------- +VISU_VectorsAct +::~VISU_VectorsAct() +{} -void VISU_VectorsAct::SetPipeLine(VISU_PipeLine* thePipeLine) { - if((myPipeLine = dynamic_cast(thePipeLine))){ - VISU_Actor::SetPipeLine(myPipeLine); - myPipeLine->Delete(); - } +//---------------------------------------------------------------------------- +void +VISU_VectorsAct +::SetPipeLine(VISU_PipeLine* thePipeLine) +{ + myVectorsPL = dynamic_cast(thePipeLine); + VISU_Actor::SetPipeLine(myVectorsPL); + myVectorsPL->Delete(); +} + + +//---------------------------------------------------------------------------- +vtkDataSet* +VISU_VectorsAct +::GetInput() +{ + return GetCurrentPL()->GetOutput(); } -void VISU_VectorsAct::SetTransform(VTKViewer_Transform* theTransform){ - myPipeLine->SetTransform(theTransform); - Modified(); +//---------------------------------------------------------------------------- +void +VISU_VectorsAct +::SetTransform(VTKViewer_Transform* theTransform) +{ + Superclass::SetTransform(theTransform); + myVectorsPL->SetTransform(theTransform); } -void VISU_VectorsAct::SetMapper(vtkMapper* theMapper){ +//---------------------------------------------------------------------------- +void +VISU_VectorsAct +::SetMapper(vtkMapper* theMapper) +{ if(theMapper){ myPassFilter[0]->SetInput(theMapper->GetInput()); - myPassFilter[0]->Update(); + myPassFilter[1]->SetInput(myPassFilter[0]->GetPolyDataOutput()); - myPassFilter[1]->Update(); + myPassFilter[2]->SetInput(myPassFilter[1]->GetPolyDataOutput()); - myPassFilter[2]->Update(); + myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput()); - myPassFilter[3]->Update(); + if(vtkDataSetMapper* aMapper = dynamic_cast(theMapper)) aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput()); else if(vtkPolyDataMapper* aMapper = dynamic_cast(theMapper)) diff --git a/src/OBJECT/VISU_VectorsAct.h b/src/OBJECT/VISU_VectorsAct.h index ae5bc694..921b0fc6 100644 --- a/src/OBJECT/VISU_VectorsAct.h +++ b/src/OBJECT/VISU_VectorsAct.h @@ -37,19 +37,32 @@ class VISU_VectorsPL; class VTKOCC_EXPORT VISU_VectorsAct : public VISU_ScalarMapAct { public: vtkTypeMacro(VISU_VectorsAct,VISU_ScalarMapAct); - static VISU_VectorsAct* New(); - ~VISU_VectorsAct(); - virtual void SetPipeLine(VISU_PipeLine* thePipeLine); + static + VISU_VectorsAct* + New(); + + virtual + void + SetPipeLine(VISU_PipeLine* thePipeLine); - virtual void SetTransform(VTKViewer_Transform* theTransform); + virtual + vtkDataSet* + GetInput(); - virtual void SetMapper(vtkMapper* theMapper); + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + virtual + void + SetMapper(vtkMapper* theMapper); protected: VISU_VectorsAct(); + ~VISU_VectorsAct(); - VISU_VectorsPL* myPipeLine; + VISU_VectorsPL* myVectorsPL; }; #endif diff --git a/src/PIPELINE/Makefile.in b/src/PIPELINE/Makefile.in index 5b46996d..8f775a80 100644 --- a/src/PIPELINE/Makefile.in +++ b/src/PIPELINE/Makefile.in @@ -32,44 +32,81 @@ VPATH=.:@srcdir@ @COMMENCE@ -EXPORT_HEADERS = VISU_PipeLine.hxx VISU_PipeLineUtils.hxx \ - VISU_MeshPL.hxx VISU_ScalarMapPL.hxx \ - VISU_CutPlanesPL.hxx VISU_CutLinesPL.hxx \ - VISU_IsoSurfacesPL.hxx VISU_DeformedShapePL.hxx \ - VISU_VectorsPL.hxx VISU_StreamLinesPL.hxx \ - VISU_LookupTable.hxx VISU_ScalarBarActor.hxx \ - VISU_Extractor.hxx VISU_FieldTransform.hxx \ - VISU_UsedPointsFilter.hxx VISU_Plot3DPL.hxx +EXPORT_HEADERS = \ + VISU_PipeLine.hxx \ + VISU_PipeLineUtils.hxx \ + VISU_MeshPL.hxx \ + VISU_ScalarMapPL.hxx \ + VISU_CutPlanesPL.hxx \ + VISU_CutLinesPL.hxx \ + VISU_IsoSurfacesPL.hxx \ + VISU_DeformedShapePL.hxx \ + VISU_VectorsPL.hxx \ + VISU_StreamLinesPL.hxx \ + VISU_LookupTable.hxx \ + VISU_ScalarBarActor.hxx \ + VISU_Extractor.hxx \ + VISU_FieldTransform.hxx \ + VISU_UsedPointsFilter.hxx \ + VISU_GaussPointsPL.hxx \ + VISU_Plot3DPL.hxx \ + VISU_OpenGLPointSpriteMapper.hxx \ + VISU_ImplicitFunctionWidget.hxx \ + SALOME_ExtractGeometry.h \ + VISU_ScalarBarCtrl.hxx \ + VISU_PlanesWidget.hxx \ + VISU_SphereWidget.hxx \ + VISU_WidgetCtrl.hxx \ + VISU_ScalarMapOnDeformedShapePL.hxx # Libraries targets LIB = libVisuPipeLine.la -LIB_SRC = VISU_PipeLine.cxx VISU_PipeLineUtils.cxx \ - VISU_MeshPL.cxx VISU_ScalarMapPL.cxx \ - VISU_CutPlanesPL.cxx VISU_CutLinesPL.cxx \ - VISU_IsoSurfacesPL.cxx VISU_DeformedShapePL.cxx \ - VISU_VectorsPL.cxx VISU_StreamLinesPL.cxx \ - VISU_LookupTable.cxx VISU_ScalarBarActor.cxx \ - VISU_Extractor.cxx VISU_FieldTransform.cxx \ - VISU_UsedPointsFilter.cxx VISU_Plot3DPL.cxx \ - SALOME_ExtractGeometry.cxx +LIB_SRC = \ + VISU_PipeLine.cxx \ + VISU_PipeLineUtils.cxx \ + VISU_MeshPL.cxx \ + VISU_ScalarMapPL.cxx \ + VISU_CutPlanesPL.cxx \ + VISU_CutLinesPL.cxx \ + VISU_IsoSurfacesPL.cxx \ + VISU_DeformedShapePL.cxx \ + VISU_VectorsPL.cxx \ + VISU_StreamLinesPL.cxx \ + VISU_LookupTable.cxx \ + VISU_ScalarBarActor.cxx \ + VISU_Extractor.cxx \ + VISU_FieldTransform.cxx \ + VISU_UsedPointsFilter.cxx \ + VISU_GaussPointsPL.cxx \ + VISU_Plot3DPL.cxx \ + SALOME_ExtractGeometry.cxx \ + VISU_OpenGLPointSpriteMapper.cxx \ + VISU_ImplicitFunctionWidget.cxx \ + VISU_PlanesWidget.cxx \ + VISU_SphereWidget.cxx \ + VISU_WidgetCtrl.cxx \ + VISU_ScalarBarCtrl.cxx \ + VISU_ScalarMapOnDeformedShapePL.cxx # Executables targets -BIN = VISUPipeLine +BIN = VISUPipeLine VISU_img2vti BIN_SRC = -CPPFLAGS+= $(VTK_INCLUDES) \ +CPPFLAGS+= \ + $(VTK_INCLUDES) \ -I${KERNEL_ROOT_DIR}/include/salome \ -I${GUI_ROOT_DIR}/include/salome \ -I${MED_ROOT_DIR}/include/salome \ $(HDF5_INCLUDES) $(BOOST_CPPFLAGS) -LDFLAGS+= $(VTK_LIBS) -lVTKViewer -lVisuConvertor \ +LDFLAGS+= \ + $(VTK_LIBS) -lVTKViewer -lVisuConvertor \ -L${KERNEL_ROOT_DIR}/lib/salome -lSALOMELocalTrace \ -L${GUI_ROOT_DIR}/lib/salome \ -L${MED_ROOT_DIR}/lib/salome -LDFLAGSFORBIN=$(LDFLAGS) -lOpUtil -lMEDWrapper -lMEDWrapper_V2_2 -lMEDWrapper_V2_1 -lMEDWrapperBase -lsuit -lqtx -lSALOMEBasics +LDFLAGSFORBIN=$(LDFLAGS) -lOpUtil -lMEDWrapper -lMEDWrapper_V2_2 -lMEDWrapper_V2_1 -lMEDWrapperBase -lmed_V2_1 -lsuit -lqtx -lSALOMEBasics @CONCLUDE@ diff --git a/src/PIPELINE/SALOME_ExtractGeometry.cxx b/src/PIPELINE/SALOME_ExtractGeometry.cxx index 13655093..5a1762e8 100755 --- a/src/PIPELINE/SALOME_ExtractGeometry.cxx +++ b/src/PIPELINE/SALOME_ExtractGeometry.cxx @@ -41,80 +41,158 @@ using namespace std; #endif +//---------------------------------------------------------------------------- vtkStandardNewMacro(SALOME_ExtractGeometry); -SALOME_ExtractGeometry::SALOME_ExtractGeometry() +//---------------------------------------------------------------------------- +SALOME_ExtractGeometry +::SALOME_ExtractGeometry(): + myStoreMapping(false), + myIsDoneShallowCopy(false) {} -SALOME_ExtractGeometry::~SALOME_ExtractGeometry() +SALOME_ExtractGeometry +::~SALOME_ExtractGeometry() {} -vtkIdType SALOME_ExtractGeometry::GetElemObjId(int theVtkID) + +//---------------------------------------------------------------------------- +unsigned long int +SALOME_ExtractGeometry +::GetMTime() { - if (myElemVTK2ObjIds.empty()) - return theVtkID; + unsigned long int aTime = vtkExtractGeometry::GetMTime(); + return aTime; +} - if (theVtkID < 0 || myElemVTK2ObjIds.size() <= theVtkID) - return -1; -#if defined __GNUC_2__ - return myElemVTK2ObjIds[theVtkID]; -#else - return myElemVTK2ObjIds.at(theVtkID); -#endif +//---------------------------------------------------------------------------- +vtkImplicitBoolean* +SALOME_ExtractGeometry +::GetImplicitBoolean() +{ + return myImplicitBoolean.GetPointer(); } -vtkIdType SALOME_ExtractGeometry::GetNodeObjId(int theVtkID) +void +SALOME_ExtractGeometry +::SetImplicitFunction(vtkImplicitFunction* theImplicitFunction) { - if (myNodeVTK2ObjIds.empty()) - return theVtkID; + myImplicitBoolean = dynamic_cast(theImplicitFunction); + vtkExtractGeometry::SetImplicitFunction(theImplicitFunction); +} - if (theVtkID < 0 || myNodeVTK2ObjIds.size() <= theVtkID) - return -1; -#if defined __GNUC_2__ - return myNodeVTK2ObjIds[theVtkID]; -#else - return myNodeVTK2ObjIds.at(theVtkID); -#endif +//---------------------------------------------------------------------------- +void +SALOME_ExtractGeometry +::SetStoreMapping(bool theStoreMapping) +{ + myStoreMapping = theStoreMapping; + Modified(); +} + +bool +SALOME_ExtractGeometry +::GetStoreMapping() const +{ + return myStoreMapping; } -void SALOME_ExtractGeometry::SetImplicitBoolean(vtkImplicitBoolean* theImplicitBoolean) +//---------------------------------------------------------------------------- +vtkIdType +SALOME_ExtractGeometry +::GetElemVTKId(vtkIdType theID) +{ + if(!myStoreMapping||myIsDoneShallowCopy){ + return theID; + } + vtkIdType iEnd = myElemVTK2ObjIds.size(); + for(vtkIdType i = 0; i < iEnd; i++) + if(myElemVTK2ObjIds[i] == theID) + return i; + + return -1; +} + +vtkIdType +SALOME_ExtractGeometry +::GetNodeVTKId(vtkIdType theID) { - myImplicitBoolean = theImplicitBoolean; - SetImplicitFunction(theImplicitBoolean); + if (!myStoreMapping||myIsDoneShallowCopy){ + return theID; + } + vtkIdType iEnd = myNodeVTK2ObjIds.size(); + for(vtkIdType i = 0; i < iEnd; i++) + if(myNodeVTK2ObjIds[i] == theID) + return i; + + return -1; } -void SALOME_ExtractGeometry::SetStoreMapping(bool theStoreMapping) +//---------------------------------------------------------------------------- +vtkIdType +SALOME_ExtractGeometry +::GetElemObjId(int theVtkID) { - myStoreMapping = theStoreMapping; - Modified(); + if (!myStoreMapping||myIsDoneShallowCopy){ + return theVtkID; + } + // + if (theVtkIDImplicitFunction; + + if(!myIsDoneShallowCopy && myImplicitBoolean.GetPointer()){ if(vtkImplicitFunctionCollection* aFunction = myImplicitBoolean->GetFunction()){ - if(aFunction->GetNumberOfItems() == 0){ - myElemVTK2ObjIds.clear(); - myNodeVTK2ObjIds.clear(); - - vtkDebugMacro(<< "Extracting geometry - ShallowCopy"); - GetOutput()->ShallowCopy(GetInput()); - Modified(); - return; - } + myIsDoneShallowCopy = aFunction->GetNumberOfItems() == 0; } } + + if(myIsDoneShallowCopy){ + GetOutput()->ShallowCopy(GetInput()); + Modified(); + return; + } + Execute2(); } -void SALOME_ExtractGeometry::Execute2() +void +SALOME_ExtractGeometry +::Execute2() { vtkIdType ptId, numPts, numCells, i, cellId, newCellId, newId, *pointMap; vtkIdList *cellPts; @@ -134,8 +212,6 @@ void SALOME_ExtractGeometry::Execute2() numCells = input->GetNumberOfCells(); numPts = input->GetNumberOfPoints(); - vtkDebugMacro(<< "Extracting geometry"); - if ( ! this->ImplicitFunction ) { vtkErrorMacro(<<"No implicit function specified"); @@ -171,9 +247,7 @@ void SALOME_ExtractGeometry::Execute2() vtkFloatArray *newScalars = NULL; if(myStoreMapping){ - myElemVTK2ObjIds.clear(); myElemVTK2ObjIds.reserve(numCells); - myNodeVTK2ObjIds.clear(); myNodeVTK2ObjIds.reserve(numPts); } @@ -186,7 +260,8 @@ void SALOME_ExtractGeometry::Execute2() { newId = newPts->InsertNextPoint(x); pointMap[ptId] = newId; - myNodeVTK2ObjIds.push_back(ptId); + if(myStoreMapping) + myNodeVTK2ObjIds.push_back(ptId); outputPD->CopyData(pd,ptId,newId); } } @@ -209,7 +284,8 @@ void SALOME_ExtractGeometry::Execute2() { newId = newPts->InsertNextPoint(x); pointMap[ptId] = newId; - myNodeVTK2ObjIds.push_back(ptId); + if(myStoreMapping) + myNodeVTK2ObjIds.push_back(ptId); outputPD->CopyData(pd,ptId,newId); } } @@ -262,7 +338,8 @@ void SALOME_ExtractGeometry::Execute2() x = input->GetPoint(ptId); newId = newPts->InsertNextPoint(x); pointMap[ptId] = newId; - myNodeVTK2ObjIds.push_back(ptId); + if(myStoreMapping) + myNodeVTK2ObjIds.push_back(ptId); outputPD->CopyData(pd,ptId,newId); } newCellPts->InsertId(i,pointMap[ptId]); @@ -273,7 +350,8 @@ void SALOME_ExtractGeometry::Execute2() if ( npts >= numCellPts || (this->ExtractBoundaryCells && npts > 0) ) { newCellId = output->InsertNextCell(cell->GetCellType(),newCellPts); - myElemVTK2ObjIds.push_back(cellId); + if(myStoreMapping) + myElemVTK2ObjIds.push_back(cellId); outputCD->CopyData(cd,cellId,newCellId); } }//for all cells diff --git a/src/PIPELINE/SALOME_ExtractGeometry.h b/src/PIPELINE/SALOME_ExtractGeometry.h index 74c1ec30..b225434f 100755 --- a/src/PIPELINE/SALOME_ExtractGeometry.h +++ b/src/PIPELINE/SALOME_ExtractGeometry.h @@ -22,11 +22,10 @@ #include #include -#include #include -//class vtkImplicitBoolean; +class vtkImplicitBoolean; class SALOME_ExtractGeometry : public vtkExtractGeometry { @@ -35,18 +34,37 @@ public: static SALOME_ExtractGeometry *New(); - void SetImplicitBoolean(vtkImplicitBoolean* theImplicitBoolean); - vtkImplicitBoolean* GetImplicitBoolean() const { - return myImplicitBoolean.GetPointer(); - } + virtual + void + SetImplicitFunction(vtkImplicitFunction* theImplicitFunction); - void SetStoreMapping(bool theStoreMapping); - bool GetStoreMapping() const { - return myStoreMapping; - } + virtual + unsigned long int + GetMTime(); - virtual vtkIdType GetNodeObjId(int theID); - virtual vtkIdType GetElemObjId(int theID); + vtkImplicitBoolean* + GetImplicitBoolean(); + + bool + GetStoreMapping() const; + void + SetStoreMapping(bool theStoreMapping); + + virtual + vtkIdType + GetNodeObjId(vtkIdType theID); + + virtual + vtkIdType + GetElemObjId(vtkIdType theID); + + virtual + vtkIdType + GetNodeVTKId(vtkIdType theID); + + virtual + vtkIdType + GetElemVTKId(vtkIdType theID); protected: SALOME_ExtractGeometry(); @@ -57,6 +75,7 @@ protected: private: bool myStoreMapping; + bool myIsDoneShallowCopy; typedef std::vector TVectorId; TVectorId myElemVTK2ObjIds; TVectorId myNodeVTK2ObjIds; diff --git a/src/PIPELINE/VISUPipeLine.cxx b/src/PIPELINE/VISUPipeLine.cxx index e1f35eaa..d1ac8fe3 100644 --- a/src/PIPELINE/VISUPipeLine.cxx +++ b/src/PIPELINE/VISUPipeLine.cxx @@ -33,15 +33,17 @@ #include "VISU_DeformedShapePL.hxx" #include "VISU_VectorsPL.hxx" #include "VISU_StreamLinesPL.hxx" +#include "VISU_GaussPointsPL.hxx" #include "VISU_Plot3DPL.hxx" -typedef VISU_Plot3DPL TPresent; +typedef VISU_GaussPointsPL TPresent; #include #include #include #include +#include #include #include #include @@ -64,6 +66,9 @@ int main(int argc, char** argv){ vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); VISU_Convertor* aConvertor = CreateConvertor(argv[1]); + aConvertor->BuildEntities(); + aConvertor->BuildFields(); + aConvertor->BuildMinMax(); const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap(); VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); if(aMeshMapIter == aMeshMap.end()) return 0; @@ -74,7 +79,10 @@ int main(int argc, char** argv){ if(isOnlyMesh){ const VISU::TEntity& anEntity = VISU::CELL_ENTITY; aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity); - vtkUnstructuredGrid* aDataSet = aConvertor->GetMeshOnEntity(aMeshName,anEntity); + + VISU::PIDMapper anIDMapper = + aConvertor->GetMeshOnEntity(aMeshName,anEntity); + VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); VISU_MeshPL* aPresent = VISU_MeshPL::New(); aPresent->SetInput(aDataSet); @@ -100,23 +108,43 @@ int main(int argc, char** argv){ VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ const VISU::PField aField = aFieldMapIter->second; - if(aField->myNbComp == 1) continue; + /* + if(aField->myNbComp == 1) + continue; + */ const string& aFieldName = aFieldMapIter->first; const VISU::TValField& aValField = aField->myValField; VISU::TValField::const_iterator aValFieldIter = aValField.begin(); if(aValFieldIter == aValField.end()) return 0; int aTimeStamp = aValFieldIter->first; - vtkUnstructuredGrid* aDataSet = aConvertor->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); TPresent* aPresent = TPresent::New(); - aPresent->SetInput(aDataSet); + VISU::PIDMapper anIDMapper; + if(anEntity != VISU::NODE_ENTITY){ + VISU::PGaussPtsIDMapper aGaussPtsIDMapper = aConvertor->GetTimeStampOnGaussPts(aMeshName,anEntity,aFieldName,aTimeStamp); + aPresent->SetGaussPtsIDMapper(aGaussPtsIDMapper); + }else{ + continue; + VISU::PIDMapper anIDMapper = aConvertor->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); + aPresent->SetIDMapper(anIDMapper); + } + aPresent->Build(); aPresent->Init(); - aPresent->SetSourceRange(); - //aPresent->SetNumberOfContours(50); - //aPresent->SetNbParts(1); - //aPresent->SetOrientation(VISU_CutPlanesPL::XY,0.0,0.0); - //aPresent->SetScaling(VTK_SCALE_LOG10); + + char aMainTexture[80]; + strcpy( aMainTexture, getenv( "VISU_ROOT_DIR" ) ); + strcat( aMainTexture, "/share/salome/resources/sprite_texture.vti" ); + //cout << aMainTexture << endl; + + char anAlphaTexture[80]; + strcpy( anAlphaTexture, getenv( "VISU_ROOT_DIR" ) ); + strcat( anAlphaTexture, "/share/salome/resources/sprite_alpha.vti" ); + //cout << anAlphaTexture << endl; + + vtkSmartPointer aTextureValue = VISU_GaussPointsPL::MakeTexture( aMainTexture, anAlphaTexture ); + aPresent->SetImageData( aTextureValue.GetPointer() ); + aPresent->Update(); vtkActor* anActor = vtkActor::New(); @@ -125,8 +153,6 @@ int main(int argc, char** argv){ VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New(); aScalarBar->SetLookupTable(aPresent->GetBarTable()); - aPresent->Build(); - ren->AddActor(anActor); ren->AddActor2D(aScalarBar); diff --git a/src/PIPELINE/VISU_CutLinesPL.cxx b/src/PIPELINE/VISU_CutLinesPL.cxx index eb7b71d2..b518dfad 100644 --- a/src/PIPELINE/VISU_CutLinesPL.cxx +++ b/src/PIPELINE/VISU_CutLinesPL.cxx @@ -37,7 +37,6 @@ vtkStandardNewMacro(VISU_CutLinesPL); VISU_CutLinesPL::VISU_CutLinesPL(){} void VISU_CutLinesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ - VISU_CutPlanesPL::ShallowCopy(thePipeLine); if(VISU_CutLinesPL *aPipeLine = dynamic_cast(thePipeLine)){ SetOrientation(aPipeLine->GetPlaneOrientation(1), aPipeLine->GetRotateX(1),aPipeLine->GetRotateY(1),1); @@ -45,6 +44,7 @@ void VISU_CutLinesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ SetDefault(); if (!aPipeLine->IsDefault()) SetPosition(aPipeLine->GetPosition()); } + VISU_CutPlanesPL::ShallowCopy(thePipeLine); } void VISU_CutLinesPL::Init(){ diff --git a/src/PIPELINE/VISU_CutPlanesPL.cxx b/src/PIPELINE/VISU_CutPlanesPL.cxx index 32fb5612..63dd3e5a 100644 --- a/src/PIPELINE/VISU_CutPlanesPL.cxx +++ b/src/PIPELINE/VISU_CutPlanesPL.cxx @@ -49,7 +49,6 @@ VISU_CutPlanesPL::~VISU_CutPlanesPL(){ } void VISU_CutPlanesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ - VISU_ScalarMapPL::ShallowCopy(thePipeLine); if(VISU_CutPlanesPL *aPipeLine = dynamic_cast(thePipeLine)){ SetOrientation(aPipeLine->GetPlaneOrientation(), aPipeLine->GetRotateX(),aPipeLine->GetRotateY()); @@ -58,6 +57,7 @@ void VISU_CutPlanesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ for (int i = 0, iend = GetNbParts(); i < iend; i++) if(!aPipeLine->IsPartDefault(i)) SetPartPosition(i, aPipeLine->GetPartPosition(i)); } + VISU_ScalarMapPL::ShallowCopy(thePipeLine); } void VISU_CutPlanesPL::Init(){ diff --git a/src/PIPELINE/VISU_DeformedShapePL.cxx b/src/PIPELINE/VISU_DeformedShapePL.cxx index c276548d..0b8e3462 100644 --- a/src/PIPELINE/VISU_DeformedShapePL.cxx +++ b/src/PIPELINE/VISU_DeformedShapePL.cxx @@ -47,10 +47,10 @@ VISU_DeformedShapePL::~VISU_DeformedShapePL(){ } void VISU_DeformedShapePL::ShallowCopy(VISU_PipeLine *thePipeLine){ - VISU_ScalarMapPL::ShallowCopy(thePipeLine); if(VISU_DeformedShapePL *aPipeLine = dynamic_cast(thePipeLine)){ SetScale(aPipeLine->GetScale()); } + VISU_ScalarMapPL::ShallowCopy(thePipeLine); } float VISU_DeformedShapePL::GetScaleFactor(vtkDataSet* theDataSet){ @@ -74,20 +74,27 @@ float VISU_DeformedShapePL::GetScaleFactor(vtkDataSet* theDataSet){ void VISU_DeformedShapePL::SetScale(float theScale) { - if(myScaleFactor == theScale) return; + myWarpVector->SetScaleFactor(theScale); myScaleFactor = theScale; - myWarpVector->SetScaleFactor(myScaleFactor); Modified(); } float VISU_DeformedShapePL::GetScale() { - return myWarpVector->GetScaleFactor(); + return myScaleFactor; } void VISU_DeformedShapePL::Init(){ VISU_ScalarMapPL::Init(); float aScalarRange[2]; GetSourceRange(aScalarRange); - SetScale(GetScaleFactor(GetInput2())/aScalarRange[1]); + + vtkDataSet* aDataSet = GetInput2(); + float aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet ); + + static double EPS = 1.0 / VTK_LARGE_FLOAT; + if(fabs(aScalarRange[1]) > EPS) + SetScale(aScaleFactor / aScalarRange[1]); + else + SetScale(0.0); } VISU_ScalarMapPL::THook* VISU_DeformedShapePL::DoHook(){ diff --git a/src/PIPELINE/VISU_Extractor.cxx b/src/PIPELINE/VISU_Extractor.cxx index f4bcfabb..b6423a39 100644 --- a/src/PIPELINE/VISU_Extractor.cxx +++ b/src/PIPELINE/VISU_Extractor.cxx @@ -33,53 +33,64 @@ #include #include #include +#include using namespace std; vtkStandardNewMacro(VISU_Extractor); -VISU_Extractor::VISU_Extractor(){ - myScalarMode = 0; +VISU_Extractor::VISU_Extractor() +{ + myScalarMode = 1; } -VISU_Extractor::~VISU_Extractor(){ -} +VISU_Extractor::~VISU_Extractor() +{} -void VISU_Extractor::SetScalarMode(int theScalarMode){ +void VISU_Extractor::SetScalarMode(int theScalarMode) +{ if(myScalarMode != theScalarMode){ myScalarMode = theScalarMode; Modified(); } } - template void -execute(int theNbComp, int theScalarMode, TypeData* theInputData, TypeData* theOutputData){ - vtkDataArray *inVectors = theInputData->GetVectors(); - if ( !inVectors || theNbComp < 1 ) +execute(int theNbElems, + int theScalarMode, + TypeData* theInputData, + TypeData* theOutputData) +{ + if(theNbElems < 1 ) return; - vtkFloatArray *newScalars = vtkFloatArray::New(); - ostringstream aName; - aName<GetName(); aName<<", "; aName<SetName(aName.str().c_str()); - newScalars->SetNumberOfComponents(1); - newScalars->SetNumberOfTuples(theNbComp); - for (int ptId = 0; ptId < theNbComp; ptId++) { - float v[3], s; - inVectors->GetTuple(ptId,v); - if ( theScalarMode < 1 || theScalarMode > 3) - s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); - else - s = v[theScalarMode - 1]; - newScalars->SetTuple1(ptId, s); + vtkDataArray* aFieldArray = theInputData->GetArray("VISU_FIELD"); + if(vtkFloatArray *aFloatArray = dynamic_cast(aFieldArray)){ + int aNbComp = aFloatArray->GetNumberOfComponents(); + std::vector anArray(aNbComp < 3? 3: aNbComp); + // + vtkFloatArray *aScalars = vtkFloatArray::New(); + aScalars->SetNumberOfTuples(theNbElems); + aScalars->SetNumberOfComponents(1); + // + if(!theScalarMode){ + for(int anId = 0; anId < theNbElems; anId++){ + aFloatArray->GetTuple(anId,&anArray[0]); + float aVector[3] = {anArray[0], anArray[1], anArray[2]}; + float aScalar = sqrt(aVector[0]*aVector[0] + aVector[1]*aVector[1] + aVector[2]*aVector[2]); + aScalars->SetTuple1(anId,aScalar); + } + }else{ + for(int anId = 0; anId < theNbElems; anId++){ + aFloatArray->GetTuple(anId,&anArray[0]); + aScalars->SetTuple1(anId,anArray[theScalarMode - 1]); + } + } + theOutputData->SetScalars(aScalars); + aScalars->Delete(); } - theOutputData->SetScalars(newScalars); - //theOutputData->SetActiveScalars(newScalars->GetName()); - newScalars->Delete(); } - void VISU_Extractor::Execute(){ vtkDataSet *input = this->GetInput(), *output = this->GetOutput(); output->CopyStructure(input); @@ -87,21 +98,23 @@ void VISU_Extractor::Execute(){ output->GetCellData()->CopyAllOff(); if(input->GetPointData()->GetNumberOfArrays()){ output->GetPointData()->CopyVectorsOn(); - int nbComp = input->GetNumberOfPoints(); + int aNbElems = input->GetNumberOfPoints(); vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData(); if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) - execute(nbComp,myScalarMode,inData,outData); + execute(aNbElems,myScalarMode,inData,outData); else output->GetPointData()->CopyScalarsOn(); outData->PassData(inData); + outData->AddArray(inData->GetArray("VISU_FIELD")); }else{ output->GetCellData()->CopyVectorsOn(); - int nbComp = input->GetNumberOfCells(); + int aNbElems = input->GetNumberOfCells(); vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData(); if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) - execute(nbComp,myScalarMode,inData,outData); + execute(aNbElems,myScalarMode,inData,outData); else output->GetCellData()->CopyScalarsOn(); outData->PassData(inData); + outData->AddArray(inData->GetArray("VISU_FIELD")); } } diff --git a/src/PIPELINE/VISU_FieldTransform.cxx b/src/PIPELINE/VISU_FieldTransform.cxx index 5fd70742..82081859 100644 --- a/src/PIPELINE/VISU_FieldTransform.cxx +++ b/src/PIPELINE/VISU_FieldTransform.cxx @@ -15,67 +15,124 @@ #include #include +static float Tolerance = 1.0 / VTK_LARGE_FLOAT; + using namespace std; vtkStandardNewMacro(VISU_FieldTransform); -double VISU_FieldTransform::Ident(double theArg){ +double +VISU_FieldTransform +::Ident(double theArg) +{ return theArg; } -double VISU_FieldTransform::Log10(double theArg){ - if(theArg <= 0.0) return -VTK_LARGE_FLOAT; + +double +VISU_FieldTransform +::Log10(double theArg) +{ + if(theArg <= 0.0) + return -VTK_LARGE_FLOAT; + return log10(theArg); } -VISU_FieldTransform::VISU_FieldTransform(){ +VISU_FieldTransform +::VISU_FieldTransform() +{ myFunction = &Ident; myTransform = NULL; + + myScalarRange[0] = VTK_LARGE_FLOAT; + myScalarRange[1] = -VTK_LARGE_FLOAT; } -VISU_FieldTransform::~VISU_FieldTransform() { +VISU_FieldTransform +::~VISU_FieldTransform() +{ SetSpaceTransform(NULL); } -void VISU_FieldTransform::Update(){ - if(myTransform && myTransform->GetMTime() > vtkSource::GetMTime()) - Modified(); +void +VISU_FieldTransform +::Update() +{ vtkSource::Update(); } -unsigned long VISU_FieldTransform::GetMTime(){ - if(myTransform && myTransform->GetMTime() > vtkSource::GetMTime()) - return myTransform->GetMTime(); - return vtkSource::GetMTime(); +unsigned long +VISU_FieldTransform +::GetMTime() +{ + unsigned long aTime = Superclass::GetMTime(); + if(myTransform) + aTime = max(aTime,myTransform->GetMTime()); + + return aTime; } -void VISU_FieldTransform::SetScalarTransform(TTransformFun theFunction) { +void +VISU_FieldTransform +::SetScalarTransform(TTransformFun theFunction) +{ + if(myFunction == theFunction) + return; + + if(theFunction == NULL) + theFunction = &Ident; + myFunction = theFunction; - if(myFunction == NULL) myFunction = &Ident; + Modified(); } void VISU_FieldTransform::SetSpaceTransform(VTKViewer_Transform* theTransform){ - if(myTransform != theTransform){ - if (myTransform != NULL) myTransform->UnRegister(this); - myTransform = theTransform; - if (myTransform != NULL) myTransform->Register(this); - this->Modified(); - } + if(myTransform == theTransform) + return; + + if(myTransform != NULL) + myTransform->UnRegister(this); + + myTransform = theTransform; + + if(theTransform != NULL) + theTransform->Register(this); + + Modified(); } -void VISU_FieldTransform::SetScalarRange(float theScalarRange[2]) { +void +VISU_FieldTransform +::SetScalarRange(float theScalarRange[2]) +{ + float aDelta = + fabs(myScalarRange[0] - theScalarRange[0]) + + fabs(myScalarRange[1] - theScalarRange[1]); + if(aDelta < Tolerance) + return; + myScalarRange[0] = theScalarRange[0]; myScalarRange[1] = theScalarRange[1]; + Modified(); } -void VISU_FieldTransform::SetScalarMin(float theValue){ + +void +VISU_FieldTransform +::SetScalarMin(float theValue) +{ float aScalarRange[2] = {theValue, GetScalarRange()[1]}; SetScalarRange(aScalarRange); } -void VISU_FieldTransform::SetScalarMax(float theValue){ + +void +VISU_FieldTransform +::SetScalarMax(float theValue) +{ float aScalarRange[2] = {GetScalarRange()[0], theValue}; SetScalarRange(aScalarRange); } @@ -84,67 +141,84 @@ void VISU_FieldTransform::SetScalarMax(float theValue){ template void ExecVectors(VISU_FieldTransform::TTransformFun theFunction, VTKViewer_Transform* theTransform, - float theScalarRange[2], int theNbComponent, - TypeData* theInputData, TypeData* theOutputData) + float theScalarRange[2], + int theNbOfTuples, + TypeData* theInputData, + TypeData* theOutputData) { - vtkDataArray *inVectors = theInputData->GetVectors(); - if ( !inVectors || theNbComponent < 1 ) return; - vtkFloatArray *newVectors = vtkFloatArray::New(); - newVectors->SetNumberOfComponents(3); - newVectors->SetNumberOfTuples(theNbComponent); + vtkDataArray *anInVectors = theInputData->GetVectors(); + if ( !anInVectors || theNbOfTuples < 1 ) + return; + vtkFloatArray *aNewVectors = vtkFloatArray::New(); + aNewVectors->SetNumberOfComponents(3); + aNewVectors->SetNumberOfTuples(theNbOfTuples); float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])}; - float *V, v[3], vMag, aDelta = aScalarRange[1] - aScalarRange[0]; + float aDelta = aScalarRange[1] - aScalarRange[0]; float aScale[3] = {1.0, 1.0, 1.0}; + static float EPS = 1.0 / VTK_LARGE_FLOAT; if(theTransform){ aScale[0] = theTransform->GetScale()[0]; aScale[1] = theTransform->GetScale()[1]; aScale[2] = theTransform->GetScale()[2]; } if(theFunction == &(VISU_FieldTransform::Ident)){ - for (int ptId = 0; ptId < theNbComponent; ptId++) { - V = inVectors->GetTuple3(ptId); - v[0] = V[0]*aScale[0]; - v[1] = V[1]*aScale[1]; - v[2] = V[2]*aScale[2]; - newVectors->SetTuple3(ptId, v[0], v[1], v[2]); + for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { + float anInVec[3]; + anInVectors->GetTuple(aTupleId,anInVec); + float anNewVec[3]; + anNewVec[0] = anInVec[0]*aScale[0]; + anNewVec[1] = anInVec[1]*aScale[1]; + anNewVec[2] = anInVec[2]*aScale[2]; + aNewVectors->SetTuple(aTupleId,anNewVec); } }else{ - for (int ptId = 0; ptId < theNbComponent; ptId++) { - V = inVectors->GetTuple3(ptId); - vMag = vtkMath::Norm(V); - vMag = ((*theFunction)(vMag) - aScalarRange[0]) / aDelta * theScalarRange[1] / vMag; - if(vMag <= 0.0) vMag = 0.0; - v[0] = V[0]*vMag*aScale[0]; - v[1] = V[1]*vMag*aScale[1]; - v[2] = V[2]*vMag*aScale[2]; - newVectors->SetTuple3(ptId, v[0], v[1], v[2]); + for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { + float anInVec[3]; + anInVectors->GetTuple(aTupleId,anInVec); + float aMagn = vtkMath::Norm(anInVec); + if(aMagn > EPS) + aMagn = ((*theFunction)(aMagn) - aScalarRange[0]) / aDelta * theScalarRange[1] / aMagn; + if(aMagn < 0.0) + aMagn = 0.0; + float anNewVec[3]; + anNewVec[0] = anInVec[0]*aMagn*aScale[0]; + anNewVec[1] = anInVec[1]*aMagn*aScale[1]; + anNewVec[2] = anInVec[2]*aMagn*aScale[2]; + aNewVectors->SetTuple(aTupleId,anNewVec); } } - theOutputData->SetVectors(newVectors); - newVectors->Delete(); + theOutputData->SetVectors(aNewVectors); + aNewVectors->Delete(); } template void -ExecScalars(VISU_FieldTransform::TTransformFun theFunction, float theScalarRange[2], - int theNbComponent, TypeData* theInputData, TypeData* theOutputData) +ExecScalars(VISU_FieldTransform::TTransformFun theFunction, + float theScalarRange[2], + int theNbOfTuples, + TypeData* theInputData, + TypeData* theOutputData) { - vtkDataArray *inScalars = theInputData->GetScalars(); - if ( !inScalars || theNbComponent < 1 ) + vtkDataArray *anInScalars = theInputData->GetScalars(); + if ( !anInScalars || theNbOfTuples < 1 ) return; - vtkFloatArray *newScalars = vtkFloatArray::New(); - newScalars->SetNumberOfComponents(1); - newScalars->SetNumberOfTuples(theNbComponent); + vtkFloatArray *aNewScalars = vtkFloatArray::New(); + aNewScalars->SetNumberOfComponents(1); + aNewScalars->SetNumberOfTuples(theNbOfTuples); float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])}; - for (int ptId = 0; ptId < theNbComponent; ptId++) { - float s = (*theFunction)(inScalars->GetTuple1(ptId )); - if(s < aScalarRange[0]) s = aScalarRange[0]; - newScalars->SetTuple1(ptId, s); + for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { + float aScalar = (*theFunction)(anInScalars->GetTuple1(aTupleId)); + if(aScalar < aScalarRange[0]) + aScalar = aScalarRange[0]; + aNewScalars->SetTuple1(aTupleId,aScalar); } - theOutputData->SetScalars(newScalars); - newScalars->Delete(); + theOutputData->SetScalars(aNewScalars); + aNewScalars->Delete(); } -void VISU_FieldTransform::Execute(){ +void +VISU_FieldTransform +::Execute() +{ vtkDataSet *input = this->GetInput(), *output = this->GetOutput(); output->CopyStructure(input); if(myFunction != &Ident || (myTransform && !myTransform->IsIdentity())){ diff --git a/src/PIPELINE/VISU_GaussPointsPL.cxx b/src/PIPELINE/VISU_GaussPointsPL.cxx new file mode 100644 index 00000000..8d1d0dff --- /dev/null +++ b/src/PIPELINE/VISU_GaussPointsPL.cxx @@ -0,0 +1,699 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File: VISU_GaussPoints.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_GaussPointsPL.hxx" +#include "VISU_DeformedShapePL.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "SALOME_ExtractGeometry.h" +#include "VISU_DeformedShapePL.hxx" +#include "VISU_OpenGLPointSpriteMapper.hxx" +#include "VTKViewer_PassThroughFilter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(VISU_GaussPointsPL); + +//---------------------------------------------------------------------------- +VISU_GaussPointsPL +::VISU_GaussPointsPL(): + myIsDeformed(false), + myScaleFactor(0.0), + myResolution( 8 ), + myMagnificationIncrement(2) +{ + myExtractGeometry->SetExtractInside(0); + + myPSMapper = VISU_OpenGLPointSpriteMapper::New(); + myPSMapper->SetColorModeToMapScalars(); + myPSMapper->ScalarVisibilityOn(); + + myGeomFilter = vtkGeometryFilter::New(); + + myWarpVector = vtkWarpVector::New(); + myCellDataToPointData = vtkCellDataToPointData::New(); + myCellDataToPointData->SetPassCellData(true); + + myGlyph = vtkGlyph3D::New(); + myGlyph->SetScaleModeToScaleByScalar(); + myGlyph->SetColorModeToColorByScalar(); + myGlyph->ClampingOn(); + + myExtractor->SetInput( myExtractGeometry->GetOutput() ); + myFieldTransform->SetInput( myExtractor->GetOutput() ); + + myCellDataToPointData->SetInput( myFieldTransform->GetUnstructuredGridOutput() ); + + mySphereSource = vtkSphereSource::New(); + myGlyph->SetSource( mySphereSource->GetOutput() ); + + for(int i = 0; i < 2; i++) + myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); +} + + +//---------------------------------------------------------------------------- +VISU_GaussPointsPL +::~VISU_GaussPointsPL() +{ + if (this->myPSMapper) + { + this->myPSMapper->Delete(); + this->myPSMapper = NULL; + } + if (this->myGeomFilter) + { + this->myGeomFilter->Delete(); + this->myGeomFilter = NULL; + } + + myWarpVector->Delete(); + + myCellDataToPointData->Delete(); + + myGlyph->Delete(); + + mySphereSource->Delete(); + + for(int i = 0; i < 2; i++) + myPassFilter[i]->Delete(); +} + + +//---------------------------------------------------------------------------- +void +CopyGlyph( vtkGlyph3D* source, vtkGlyph3D* dest ) +{ + dest->SetRange( source->GetRange() ); + dest->SetScaling( source->GetScaling() ); + dest->SetClamping( source->GetClamping() ); + dest->SetScaleMode( source->GetScaleMode() ); + dest->SetColorMode( source->GetColorMode() ); + dest->SetScaleFactor( source->GetScaleFactor() ); +} + + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::ShallowCopy(VISU_PipeLine *thePipeLine) +{ + if(VISU_GaussPointsPL *aPipeLine = dynamic_cast(thePipeLine)){ + // To restore mapper input from pipeline + vtkPolyData* aDatsSet = myPSMapper->GetInput(); + myPSMapper->ShallowCopy(aPipeLine->GetPSMapper()); + myPSMapper->SetInput(aDatsSet); + + SetPrimitiveType(aPipeLine->GetPrimitiveType()); + SetBicolor(aPipeLine->GetBicolor()); + SetClamp(aPipeLine->GetClamp()); + SetSize(aPipeLine->GetSize()); + SetMinSize(aPipeLine->GetMinSize()); + SetMaxSize(aPipeLine->GetMaxSize()); + SetMagnification(aPipeLine->GetMagnification()); + SetMagnificationIncrement(aPipeLine->GetMagnificationIncrement()); + SetAlphaThreshold(aPipeLine->GetAlphaThreshold()); + SetResolution(aPipeLine->GetResolution()); + + SetIsDeformed( aPipeLine->GetIsDeformed() ); + SetScale( aPipeLine->GetScale() ); + + mySphereSource->SetRadius( aPipeLine->mySphereSource->GetRadius() ); + CopyGlyph( aPipeLine->myGlyph, this->myGlyph ); + } + Superclass::ShallowCopy(thePipeLine); +} + + +//---------------------------------------------------------------------------- +VISU_PipeLine::TMapper* +VISU_GaussPointsPL +::GetMapper() +{ + return GetPSMapper(); +} + +VISU_OpenGLPointSpriteMapper* +VISU_GaussPointsPL +::GetPSMapper() +{ + if(GetInput()){ + if(!myPSMapper->GetInput()){ + GetInput2()->Update(); + Build(); + Init(); + } + myPSMapper->Update(); + } + return myPSMapper; +} + +vtkDataSet* +VISU_GaussPointsPL +::GetPickableDataSet() +{ + return myGeomFilter->GetOutput(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::Init() +{ + Superclass::Init(); + + vtkDataSet* aDataSet = GetParentMesh(); + float aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet ); + + float* aScalarRange = GetScalarRange(); + static double EPS = 1.0 / VTK_LARGE_FLOAT; + if(fabs(aScalarRange[1]) > EPS) + SetScale( aScaleFactor / aScalarRange[1] ); + else + SetScale(0.0); + + // Deformed Shape + myPassFilter[0]->SetInput(myCellDataToPointData->GetUnstructuredGridOutput()); + + myGeomFilter->SetInput( myPassFilter[0]->GetOutput() ); + + // Geometrical Sphere + myPassFilter[1]->SetInput(myGeomFilter->GetOutput()); + + myPSMapper->SetInput( myPassFilter[1]->GetPolyDataOutput() ); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::Build() +{ +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::Update() +{ + //cout << "VISU_GaussPointsPL::Update()" << endl; + float* aScalarRange = GetScalarRange(); + mySourceScalarRange[0] = aScalarRange[0]; + mySourceScalarRange[1] = aScalarRange[1]; + myDeltaScalarRange = aScalarRange[1] - aScalarRange[0]; + + SetAverageCellSize( VISU_DeformedShapePL::GetScaleFactor( GetParentMesh() ) ); + + vtkMapper* aMapper = GetMapper(); + vtkDataSet* aDataSet = aMapper->GetInput(); + vtkCellData* aCellData = aDataSet->GetCellData(); + myScalarArray = aCellData->GetScalars(); + + myPSMapper->SetLookupTable( myMapperTable ); + myPSMapper->SetScalarRange( aScalarRange ); + + this->UpdateGlyph(); + + VISU_ScalarMapPL::Update(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::UpdateGlyph() +{ + //cout << "VISU_GaussPointsPL::UpdateGlyph()" << endl; + + float* aScalarRange = GetScalarRange(); + + if( myPSMapper->GetPointSpriteMode() == 0 ) // Results + { + //cout << "Results" << endl; + myGlyph->ClampingOn(); + myGlyph->SetScaleModeToScaleByScalar(); + myGlyph->SetColorModeToColorByScalar(); + + float aRange = 0; + float aMinSize = GetMinSize(); + float aMaxSize = GetMaxSize(); + if( fabs( aMaxSize - aMinSize ) > 0.0001 ) + aRange = ( aScalarRange[1] - aScalarRange[0] ) / ( aMaxSize - aMinSize ); + float aMinRange = aScalarRange[0] - aMinSize * aRange; + float aMaxRange = aMinRange + aRange; + + myGlyph->SetRange( aMinRange, aMaxRange ); + myGlyph->SetScaleFactor( 1.0 ); + } + else if( myPSMapper->GetPointSpriteMode() == 1 ) // Geometry + { + //cout << "Geometry" << endl; + myGlyph->ClampingOff(); + myGlyph->SetScaleModeToDataScalingOff(); + myGlyph->SetColorModeToColorByScale(); + + myGlyph->SetScaleFactor( GetSize() ); + } + else if( myPSMapper->GetPointSpriteMode() == 2 ) // Outside + { + //cout << "Outside" << endl; + myGlyph->ClampingOff(); + myGlyph->SetScaleModeToDataScalingOff(); + myGlyph->SetColorModeToColorByScalar(); + + myGlyph->SetScaleFactor( GetSize() ); + } + + mySphereSource->SetRadius( GetMagnification() * GetAverageCellSize() / 2. ); +} + +//---------------------------------------------------------------------------- +VISU::TGaussPointID +VISU_GaussPointsPL +::GetObjID(vtkIdType theID) const +{ + return myGaussPtsIDMapper->GetObjID(theID); +} + +float* +VISU_GaussPointsPL +::GetNodeCoord(int theObjID) +{ + vtkIdType anID = GetNodeVTKID(theObjID); + vtkDataSet* aDataSet = myGeomFilter->GetInput(); + return aDataSet->GetPoint(anID); +} + +void +VISU_GaussPointsPL +::SetGaussPtsIDMapper(const VISU::PGaussPtsIDMapper& theGaussPtsIDMapper) +{ + myGaussPtsIDMapper = theGaussPtsIDMapper; + SetIDMapper(myGaussPtsIDMapper); +} + +const VISU::PGaussPtsIDMapper& +VISU_GaussPointsPL +::GetGaussPtsIDMapper() const +{ + return myGaussPtsIDMapper; +} + +VISU::TVTKOutput* +VISU_GaussPointsPL +::GetParentMesh() const +{ + VISU::TNamedIDMapper* aNamedIDMapper = myGaussPtsIDMapper->GetParent(); + return aNamedIDMapper->GetVTKOutput(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetIsDeformed( bool theIsDeformed ) +{ + if( theIsDeformed ) + { + myWarpVector->SetInput( myCellDataToPointData->GetUnstructuredGridOutput() ); + myPassFilter[0]->SetInput(myWarpVector->GetOutput()); + } + else + myPassFilter[0]->SetInput(myCellDataToPointData->GetUnstructuredGridOutput()); + + myIsDeformed = theIsDeformed; + + Modified(); +} + +//---------------------------------------------------------------------------- +bool +VISU_GaussPointsPL +::GetIsDeformed() const +{ + return myIsDeformed; +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetBicolor(bool theBicolor) +{ + if(GetBicolor() == theBicolor) + return; + + myMapperTable->SetBicolor( theBicolor ); + myBarTable->SetBicolor( theBicolor ); + + Modified(); +} + +//---------------------------------------------------------------------------- +bool +VISU_GaussPointsPL +::GetBicolor() +{ + return myMapperTable->GetBicolor(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetIsColored(bool theIsColored) +{ + myPSMapper->SetPointSpriteMode( theIsColored ? 0 : 1 ); // Results / Geometry + Modified(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetPrimitiveType(int thePrimitiveType) +{ + if( thePrimitiveType == VISU_OpenGLPointSpriteMapper::GeomSphere ) + { + myGlyph->SetInput( myGeomFilter->GetOutput() ); + myPassFilter[1]->SetInput(myGlyph->GetOutput()); + } + else + myPassFilter[1]->SetInput(myGeomFilter->GetOutput()); + + myPSMapper->SetPrimitiveType( thePrimitiveType ); + + Modified(); +} + +//---------------------------------------------------------------------------- +int +VISU_GaussPointsPL +::GetPrimitiveType() +{ + return myPSMapper->GetPrimitiveType(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetMaximumSupportedSize() +{ + return myPSMapper->GetMaximumSupportedSize(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetClamp(float theClamp) +{ + myPSMapper->SetPointSpriteClamp( theClamp ); + Modified(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetClamp() +{ + return myPSMapper->GetPointSpriteClamp(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetSize(float theSize) +{ + myPSMapper->SetPointSpriteSize( theSize ); + Modified(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetSize() +{ + return myPSMapper->GetPointSpriteSize(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetMinSize(float theMinSize) +{ + myPSMapper->SetPointSpriteMinSize( theMinSize ); + Modified(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetMinSize() +{ + return myPSMapper->GetPointSpriteMinSize(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetMaxSize(float theMaxSize) +{ + myPSMapper->SetPointSpriteMaxSize( theMaxSize ); + Modified(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetMaxSize() +{ + return myPSMapper->GetPointSpriteMaxSize(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetMagnification(float theMagnification) +{ + myPSMapper->SetPointSpriteMagnification( theMagnification ); + Modified(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetMagnification() +{ + return myPSMapper->GetPointSpriteMagnification(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetMagnificationIncrement(float theIncrement) +{ + myMagnificationIncrement = theIncrement; +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetAlphaThreshold(float theAlphaThreshold) +{ + myPSMapper->SetPointSpriteAlphaThreshold( theAlphaThreshold ); + Modified(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetAlphaThreshold() +{ + return myPSMapper->GetPointSpriteAlphaThreshold(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetResolution(int theResolution) +{ + myResolution = theResolution; + mySphereSource->SetThetaResolution( myResolution ); + mySphereSource->SetPhiResolution( myResolution ); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::ChangeMagnification( bool up ) +{ + float anIncrement = up ? myMagnificationIncrement : 1.0 / myMagnificationIncrement; + SetMagnification( GetMagnification() * anIncrement ); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetPointSize(vtkIdType theID, vtkDataArray* theScalarArray) +{ + float aMaxSize = GetAverageCellSize() * GetMaxSize(); + float aMinSize = GetAverageCellSize() * GetMinSize(); + float aDelta = aMaxSize - aMinSize; + float aVal = theScalarArray->GetTuple1(theID); + + return aMinSize + aDelta*(aVal - mySourceScalarRange[0])/myDeltaScalarRange; +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetMaxPointSize() +{ + return GetAverageCellSize() * GetMaxSize(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetPointSize(vtkIdType theID) +{ + vtkMapper* aMapper = GetMapper(); + vtkDataSet* aDataSet = aMapper->GetInput(); + vtkCellData* aCellData = aDataSet->GetCellData(); + vtkDataArray* aScalarArray = aCellData->GetScalars(); + return GetPointSize(theID,aScalarArray); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetAverageCellSize(float theAverageCellSize) +{ + myPSMapper->SetAverageCellSize( theAverageCellSize ); + Modified(); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPointsPL +::GetAverageCellSize() +{ + return myPSMapper->GetAverageCellSize(); +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetImageData(vtkImageData* theImageData) +{ + myPSMapper->SetImageData( theImageData ); +} + +//---------------------------------------------------------------------------- +vtkSmartPointer +VISU_GaussPointsPL +::MakeTexture( const char* theMainTexture, + const char* theAlphaTexture ) +{ + if( !theMainTexture || !theAlphaTexture ) + return 0; + + vtkXMLImageDataReader* aMainReader = vtkXMLImageDataReader::New(); + vtkXMLImageDataReader* anAlphaReader = vtkXMLImageDataReader::New(); + + aMainReader->SetFileName( theMainTexture ); + anAlphaReader->SetFileName( theAlphaTexture ); + + aMainReader->Update(); + anAlphaReader->Update(); + + vtkImageData* aMainImageData = aMainReader->GetOutput(); + vtkImageData* anAlphaImageData = anAlphaReader->GetOutput(); + + int* aMainImageSize = aMainImageData->GetDimensions(); + int* anAlphaImageSize = anAlphaImageData->GetDimensions(); + if(aMainImageSize[0] != anAlphaImageSize[0] || aMainImageSize[1] != anAlphaImageSize[1]) + return NULL; + + vtkSmartPointer aCompositeImageData = vtkImageData::New(); + aCompositeImageData->Delete(); + + int aNbCompositeComponents = 4; + aCompositeImageData->SetDimensions(aMainImageSize); + aCompositeImageData->SetScalarTypeToUnsignedChar(); + aCompositeImageData->SetNumberOfScalarComponents(aNbCompositeComponents); + aCompositeImageData->AllocateScalars(); + + unsigned char* aMainDataPtr = (unsigned char*)aMainImageData->GetScalarPointer(); + unsigned char* anAlphaDataPtr = (unsigned char*)anAlphaImageData->GetScalarPointer(); + unsigned char *aCompositeDataPtr = (unsigned char * )aCompositeImageData->GetScalarPointer(); + + int aNbMainComponents = aMainImageData->GetNumberOfScalarComponents(); + int aNbAlphaComponents = anAlphaImageData->GetNumberOfScalarComponents(); + int aCompositeSize = aMainImageSize[0] * aMainImageSize[1] * aNbCompositeComponents; + + int aMainId = 0, anAlphaId = 0, aCompositeId = 0; + for(; aCompositeId < aCompositeSize;) + { + aCompositeDataPtr[aCompositeId] = aMainDataPtr[aMainId]; + aCompositeDataPtr[aCompositeId + 1] = aMainDataPtr[aMainId + 1]; + aCompositeDataPtr[aCompositeId + 2] = aMainDataPtr[aMainId + 2]; + aCompositeDataPtr[aCompositeId + 3] = anAlphaDataPtr[anAlphaId]; + + aMainId += aNbMainComponents; + anAlphaId += aNbAlphaComponents; + aCompositeId += aNbCompositeComponents; + } + aMainReader->Delete(); + anAlphaReader->Delete(); + aCompositeImageData->Update(); + + return aCompositeImageData; +} + +void VISU_GaussPointsPL::SetScale( float theScale ) +{ + myWarpVector->SetScaleFactor( theScale ); + myScaleFactor = GetScale(); + Modified(); +} + +float VISU_GaussPointsPL::GetScale() +{ + return myWarpVector->GetScaleFactor(); +} + +void VISU_GaussPointsPL::SetMapScale( float theMapScale ) +{ + VISU_ScalarMapPL::SetMapScale( theMapScale ); + + myWarpVector->SetScaleFactor( myScaleFactor * theMapScale ); + Modified(); +} diff --git a/src/PIPELINE/VISU_GaussPointsPL.hxx b/src/PIPELINE/VISU_GaussPointsPL.hxx new file mode 100644 index 00000000..b342ab56 --- /dev/null +++ b/src/PIPELINE/VISU_GaussPointsPL.hxx @@ -0,0 +1,291 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File: VISU_GaussPointsPL.hxx +// Author: +// Module : VISU + +#ifndef VISU_GaussPointsPL_HeaderFile +#define VISU_GaussPointsPL_HeaderFile + +#include "VISU_ScalarMapPL.hxx" +#include "VISU_Convertor.hxx" + +#include + +class VTKViewer_PassThroughFilter; +class VISU_OpenGLPointSpriteMapper; + +class vtkGeometryFilter; +class vtkGlyph3D; +class vtkSphereSource; +class vtkDataArray; +class vtkImageData; +class vtkPointSet; + +class vtkCellDataToPointData; +class vtkWarpVector; +class SALOME_Transform; + +//! Pipeline for the Gauss Points presentation. +/*! + * This class uses the special mapper (VISU_OpenGLPointSpriteMapper) + * for rendering the Gauss Points as Point Sprites. + */ +class VISU_GaussPointsPL : public VISU_ScalarMapPL +{ +protected: + VISU_GaussPointsPL(); + + virtual + ~VISU_GaussPointsPL(); + +public: + vtkTypeMacro(VISU_GaussPointsPL,VISU_ScalarMapPL); + + static + VISU_GaussPointsPL* New(); + + virtual + void + ShallowCopy(VISU_PipeLine *thePipeLine); + + //! Get the native mapper. + virtual + TMapper* + GetMapper(); + + //! Get the internal #VISU_OpenGLPointSpriteMapper. + VISU_OpenGLPointSpriteMapper* + GetPSMapper(); + + //! Get an intermediate dataset that can be picked + vtkDataSet* + GetPickableDataSet(); + + //! Redefined method for initialization of the pipeline. + virtual + void + Init(); + + //! Redefined method for building the pipeline. + virtual + void + Build(); + + //! Redefined method for updating the pipeline. + virtual + void + Update(); + + //! Update glyph. + void + UpdateGlyph(); + + virtual + VISU::TGaussPointID + GetObjID(vtkIdType theID) const; + + virtual + float* + GetNodeCoord(vtkIdType theObjID); + + void + SetGaussPtsIDMapper(const VISU::PGaussPtsIDMapper& theGaussPtsIDMapper); + + const VISU::PGaussPtsIDMapper& + GetGaussPtsIDMapper() const; + + VISU::TVTKOutput* + GetParentMesh() const; + + //! Set the Bicolor mode. + /*! + * When the Bicolor parameter is set to true, scalar bars are + * drawing with two colors : red color correspoonds to positive + * scalar values, blue color - to negative values. + */ + void + SetBicolor(bool theBicolor); + + //! Get the Bicolor mode. + bool + GetBicolor(); + + //! Set the Multicolored mode. + /*! + * This parameter is using to switch between Results and Geometry + * modes. Multiple colors are using when the presentation is + * drawing in the Results mode, one color - in the Geometry mode. + */ + void + SetIsColored(bool theIsColored); + + //! Set type of the primitives. + void + SetPrimitiveType(int thePrimitiveType); + + //! Get type of the primitives. + int + GetPrimitiveType(); + + //! Get the maximum Point Sprite size, which is supported by hardware. + float + GetMaximumSupportedSize(); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper::SetPointSpriteClamp. + void + SetClamp(float theClamp); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper.vtkGetMacro(PointSpriteClamp, float). + float + GetClamp(); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper::SetPointSpriteSize. + void + SetSize(float theSize); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper.vtkGetMacro(PointSpriteSize, float). + float + GetSize(); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper::SetPointSpriteMinSize. + void + SetMinSize(float theMinSize); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper.vtkGetMacro(PointSpriteMinSize, float). + float + GetMinSize(); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper::SetPointSpriteMinSize. + void + SetMaxSize(float theMaxSize); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper.vtkGetMacro(PointSpriteMaxSize, float). + float + GetMaxSize(); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper::SetPointSpriteMagnification. + void + SetMagnification(float theMagnification); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper.vtkGetMacro(PointSpriteMagnification, float). + float + GetMagnification(); + + //! Set the increment of changing Magnification parameter. + void + SetMagnificationIncrement(float theIncrement); + + //! Get the increment of changing Magnification parameter. + float + GetMagnificationIncrement() { return myMagnificationIncrement; } + + //! Redirect the request to VISU_OpenGLPointSpriteMapper::SetPointSpriteAlphaThreshold. + void + SetAlphaThreshold(float theAlphaThreshold); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper.vtkGetMacro(PointSpriteAlphaThreshold, float). + float + GetAlphaThreshold(); + + //! Set resolution of the Geometrical Sphere. + void + SetResolution(int theResolution); + + //! Get resolution of the Geometrical Sphere. + int + GetResolution() { return myResolution; } + + //! Method for changing the Magnification parameter. + void + ChangeMagnification( bool up ); + + //! Get the maximum size of Point Sprites in the presentation. + float + GetMaxPointSize(); + + //! Get point size by element's Id. + float + GetPointSize(vtkIdType theID); + + //! Get point size by element's Id using the specified scalar array. + float + GetPointSize(vtkIdType theID, vtkDataArray* theScalarArray); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper.vtkSetMacro(AverageCellSize, float). + void + SetAverageCellSize(float AverageCellSize); + + //! Redirect the request to VISU_OpenGLPointSpriteMapper.vtkGetMacro(AverageCellSize, float). + float + GetAverageCellSize(); + + //! Set image data for the Point Sprite texture. + void + SetImageData(vtkImageData* theImageData); + + //! Make the image data for Point Sprite texture. + /*! + * First parameter - texture for shape. + * Second parameter - texture for alpha mask. + */ + static + vtkSmartPointer + MakeTexture( const char* theMainTexture, + const char* theAlphaTexture ); + +public: + virtual void SetIsDeformed( bool theIsDeformed ); + virtual bool GetIsDeformed() const; + + virtual void SetScale( float theScale ); + virtual float GetScale(); + virtual void SetMapScale( float theMapScale = 1.0 ); + +protected: + bool myIsDeformed; + float myScaleFactor; + vtkWarpVector *myWarpVector; + vtkCellDataToPointData* myCellDataToPointData; + std::vector myPassFilter; + + vtkGlyph3D* myGlyph; + vtkSphereSource* mySphereSource; + int myResolution; + +protected: + VISU_OpenGLPointSpriteMapper* myPSMapper; + VISU::PGaussPtsIDMapper myGaussPtsIDMapper; + + vtkGeometryFilter* myGeomFilter; + + vtkDataArray *myScalarArray; + float mySourceScalarRange[2]; + float myDeltaScalarRange; + + int myPrimitiveType; + float myMagnificationIncrement; +}; + +#endif diff --git a/src/PIPELINE/VISU_ImplicitFunctionWidget.cxx b/src/PIPELINE/VISU_ImplicitFunctionWidget.cxx new file mode 100644 index 00000000..3a3c21a8 --- /dev/null +++ b/src/PIPELINE/VISU_ImplicitFunctionWidget.cxx @@ -0,0 +1,136 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_ImplicitFunctionWidget.cxx +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#include "VISU_ImplicitFunctionWidget.hxx" +// +#include +#include +#include +#include +#include +#include +#include +#include +// +vtkStandardNewMacro(VISU_UnScaledActor); + +//==================================================================== +// function: VISU_UnScaledActor +// purpose: +//==================================================================== +VISU_UnScaledActor::VISU_UnScaledActor() +{ + for (int i=0; i<3; ++i){ + myCenter[i]=0.; + } + mySize=24; +} +//==================================================================== +// function: SetCenter +// purpose: +//==================================================================== +void VISU_UnScaledActor::SetCenter(float *pC) +{ + for (int i=0; i<3; ++i){ + myCenter[i]=pC[i]; + } +} +//==================================================================== +// function:GetBounds +// purpose: +//==================================================================== +float* VISU_UnScaledActor::GetBounds() +{ + Superclass::GetBounds(); + // + for (int i=0; i<3; ++i){ + Bounds[2*i]=myCenter[i]; + Bounds[2*i+1]=myCenter[i]; + } + return Bounds; +} +//==================================================================== +// function:Render +// purpose: +//==================================================================== +void VISU_UnScaledActor::Render(vtkRenderer *theRenderer) +{ + if(theRenderer){ + float P[2][3] = {{-1.0, -1.0, 0.0},{+1.0, +1.0, 0.0}}; + theRenderer->ViewToWorld(P[0][0],P[0][1],P[0][2]); + theRenderer->ViewToWorld(P[1][0],P[1][1],P[1][2]); + float aWorldDiag = sqrt((P[1][0]-P[0][0])*(P[1][0]-P[0][0])+ + (P[1][1]-P[0][1])*(P[1][1]-P[0][1])+ + (P[1][2]-P[0][2])*(P[1][2]-P[0][2])); + int* aSize = theRenderer->GetRenderWindow()->GetSize(); + float aWinDiag = sqrt(float(aSize[0]*aSize[0]+aSize[1]*aSize[1])); + vtkDataSet* aDataSet = GetMapper()->GetInput(); + float aLength = aDataSet->GetLength(); + float aPrecision = 1.e-3; + float anOldScale = GetScale()[0]; + float aScale = + mySize*aWorldDiag/aWinDiag/aLength*sqrt(float(aSize[0])/float(aSize[1])); + + SetOrigin(myCenter); + // + if(fabs(aScale - anOldScale)/aScale > aPrecision){ + SetScale(aScale); + } + } + vtkFollower::Render(theRenderer); + +} +//==================================================================== +// function:SetSize +// purpose: +//==================================================================== +void VISU_UnScaledActor::SetSize(int theSize) +{ + mySize = theSize; +} + +//================================================================== +// class: VISU_ImplicitFunctionWidget +// +vtkCxxRevisionMacro(VISU_ImplicitFunctionWidget, "$Revision$"); +//================================================================== +// function: VISU_ImplicitFunctionWidget +// purpose : +//================================================================== +VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget() +: + vtk3DWidget() +{ +} +//================================================================== +// function: ~ +// purpose : +//================================================================== +VISU_ImplicitFunctionWidget::~VISU_ImplicitFunctionWidget() +{ +} diff --git a/src/PIPELINE/VISU_ImplicitFunctionWidget.hxx b/src/PIPELINE/VISU_ImplicitFunctionWidget.hxx new file mode 100644 index 00000000..8f46e43b --- /dev/null +++ b/src/PIPELINE/VISU_ImplicitFunctionWidget.hxx @@ -0,0 +1,79 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VISU_PlanesWidget.h +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#ifndef __VISU_ImplicitFunctionWidget_h +#define __VISU_ImplicitFunctionWidget_h +//// +//================================================================== +// class : VISU_UnScaledActor +// purpose : +//================================================================== +#include +class VISU_UnScaledActor: public vtkFollower +{ + +public: + + vtkTypeMacro(VISU_UnScaledActor,vtkFollower); + static VISU_UnScaledActor *New(); + + + void SetCenter(float *); + virtual void SetSize(int theSize); + virtual void Render(vtkRenderer *theRenderer); + virtual float *GetBounds(); + +protected: + VISU_UnScaledActor(); + ~VISU_UnScaledActor(){} + + float myCenter[3]; + int mySize; +}; + +#include + +class vtkImplicitFunction; + +class VISU_ImplicitFunctionWidget : public vtk3DWidget +{ +public: + vtkTypeRevisionMacro(VISU_ImplicitFunctionWidget,vtk3DWidget); + + virtual vtkImplicitFunction* ImplicitFunction()=0; + +protected: + VISU_ImplicitFunctionWidget(); + ~VISU_ImplicitFunctionWidget(); + +private: + VISU_ImplicitFunctionWidget(const VISU_ImplicitFunctionWidget&); //Not implemented + void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented +}; + +#endif diff --git a/src/PIPELINE/VISU_IsoSurfacesPL.cxx b/src/PIPELINE/VISU_IsoSurfacesPL.cxx index 7462ff51..8e14bca9 100644 --- a/src/PIPELINE/VISU_IsoSurfacesPL.cxx +++ b/src/PIPELINE/VISU_IsoSurfacesPL.cxx @@ -48,12 +48,12 @@ VISU_IsoSurfacesPL::~VISU_IsoSurfacesPL(){ } void VISU_IsoSurfacesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ - VISU_ScalarMapPL::ShallowCopy(thePipeLine); if(VISU_IsoSurfacesPL *aPipeLine = dynamic_cast(thePipeLine)){ SetNbParts(aPipeLine->GetNbParts()); float aRange[2] = {aPipeLine->GetMin(), aPipeLine->GetMax()}; SetRange(aRange); } + VISU_ScalarMapPL::ShallowCopy(thePipeLine); } int VISU_IsoSurfacesPL::GetNbParts() { @@ -97,14 +97,13 @@ void VISU_IsoSurfacesPL::Init(){ } VISU_ScalarMapPL::THook* VISU_IsoSurfacesPL::DoHook(){ + VISU::CellDataToPoint(myContourFilter,myCellDataToPointData,GetInput2(),myFieldTransform); return myContourFilter->GetOutput(); } -void VISU_IsoSurfacesPL::Update(){ - VISU::CellDataToPoint(myContourFilter,myCellDataToPointData,GetInput2(),myFieldTransform); - SetMapScale(); - +void VISU_IsoSurfacesPL::Update() +{ VISU_ScalarMapPL::Update(); } diff --git a/src/PIPELINE/VISU_LookupTable.cxx b/src/PIPELINE/VISU_LookupTable.cxx index 06f21c5a..c15fdd27 100644 --- a/src/PIPELINE/VISU_LookupTable.cxx +++ b/src/PIPELINE/VISU_LookupTable.cxx @@ -40,7 +40,26 @@ VISU_LookupTable *VISU_LookupTable::New() { } VISU_LookupTable::VISU_LookupTable(int sze, int ext) - : vtkLookupTable(sze, ext), myScale(1.0) {} + : vtkLookupTable(sze, ext), myScale(1.0), myBicolor(false) {} + +void VISU_LookupTable::SetMapScale(float theScale) +{ + if( myScale != theScale ) + { + myScale = theScale; + Modified(); + } +} + +void VISU_LookupTable::SetBicolor( bool theBicolor ) +{ + if( myBicolor != theBicolor ) + { + myBicolor = theBicolor; + Modified(); + } +} + int VISU_LookupTable::ComputeLogRange(float inRange[2], float outRange[2]){ if(inRange[0] >= inRange[1]) @@ -65,9 +84,13 @@ unsigned char* VISU_LookupTable::MapValue(float v) { float aLowBound = log10(this->TableRange[0]); v = pow(10.0f,aLowBound + (v - aLowBound)*myScale); return vtkLookupTable::MapValue(v); - }else{ + } else if (!myBicolor) { v = this->TableRange[0] + (v - this->TableRange[0])*myScale; return vtkLookupTable::MapValue(v); + } else { + unsigned char* table = this->Table->GetPointer(0); + int index = v > 0 ? 4*static_cast(this->GetNumberOfColors()-1) : 0; + return &table[index]; } } @@ -113,29 +136,35 @@ inline float VISU_ApplyLogScale(float v, float range[2], inline unsigned char *VISU_LinearLookup(float v, unsigned char *table, float maxIndex, - float shift, float scale) + float shift, float scale, + bool bicolor) { - float findx = (v + shift)*scale; - if (findx < 0) - { - findx = 0; - } - if (findx > maxIndex) - { - findx = maxIndex; - } - return &table[4*static_cast(findx)]; - /* round - return &table[4*(int)(findx + 0.5f)]; - */ + if( !bicolor ) + { + float findx = (v + shift)*scale; + if (findx < 0) + findx = 0; + if (findx > maxIndex) + findx = maxIndex; + + return &table[4*static_cast(findx)]; + // round + //return &table[4*(int)(findx + 0.5f)]; + } + else + { + int index = v > 0 ? 4*static_cast(maxIndex) : 0; + return &table[index]; + } } // accelerate the mapping by copying the data in 32-bit chunks instead // of 8-bit chunks template void VISU_LookupTableMapData(vtkLookupTable *self, T *input, - unsigned char *output, int length, - int inIncr, int outFormat, float theMapScale) + unsigned char *output, int length, + int inIncr, int outFormat, + float theMapScale, bool bicolor) { int i = length; float *range = self->GetTableRange(); @@ -169,7 +198,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, while (--i >= 0) { val = VISU_ApplyLogScale(*input, range, logRange); - cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = *cptr++; *output++ = *cptr++; *output++ = *cptr++; @@ -182,7 +211,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, while (--i >= 0) { val = VISU_ApplyLogScale(*input, range, logRange); - cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = *cptr++; *output++ = *cptr++; *output++ = *cptr++; @@ -194,7 +223,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, while (--i >= 0) { val = VISU_ApplyLogScale(*input, range, logRange); - cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + cptr[2]*0.11 + 0.5); *output++ = cptr[3]; @@ -206,7 +235,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, while (--i >= 0) { val = VISU_ApplyLogScale(*input, range, logRange); - cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + cptr[2]*0.11 + 0.5); input += inIncr; @@ -233,7 +262,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, { while (--i >= 0) { - cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = *cptr++; *output++ = *cptr++; *output++ = *cptr++; @@ -245,7 +274,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, { while (--i >= 0) { - cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = *cptr++; *output++ = *cptr++; *output++ = *cptr++; @@ -256,7 +285,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, { while (--i >= 0) { - cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + cptr[2]*0.11 + 0.5); *output++ = cptr[3]; @@ -267,7 +296,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, { while (--i >= 0) { - cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + cptr[2]*0.11 + 0.5); input += inIncr; @@ -300,7 +329,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, while (--i >= 0) { val = VISU_ApplyLogScale(*input, range, logRange); - cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = *cptr++; *output++ = *cptr++; *output++ = *cptr++; @@ -313,7 +342,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, while (--i >= 0) { val = VISU_ApplyLogScale(*input, range, logRange); - cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = *cptr++; *output++ = *cptr++; *output++ = *cptr++; @@ -325,7 +354,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, while (--i >= 0) { val = VISU_ApplyLogScale(*input, range, logRange); - cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + cptr[2]*0.11 + 0.5); *output++ = static_cast(alpha*cptr[3]); @@ -337,7 +366,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, while (--i >= 0) { val = VISU_ApplyLogScale(*input, range, logRange); - cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + cptr[2]*0.11 + 0.5); input += inIncr; @@ -364,7 +393,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, { while (--i >= 0) { - cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale, bicolor); *output++ = *cptr++; *output++ = *cptr++; *output++ = *cptr++; @@ -376,7 +405,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, { while (--i >= 0) { - cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale, bicolor); *output++ = *cptr++; *output++ = *cptr++; *output++ = *cptr++; @@ -387,7 +416,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, { while (--i >= 0) { - cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale, bicolor); *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + cptr[2]*0.11 + 0.5); *output++ = static_cast(cptr[3]*alpha); @@ -398,7 +427,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, { while (--i >= 0) { - cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale, bicolor); *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + cptr[2]*0.11 + 0.5); input += inIncr; @@ -414,7 +443,8 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input, template void VISU_LookupTableMapMag(vtkLookupTable *self, T *input, unsigned char *output, int length, - int inIncr, int outFormat, float theMapScale) + int inIncr, int outFormat, + float theMapScale, bool bicolor) { double tmp, sum; double *mag; @@ -433,7 +463,7 @@ void VISU_LookupTableMapMag(vtkLookupTable *self, T *input, mag[i] = sqrt(sum); } - VISU_LookupTableMapData(self, mag, output, length, 1, outFormat, theMapScale); + VISU_LookupTableMapData(self, mag, output, length, 1, outFormat, theMapScale, bicolor); delete [] mag; } @@ -455,43 +485,43 @@ void VISU_LookupTable::MapScalarsThroughTable2(void *input, break; case VTK_CHAR: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_UNSIGNED_CHAR: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_SHORT: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_UNSIGNED_SHORT: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_INT: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_UNSIGNED_INT: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_LONG: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_UNSIGNED_LONG: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_FLOAT: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; case VTK_DOUBLE: VISU_LookupTableMapMag(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); return; default: vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType"); @@ -515,7 +545,7 @@ void VISU_LookupTable::MapScalarsThroughTable2(void *input, VISU_LookupTableMapData(this, static_cast(newInput->GetPointer(0)), output,numberOfValues, - inputIncrement,outputFormat,myScale); + inputIncrement,outputFormat,myScale,myBicolor); newInput->Delete(); bitArray->Delete(); } @@ -523,52 +553,52 @@ void VISU_LookupTable::MapScalarsThroughTable2(void *input, case VTK_CHAR: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_UNSIGNED_CHAR: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_SHORT: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_UNSIGNED_SHORT: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_INT: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_UNSIGNED_INT: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_LONG: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_UNSIGNED_LONG: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_FLOAT: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; case VTK_DOUBLE: VISU_LookupTableMapData(this,static_cast(input),output, - numberOfValues,inputIncrement,outputFormat,myScale); + numberOfValues,inputIncrement,outputFormat,myScale,myBicolor); break; default: diff --git a/src/PIPELINE/VISU_LookupTable.hxx b/src/PIPELINE/VISU_LookupTable.hxx index 769ba892..20f7c23e 100644 --- a/src/PIPELINE/VISU_LookupTable.hxx +++ b/src/PIPELINE/VISU_LookupTable.hxx @@ -20,8 +20,11 @@ class VISU_LookupTable: public vtkLookupTable { int inputDataType, int numberOfValues, int inputIncrement, int outputIncrement); - float GetMapScale() { return myScale; } - void SetMapScale(float theScale = 1.0) { myScale = theScale; Modified(); } + float GetMapScale() { return myScale; } + void SetMapScale(float theScale = 1.0); + + float GetBicolor() { return myBicolor; } + void SetBicolor( bool theBicolor ); static int ComputeLogRange(float inRange[2], float outRange[2]); unsigned char *MapValue(float v); @@ -31,5 +34,7 @@ class VISU_LookupTable: public vtkLookupTable { ~VISU_LookupTable() {}; float myScale; + + bool myBicolor; }; #endif // VISU_LookupTable_H diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx new file mode 100755 index 00000000..d8eb9e8a --- /dev/null +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx @@ -0,0 +1,884 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File: VISU_OpenGLPointSpriteMapper.cxx +// Author: +// Module : VISU + +#include "VISU_OpenGLPointSpriteMapper.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#ifndef VTK_IMPLEMENT_MESA_CXX +vtkCxxRevisionMacro(VISU_OpenGLPointSpriteMapper, "Revision$"); +vtkStandardNewMacro(VISU_OpenGLPointSpriteMapper); +#endif + +// some definitions for what the polydata has in it +#define VTK_PDPSM_COLORS 0x0001 +#define VTK_PDPSM_CELL_COLORS 0x0002 +#define VTK_PDPSM_POINT_TYPE_FLOAT 0x0004 +#define VTK_PDPSM_POINT_TYPE_DOUBLE 0x0008 +#define VTK_PDPSM_NORMAL_TYPE_FLOAT 0x0010 +#define VTK_PDPSM_NORMAL_TYPE_DOUBLE 0x0020 +#define VTK_PDPSM_OPAQUE_COLORS 0x0040 + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif + +#ifndef GL_OBJECT_INFO_LOG_LENGTH_ARB +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 +#endif + +#ifndef GL_VERTEX_SHADER_ARB +#define GL_VERTEX_SHADER_ARB 0x8B31 +#endif + +#ifndef GL_VERTEX_PROGRAM_POINT_SIZE_ARB +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#endif + +#ifndef GL_ARB_point_sprite +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif + +#ifndef GL_ARB_shader_objects +typedef char GLcharARB; +#endif + +#ifndef GL_ARB_vertex_buffer_object +typedef ptrdiff_t GLsizeiptrARB; + +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_STATIC_DRAW_ARB 0x88E4 +#endif + +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); + +typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); +typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); + +static PFNGLSHADERSOURCEARBPROC vglShaderSourceARB = NULL; +static PFNGLCREATESHADEROBJECTARBPROC vglCreateShaderObjectARB = NULL; +static PFNGLCOMPILESHADERARBPROC vglCompileShaderARB = NULL; +static PFNGLCREATEPROGRAMOBJECTARBPROC vglCreateProgramObjectARB = NULL; +static PFNGLATTACHOBJECTARBPROC vglAttachObjectARB = NULL; +static PFNGLLINKPROGRAMARBPROC vglLinkProgramARB = NULL; +static PFNGLUSEPROGRAMOBJECTARBPROC vglUseProgramObjectARB = NULL; +static PFNGLGETOBJECTPARAMETERIVARBPROC vglGetObjectParameterivARB = NULL; +static PFNGLGETINFOLOGARBPROC vglGetInfoLogARB = NULL; +static PFNGLGETATTRIBLOCATIONARBPROC vglGetAttribLocationARB = NULL; +static PFNGLVERTEXATTRIB1FARBPROC vglVertexAttrib1fARB = NULL; + +static PFNGLGENBUFFERSARBPROC vglGenBuffersARB = NULL; +static PFNGLBINDBUFFERARBPROC vglBindBufferARB = NULL; +static PFNGLBUFFERDATAARBPROC vglBufferDataARB = NULL; +static PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB = NULL; + +int InitializeARB() +{ + void* OpenGLLibrary = dlopen( "libGL.so", RTLD_LAZY ); + + vglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)dlsym( OpenGLLibrary, "glShaderSourceARB" ); + vglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)dlsym( OpenGLLibrary, "glCreateShaderObjectARB" ); + vglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)dlsym( OpenGLLibrary, "glCompileShaderARB" ); + vglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)dlsym( OpenGLLibrary, "glCreateProgramObjectARB" ); + vglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)dlsym( OpenGLLibrary, "glAttachObjectARB" ); + vglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)dlsym( OpenGLLibrary, "glLinkProgramARB" ); + vglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( OpenGLLibrary, "glUseProgramObjectARB" ); + vglGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)dlsym( OpenGLLibrary, "glGetObjectParameterivARB" ); + vglGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)dlsym( OpenGLLibrary, "glGetInfoLogARB" ); + vglGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)dlsym( OpenGLLibrary, "glGetAttribLocationARB" ); + vglVertexAttrib1fARB = (PFNGLVERTEXATTRIB1FARBPROC)dlsym( OpenGLLibrary, "glVertexAttrib1fARB" ); + + vglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)dlsym( OpenGLLibrary, "glGenBuffersARB" ); + vglBindBufferARB = (PFNGLBINDBUFFERARBPROC)dlsym( OpenGLLibrary, "glBindBufferARB" ); + vglBufferDataARB = (PFNGLBUFFERDATAARBPROC)dlsym( OpenGLLibrary, "glBufferDataARB" ); + vglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)dlsym( OpenGLLibrary, "glDeleteBuffersARB" ); + + return 1; +}; + +static int IsARBInitialized = InitializeARB(); +static float Tolerance = 1.0 / VTK_LARGE_FLOAT; + +//----------------------------------------------------------------------------- +// Construct empty object. +VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper() +{ + this->RenderMode = VISU_OpenGLPointSpriteMapper::Occlude; + + this->ListId = 0; + this->TotalCells = 0; + this->ExtensionsInitialized = 0; + this->DefaultPointSize = 20.0; + this->AverageCellSize = 0.0; + + this->UsePointSprites = true; + this->UseTextures = true; + this->UseShader = true; + + this->PrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite; + + this->PointSpriteMode = 0; + + this->PointSpriteClamp = 256.0; + this->PointSpriteSize = 0.2; + this->PointSpriteMinSize = 0.1; + this->PointSpriteMaxSize = 0.3; + this->PointSpriteMagnification = 1.0; + + this->PointSpriteAlphaThreshold = 0.5; + this->PointSpriteTexture = 0; + + this->UseOpenGLMapper = false; + + this->TempMapper = vtkPolyDataMapper::New(); +} +//----------------------------------------------------------------------------- +VISU_OpenGLPointSpriteMapper::~VISU_OpenGLPointSpriteMapper() +{ + glDeleteTextures( 1, &PointSpriteTexture ); + + if( this->LastWindow ) + this->ReleaseGraphicsResources(this->LastWindow); + + if( this->TempMapper ) + this->TempMapper->Delete(); +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::ShallowCopy( vtkAbstractMapper* mapper ) +{ + VISU_OpenGLPointSpriteMapper* m = VISU_OpenGLPointSpriteMapper::SafeDownCast(mapper); + if( m != NULL ) + { + this->SetPrimitiveType( m->GetPrimitiveType() ); + + this->SetPointSpriteMode( m->GetPointSpriteMode() ); + + this->SetPointSpriteClamp( m->GetPointSpriteClamp() ); + this->SetPointSpriteSize( m->GetPointSpriteSize() ); + this->SetPointSpriteMinSize( m->GetPointSpriteMinSize() ); + this->SetPointSpriteMaxSize( m->GetPointSpriteMaxSize() ); + this->SetPointSpriteMagnification( m->GetPointSpriteMagnification() ); + + this->SetImageData( m->GetImageData() ); + this->SetPointSpriteAlphaThreshold( m->GetPointSpriteAlphaThreshold() ); + } + + this->TempMapper->ShallowCopy( m ); + this->TempMapper->SetInput( this->GetInput() ); + Superclass::ShallowCopy( this->TempMapper ); + +} +//----------------------------------------------------------------------------- +char* readFromFile( std::string fileName ) +{ + FILE* file = fopen( fileName.c_str(), "r" ); + + char* content = NULL; + int count = 0; + + if( file != NULL ) + { + fseek( file, 0, SEEK_END ); + count = ftell( file ); + rewind( file ); + + if( count > 0 ) + { + content = ( char* )malloc( sizeof( char ) * ( count + 1 ) ); + count = fread( content, sizeof( char ), count, file ); + content[ count ] = '\0'; + } + fclose( file ); + } + + return content; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::PrintInfoLog( GLhandleARB obj ) +{ + int infologLength = 0; + int charsWritten = 0; + char* infoLog; + + vglGetObjectParameterivARB( obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength ); + + if( infologLength > 0 ) + { + infoLog = ( char* )malloc( infologLength ); + vglGetInfoLogARB( obj, infologLength, &charsWritten, infoLog ); + printf( "%s\n", infoLog ); + free( infoLog ); + } +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::InitShader() +{ + //cout << "Initializing vertex program" << endl; + + std::string fileName = std::string( getenv( "VISU_ROOT_DIR") ) + + "/share/salome/resources/Vertex_Program_ARB.txt"; + + char* shader = readFromFile( fileName ); + + GLhandleARB VertexShader = vglCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); + vglShaderSourceARB( VertexShader, 1, (const GLcharARB**)&shader, NULL ); + vglCompileShaderARB( VertexShader ); + //this->PrintInfoLog( VertexShader ); + + this->VertexProgram = vglCreateProgramObjectARB(); + vglAttachObjectARB( this->VertexProgram, VertexShader ); + + vglLinkProgramARB( this->VertexProgram ); + //this->PrintInfoLog( VertexProgram ); + /* + cout << "Shader from " << fileName << endl; + for( int i = 0; i < strlen( shader ); i++ ) + cout << shader[i]; + cout << endl; + + if( glGetError() == GL_NO_ERROR ) + cout << "Loading vertex program... ok" << endl << endl; + else + cout << "Loading vertex program... failed" << endl << endl; + */ + free( shader ); +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetShaderVariable( const char* variable, float value ) +{ + //cout << this->VertexProgram << " "; + //cout << vglGetAttribLocationARB( this->VertexProgram, variable ) << " "; + //cout << variable << " " << value << endl; + + vglVertexAttrib1fARB( vglGetAttribLocationARB( this->VertexProgram, variable ), value ); +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetPrimitiveType( int thePrimitiveType ) +{ + if( this->PrimitiveType == thePrimitiveType ) + return; + + this->PrimitiveType = thePrimitiveType; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetPointSpriteMode( int theMode ) +{ + if( this->PointSpriteMode == theMode ) + return; + + this->PointSpriteMode = theMode; + this->Modified(); +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetPointSpriteClamp( float theClamp ) +{ + if( fabs( this->PointSpriteClamp - theClamp ) < Tolerance ) + return; + + this->PointSpriteClamp = theClamp; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetPointSpriteSize( float theSize ) +{ + if( fabs( this->PointSpriteSize - theSize ) < Tolerance ) + return; + + this->PointSpriteSize = theSize; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetPointSpriteMinSize( float theMinSize ) +{ + if( fabs( this->PointSpriteMinSize - theMinSize ) < Tolerance ) + return; + + this->PointSpriteMinSize = theMinSize; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetPointSpriteMaxSize( float theMaxSize ) +{ + if( fabs( this->PointSpriteMaxSize - theMaxSize ) < Tolerance ) + return; + + this->PointSpriteMaxSize = theMaxSize; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetPointSpriteMagnification( float theMagnification ) +{ + if( fabs( this->PointSpriteMagnification - theMagnification ) < Tolerance ) + return; + + this->PointSpriteMagnification = theMagnification; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::SetPointSpriteAlphaThreshold( float theAlphaThreshold ) +{ + if( fabs( this->PointSpriteAlphaThreshold - theAlphaThreshold ) < Tolerance ) + return; + + this->PointSpriteAlphaThreshold = theAlphaThreshold; +} +//----------------------------------------------------------------------------- +bool VISU_OpenGLPointSpriteMapper::InitExtensions() +{ + char* ext = (char*)glGetString( GL_EXTENSIONS ); + //cout << "OpenGL extensions : " << ext << endl; + + if( strstr( ext, "GL_ARB_point_sprite" ) == NULL || + strstr( ext, "GL_ARB_shader_objects" ) == NULL || + strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL ) + { + vtkWarningMacro(<<"Initializing ARB extensions failed"); + + this->UseOpenGLMapper = true; + + return false; + } + + if( this->UseShader ) + this->InitShader(); + + this->ExtensionsInitialized = 1; + return true; +} + +//----------------------------------------------------------------------------- +float ViewToDisplay( vtkRenderer* theRenderer ) +{ + float p1[3], p2[3]; + + theRenderer->SetViewPoint( 0.0, 0.0, 0.0 ); + theRenderer->ViewToDisplay(); + theRenderer->GetDisplayPoint( p1 ); + + theRenderer->SetViewPoint( 1.0, 1.0, 1.0 ); + theRenderer->ViewToDisplay(); + theRenderer->GetDisplayPoint( p2 ); + + float coefficient = sqrt( pow( p2[0] - p1[0], 2 ) + pow( p2[1] - p1[1], 2 ) ) / sqrt( 2 ); + //cout << p1[0] << " " << p1[1] << " " << p1[2] << endl; + //cout << p2[0] << " " << p2[1] << " " << p2[2] << endl; + //cout << "ZOOM : " << coefficient << endl; + + return coefficient; +} + +//----------------------------------------------------------------------------- +// +// Receives from Actor -> maps data to primitives +// +void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) +{ + bool isUseThisMapper = !( this->UseOpenGLMapper || + this->PrimitiveType == VISU_OpenGLPointSpriteMapper::GeomSphere ); + + if( !this->ExtensionsInitialized && isUseThisMapper ) + { + if( !this->InitExtensions() ) + return; + } + + if( !isUseThisMapper ) + { + MAPPER_SUPERCLASS::RenderPiece( ren, act ); + return; + } + + vtkIdType numPts; + vtkPolyData *input= this->GetInput(); + + // + // make sure that we've been properly initialized + // + if (ren->GetRenderWindow()->CheckAbortStatus()) + return; + + if ( input == NULL ) + { + vtkErrorMacro(<< "No input!"); + return; + } + else + { + this->InvokeEvent(vtkCommand::StartEvent,NULL); + input->Update(); + this->InvokeEvent(vtkCommand::EndEvent,NULL); + + numPts = input->GetNumberOfPoints(); + } + + if (numPts == 0) + { + vtkDebugMacro(<< "No points!"); + return; + } + + if ( this->LookupTable == NULL ) + this->CreateDefaultLookupTable(); + + // make sure our window is current + ren->GetRenderWindow()->MakeCurrent(); + + if( this->UsePointSprites ) //&& this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite ) + this->InitPointSprites(); + + // Initializing the texture for Point Sprites + if( this->UseTextures && this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite ) + this->InitTextures(); + + vglUseProgramObjectARB( this->VertexProgram ); + float aViewToDisplay = ViewToDisplay( ren ); + this->SetShaderVariable( "mode", this->PointSpriteMode ); + this->SetShaderVariable( "clampSize", this->PointSpriteClamp ); + this->SetShaderVariable( "geomSize", aViewToDisplay * this->AverageCellSize * this->PointSpriteSize ); + this->SetShaderVariable( "minSize", aViewToDisplay * this->AverageCellSize * this->PointSpriteMinSize ); + this->SetShaderVariable( "maxSize", aViewToDisplay * this->AverageCellSize * this->PointSpriteMaxSize ); + this->SetShaderVariable( "magnification", this->PointSpriteMagnification ); + + // + // if something has changed regenerate colors and display lists + // if required + // + int noAbort=1; + if ( this->GetMTime() > this->BuildTime || + input->GetMTime() > this->BuildTime || + act->GetProperty()->GetMTime() > this->BuildTime || + ren->GetRenderWindow() != this->LastWindow) + { + // sets this->Colors as side effect + this->MapScalars( act->GetProperty()->GetOpacity() ); + + if (!this->ImmediateModeRendering && + !this->GetGlobalImmediateModeRendering()) + { + this->ReleaseGraphicsResources(ren->GetRenderWindow()); + this->LastWindow = ren->GetRenderWindow(); + + // get a unique display list id + this->ListId = glGenLists(1); + glNewList(this->ListId,GL_COMPILE); + + noAbort = this->Draw(ren,act); + glEndList(); + + // Time the actual drawing + this->Timer->StartTimer(); + glCallList(this->ListId); + this->Timer->StopTimer(); + } + else + { + this->ReleaseGraphicsResources(ren->GetRenderWindow()); + this->LastWindow = ren->GetRenderWindow(); + } + if (noAbort) + this->BuildTime.Modified(); + } + // if nothing changed but we are using display lists, draw it + else + { + if (!this->ImmediateModeRendering && + !this->GetGlobalImmediateModeRendering()) + { + // Time the actual drawing + this->Timer->StartTimer(); + glCallList(this->ListId); + this->Timer->StopTimer(); + } + } + + // if we are in immediate mode rendering we always + // want to draw the primitives here + if (this->ImmediateModeRendering || + this->GetGlobalImmediateModeRendering()) + { + // sets this->Colors as side effect + this->MapScalars( act->GetProperty()->GetOpacity() ); + + // Time the actual drawing + this->Timer->StartTimer(); + this->Draw(ren,act); + this->Timer->StopTimer(); + } + + this->TimeToDraw = (float)this->Timer->GetElapsedTime(); + + // If the timer is not accurate enough, set it to a small + // time so that it is not zero + if ( this->TimeToDraw == 0.0 ) + this->TimeToDraw = 0.0001; + + vglUseProgramObjectARB( 0 ); + + if( this->UsePointSprites ) //&& this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite ) + this->CleanupPointSprites(); +} +//----------------------------------------------------------------------------- +float VISU_OpenGLPointSpriteMapper::GetMaximumSupportedSize() +{ + float maximumSupportedSize = 512.0; + //glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maximumSupportedSize ); + + return maximumSupportedSize; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::InitPointSprites() +{ + glEnable( GL_POINT_SPRITE_ARB ); + glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB ); + + switch (this->RenderMode) + { + case VISU_OpenGLPointSpriteMapper::Accumulate: + { + glDisable(GL_DEPTH_TEST); + + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE ); + + glEnable( GL_ALPHA_TEST ); + glAlphaFunc( GL_GREATER, this->PointSpriteAlphaThreshold ); + break; + } + + case VISU_OpenGLPointSpriteMapper::Occlude: + { + glDepthFunc( GL_LEQUAL ); + glEnable( GL_DEPTH_TEST ); + + glEnable( GL_ALPHA_TEST ); + glAlphaFunc( GL_GREATER, this->PointSpriteAlphaThreshold ); + + glDisable( GL_BLEND ); + break; + } + + default: + { + break; + } + } + // Disable Lighting/Shading. + glDisable( GL_LIGHTING ); + + // Disable material properties + glDisable( GL_COLOR_MATERIAL ); +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::CleanupPointSprites() +{ + // Set GL params back to normal to stop other vtkMappers displaying wrongly + glDisable( GL_ALPHA_TEST ); + + glEnable( GL_BLEND ); + + glEnable( GL_DEPTH_TEST ); + glEnable( GL_LIGHTING ); + glEnable( GL_COLOR_MATERIAL ); + + glDisable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB ); + glDisable( GL_POINT_SPRITE_ARB ); +} + + +//----------------------------------------------------------------------------- +void +VISU_OpenGLPointSpriteMapper +::SetImageData( vtkImageData* theImageData ) +{ + //cout << "VISU_OpenGLPointSpriteMapper::SetImageData " << theImageData << endl; + this->ImageData = theImageData; +} + +vtkImageData* +VISU_OpenGLPointSpriteMapper +::GetImageData() +{ + return this->ImageData.GetPointer(); +} + + +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::InitTextures() +{ + //cout << "VISU_OpenGLPointSpriteMapper::InitTextures " << this->GetImageData() << endl; + if( !this->GetImageData() ) + return; + + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + + int* aSize = GetImageData()->GetDimensions(); + unsigned char* dataPtr = (unsigned char*)GetImageData()->GetScalarPointer(); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aSize[0], aSize[1], 0, + GL_RGBA, GL_UNSIGNED_BYTE, dataPtr ); + + //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glEnable( GL_TEXTURE_2D ); + glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); + glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture ); +} + +//----------------------------------------------------------------------------- +int ComputeHue( int r, int g, int b ) +{ + int h = 0; + + int max = r; + int whatmax = 0; + if( g > max ) { + max = g; + whatmax = 1; + } + if( b > max ) { + max = b; + whatmax = 2; + } + + int min = r; + if ( g < min ) min = g; + if ( b < min ) min = b; + int delta = max-min; + + if( delta == 0 ) + h = 0; + else if( whatmax == 0 ) { + if ( g >= b ) + h = (120*(g-b)+delta)/(2*delta); + else + h = (120*(g-b+delta)+delta)/(2*delta) + 300; + } + else if( whatmax == 1 ) { + if ( b > r ) + h = 120 + (120*(b-r)+delta)/(2*delta); + else + h = 60 + (120*(b-r+delta)+delta)/(2*delta); + } + else { + if ( r > g ) + h = 240 + (120*(r-g)+delta)/(2*delta); + else + h = 180 + (120*(r-g+delta)+delta)/(2*delta); + } + + return h + 1; +} + +//----------------------------------------------------------------------------- +struct TVertex +{ + GLfloat r, g, b, hue; + GLfloat vx, vy, vz; +}; + +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *thePoints, + vtkUnsignedCharArray *theColors, + vtkFloatArray *theAlpha, + vtkIdType &theCellNum, + int &theNoAbort, + vtkCellArray *theCells, + vtkRenderer *theRenderer, + vtkActor* theActor) +{ + //cout << "VISU_OpenGLPointSpriteMapper::DrawPoints" << endl; + + //if( this->PrimitiveType == VISU_OpenGLPointSpriteMapper::OpenGLPoint ) + // glEnable( GL_POINT_SMOOTH ); + + glPointSize( this->DefaultPointSize ); + + TVertex* aVertexArr = new TVertex[ this->TotalCells ]; + + float* aPropertyColor = theActor->GetProperty()->GetColor(); + float aColor[3] = {aPropertyColor[0], aPropertyColor[1], aPropertyColor[2]}; + + unsigned long i = 0; + vtkIdType *pts = 0; + vtkIdType npts = 0; + for( theCells->InitTraversal(); theCells->GetNextCell( npts, pts ); i++ ) + { + TVertex& aVertex = aVertexArr[i]; + vtkIdType aPointId = pts[0]; + float* aCoords = thePoints->GetPoint( aPointId ); + aVertex.vx = aCoords[0]; + aVertex.vy = aCoords[1]; + aVertex.vz = aCoords[2]; + + int aRed, aGreen, aBlue; + if( theColors && this->PointSpriteMode != 1 ) + { + unsigned char *col = theColors->GetPointer(pts[0] << 2); + aRed = int(col[0]); + aGreen = int(col[1]); + aBlue = int(col[2]); + + aColor[0] = aRed / 255.0; + aColor[1] = aGreen / 255.0; + aColor[2] = aBlue / 255.0; + } + + aVertex.r = aColor[0]; + aVertex.g = aColor[1]; + aVertex.b = aColor[2]; + aVertex.hue = ComputeHue( aRed, aGreen, aBlue ); + } + + GLuint aBufferObjectID = 0; + vglGenBuffersARB( 1, &aBufferObjectID ); + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); + + int nArrayObjectSize = sizeof( TVertex ) * this->TotalCells; + vglBufferDataARB( GL_ARRAY_BUFFER_ARB, nArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB ); + + delete [] aVertexArr; + + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); + + glColorPointer( 4, GL_FLOAT, sizeof(TVertex), (void*)0 ); + glVertexPointer( 3, GL_FLOAT, sizeof(TVertex), (void*)(4*sizeof(GLfloat)) ); + + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + glDrawArrays( GL_POINTS, 0, this->TotalCells ); + + glDisableClientState( GL_COLOR_ARRAY ); + glDisableClientState( GL_VERTEX_ARRAY ); + + vglDeleteBuffersARB( 1, &aBufferObjectID ); + + //if( this->PrimitiveType == VISU_OpenGLPointSpriteMapper::OpenGLPoint ) + // glDisable( GL_POINT_SMOOTH ); +} + +//----------------------------------------------------------------------------- +int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *aren, vtkActor *act) +{ + + if( this->UseOpenGLMapper || + this->PrimitiveType == VISU_OpenGLPointSpriteMapper::GeomSphere ) + return MAPPER_SUPERCLASS::Draw( aren, act ); + + vtkOpenGLRenderer *ren = (vtkOpenGLRenderer *)aren; + vtkUnsignedCharArray *colors = NULL; + vtkFloatArray *alpha = NULL; + vtkPolyData *input = this->GetInput(); + vtkPoints *points; + int noAbort = 1; + int cellScalars = 0; + vtkIdType cellNum = 0; + float tran; + + // get the transparency + tran = act->GetProperty()->GetOpacity(); + + // if the primitives are invisable then get out of here + if (tran <= 0.0) + { + return noAbort; + } + + // and draw the display list + points = input->GetPoints(); + + // are they cell or point scalars + if ( this->Colors ) + { + colors = this->Colors; + if ( (this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA || + this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA || + !input->GetPointData()->GetScalars() ) + && this->ScalarMode != VTK_SCALAR_MODE_USE_POINT_FIELD_DATA) + { + cellScalars = 1; + } + } + + // we need to know the total number of cells so that we can report progress + this->TotalCells = input->GetVerts()->GetNumberOfCells(); + + this->DrawPoints(points, colors, alpha, cellNum, noAbort, input->GetVerts(), ren, act); + + this->UpdateProgress(1.0); + return noAbort; +} +//----------------------------------------------------------------------------- +// Release the graphics resources used by this mapper. In this case, release +// the display list if any. +void VISU_OpenGLPointSpriteMapper::ReleaseGraphicsResources(vtkWindow *win) +{ + this->Superclass::ReleaseGraphicsResources(win); + + if (this->ListId && win) + { + win->MakeCurrent(); + glDeleteLists(this->ListId,1); + this->ListId = 0; + } + this->LastWindow = NULL; +} diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx new file mode 100755 index 00000000..1ddb55ff --- /dev/null +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx @@ -0,0 +1,285 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File: VISU_OpenGLPointSpriteMapper.hxx +// Author: +// Module : VISU + +#ifndef VISU_OpenGLPointSpriteMapper_HeaderFile +#define VISU_OpenGLPointSpriteMapper_HeaderFile + +#if defined(_MSC_VER) +# pragma warning ( disable : 4275 ) +#endif + +#include + +#include +#include + +class vtkCellArray; +class vtkPoints; +class vtkProperty; +class vtkRenderWindow; +class vtkOpenGLRenderer; +class vtkOpenGLTexture; +class vtkBMPReader; +class vtkImageData; +class vtkFloatArray; +class vtkXMLImageDataReader; + +#ifndef VTK_IMPLEMENT_MESA_CXX +#include +#define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper +#else +#include +#define MAPPER_SUPERCLASS vtkMesaPolyDataMapper +#endif + +#ifndef GL_ARB_shader_objects +typedef GLuint GLhandleARB; +#endif + +//---------------------------------------------------------------------------- +//! OpenGL Point Sprites PolyData Mapper. +/*! + * VISU_OpenGLPointSpriteMapper is a class that maps polygonal data + * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping + * to the rendering/graphics hardware/software. It is now possible to set a + * memory limit for the pipeline in the mapper. If the total estimated memory + * usage of the pipeline is larger than this limit, the mapper will divide + * the data into pieces and render each in a for loop. + */ +class VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS +{ +public: + //! The Point Sprites rendering mode. + /*! + * Accumulate : Uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), and no depth testing + * so that points are accumulated. Suitable for Galaxy plots. + * Occlude : No blending. Particles are solid spheres and depth testing is + * used as usual. Suitable for most particle simulations without the need + * for opacity. + */ + enum RenderModes { Accumulate = 0, Occlude }; + + enum PrimitiveTypes { PointSprite = 0, OpenGLPoint, GeomSphere }; + + static VISU_OpenGLPointSpriteMapper *New(); + vtkTypeRevisionMacro(VISU_OpenGLPointSpriteMapper,MAPPER_SUPERCLASS); + + void ShallowCopy(vtkAbstractMapper*); + + //! Set the initial point size to be used. + /*! + * This value forms the base upon which the distance attenuation acts. + * Usually the pointsize is set to the maximum supported by the graphics + * card for sprite display, then the quadratic factors are adjusted to + * bring the size down. + */ + vtkSetMacro(DefaultPointSize, float); + + //! Get the initial point size to be used. + vtkGetMacro(DefaultPointSize, float); + + //! Set Average Cell Size. + vtkSetMacro(AverageCellSize, float); + + //! Get Average Cell Size. + vtkGetMacro(AverageCellSize, float); + + //! Set the Render Mode for the mapper. + vtkSetMacro(RenderMode, int); + + //! Get the Render Mode for the mapper. + vtkGetMacro(RenderMode, int); + + //! Implement superclass render method. + virtual void RenderPiece(vtkRenderer *ren, vtkActor *a); + + //! Release any graphics resources that are being consumed by this mapper. + void ReleaseGraphicsResources(vtkWindow *); + + //! Draw method for OpenGL. + virtual int Draw(vtkRenderer *ren, vtkActor *a); + + //! Return the maximum point size supported by the graphics hardware. + static float GetMaximumSupportedSize(); + + //! Set usage of #vtkOpenGLPolyDataMapper. + /*! + * This flags prevents using of the VISU_OpenGLPointSpriteMapper + * (#vtkOpenGLPolyDataMapper is using instead). + */ + vtkSetMacro(UseOpenGLMapper, bool); + + //! Get usage of #vtkOpenGLPolyDataMapper. + vtkGetMacro(UseOpenGLMapper, bool); + + //! Set usage of Point Sprites. + vtkSetMacro(UsePointSprites, bool); + + //! Get usage of Point Sprites. + vtkGetMacro(UsePointSprites, bool); + + //! Set usage of textures for Point Sprites. + /*! Works only if usage of Point Sprites is turned on. */ + vtkSetMacro(UseTextures, bool); + + //! Get usage of textures for Point Sprites. + vtkGetMacro(UseTextures, bool); + + //! Set usage of vertex shader. + /*! Works only if usage of Point Sprites is turned on. */ + vtkSetMacro(UseShader, bool); + + //! Get usage of vertex shader. + vtkGetMacro(UseShader, bool); + + //! Point Sprite drawing mode + /*! + * 0 - Results - different colors, different sizes. + * 1 - Geometry - fixed color, fixed size. + * 2 - Outside - different colors, fixed size. + */ + vtkGetMacro(PointSpriteMode, int); + void SetPointSpriteMode( int ); + + //! Get the Primitive type + vtkGetMacro(PrimitiveType, int); + + //! Set the Primitive type + void SetPrimitiveType( int ); + + //! Set Point Sprite Clamp. + void SetPointSpriteClamp( float ); + + //! Get Point Sprite Clamp. + vtkGetMacro(PointSpriteClamp, float); + + //! Set Point Sprite Const Size. + void SetPointSpriteSize( float ); + + //! Get Point Sprite Const Size. + vtkGetMacro(PointSpriteSize, float); + + //! Set Point Sprite Minimum Size. + void SetPointSpriteMinSize( float ); + + //! Get Point Sprite Minimum Size. + vtkGetMacro(PointSpriteMinSize, float); + + //! Set Point Sprite Maximum Size. + void SetPointSpriteMaxSize( float ); + + //! Get Point Sprite Maximum Size. + vtkGetMacro(PointSpriteMaxSize, float); + + //! Set Point Sprite Magnification. + void SetPointSpriteMagnification( float ); + + //! Get Point Sprite Magnification. + vtkGetMacro(PointSpriteMagnification, float); + + //! Set Point Sprite AlphaThreshold. + void SetPointSpriteAlphaThreshold( float ); + + //! Get Point Sprite AlphaThreshold. + vtkGetMacro(PointSpriteAlphaThreshold, float); + + //! Set ImageData for Point Sprite Texture. + void SetImageData(vtkImageData* theImageData); + + //! Get ImageData for Point Sprite Texture. + vtkImageData* GetImageData(); + +protected: + VISU_OpenGLPointSpriteMapper(); + ~VISU_OpenGLPointSpriteMapper(); + + //! Internal method of the Point Sprites drawing. + void DrawPoints(vtkPoints *p, + vtkUnsignedCharArray *c, + vtkFloatArray *alpha, + vtkIdType &cellNum, + int &noAbort, + vtkCellArray *ca, + vtkRenderer *ren, + vtkActor *act); + + //! Initializing OpenGL extensions. + bool InitExtensions(); + + //! Activate Point Sprites. + void InitPointSprites(); + + //! Deactivate Point Sprites. + void CleanupPointSprites(); + + //! Initializing textures for Point Sprites. + void InitTextures(); + + //! Initializing of the Vertex Shader. + void InitShader(); + + //! Set Vertex Shader variable. + void SetShaderVariable( const char* variable, float value ); + + //! Getting information about Vertex Shader compiling and linking. + void PrintInfoLog( GLhandleARB ); + +private: + bool UseOpenGLMapper; + + bool UsePointSprites; + bool UseTextures; + bool UseShader; + + int RenderMode; + int ListId; + vtkIdType TotalCells; + int ExtensionsInitialized; + float DefaultPointSize; + + GLhandleARB VertexProgram; + + int PrimitiveType; + + int PointSpriteMode; + + float PointSpriteClamp; + float PointSpriteSize; + float PointSpriteMinSize; + float PointSpriteMaxSize; + float PointSpriteMagnification; + + GLuint PointSpriteTexture; + float PointSpriteAlphaThreshold; + + float AverageCellSize; + + vtkSmartPointer ImageData; + vtkPolyDataMapper* TempMapper; +}; + +#endif diff --git a/src/PIPELINE/VISU_PipeLine.cxx b/src/PIPELINE/VISU_PipeLine.cxx index d670a681..9fcd66fd 100644 --- a/src/PIPELINE/VISU_PipeLine.cxx +++ b/src/PIPELINE/VISU_PipeLine.cxx @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -51,70 +52,115 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif -VISU_PipeLine::VISU_PipeLine() +VISU_PipeLine +::VISU_PipeLine(): + myMapper(vtkDataSetMapper::New()), + myExtractGeometry(SALOME_ExtractGeometry::New()) { - if(MYDEBUG) MESSAGE("VISU_PipeLine - "<Delete(); + // Clipping planes - myExtractGeometry = SALOME_ExtractGeometry::New(); - //myExtractGeometry->SetReleaseDataFlag(true); myExtractGeometry->Delete(); - //myExtractGeometry->DebugOn(); + myExtractGeometry->SetStoreMapping(true); vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New(); - myExtractGeometry->SetImplicitBoolean(anImplicitBoolean); + myExtractGeometry->SetImplicitFunction(anImplicitBoolean); anImplicitBoolean->SetOperationTypeToIntersection(); anImplicitBoolean->Delete(); - // Mapper - myMapper = TMapper::New(); - myInput = NULL; - myIsShrinkable = false; - SetDebug(MYVTKDEBUG); } -VISU_PipeLine::~VISU_PipeLine() +VISU_PipeLine +::~VISU_PipeLine() { - if(MYDEBUG) MESSAGE("~VISU_PipeLine - "<Delete(); + if(MYDEBUG) MESSAGE("VISU_PipeLine::~VISU_PipeLine - "<GetInput()); - myMapper->ShallowCopy(thePipeLine->GetMapper()); - myExtractGeometry->SetImplicitBoolean(thePipeLine->myExtractGeometry->GetImplicitBoolean()); +// Turn debugging output on. +void +VISU_PipeLine +::DebugOn() +{ + myExtractGeometry->DebugOn(); + Superclass::DebugOn(); +} + +// Turn debugging output off. +void +VISU_PipeLine +::DebugOff() +{ + myExtractGeometry->DebugOff(); + Superclass::DebugOff(); +} + +void +VISU_PipeLine +::ShallowCopy(VISU_PipeLine *thePipeLine) +{ + SetImplicitFunction(thePipeLine->GetImplicitFunction()); + + // To restore mapper input from pipeline + vtkDataSet* aDatsSet = myMapper->GetInput(); + GetMapper()->ShallowCopy(thePipeLine->GetMapper()); + myMapper->SetInput(aDatsSet); + Build(); } -void VISU_PipeLine::SameAs(VISU_PipeLine *thePipeLine){ +void +VISU_PipeLine +::SameAs(VISU_PipeLine *thePipeLine) +{ ShallowCopy(thePipeLine); - myExtractGeometry->SetImplicitBoolean(vtkImplicitBoolean::New()); - myExtractGeometry->GetImplicitBoolean()->Delete(); + SetImplicitFunction(vtkImplicitBoolean::New()); + GetImplicitFunction()->Delete(); } -TInput* VISU_PipeLine::GetInput() const +TInput* +VISU_PipeLine +::GetInput() const { - return myInput; + return myInput.GetPointer(); } -TInput* VISU_PipeLine::GetInput2() const +vtkDataSet* +VISU_PipeLine +::GetOutput() +{ + return GetMapper()->GetInput(); +} + +TInput* +VISU_PipeLine +::GetInput2() const { vtkUnstructuredGrid* aDataSet = myExtractGeometry->GetOutput(); aDataSet->Update(); return aDataSet; } -void VISU_PipeLine::SetInput(TInput* theInput) +void +VISU_PipeLine +::SetInput(TInput* theInput) { + if(theInput) + theInput->Update(); + myExtractGeometry->SetInput(theInput); - if((myInput = theInput)) - myInput->Update(); + myInput = theInput; Modified(); } -VISU_PipeLine::TMapper* VISU_PipeLine::GetMapper() +VISU_PipeLine::TMapper* +VISU_PipeLine +::GetMapper() { if(GetInput()){ if(!myMapper->GetInput()){ @@ -123,15 +169,19 @@ VISU_PipeLine::TMapper* VISU_PipeLine::GetMapper() } myMapper->Update(); } - return myMapper; + return myMapper.GetPointer(); } -void VISU_PipeLine::Update() +void +VISU_PipeLine +::Update() { myMapper->Update(); } -int VISU_PipeLine::CheckAvailableMemory(const float& theSize) +int +VISU_PipeLine +::CheckAvailableMemory(const float& theSize) { try{ if(theSize > ULONG_MAX) return 0; @@ -152,7 +202,10 @@ int VISU_PipeLine::CheckAvailableMemory(const float& theSize) return 0; } -float VISU_PipeLine::GetAvailableMemory(float theSize, float theMinSize) +float +VISU_PipeLine +::GetAvailableMemory(float theSize, + float theMinSize) { while(!CheckAvailableMemory(theSize)) if(theSize > theMinSize) @@ -163,8 +216,9 @@ float VISU_PipeLine::GetAvailableMemory(float theSize, float theMinSize) } //------------------------ Clipping planes ----------------------------------- - -bool VISU_PipeLine::AddClippingPlane(vtkPlane* thePlane) +bool +VISU_PipeLine +::AddClippingPlane(vtkPlane* thePlane) { if (thePlane) { if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) { @@ -182,7 +236,9 @@ bool VISU_PipeLine::AddClippingPlane(vtkPlane* thePlane) return true; } -vtkPlane* VISU_PipeLine::GetClippingPlane(vtkIdType theID) const +vtkPlane* +VISU_PipeLine +::GetClippingPlane(vtkIdType theID) const { vtkPlane* aPlane = NULL; if(theID >= 0 && theID < GetNumberOfClippingPlanes()){ @@ -198,7 +254,9 @@ vtkPlane* VISU_PipeLine::GetClippingPlane(vtkIdType theID) const return aPlane; } -void VISU_PipeLine::RemoveAllClippingPlanes() +void +VISU_PipeLine +::RemoveAllClippingPlanes() { if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){ vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction(); @@ -207,7 +265,9 @@ void VISU_PipeLine::RemoveAllClippingPlanes() } } -vtkIdType VISU_PipeLine::GetNumberOfClippingPlanes() const +vtkIdType +VISU_PipeLine +::GetNumberOfClippingPlanes() const { if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){ vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction(); @@ -216,9 +276,13 @@ vtkIdType VISU_PipeLine::GetNumberOfClippingPlanes() const return 0; } -static void ComputeBoundsParam (vtkDataSet* theDataSet, - float theDirection[3], float theMinPnt[3], - float& theMaxBoundPrj, float& theMinBoundPrj) +static +void +ComputeBoundsParam (vtkDataSet* theDataSet, + float theDirection[3], + float theMinPnt[3], + float& theMaxBoundPrj, + float& theMinBoundPrj) { float aBounds[6]; theDataSet->GetBounds(aBounds); @@ -260,8 +324,12 @@ static void ComputeBoundsParam (vtkDataSet* theDataSet, theMinPnt[2] = aMinPnt[2]; } -static void DistanceToPosition (vtkDataSet* theDataSet, - float theDirection[3], float theDist, float thePos[3]) +static +void +DistanceToPosition(vtkDataSet* theDataSet, + float theDirection[3], + float theDist, + float thePos[3]) { float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3]; ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj); @@ -271,8 +339,12 @@ static void DistanceToPosition (vtkDataSet* theDataSet, thePos[2] = aMinPnt[2]-theDirection[2]*aLength; } -static void PositionToDistance (vtkDataSet* theDataSet, - float theDirection[3], float thePos[3], float& theDist) +static +void +PositionToDistance (vtkDataSet* theDataSet, + float theDirection[3], + float thePos[3], + float& theDist) { float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3]; ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj); @@ -280,7 +352,11 @@ static void PositionToDistance (vtkDataSet* theDataSet, theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj); } -void VISU_PipeLine::SetPlaneParam (float theDir[3], float theDist, vtkPlane* thePlane) +void +VISU_PipeLine +::SetPlaneParam(float theDir[3], + float theDist, + vtkPlane* thePlane) { thePlane->SetNormal(theDir); float anOrigin[3]; @@ -288,7 +364,11 @@ void VISU_PipeLine::SetPlaneParam (float theDir[3], float theDist, vtkPlane* the thePlane->SetOrigin(anOrigin); } -void VISU_PipeLine::GetPlaneParam (float theDir[3], float& theDist, vtkPlane* thePlane) +void +VISU_PipeLine +::GetPlaneParam(float theDir[3], + float& theDist, + vtkPlane* thePlane) { thePlane->GetNormal(theDir); @@ -301,7 +381,9 @@ void VISU_PipeLine::GetPlaneParam (float theDir[3], float& theDist, vtkPlane* th //function : IsPlanarInput //purpose : //======================================================================= -bool VISU_PipeLine::IsPlanarInput() const +bool +VISU_PipeLine +::IsPlanarInput() const { float aBounds[6]; GetInput()->GetBounds( aBounds ); // xmin,xmax, ymin,ymax, zmin,zmax @@ -312,3 +394,89 @@ bool VISU_PipeLine::IsPlanarInput() const return false; } + +//======================================================================= +vtkIdType +VISU_PipeLine +::GetNodeObjID(vtkIdType theID) +{ + vtkIdType anID = myExtractGeometry->GetNodeObjId(theID); + return myIDMapper->GetNodeObjID(anID); +} + +vtkIdType +VISU_PipeLine +::GetNodeVTKID(vtkIdType theID) +{ + vtkIdType anID = myIDMapper->GetNodeVTKID(theID); + return myExtractGeometry->GetNodeVTKId(anID); +} + +float* +VISU_PipeLine +::GetNodeCoord(int theObjID) +{ + return myIDMapper->GetNodeCoord(theObjID); +} + +//======================================================================= +vtkIdType +VISU_PipeLine +::GetElemObjID(vtkIdType theID) +{ + vtkIdType anID = myExtractGeometry->GetElemObjId(theID); + return myIDMapper->GetElemObjID(anID); +} + +vtkIdType +VISU_PipeLine +::GetElemVTKID(vtkIdType theID) +{ + vtkIdType anID = myIDMapper->GetElemVTKID(theID); + return myExtractGeometry->GetElemVTKId(anID); +} + +vtkCell* +VISU_PipeLine +::GetElemCell(vtkIdType theObjID) +{ + return myIDMapper->GetElemCell(theObjID); +} + +//======================================================================= +void +VISU_PipeLine +::SetIDMapper(const VISU::PIDMapper& theIDMapper) +{ + myIDMapper = theIDMapper; + SetInput(myIDMapper->GetVTKOutput()); +} + +const VISU::PIDMapper& +VISU_PipeLine +::GetIDMapper() const +{ + return myIDMapper; +} + +//======================================================================= +void +VISU_PipeLine +::SetImplicitFunction(vtkImplicitFunction *theFunction) +{ + myExtractGeometry->SetImplicitFunction(theFunction); +} + +vtkImplicitFunction * +VISU_PipeLine +::GetImplicitFunction() +{ + return myExtractGeometry->GetImplicitFunction(); +} + +SALOME_ExtractGeometry* +VISU_PipeLine +::GetExtractGeometryFilter() +{ + return myExtractGeometry.GetPointer(); +} diff --git a/src/PIPELINE/VISU_PipeLine.hxx b/src/PIPELINE/VISU_PipeLine.hxx index 4dd6db6e..5e2a1ed8 100644 --- a/src/PIPELINE/VISU_PipeLine.hxx +++ b/src/PIPELINE/VISU_PipeLine.hxx @@ -27,35 +27,50 @@ #ifndef VISU_PipeLine_HeaderFile #define VISU_PipeLine_HeaderFile +#include #include #include -#include +#include "VISU_IDMapper.hxx" + +class vtkCell; +class vtkDataSet; +class vtkImplicitFunction; template class TVTKSmartPtr: public vtkSmartPointer { public: - TVTKSmartPtr() {} - TVTKSmartPtr(T* r, bool theIsOwner = false): vtkSmartPointer(r) { + TVTKSmartPtr() + {} + + TVTKSmartPtr(T* r, bool theIsOwner = false): vtkSmartPointer(r) + { if(r && theIsOwner) r->Delete(); } - TVTKSmartPtr& operator()(T* r, bool theIsOwner = false){ + + TVTKSmartPtr& operator()(T* r, bool theIsOwner = false) + { vtkSmartPointer::operator=(r); if(r && theIsOwner) r->Delete(); return *this; } - TVTKSmartPtr& operator=(T* r){ + + TVTKSmartPtr& operator=(T* r) + { vtkSmartPointer::operator=(r); return *this; } - operator T* () const { + + operator T* () const + { return vtkSmartPointer::GetPointer(); } }; +class vtkMapper; class vtkDataSetMapper; class vtkUnstructuredGrid; class vtkExtractGeometry; @@ -64,54 +79,151 @@ class vtkPlane; class SALOME_ExtractGeometry; -typedef vtkUnstructuredGrid TInput; +typedef VISU::TVTKOutput TInput; class VISU_PipeLine : public vtkObject{ public: vtkTypeMacro(VISU_PipeLine,vtkObject); - virtual ~VISU_PipeLine(); + virtual + ~VISU_PipeLine(); + + virtual + void + DebugOn(); - virtual void ShallowCopy(VISU_PipeLine *thePipeLine); - virtual void SameAs(VISU_PipeLine *thePipeLine); + virtual + void + DebugOff(); + + virtual + void + ShallowCopy(VISU_PipeLine *thePipeLine); + + virtual + void + SameAs(VISU_PipeLine *thePipeLine); public: - virtual void SetInput(TInput* theInput); - virtual TInput* GetInput() const; + virtual + void + SetInput(TInput* theInput); + + virtual + TInput* + GetInput() const; + + virtual + vtkDataSet* + GetOutput(); - bool IsPlanarInput() const; + bool + IsPlanarInput() const; - typedef vtkDataSetMapper TMapper; - virtual TMapper* GetMapper(); + typedef vtkMapper TMapper; - virtual void Init() = 0; - virtual void Update(); + virtual + TMapper* + GetMapper(); - static int CheckAvailableMemory(const float& theSize); - static float GetAvailableMemory(float theSize = 16*1024*1024.0, - float theMinSize = 1024*1024.0); + virtual + void + Init() = 0; + + virtual + void + Update(); + + static + int + CheckAvailableMemory(const float& theSize); + + static + float + GetAvailableMemory(float theSize = 16*1024*1024.0, + float theMinSize = 1024*1024.0); // Clipping planes - void RemoveAllClippingPlanes(); - vtkIdType GetNumberOfClippingPlanes() const; - bool AddClippingPlane(vtkPlane* thePlane); - vtkPlane* GetClippingPlane(vtkIdType theID) const; + void + RemoveAllClippingPlanes(); + + vtkIdType + GetNumberOfClippingPlanes() const; - void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane); - void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane); + bool + AddClippingPlane(vtkPlane* thePlane); - bool IsShrinkable() { return myIsShrinkable; } + vtkPlane* + GetClippingPlane(vtkIdType theID) const; + + void + SetPlaneParam(float theDir[3], + float theDist, + vtkPlane* thePlane); + + void + GetPlaneParam(float theDir[3], + float& theDist, + vtkPlane* thePlane); + + bool + IsShrinkable() { return myIsShrinkable; } + + virtual + vtkIdType + GetNodeObjID(vtkIdType theID); + + virtual + vtkIdType + GetNodeVTKID(vtkIdType theID); + + virtual + float* + GetNodeCoord(vtkIdType theObjID); + + virtual + vtkIdType + GetElemObjID(vtkIdType theID); + + virtual + vtkIdType + GetElemVTKID(vtkIdType theID); + + virtual + vtkCell* + GetElemCell(vtkIdType theObjID); + + void + SetIDMapper(const VISU::PIDMapper& theIDMapper); + + const VISU::PIDMapper& + GetIDMapper()const; + + void + SetImplicitFunction(vtkImplicitFunction *theFunction); + + vtkImplicitFunction* + GetImplicitFunction(); + + SALOME_ExtractGeometry* + GetExtractGeometryFilter(); protected: VISU_PipeLine(); VISU_PipeLine(const VISU_PipeLine&); - virtual TInput* GetInput2() const; - virtual void Build() = 0; + virtual + TInput* + GetInput2() const; + + virtual + void + Build() = 0; bool myIsShrinkable; - TInput *myInput; - TMapper *myMapper; + TVTKSmartPtr myInput; + VISU::PIDMapper myIDMapper; + TVTKSmartPtr myMapper; // Clipping planes TVTKSmartPtr myExtractGeometry; diff --git a/src/PIPELINE/VISU_PipeLineUtils.hxx b/src/PIPELINE/VISU_PipeLineUtils.hxx index df7c8219..7b252350 100644 --- a/src/PIPELINE/VISU_PipeLineUtils.hxx +++ b/src/PIPELINE/VISU_PipeLineUtils.hxx @@ -59,10 +59,12 @@ namespace VISU{ void Mul(const float A[3], float b, float C[3]); // C = A * b void Sub(const float A[3], const float B[3], float C[3]); // C = A - B - template void CellDataToPoint(TItem* theTItem, - vtkCellDataToPointData *theFilter, - vtkDataSet* theDataSet, - VISU_FieldTransform *theFieldTransform) + template + void + CellDataToPoint(TItem* theTItem, + vtkCellDataToPointData *theFilter, + vtkDataSet* theDataSet, + VISU_FieldTransform *theFieldTransform) { if(theDataSet->GetCellData()->GetNumberOfArrays()){ theFilter->SetInput(theFieldTransform->GetUnstructuredGridOutput()); @@ -72,10 +74,12 @@ namespace VISU{ theTItem->SetInput(theFieldTransform->GetUnstructuredGridOutput()); } - template void ToCellCenters(TItem* theTItem, - vtkCellCenters *theFilter, - vtkDataSet* theDataSet, - VISU_FieldTransform *theFieldTransform) + template + void + ToCellCenters(TItem* theTItem, + vtkCellCenters *theFilter, + vtkDataSet* theDataSet, + VISU_FieldTransform *theFieldTransform) { if(theDataSet->GetCellData()->GetNumberOfArrays()){ theFilter->SetInput(theFieldTransform->GetUnstructuredGridOutput()); diff --git a/src/PIPELINE/VISU_PlanesWidget.cxx b/src/PIPELINE/VISU_PlanesWidget.cxx new file mode 100644 index 00000000..93efa07b --- /dev/null +++ b/src/PIPELINE/VISU_PlanesWidget.cxx @@ -0,0 +1,1614 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_ImplicitFunctionWidget.cxx +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#include "VISU_PlanesWidget.hxx" +#include "VISU_ImplicitFunctionWidget.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//// +#include +#include +#include +#include + +static + bool IsValidPlane2Position(vtkPlane *pPx, + vtkDataSet *pDataSet, + float aTol=0.003); +static + void GetBndPoints(vtkDataSet *pDataSet, + float aPnts[24]); +static + float DistanceToPlane(const float x[3], + const float n[3], + const float p0[3]); + +vtkCxxRevisionMacro(VISU_PlanesWidget, "$Revision$"); +vtkStandardNewMacro(VISU_PlanesWidget); + +//================================================================== +// function: VISU_PlanesWidget +// purpose : +//================================================================== +VISU_PlanesWidget::VISU_PlanesWidget() +: + VISU_ImplicitFunctionWidget() +{ + State = VISU_PlanesWidget::Start; + EventCallbackCommand->SetCallback(VISU_PlanesWidget::ProcessEvents); + + NormalToXAxis = 0; + NormalToYAxis = 0; + NormalToZAxis = 0; + + HandleMoveEvent = true; + HandleLeftButtonEvent = true; + HandleMiddleButtonEvent = false; + HandleRightButtonEvent = false; + + // Build the representation of the widget + // + myPlane1 = vtkPlane::New(); + myPlane1->SetNormal(0,0,1); + myPlane1->SetOrigin(0,0,0); + // + myDistance = 10.; + myPlane2 = vtkPlane::New(); + myPlane2->SetNormal(0.,0.,-1.); + myPlane2->SetOrigin(0,0,myDistance); + // + myImplicitFunction = vtkImplicitBoolean::New(); + myImplicitFunction->SetOperationType(VTK_UNION); + // + myBox = vtkImageData::New(); + myBox->SetDimensions(2,2,2); + myOutline = vtkOutlineFilter::New(); + myOutline->SetInput(myBox); + myOutlineMapper = vtkPolyDataMapper::New(); + myOutlineMapper->SetInput(myOutline->GetOutput()); + myOutlineActor = vtkActor::New(); + this->myOutlineActor->SetMapper(this->myOutlineMapper); + this->myOutlineActor->PickableOff(); + this->OutlineTranslation = 0; + + this->myCutter1 = vtkCutter::New(); + this->myCutter1->SetInput(myBox); + this->myCutter1->SetCutFunction(myPlane1); + this->myCutMapper1 = vtkPolyDataMapper::New(); + this->myCutMapper1->SetInput(this->myCutter1->GetOutput()); + this->myCutActor1 = vtkActor::New(); + this->myCutActor1->SetMapper(this->myCutMapper1); + this->myDrawPlane = 1; + + this->myEdges1 = vtkFeatureEdges::New(); + myEdges1->SetColoring(0); + this->myEdges1->SetInput(this->myCutter1->GetOutput()); + this->myEdgesMapper1 = vtkPolyDataMapper::New(); + this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput()); + this->myEdgesActor1 = vtkActor::New(); + this->myEdgesActor1->SetMapper(this->myEdgesMapper1); + myEdgesActor1->GetProperty()->SetLineWidth(4.); + myEdgesActor1->GetProperty()->SetColor(0., .5, .7); + + this->myCutter2 = vtkCutter::New(); + this->myCutter2->SetInput(myBox); + this->myCutter2->SetCutFunction(this->myPlane2); + this->myCutMapper2 = vtkPolyDataMapper::New(); + this->myCutMapper2->SetInput(this->myCutter2->GetOutput()); + this->myCutActor2 = vtkActor::New(); + this->myCutActor2->SetMapper(this->myCutMapper2); + + myEdges2 = vtkFeatureEdges::New(); + myEdges2->SetColoring(0); + myEdges2->SetInput(myCutter2->GetOutput()); + myEdgesMapper2 = vtkPolyDataMapper::New(); + myEdgesMapper2->SetInput(myEdges2->GetOutput()); + myEdgesActor2 = vtkActor::New(); + myEdgesActor2->SetMapper(myEdgesMapper2); + myEdgesActor2->GetProperty()->SetLineWidth(4.); + myEdgesActor2->GetProperty()->SetColor(.7, .0, .0); + + // Create the + plane normal + this->LineSource = vtkLineSource::New(); + this->LineSource->SetResolution(1); + this->LineMapper = vtkPolyDataMapper::New(); + this->LineMapper->SetInput(this->LineSource->GetOutput()); + this->LineActor = vtkActor::New(); + this->LineActor->SetMapper(this->LineMapper); + + this->ConeSource = vtkConeSource::New(); + this->ConeSource->SetResolution(12); + this->ConeSource->SetAngle(20.); + this->ConeMapper = vtkPolyDataMapper::New(); + this->ConeMapper->SetInput(this->ConeSource->GetOutput()); + this->ConeActor = VISU_UnScaledActor::New(); + this->ConeActor->SetMapper(this->ConeMapper); + ConeActor->SetSize(36); + ConeActor->SetCenter(ConeSource->GetCenter()); + + // Create the - plane normal + this->LineSource2 = vtkLineSource::New(); + this->LineSource2->SetResolution(1); + this->LineMapper2 = vtkPolyDataMapper::New(); + this->LineMapper2->SetInput(this->LineSource2->GetOutput()); + this->LineActor2 = vtkActor::New(); + this->LineActor2->SetMapper(this->LineMapper2); + + this->ConeSource2 = vtkConeSource::New(); + this->ConeSource2->SetResolution(12); + this->ConeSource2->SetAngle(20.); + this->ConeMapper2 = vtkPolyDataMapper::New(); + this->ConeMapper2->SetInput(this->ConeSource2->GetOutput()); + this->ConeActor2 = VISU_UnScaledActor::New(); + this->ConeActor2->SetMapper(this->ConeMapper2); + ConeActor2->SetSize(36); + ConeActor2->SetCenter(ConeSource2->GetCenter()); + + // Create the origin handle + this->Sphere = vtkSphereSource::New(); + this->Sphere->SetThetaResolution(16); + this->Sphere->SetPhiResolution(8); + this->SphereMapper = vtkPolyDataMapper::New(); + this->SphereMapper->SetInput(this->Sphere->GetOutput()); + this->SphereActor = VISU_UnScaledActor::New(); + this->SphereActor->SetMapper(this->SphereMapper); + SphereActor->SetSize(36); + SphereActor->SetCenter(Sphere->GetCenter()); + + this->Transform = vtkTransform::New(); + + // Define the point coordinates + float bounds[6]; + bounds[0] = -0.5; + bounds[1] = 0.5; + bounds[2] = -0.5; + bounds[3] = 0.5; + bounds[4] = -0.5; + bounds[5] = 0.5; + + // Initial creation of the widget, serves to initialize it + this->PlaceWidget(bounds); + + //Manage the picking stuff + this->Picker = vtkCellPicker::New(); + this->Picker->SetTolerance(0.005); + this->Picker->AddPickList(this->myCutActor1); + this->Picker->AddPickList(this->myCutActor2); + this->Picker->AddPickList(this->LineActor); + this->Picker->AddPickList(this->ConeActor); + this->Picker->AddPickList(this->LineActor2); + this->Picker->AddPickList(this->ConeActor2); + this->Picker->AddPickList(this->SphereActor); + this->Picker->AddPickList(this->myOutlineActor); + this->Picker->PickFromListOn(); + + // Set up the initial properties + this->CreateDefaultProperties(); + +} +//================================================================== +// function: ~ +// purpose : +//================================================================== +VISU_PlanesWidget::~VISU_PlanesWidget() +{ + myPlane1->Delete(); + + this->myPlane2->Delete(); + this->myImplicitFunction->Delete(); + + myBox->Delete(); + this->myOutline->Delete(); + this->myOutlineMapper->Delete(); + this->myOutlineActor->Delete(); + + this->myCutter1->Delete(); + this->myCutMapper1->Delete(); + this->myCutActor1->Delete(); + + this->myEdges1->Delete(); + this->myEdgesMapper1->Delete(); + this->myEdgesActor1->Delete(); + + myCutter2->Delete(); + myCutMapper2->Delete(); + myCutActor2->Delete(); + + myEdges2->Delete(); + myEdgesMapper2->Delete(); + myEdgesActor2->Delete(); + + this->LineSource->Delete(); + this->LineMapper->Delete(); + this->LineActor->Delete(); + + this->ConeSource->Delete(); + this->ConeMapper->Delete(); + this->ConeActor->Delete(); + + this->LineSource2->Delete(); + this->LineMapper2->Delete(); + this->LineActor2->Delete(); + + this->ConeSource2->Delete(); + this->ConeMapper2->Delete(); + this->ConeActor2->Delete(); + + this->Sphere->Delete(); + this->SphereMapper->Delete(); + this->SphereActor->Delete(); + + this->Transform->Delete(); + + this->Picker->Delete(); + + this->NormalProperty->Delete(); + this->SelectedNormalProperty->Delete(); + this->PlaneProperty->Delete(); + this->SelectedPlaneProperty->Delete(); + this->OutlineProperty->Delete(); + this->SelectedOutlineProperty->Delete(); + this->EdgesProperty->Delete(); +} +//================================================================== +// function: ImplicitFunction +// purpose : +//================================================================== +vtkImplicitFunction* VISU_PlanesWidget::ImplicitFunction() +{ + return this->myImplicitFunction; +} +//================================================================== +// function: SetDistance +// purpose : +//================================================================== +void VISU_PlanesWidget::SetDistance(const float theDistance) +{ + if( theDistance <= 0.0 || theDistance == myDistance ) + return; + + myDistance=theDistance; + // + float *origin, *normal, oNew[3], aN2[3]; + origin = myPlane1->GetOrigin(); + normal = myPlane1->GetNormal(); + vtkMath::Normalize(normal); + oNew[0] = origin[0] + myDistance*normal[0]; + oNew[1] = origin[1] + myDistance*normal[1]; + oNew[2] = origin[2] + myDistance*normal[2]; + myPlane2->SetOrigin(oNew); + aN2[0] = -normal[0]; + aN2[1] = -normal[1]; + aN2[2] = -normal[2]; + myPlane2->SetNormal(aN2); +} +//================================================================== +// function: Distance +// purpose : +//================================================================== +float VISU_PlanesWidget::Distance()const +{ + return myDistance; +} +//================================================================== +// function: SetEnabled +// purpose : +//================================================================== +void VISU_PlanesWidget::SetEnabled(int enabling) +{ + if ( ! this->Interactor ) { + vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget"); + return; + } + + if ( enabling ) {//------------------------------------------------------------ + vtkDebugMacro(<<"Enabling plane widget"); + + if ( this->Enabled ){ //already enabled, just return + return; + } + + if ( ! this->CurrentRenderer ){ + this->CurrentRenderer = this->Interactor->FindPokedRenderer( + this->Interactor->GetLastEventPosition()[0], + this->Interactor->GetLastEventPosition()[1]); + if (this->CurrentRenderer == NULL) { + return; + } + } + // + vtkCamera *pCamera=CurrentRenderer->GetActiveCamera(); + pCamera->SetParallelProjection(1); + // + this->myImplicitFunction->AddFunction(myPlane1); + this->myImplicitFunction->AddFunction(this->myPlane2); + + this->Enabled = 1; + + // listen for the following events + vtkRenderWindowInteractor *i = this->Interactor; + if( this->HandleMoveEvent ) { + i->AddObserver(vtkCommand::MouseMoveEvent, + this->EventCallbackCommand, + this->Priority); + } + if( this->HandleLeftButtonEvent ) { + i->AddObserver(vtkCommand::LeftButtonPressEvent, + this->EventCallbackCommand, + this->Priority); + i->AddObserver(vtkCommand::LeftButtonReleaseEvent, + this->EventCallbackCommand, + this->Priority); + } + if( this->HandleMiddleButtonEvent ) { + i->AddObserver(vtkCommand::MiddleButtonPressEvent, + this->EventCallbackCommand, + this->Priority); + i->AddObserver(vtkCommand::MiddleButtonReleaseEvent, + this->EventCallbackCommand, + this->Priority); + } + if( this->HandleRightButtonEvent ) { + i->AddObserver(vtkCommand::RightButtonPressEvent, + this->EventCallbackCommand, + this->Priority); + i->AddObserver(vtkCommand::RightButtonReleaseEvent, + this->EventCallbackCommand, + this->Priority); + } + // add the outline + this->CurrentRenderer->AddActor(this->myOutlineActor); + this->myOutlineActor->SetProperty(this->OutlineProperty); + + // add the edges + this->CurrentRenderer->AddActor(this->myEdgesActor1); + this->CurrentRenderer->AddActor(myEdgesActor2); + + this->myOutlineActor->SetProperty(this->EdgesProperty); + + // add the normal vector + this->CurrentRenderer->AddActor(this->LineActor); + this->LineActor->SetProperty(this->NormalProperty); + this->CurrentRenderer->AddActor(this->ConeActor); + this->ConeActor->SetProperty(this->NormalProperty); + + this->CurrentRenderer->AddActor(this->LineActor2); + this->LineActor2->SetProperty(this->NormalProperty); + this->CurrentRenderer->AddActor(this->ConeActor2); + this->ConeActor2->SetProperty(this->NormalProperty); + + // add the origin handle + this->CurrentRenderer->AddActor(this->SphereActor); + this->SphereActor->SetProperty(this->NormalProperty); + + // add the plane (if desired) + if ( this->myDrawPlane ) { + this->CurrentRenderer->AddActor(this->myCutActor1); + this->CurrentRenderer->AddActor(this->myCutActor2); + } + this->myCutActor1->SetProperty(this->PlaneProperty); + myCutActor2->SetProperty(this->PlaneProperty); + + this->UpdateRepresentation(); + //this->SizeHandles(); + this->InvokeEvent(vtkCommand::EnableEvent,NULL); + } + + else {//disabling---------------------------------------------------------- + vtkDebugMacro(<<"Disabling plane widget"); + + if ( ! this->Enabled ) {//already disabled, just return + return; + } + + if(vtkImplicitFunctionCollection* aFunction = this->myImplicitFunction->GetFunction()){ + aFunction->RemoveAllItems(); + this->myImplicitFunction->Modified(); // VTK bug + } + + this->Enabled = 0; + + // don't listen for events any more + this->Interactor->RemoveObserver(this->EventCallbackCommand); + + // turn off the various actors + this->CurrentRenderer->RemoveActor(this->myOutlineActor); + this->CurrentRenderer->RemoveActor(this->myEdgesActor1); + this->CurrentRenderer->RemoveActor(myEdgesActor2); + this->CurrentRenderer->RemoveActor(this->LineActor); + this->CurrentRenderer->RemoveActor(this->ConeActor); + this->CurrentRenderer->RemoveActor(this->LineActor2); + this->CurrentRenderer->RemoveActor(this->ConeActor2); + this->CurrentRenderer->RemoveActor(this->SphereActor); + this->CurrentRenderer->RemoveActor(this->myCutActor1); + this->CurrentRenderer->RemoveActor(myCutActor2); + + this->InvokeEvent(vtkCommand::DisableEvent,NULL); + this->CurrentRenderer = NULL; + } + + this->Interactor->Render(); +} +//================================================================== +// function: ProcessEvents +// purpose : +//================================================================== +void VISU_PlanesWidget::ProcessEvents(vtkObject* vtkNotUsed(object), + unsigned long event, + void* clientdata, + void* vtkNotUsed(calldata)) +{ + VISU_PlanesWidget* self = + reinterpret_cast( clientdata ); + + //okay, let's do the right thing + switch(event) + { + case vtkCommand::LeftButtonPressEvent: + self->OnLeftButtonDown(); + break; + case vtkCommand::LeftButtonReleaseEvent: + self->OnLeftButtonUp(); + break; + case vtkCommand::MiddleButtonPressEvent: + self->OnMiddleButtonDown(); + break; + case vtkCommand::MiddleButtonReleaseEvent: + self->OnMiddleButtonUp(); + break; + case vtkCommand::RightButtonPressEvent: + self->OnRightButtonDown(); + break; + case vtkCommand::RightButtonReleaseEvent: + self->OnRightButtonUp(); + break; + case vtkCommand::MouseMoveEvent: + self->OnMouseMove(); + break; + default: + break; + } +} +//================================================================== +// function: HighlightNormal +// purpose : +//================================================================== +void VISU_PlanesWidget::HighlightNormal(int highlight) +{ + if ( highlight ) { + this->LineActor->SetProperty(this->SelectedNormalProperty); + this->ConeActor->SetProperty(this->SelectedNormalProperty); + this->LineActor2->SetProperty(this->SelectedNormalProperty); + this->ConeActor2->SetProperty(this->SelectedNormalProperty); + this->SphereActor->SetProperty(this->SelectedNormalProperty); + } + else + { + this->LineActor->SetProperty(this->NormalProperty); + this->ConeActor->SetProperty(this->NormalProperty); + this->LineActor2->SetProperty(this->NormalProperty); + this->ConeActor2->SetProperty(this->NormalProperty); + this->SphereActor->SetProperty(this->NormalProperty); + } +} +//================================================================== +// function: HighlightPlane +// purpose : +//================================================================== +void VISU_PlanesWidget::HighlightPlane(int highlight) +{ + if ( highlight ) { + this->myCutActor1->SetProperty(this->SelectedPlaneProperty); + myCutActor2->SetProperty(this->SelectedPlaneProperty); + } + else { + this->myCutActor1->SetProperty(this->PlaneProperty); + myCutActor2->SetProperty(this->PlaneProperty); + } +} +//================================================================== +// function: HighlightOutline +// purpose : +//================================================================== +void VISU_PlanesWidget::HighlightOutline(int highlight) +{ + if (highlight) { + this->myOutlineActor->SetProperty(this->SelectedOutlineProperty); + } + else { + this->myOutlineActor->SetProperty(this->OutlineProperty); + } +} +//================================================================== +// function: OnLeftButtonDown +// purpose : +//================================================================== +void VISU_PlanesWidget::OnLeftButtonDown() +{ + // We're only here if we are enabled + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + // + // Okay, we can process this. See if we've picked anything. + // Make sure it's in the activated renderer + vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); + if ( ren != this->CurrentRenderer ) { + this->State = VISU_PlanesWidget::Outside; + return; + } + + vtkAssemblyPath *path; + this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); + path = this->Picker->GetPath(); + + if ( path == NULL ) {//not picking this widget + this->HighlightPlane(0); + this->HighlightNormal(0); + this->HighlightOutline(0); + this->State = VISU_PlanesWidget::Outside; + return; + } + + vtkProp *prop = path->GetFirstNode()->GetProp(); + this->ValidPick = 1; + this->Picker->GetPickPosition(this->LastPickPosition); + // + if ( prop == this->ConeActor || prop == this->LineActor || + prop == this->ConeActor2 || prop == this->LineActor2 ) { + this->HighlightPlane(1); + this->HighlightNormal(1); + this->State = VISU_PlanesWidget::Rotating; + } + else if ( prop == this->myCutActor1) { + this->HighlightPlane(1); + this->State = VISU_PlanesWidget::Pushing; + } + else if ( prop == this->SphereActor ) { + this->HighlightNormal(1); + this->State = VISU_PlanesWidget::MovingOrigin; + } + else if (prop == myCutActor2) { + this->HighlightPlane(1); + this->State = VISU_PlanesWidget::ChangeDistance; + } + else { + if ( this->OutlineTranslation ) { + this->HighlightOutline(1); + this->State = VISU_PlanesWidget::MovingOutline; + } + } + + this->EventCallbackCommand->SetAbortFlag(1); + this->StartInteraction(); + this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnLeftButtonUp +// purpose : +//================================================================== +void VISU_PlanesWidget::OnLeftButtonUp() +{ + if ( this->State == VISU_PlanesWidget::Outside ) { + return; + } + + this->State = VISU_PlanesWidget::Start; + this->HighlightPlane(0); + this->HighlightOutline(0); + this->HighlightNormal(0); + //this->SizeHandles(); + + this->EventCallbackCommand->SetAbortFlag(1); + this->EndInteraction(); + this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnMiddleButtonDown +// purpose : +//================================================================== +void VISU_PlanesWidget::OnMiddleButtonDown() +{ + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + + // Okay, we can process this. See if we've picked anything. + // Make sure it's in the activated renderer + vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); + if ( ren != this->CurrentRenderer ) { + this->State = VISU_PlanesWidget::Outside; + return; + } + + // Okay, we can process this. + vtkAssemblyPath *path; + this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); + path = this->Picker->GetPath(); + + if ( path == NULL ) {//nothing picked + this->State = VISU_PlanesWidget::Outside; + return; + } + + this->ValidPick = 1; + this->Picker->GetPickPosition(this->LastPickPosition); + this->State = VISU_PlanesWidget::MovingPlane; + this->HighlightNormal(1); + this->HighlightPlane(1); + + this->EventCallbackCommand->SetAbortFlag(1); + this->StartInteraction(); + this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnMiddleButtonUp +// purpose : +//================================================================== +void VISU_PlanesWidget::OnMiddleButtonUp() +{ + if ( this->State == VISU_PlanesWidget::Outside ) { + return; + } + + this->State = VISU_PlanesWidget::Start; + this->HighlightPlane(0); + this->HighlightOutline(0); + this->HighlightNormal(0); + //this->SizeHandles(); + + this->EventCallbackCommand->SetAbortFlag(1); + this->EndInteraction(); + this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnRightButtonDown +// purpose : +//================================================================== +void VISU_PlanesWidget::OnRightButtonDown() +{ + this->State = VISU_PlanesWidget::Scaling; + + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + + // Okay, we can process this. See if we've picked anything. + // Make sure it's in the activated renderer + vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); + if ( ren != this->CurrentRenderer ) { + this->State = VISU_PlanesWidget::Outside; + return; + } + + // Okay, we can process this. Try to pick handles first; + // if no handles picked, then pick the bounding box. + vtkAssemblyPath *path; + this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); + path = this->Picker->GetPath(); + if ( path == NULL ){ //nothing picked + this->State = VISU_PlanesWidget::Outside; + return; + } + + this->ValidPick = 1; + this->Picker->GetPickPosition(this->LastPickPosition); + this->HighlightPlane(1); + this->HighlightOutline(1); + this->HighlightNormal(1); + + this->EventCallbackCommand->SetAbortFlag(1); + this->StartInteraction(); + this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnRightButtonUp +// purpose : +//================================================================== +void VISU_PlanesWidget::OnRightButtonUp() +{ + if ( this->State == VISU_PlanesWidget::Outside ) { + return; + } + + this->State = VISU_PlanesWidget::Start; + this->HighlightPlane(0); + this->HighlightOutline(0); + this->HighlightNormal(0); + //this->SizeHandles(); + + this->EventCallbackCommand->SetAbortFlag(1); + this->EndInteraction(); + this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnMouseMove +// purpose : +//================================================================== +void VISU_PlanesWidget::OnMouseMove() +{ + //this->SizeHandles(); + + // See whether we're active + if ( this->State == VISU_PlanesWidget::Outside || + this->State == VISU_PlanesWidget::Start ) { + return; + } + + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + + // Do different things depending on state + // Calculations everybody does + double focalPoint[4], pickPoint[4], prevPickPoint[4]; + double z, vpn[3]; + + vtkCamera *camera = this->CurrentRenderer->GetActiveCamera(); + if ( !camera ) { + return; + } + + // Compute the two points defining the motion vector + this->ComputeWorldToDisplay(this->LastPickPosition[0], this->LastPickPosition[1], + this->LastPickPosition[2], focalPoint); + z = focalPoint[2]; + this->ComputeDisplayToWorld(double(this->Interactor->GetLastEventPosition()[0]), + double(this->Interactor->GetLastEventPosition()[1]), + z, prevPickPoint); + this->ComputeDisplayToWorld(double(X), double(Y), z, pickPoint); + + // Process the motion + if ( this->State == VISU_PlanesWidget::MovingPlane ) { + //this->TranslatePlane(prevPickPoint, pickPoint); + //printf(" TranslatePlane\n"); + } + else if ( this->State == VISU_PlanesWidget::MovingOutline ) { + //this->TranslateOutline(prevPickPoint, pickPoint); + //printf(" TranslateOutline\n"); + } + else if ( this->State == VISU_PlanesWidget::MovingOrigin ) { + this->TranslateOrigin(prevPickPoint, pickPoint); + //printf(" TranslateOrigin\n"); + } + else if ( this->State == VISU_PlanesWidget::Pushing ) { + this->Push(prevPickPoint, pickPoint); + // printf(" Push\n"); + } + else if ( this->State == VISU_PlanesWidget::Scaling ) { + //this->Scale(prevPickPoint, pickPoint, X, Y); + //printf(" Scale\n"); + } + else if ( this->State == VISU_PlanesWidget::Rotating ) { + camera->GetViewPlaneNormal(vpn); + this->Rotate(X, Y, prevPickPoint, pickPoint, vpn); + //printf(" Rotate\n"); + } + else if ( this->State == VISU_PlanesWidget::ChangeDistance ) { + this->PushDistance(prevPickPoint, pickPoint); + //printf(" PushDistance\n"); + } + // Interact, if desired + this->EventCallbackCommand->SetAbortFlag(1); + this->InvokeEvent(vtkCommand::InteractionEvent,NULL); + + this->Interactor->Render(); +} +//================================================================== +// function: Push +// purpose : +//================================================================== +void VISU_PlanesWidget::Push(double *p1, double *p2) +{ + //Get the motion vector + int i; + float v[3]; + // + for (i=0; i<3; ++i){ + v[i] = p2[i] - p1[i]; + } + // + float aOr1[3], aNr1[3], aNr2[3], aD, z1; + // + myPlane1->GetOrigin(aOr1); + myPlane1->GetNormal(aNr1); + myPlane2->GetNormal(aNr2); + // + aD=vtkMath::Dot(v, aNr2); + z1 = aOr1[2]+aD*aNr2[2]; + if( z1 <= myBox->GetOrigin()[2] ){ + return; + } + // + aD=vtkMath::Dot(v, aNr1); + for (i=0; i < 3; ++i) { + aOr1[i]=aOr1[i]+aD*aNr1[i]; + } + SetOriginInternal(aOr1); + this->UpdateRepresentation(); +} +//================================================================== +// function: TranslateOrigin +// purpose : +//================================================================== +void VISU_PlanesWidget::TranslateOrigin(double *p1, double *p2) +{ + //Get the motion vector + int i; + double v[3]; + // + for (i=0; i<3; ++i){ + v[i] = p2[i] - p1[i]; + } + // + //Add to the current point, project back down onto plane + float *o = myPlane1->GetOrigin(); + float *n = myPlane1->GetNormal(); + float newOrigin[3]; + // + for (i=0; i<3; ++i){ + newOrigin[i]=o[i] + v[i]; + } + vtkPlane::ProjectPoint(newOrigin, o, n, newOrigin); + SetOriginInternal(newOrigin); + this->UpdateRepresentation(); +} +//================================================================== +// function: SetOriginInternal +// purpose : Set the origin of the plane.(for Internal calls) +//================================================================== +void VISU_PlanesWidget::SetOriginInternal(float x[3]) +{ + float *bounds = this->myOutline->GetOutput()->GetBounds(); + int i, j; + for (i=0; i<3; ++i) { + j=2*i; + if ( x[i] < bounds[j] ) { + x[i] = bounds[j]; + } + else if ( x[i] > bounds[j+1] ) { + x[i] = bounds[j+1]; + } + } + // + bool bFlag; + float aOr2[3], aNr2[3], aNr1[3]; + vtkPlane *pPx; + // + myPlane1->GetNormal(aNr1); + myPlane2->GetNormal(aNr2); + for (i=0; i<3; ++i) { + aOr2[i]=x[i]+myDistance*aNr1[i]; + } + pPx=vtkPlane::New(); + pPx->SetOrigin(aOr2); + pPx->SetNormal(aNr2); + bFlag=IsValidPlane2Position(pPx, myBox); + if (bFlag){ + myPlane1->SetOrigin(x); + myPlane2->SetOrigin(aOr2); + } + pPx->Delete(); +} +//================================================================== +// function: Rotate +// purpose : +//================================================================== +void VISU_PlanesWidget::Rotate(int X, int Y, + double *p1, double *p2, + double *vpn) +{ + double v[3]; //vector of motion + double axis[3]; //axis of rotation + double theta; //rotation angle + int i; + + // mouse motion vector in world space + for (i=0; i<3; ++i){ + v[i] = p2[i] - p1[i]; + } + // + float *origin = myPlane1->GetOrigin(); + float *normal = myPlane1->GetNormal(); + + // Create axis of rotation and angle of rotation + vtkMath::Cross(vpn,v,axis); + if ( vtkMath::Normalize(axis) == 0.0 ) { + return; + } + + int *size = this->CurrentRenderer->GetSize(); + double l2 = (X-this->Interactor->GetLastEventPosition()[0])* + (X-this->Interactor->GetLastEventPosition()[0]) + + (Y-this->Interactor->GetLastEventPosition()[1])* + (Y-this->Interactor->GetLastEventPosition()[1]); + theta = 360.0 * sqrt(l2/((double)size[0]*size[0]+size[1]*size[1])); + + //Manipulate the transform to reflect the rotation + this->Transform->Identity(); + this->Transform->Translate(origin[0],origin[1],origin[2]); + this->Transform->RotateWXYZ(theta,axis); + this->Transform->Translate(-origin[0],-origin[1],-origin[2]); + + //Set the new normal + float nNew[3], aN2[3], oNew[3]; + this->Transform->TransformNormal(normal,nNew); + // + for (i=0; i<3; ++i){ + aN2[i] = -nNew[i]; + } + vtkMath::Normalize(nNew); + for (i=0; i<3; ++i){ + oNew[i] = origin[i] + myDistance*nNew[i]; + } + // + vtkPlane *pPx=vtkPlane::New(); + pPx->SetNormal(aN2); + pPx->SetOrigin(oNew); + // + bool bFlag=IsValidPlane2Position(pPx, myBox); + if (bFlag) { + myPlane1->SetNormal(nNew); + this->myPlane2->SetNormal(aN2); + this->myPlane2->SetOrigin(oNew); + } + pPx->Delete(); + this->UpdateRepresentation(); +} +//================================================================== +// function: PushDistance +// purpose : +//================================================================== +void VISU_PlanesWidget::PushDistance(double *p1, double *p2) +{ + int i; + float v[3], *anOrigin1, *aN1, *anOrigin2, *aN2, aD; + //Get the motion vector + for (i=0; i<3; ++i){ + v[i] = p2[i] - p1[i]; + } + // + anOrigin1 = myPlane1->GetOrigin(); + aN1 = myPlane1->GetNormal(); + anOrigin2 = myPlane2->GetOrigin(); + aN2 = myPlane2->GetNormal(); + + vtkMath::Normalize(aN1); + + float origin[3]; + double distance = vtkMath::Dot( v, aN2 ); + for(i=0; i<3; ++i) { + origin[i] = anOrigin2[i] + distance * aN2[i]; + } + float d = DistanceToPlane(origin, aN1, anOrigin1); + if( d <= 0.0 ) + return; + // + bool bFlag; + float aOr2[3], aNr2[3]; + vtkPlane *pPx; + // + myPlane2->GetOrigin(aOr2); + myPlane2->GetNormal(aNr2); + pPx=vtkPlane::New(); + pPx->SetNormal(aNr2); + aD=vtkMath::Dot(v, aNr2); + for (i=0; i < 3; ++i) { + aOr2[i]=aOr2[i]+aD*aNr2[i]; + } + pPx->SetOrigin(aOr2); + bFlag=IsValidPlane2Position(pPx, myBox); + if(bFlag) { + myPlane2->SetOrigin(aOr2); + myPlane2->Modified(); + aD=DistanceToPlane(aOr2, aN1, anOrigin1); + // + myDistance=aD; + } + pPx->Delete(); + this->UpdateRepresentation(); +} + +//================================================================== +// function: TranslatePlane +// purpose : Loop through all points and translate them +//================================================================== +void VISU_PlanesWidget::TranslatePlane(double *p1, double *p2) +{ + //Get the motion vector + double v[3]; + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + + //Translate the plane + float oNew[3]; + float *origin = myPlane1->GetOrigin(); + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + myPlane1->SetOrigin(oNew); + + origin = this->myPlane2->GetOrigin(); + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + this->myPlane2->SetOrigin(oNew); + + this->UpdateRepresentation(); +} +//================================================================== +// function: TranslateOutline +// purpose :Loop through all points and translate them +//================================================================== +void VISU_PlanesWidget::TranslateOutline(double *p1, double *p2) +{ + //Get the motion vector + double v[3]; + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + + //Translate the bounding box + float *origin = myBox->GetOrigin(); + float oNew[3]; + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + myBox->SetOrigin(oNew); + + //Translate the plane + origin = myPlane1->GetOrigin(); + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + myPlane1->SetOrigin(oNew); + + origin = this->myPlane2->GetOrigin(); + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + this->myPlane2->SetOrigin(oNew); + + this->UpdateRepresentation(); +} + +//================================================================== +// function: Scale +// purpose : +//================================================================== +void VISU_PlanesWidget::Scale(double *p1, double *p2, + int vtkNotUsed(X), int Y) +{ + //Get the motion vector + double v[3]; + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + + //int res = this->PlaneSource->GetXResolution(); + float *o = myPlane1->GetOrigin(); + + // Compute the scale factor + float sf = vtkMath::Norm(v) / this->myOutline->GetOutput()->GetLength(); + if ( Y > this->Interactor->GetLastEventPosition()[1] ) { + sf = 1.0 + sf; + } + else { + sf = 1.0 - sf; + } + + this->Transform->Identity(); + this->Transform->Translate(o[0],o[1],o[2]); + this->Transform->Scale(sf,sf,sf); + this->Transform->Translate(-o[0],-o[1],-o[2]); + + float *origin = myBox->GetOrigin(); + float *spacing = myBox->GetSpacing(); + float oNew[3], p[3], pNew[3]; + p[0] = origin[0] + spacing[0]; + p[1] = origin[1] + spacing[1]; + p[2] = origin[2] + spacing[2]; + + this->Transform->TransformPoint(origin,oNew); + this->Transform->TransformPoint(p,pNew); + + myBox->SetOrigin(oNew); + myBox->SetSpacing( (pNew[0]-oNew[0]), (pNew[1]-oNew[1]), (pNew[2]-oNew[2]) ); + + this->UpdateRepresentation(); +} + + + +//================================================================== +// function: CreateDefaultProperties +// purpose : +//================================================================== +void VISU_PlanesWidget::CreateDefaultProperties() +{ + // Normal properties + this->NormalProperty = vtkProperty::New(); + this->NormalProperty->SetColor(1,1,1); + this->NormalProperty->SetLineWidth(2); + + this->SelectedNormalProperty = vtkProperty::New(); + this->SelectedNormalProperty->SetColor(1,0,0); + this->NormalProperty->SetLineWidth(2); + + // Plane properties + this->PlaneProperty = vtkProperty::New(); + this->PlaneProperty->SetAmbient(1.0); + this->PlaneProperty->SetAmbientColor(1.0,1.0,1.0); + + this->SelectedPlaneProperty = vtkProperty::New(); + this->SelectedPlaneProperty->SetAmbient(1.0); + this->SelectedPlaneProperty->SetAmbientColor(0.0,1.0,0.0); + this->SelectedPlaneProperty->SetOpacity(0.25); + + // Outline properties + this->OutlineProperty = vtkProperty::New(); + this->OutlineProperty->SetAmbient(1.0); + this->OutlineProperty->SetAmbientColor(1.0,1.0,1.0); + + this->SelectedOutlineProperty = vtkProperty::New(); + this->SelectedOutlineProperty->SetAmbient(1.0); + this->SelectedOutlineProperty->SetAmbientColor(0.0,1.0,0.0); + + // Edge property + this->EdgesProperty = vtkProperty::New(); + this->EdgesProperty->SetAmbient(1.0); + this->EdgesProperty->SetAmbientColor(1.0,1.0,1.0); +} +//================================================================== +// function: InitialPlaceWidget +// purpose : +//================================================================== +void VISU_PlanesWidget::InitialPlaceWidget(float bds[6]) +{ + float bounds[6], origin[3]; + + PlaceWidget(bds); + // + this->AdjustBounds(bds, bounds, origin); + this->SetOrigin((bounds[1]+bounds[0])/2.0, + (bounds[3]+bounds[2])/2.0, + (bounds[5]+bounds[4])/2.0); + + static float DIST_COEFF = 0.1; + SetDistance(this->InitialLength*DIST_COEFF); + // + this->UpdateRepresentation(); +} +//================================================================== +// function: PlaceWidget +// purpose : +//================================================================== +void VISU_PlanesWidget::PlaceWidget(float bds[6]) +{ + int i; + float bounds[6], origin[3]; + + this->AdjustBounds(bds, bounds, origin); + + // Set up the bounding box + myBox->SetOrigin(bounds[0],bounds[2],bounds[4]); + myBox->SetSpacing((bounds[1]-bounds[0]),(bounds[3]-bounds[2]), + (bounds[5]-bounds[4])); + this->myOutline->Update(); + + if (this->Input || this->Prop3D) { + this->LineSource->SetPoint1(myPlane1->GetOrigin()); + if ( this->NormalToYAxis ) { + myPlane1->SetNormal(0,1,0); + myPlane2->SetNormal(0,-1,0); + this->LineSource->SetPoint2(0,1,0); + } + else if ( this->NormalToZAxis ) { + myPlane1->SetNormal(0,0,1); + myPlane2->SetNormal(0,0,-1); + this->LineSource->SetPoint2(0,0,1); + } + else{ //default or x-normal + myPlane1->SetNormal(1,0,0); + myPlane2->SetNormal(-1,0,0); + this->LineSource->SetPoint2(1,0,0); + } + } + + for (i=0; i<6; i++) { + this->InitialBounds[i] = bounds[i]; + } + + this->InitialLength = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) + + (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) + + (bounds[5]-bounds[4])*(bounds[5]-bounds[4])); + + this->UpdateRepresentation(); +} +//================================================================== +// function: SetOrigin +// purpose :Set the origin of the plane.(for external calls) +//================================================================== +void VISU_PlanesWidget::SetOrigin(float x, float y, float z) +{ + float origin[3]; + origin[0] = x; + origin[1] = y; + origin[2] = z; + this->SetOrigin(origin); +} +//================================================================== +// function: SetOrigin +// purpose : Set the origin of the plane.(for external calls) +//================================================================== +void VISU_PlanesWidget::SetOrigin(float x[3]) +{ + float *bounds = this->myOutline->GetOutput()->GetBounds(); + for (int i=0; i<3; i++) { + if ( x[i] < bounds[2*i] ) { + x[i] = bounds[2*i]; + } + else if ( x[i] > bounds[2*i+1] ) { + x[i] = bounds[2*i+1]; + } + } + myPlane1->SetOrigin(x); + float *origin, *normal, oNew[3]; + origin = myPlane1->GetOrigin(); + normal = myPlane1->GetNormal(); + vtkMath::Normalize(normal); + oNew[0] = origin[0] + myDistance*normal[0]; + oNew[1] = origin[1] + myDistance*normal[1]; + oNew[2] = origin[2] + myDistance*normal[2]; + this->myPlane2->SetOrigin(oNew); + this->UpdateRepresentation(); +} +//================================================================== +// function: GetOrigin +// purpose :Get the origin of the plane. +//================================================================== +float* VISU_PlanesWidget::GetOrigin() +{ + return myPlane1->GetOrigin(); +} + +void VISU_PlanesWidget::GetOrigin(float xyz[3]) +{ + myPlane1->GetOrigin(xyz); +} +//================================================================== +// function: SetNormal +// purpose :Set the normal to the plane. +//================================================================== +void VISU_PlanesWidget::SetNormal(float x, float y, float z) +{ + float n[3]; + n[0] = x; + n[1] = y; + n[2] = z; + vtkMath::Normalize(n); + myPlane1->SetNormal(n); + n[0] =- x; + n[1] =- y; + n[2] =- z; + this->myPlane2->SetNormal(n); + + this->UpdateRepresentation(); +} + +//================================================================== +// function: SetNormal +// purpose :Set the normal to the plane. +//================================================================== +void VISU_PlanesWidget::SetNormal(float n[3]) +{ + this->SetNormal(n[0], n[1], n[2]); +} +//================================================================== +// function: GetNormal +// purpose :Get the normal to the plane. +//================================================================== +float* VISU_PlanesWidget::GetNormal() +{ + return myPlane1->GetNormal(); +} +//================================================================== +// function: GetNormal +// purpose :Get the normal to the plane. +//================================================================== +void VISU_PlanesWidget::GetNormal(float xyz[3]) +{ + myPlane1->GetNormal(xyz); +} +//================================================================== +// function: SetDrawPlane +// purpose : +//================================================================== +void VISU_PlanesWidget::SetDrawPlane(int drawPlane) +{ + if ( drawPlane == this->myDrawPlane ) { + return; + } + + this->Modified(); + this->myDrawPlane = drawPlane; + if ( this->Enabled ) { + if ( drawPlane ) { + this->CurrentRenderer->AddActor(this->myCutActor1); + this->CurrentRenderer->AddActor(myCutActor2); + } + else { + this->CurrentRenderer->RemoveActor(this->myCutActor1); + this->CurrentRenderer->RemoveActor(myCutActor2); + } + this->Interactor->Render(); + } +} +//================================================================== +// function: SetNormalToXAxis +// purpose : +//================================================================== +void VISU_PlanesWidget::SetNormalToXAxis (int var) +{ + if (this->NormalToXAxis != var) { + this->NormalToXAxis = var; + this->Modified(); + } + if (var) { + this->NormalToYAxisOff(); + this->NormalToZAxisOff(); + } +} +//================================================================== +// function: SetNormalToYAxis +// purpose : +//================================================================== +void VISU_PlanesWidget::SetNormalToYAxis (int var) +{ + if (this->NormalToYAxis != var) { + this->NormalToYAxis = var; + this->Modified(); + } + if (var) { + this->NormalToXAxisOff(); + this->NormalToZAxisOff(); + } +} +//================================================================== +// function: SetNormalToZAxis +// purpose : +//================================================================== +void VISU_PlanesWidget::SetNormalToZAxis (int var) +{ + if (this->NormalToZAxis != var) { + this->NormalToZAxis = var; + this->Modified(); + } + if (var) { + this->NormalToXAxisOff(); + this->NormalToYAxisOff(); + } +} +//================================================================== +// function: GetPolyData +// purpose : +//================================================================== +void VISU_PlanesWidget::GetPolyData(vtkPolyData *pd) +{ + pd->ShallowCopy(this->myCutter1->GetOutput()); +} +//================================================================== +// function: GetPolyDataSource +// purpose : +//================================================================== +/* +vtkPolyDataSource *VISU_PlanesWidget::GetPolyDataSource() +{ + return this->myCutter1; +} +*/ +//================================================================== +// function:GetPlane +// purpose : +//================================================================== +void VISU_PlanesWidget::GetPlane(vtkPlane *plane) +{ + if ( plane == NULL ) { + return; + } + + plane->SetNormal(myPlane1->GetNormal()); + plane->SetOrigin(myPlane1->GetOrigin()); +} +//================================================================== +// function:UpdatePlacement +// purpose : +//================================================================== +void VISU_PlanesWidget::UpdatePlacement(void) +{ + this->myOutline->Update(); + this->myCutter1->Update(); + this->myEdges1->Update(); +} +//================================================================== +// function:UpdateRepresentation +// purpose : +//================================================================== +void VISU_PlanesWidget::UpdateRepresentation() +{ + if ( ! this->CurrentRenderer ) { + return; + } + + float *origin = myPlane1->GetOrigin(); + float *normal = myPlane1->GetNormal(); + float p2[3]; + + // Setup the plane normal + float d = this->myOutline->GetOutput()->GetLength(); + + p2[0] = origin[0] + 0.30 * d * normal[0]; + p2[1] = origin[1] + 0.30 * d * normal[1]; + p2[2] = origin[2] + 0.30 * d * normal[2]; + + this->LineSource->SetPoint1(origin); + this->LineSource->SetPoint2(p2); + this->ConeSource->SetCenter(p2); + this->ConeSource->SetDirection(normal); + ConeActor->SetCenter(p2); + + p2[0] = origin[0] - 0.30 * d * normal[0]; + p2[1] = origin[1] - 0.30 * d * normal[1]; + p2[2] = origin[2] - 0.30 * d * normal[2]; + + this->LineSource2->SetPoint1(origin); + this->LineSource2->SetPoint2(p2); + this->ConeSource2->SetCenter(p2); + this->ConeSource2->SetDirection(normal); + ConeActor2->SetCenter(p2); + + // Set up the position handle + this->Sphere->SetCenter(origin); + SphereActor->SetCenter(origin); + + this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput()); +} + +//================================================================== +// function:PrintSelf +// purpose : +//================================================================== +void VISU_PlanesWidget::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); +} +//================================================================== +// function: IsValidPlane2Position +// purpose : +//================================================================== +bool IsValidPlane2Position(vtkPlane *pPx, + vtkDataSet *pDataSet, + float aTol) +{ + bool bRet; + int i, iFound; + float aD, aDmax, aPnts[24], aDiagonal; + float aTol1, aOr[3], aN[3]; + // + bRet=false; + aDiagonal=pDataSet->GetLength(); + aTol1=aDiagonal*aTol; + // + GetBndPoints(pDataSet, aPnts); + // + pPx->GetOrigin(aOr); + pPx->GetNormal(aN); + vtkMath::Normalize(aN); + // + iFound=0; + aDmax=0.; + for (i=0; i<24; i+=3){ + aD=-DistanceToPlane(aPnts+i, aN, aOr); + if (aD>aDmax){ + aDmax=aD; + iFound=1; + } + } + if (iFound && aDmax>aTol1) { + bRet=!bRet; + } + return bRet; +} +//================================================================== +// function: GetBndPoints +// purpose : +//================================================================== +void GetBndPoints(vtkDataSet *pDataSet, + float aPnts[24]) +{ + int aIndx[24]={ + 0,2,4,1,2,4,1,3,4,0,3,4, + 0,2,5,1,2,5,1,3,5,0,3,5 + }; + int i; + float *pBounds=pDataSet->GetBounds(); + // + for (i=0; i<24; ++i){ + aPnts[i]=pBounds[aIndx[i]]; + } +} +//================================================================== +// function: DistanceToPlane +// purpose : +//================================================================== +float DistanceToPlane(const float x[3], + const float n[3], + const float p0[3]) +{ + return ((float) (n[0]*(x[0]-p0[0]) + + n[1]*(x[1]-p0[1]) + + n[2]*(x[2]-p0[2]))); +} +/* +//================================================================== +// function:SizeHandles +// purpose : +//================================================================== +void VISU_PlanesWidget::SizeHandles() +{ + // float radius = + this->vtk3DWidget::SizeHandles(1.35); +} +*/ diff --git a/src/PIPELINE/VISU_PlanesWidget.hxx b/src/PIPELINE/VISU_PlanesWidget.hxx new file mode 100644 index 00000000..fdf45367 --- /dev/null +++ b/src/PIPELINE/VISU_PlanesWidget.hxx @@ -0,0 +1,312 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VISU_PlanesWidget.h +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#ifndef __VISU_PlanesWidget_h +#define __VISU_PlanesWidget_h + +#include "VISU_ImplicitFunctionWidget.hxx" +class vtkActor; +class vtkPolyDataMapper; +class vtkCellPicker; +class vtkConeSource; +class vtkLineSource; +class vtkSphereSource; +class vtkPlane; +class vtkCutter; +class vtkProperty; +class vtkImageData; +class vtkOutlineFilter; +class vtkFeatureEdges; +class vtkPolyData; +class vtkTransform; +class vtkImplicitBoolean; +class vtkImplicitFunction; +class VISU_UnScaledActor; +class vtkDataSet; + +class VISU_PlanesWidget : public VISU_ImplicitFunctionWidget +{ +public: + // Description: + // Instantiate the object. + static VISU_PlanesWidget *New(); + + vtkTypeRevisionMacro(VISU_PlanesWidget,VISU_ImplicitFunctionWidget); + void PrintSelf(ostream& os, vtkIndent indent); + + void SetDistance (const float theDistance); + float Distance()const; + + vtkGetMacro(InitialLength,float); + + virtual vtkImplicitFunction* ImplicitFunction(); + + // Description: + // Methods that satisfy the superclass' API. + virtual void SetEnabled(int); + virtual void PlaceWidget(float bounds[6]); + + // Description: + // Get the origin of the plane. + void SetOrigin(float x, float y, float z); + void SetOrigin(float x[3]); + float* GetOrigin(); + void GetOrigin(float xyz[3]); + + // Description: + // Get the normal to the plane. + void SetNormal(float x, float y, float z); + void SetNormal(float x[3]); + float* GetNormal(); + void GetNormal(float xyz[3]); + + // Description: + // Force the plane widget to be aligned with one of the x-y-z axes. + // If one axis is set on, the other two will be set off. + // Remember that when the state changes, a ModifiedEvent is invoked. + // This can be used to snap the plane to the axes if it is orginally + // not aligned. + void SetNormalToXAxis(int); + vtkGetMacro(NormalToXAxis,int); + vtkBooleanMacro(NormalToXAxis,int); + void SetNormalToYAxis(int); + vtkGetMacro(NormalToYAxis,int); + vtkBooleanMacro(NormalToYAxis,int); + void SetNormalToZAxis(int); + vtkGetMacro(NormalToZAxis,int); + vtkBooleanMacro(NormalToZAxis,int); + + // Description: + // Turn on/off tubing of the wire outline of the plane. The tube thickens + // the line by wrapping with a vtkTubeFilter. + //vtkSetMacro(Tubing,int); + //vtkGetMacro(Tubing,int); + //vtkBooleanMacro(Tubing,int); + + // Description: + // Enable/disable the drawing of the plane. In some cases the plane + // interferes with the object that it is operating on (i.e., the + // plane interferes with the cut surface it produces producing + // z-buffer artifacts.) + void SetDrawPlane(int plane); + int GetDrawPlane(){ + return myDrawPlane; + } + + // Description: + // Turn on/off the ability to translate the bounding box by grabbing it + // with the left mouse button. + vtkSetMacro(OutlineTranslation,int); + vtkGetMacro(OutlineTranslation,int); + vtkBooleanMacro(OutlineTranslation,int); + + // Description: + // Grab the polydata that defines the plane. The polydata contains a single + // polygon that is clipped by the bounding box. + void GetPolyData(vtkPolyData *pd); + + // Description: + // Satisfies superclass API. This returns a pointer to the underlying + // PolyData (which represents the plane). + //vtkPolyDataSource* GetPolyDataSource(); + + // Description: + // Get the implicit function for the plane. The user must provide the + // instance of the class vtkPlane. Note that vtkPlane is a subclass of + // vtkImplicitFunction, meaning that it can be used by a variety of filters + // to perform clipping, cutting, and selection of data. + void GetPlane(vtkPlane *plane); + + // Description: + // Satisfies the superclass API. This will change the state of the widget + // to match changes that have been made to the underlying PolyDataSource + void UpdatePlacement(void); + + // Description: + // Get the properties on the normal (line and cone). + vtkGetObjectMacro(NormalProperty,vtkProperty); + vtkGetObjectMacro(SelectedNormalProperty,vtkProperty); + + // Description: + // Get the plane properties. The properties of the plane when selected + // and unselected can be manipulated. + vtkGetObjectMacro(PlaneProperty,vtkProperty); + vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty); + + // Description: + // Get the property of the outline. + vtkGetObjectMacro(OutlineProperty,vtkProperty); + vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty); + + // Description: + // Get the property of the intersection edges. (This property also + // applies to the edges when tubed.) + vtkGetObjectMacro(EdgesProperty,vtkProperty); + + void InitialPlaceWidget(float bds[6]); + +protected: + VISU_PlanesWidget(); + ~VISU_PlanesWidget(); + +//BTX - manage the state of the widget + int State; + enum WidgetState + { + Start=0, + MovingPlane, + MovingOutline, + MovingOrigin, + Scaling, + Pushing, + Rotating, + Outside, + ChangeDistance + }; +//ETX + + //handles the events + static void ProcessEvents(vtkObject* object, unsigned long event, + void* clientdata, void* calldata); + + // ProcessEvents() dispatches to these methods. + void OnLeftButtonDown(); + void OnLeftButtonUp(); + void OnMiddleButtonDown(); + void OnMiddleButtonUp(); + void OnRightButtonDown(); + void OnRightButtonUp(); + void OnMouseMove(); + // + // Methods to manipulate the plane + void ConstrainOrigin(float x[3]); + void Rotate(int X, int Y, double *p1, double *p2, double *vpn); + void TranslatePlane(double *p1, double *p2); + void TranslateOutline(double *p1, double *p2); + void TranslateOrigin(double *p1, double *p2); + void Push(double *p1, double *p2); + void Scale(double *p1, double *p2, int X, int Y); + void PushDistance(double *p1, double *p2); + + void CreateDefaultProperties(); + + void GeneratePlane(); + //virtual void SizeHandles(); + void HighlightPlane(int highlight); + void HighlightNormal(int highlight); + void HighlightOutline(int highlight); + void UpdateRepresentation(); + void SetOriginInternal(float x[3]); + + // Controlling ivars + int NormalToXAxis; + int NormalToYAxis; + int NormalToZAxis; + + + // Flags to handle mouse events + bool HandleMoveEvent; + bool HandleLeftButtonEvent; + bool HandleMiddleButtonEvent; + bool HandleRightButtonEvent; + // The actual plane which is being manipulated + vtkPlane *myPlane1; + vtkPlane *myPlane2; + + float myDistance; + vtkImplicitBoolean *myImplicitFunction; + + // The bounding box is represented by a single voxel image data + vtkImageData *myBox; + vtkOutlineFilter *myOutline; + vtkPolyDataMapper *myOutlineMapper; + vtkActor *myOutlineActor; + + int OutlineTranslation; //whether the outline can be moved + + // The cut plane is produced with a vtkCutter + vtkCutter *myCutter1; + vtkPolyDataMapper *myCutMapper1; + vtkActor *myCutActor1; + + vtkCutter *myCutter2; + vtkPolyDataMapper *myCutMapper2; + vtkActor *myCutActor2; + + vtkFeatureEdges *myEdges2; + vtkPolyDataMapper *myEdgesMapper2; + vtkActor *myEdgesActor2; + + int myDrawPlane; + + vtkFeatureEdges *myEdges1; + vtkPolyDataMapper *myEdgesMapper1; + vtkActor *myEdgesActor1; + + // The + normal cone + vtkConeSource *ConeSource; + vtkPolyDataMapper *ConeMapper; + VISU_UnScaledActor *ConeActor; + // The + normal line + vtkLineSource *LineSource; + vtkPolyDataMapper *LineMapper; + vtkActor *LineActor; + // The - normal cone + vtkConeSource *ConeSource2; + vtkPolyDataMapper *ConeMapper2; + VISU_UnScaledActor *ConeActor2; + // The - normal line + vtkLineSource *LineSource2; + vtkPolyDataMapper *LineMapper2; + vtkActor *LineActor2; + // The origin positioning handle + vtkSphereSource *Sphere; + vtkPolyDataMapper *SphereMapper; + VISU_UnScaledActor *SphereActor; + + // Do the picking + vtkCellPicker *Picker; + + // Transform the normal (used for rotation) + vtkTransform *Transform; + // Properties used to control the appearance of selected objects and + // the manipulator in general. + vtkProperty *NormalProperty; + vtkProperty *SelectedNormalProperty; + vtkProperty *PlaneProperty; + vtkProperty *SelectedPlaneProperty; + vtkProperty *OutlineProperty; + vtkProperty *SelectedOutlineProperty; + vtkProperty *EdgesProperty; + +private: + VISU_PlanesWidget(const VISU_PlanesWidget&); //Not implemented + void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented +}; + +#endif diff --git a/src/PIPELINE/VISU_Plot3DPL.cxx b/src/PIPELINE/VISU_Plot3DPL.cxx index a7e8287e..164d9a7a 100644 --- a/src/PIPELINE/VISU_Plot3DPL.cxx +++ b/src/PIPELINE/VISU_Plot3DPL.cxx @@ -68,7 +68,6 @@ void VISU_Plot3DPL:: ShallowCopy(VISU_PipeLine *thePipeLine) { - VISU_ScalarMapPL::ShallowCopy(thePipeLine); if(VISU_Plot3DPL *aPipeLine = dynamic_cast(thePipeLine)){ SetOrientation (aPipeLine->GetPlaneOrientation(), aPipeLine->GetRotateX(), aPipeLine->GetRotateY()); @@ -78,6 +77,7 @@ ShallowCopy(VISU_PipeLine *thePipeLine) SetContourPrs( aPipeLine->GetIsContourPrs() ); SetNumberOfContours( aPipeLine->GetNumberOfContours() ); } + VISU_ScalarMapPL::ShallowCopy(thePipeLine); } VISU_CutPlanesPL::PlaneOrientation diff --git a/src/PIPELINE/VISU_ScalarBarCtrl.cxx b/src/PIPELINE/VISU_ScalarBarCtrl.cxx new file mode 100644 index 00000000..561b2432 --- /dev/null +++ b/src/PIPELINE/VISU_ScalarBarCtrl.cxx @@ -0,0 +1,520 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_ScalarBarCtrl.cxx +// Author: Peter KURNEV +// Module : VISU + +#include "VISU_ScalarBarCtrl.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +//---------------------------------------------------------------------------- +namespace +{ + inline + void + MarkValueByColor(vtkLookupTable* theTable, + float theValue, + unsigned char* theColor) + { + vtkIdType anIndex = theTable->GetIndex(theValue); + unsigned char *aTablePtr = theTable->GetPointer(anIndex); + aTablePtr[0] = theColor[0]; + aTablePtr[1] = theColor[1]; + aTablePtr[2] = theColor[2]; + } + + inline + void + CopyColor(unsigned char* theTaget, const unsigned char* theSource) + { + theTaget[0] = theSource[0]; + theTaget[1] = theSource[1]; + theTaget[2] = theSource[2]; + } + + void + FillByColor(vtkLookupTable* theTable, + unsigned char* theColor) + { + vtkIdType aNbColors = theTable->GetNumberOfColors(); + for(int i = 0; i < aNbColors; i++){ + unsigned char *aTablePtr = theTable->GetPointer(i); + CopyColor(aTablePtr,theColor); + } + } + + void + MakeBiColor(vtkLookupTable* theTable) + { + unsigned char aRedPtr[3] = {255, 0, 0}; + unsigned char aBluePtr[3] = {0, 0, 255}; + + float aRange[2]; + theTable->GetTableRange(aRange); + vtkIdType aNbColors = theTable->GetNumberOfColors(); + + float aDelta = (aRange[1]-aRange[0])/aNbColors; + float aValue = aRange[0]+0.5*aDelta; + for(int i = 0; i < aNbColors; i++){ + vtkIdType anIndex = theTable->GetIndex(aValue); + unsigned char* aTablePtr = theTable->GetPointer(anIndex); + if(aValue > 0.0){ + CopyColor(aTablePtr,aRedPtr); + }else{ + CopyColor(aTablePtr,aBluePtr); + } + aValue += aDelta; + } + } +} + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(VISU_ScalarBarCtrl); + +//---------------------------------------------------------------------------- +VISU_ScalarBarCtrl +::VISU_ScalarBarCtrl(): + myGlobalRangeIsDefined(false) +{ + myDistance=0.02; + myPosition[0]=0.15; + myPosition[1]=0.01; + myBicolor=false; + myMarked=false; + myMarkedValue=99.; + // + SetMode(eSimple); + + // Initilize global scalar bar + myGlobalLookupTable = vtkLookupTable::New(); + myGlobalLookupTable->SetHueRange(0.667,0.0); + + myGlobalScalarBar = vtkScalarBarActor::New(); + myGlobalScalarBar->SetLookupTable(myGlobalLookupTable); + myGlobalLookupTable->Delete(); + + // Initilize local scalar bar + myLocalLookupTable = vtkLookupTable::New(); + myLocalLookupTable->SetHueRange(0.667,0.0); + + myLocalScalarBar = vtkScalarBarActor::New(); + myLocalScalarBar->SetLookupTable(myLocalLookupTable); + myLocalLookupTable->Delete(); + + myBlack[0] = myBlack[1] = myBlack[2] = 0; + myGrey[0] = myGrey[1] = myGrey[2] = 192; + // + myCtrlVisibility = 1; + SetVisibility(1); +} + + +//---------------------------------------------------------------------------- +VISU_ScalarBarCtrl +::~VISU_ScalarBarCtrl() +{ + myGlobalScalarBar->Delete(); +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetMode(VISU_ScalarBarCtrl::EMode theMode) +{ + myMode = theMode; +} + +VISU_ScalarBarCtrl::EMode +VISU_ScalarBarCtrl +::GetMode() const +{ + return myMode; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetVisibility(int theVisibility) +{ + myGlobalScalarBar->SetVisibility(false); + myLocalScalarBar->SetVisibility(false); + int aVisibility = (myCtrlVisibility && theVisibility); + if(aVisibility){ + if(myMode != eSimple) + myGlobalScalarBar->SetVisibility(aVisibility); + myLocalScalarBar->SetVisibility(aVisibility); + } +} + +int +VISU_ScalarBarCtrl +::GetVisibility() const +{ + return myGlobalScalarBar->GetVisibility() || myLocalScalarBar->GetVisibility(); +} + +void +VISU_ScalarBarCtrl +::SetCtrlVisibility(int theVisibility) +{ + myCtrlVisibility = theVisibility; +} + +int +VISU_ScalarBarCtrl +::GetCtrlVisibility() const +{ + return myCtrlVisibility; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetRangeLocal(float *theRange) +{ + myLocalLookupTable->SetTableRange(theRange); +} + +void +VISU_ScalarBarCtrl +::SetRangeLocal(float theMin, + float theMax) +{ + myLocalLookupTable->SetTableRange(theMin,theMax); +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetRangeGlobal(float *theRange) +{ + myGlobalLookupTable->SetTableRange(theRange); +} + +void +VISU_ScalarBarCtrl +::SetRangeGlobal(float theMin, + float theMax) +{ + myGlobalLookupTable->SetTableRange(theMin,theMax); +} + +void +VISU_ScalarBarCtrl +::SetGlobalRangeIsDefined(bool theIsDefined) +{ + myGlobalRangeIsDefined = theIsDefined; +} + + +//---------------------------------------------------------------------------- +vtkScalarBarActor* +VISU_ScalarBarCtrl +::GetLocalBar() +{ + return myLocalScalarBar; +} + +vtkScalarBarActor* +VISU_ScalarBarCtrl +::GetGlobalBar() +{ + return myGlobalScalarBar; +} + + +//---------------------------------------------------------------------------- +vtkLookupTable* +VISU_ScalarBarCtrl +::GetLocalTable() +{ + return myLocalLookupTable; +} + +vtkLookupTable* +VISU_ScalarBarCtrl +::GetGlobalTable() +{ + return myGlobalLookupTable; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::AddToRender(vtkRenderer* theRenderer) +{ + theRenderer->AddActor2D(myGlobalScalarBar); + theRenderer->AddActor2D(myLocalScalarBar); + Update(); +} + +void +VISU_ScalarBarCtrl +::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor2D(myGlobalScalarBar); + theRenderer->RemoveActor2D(myLocalScalarBar); +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetWidth(float theWidth) +{ + myGlobalScalarBar->SetWidth(theWidth); + myLocalScalarBar->SetWidth(theWidth); +} + +float +VISU_ScalarBarCtrl +::GetWidth() const +{ + return myGlobalScalarBar->GetWidth(); +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetHeight(float theHeight) +{ + myGlobalScalarBar->SetHeight(theHeight); + myLocalScalarBar->SetHeight(theHeight); +} + + +float +VISU_ScalarBarCtrl +::GetHeight() const +{ + return myGlobalScalarBar->GetHeight(); +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetPosition(const float* thePosition) +{ + myPosition[0] = thePosition[0]; + myPosition[1] = thePosition[1]; +} + +const float* +VISU_ScalarBarCtrl::GetPosition() const +{ + return myPosition; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetSpacing(const float theSpacing) +{ + myDistance = theSpacing; +} + +float +VISU_ScalarBarCtrl +::GetSpacing() const +{ + return myDistance; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetBicolor(const bool theBicolor) +{ + myBicolor = theBicolor; +} + +bool +VISU_ScalarBarCtrl +::GetBicolor() const +{ + return myBicolor; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetMarkValue(const float theValue) +{ + myMarkedValue = theValue; +} + +float +VISU_ScalarBarCtrl +::GetMarkValue() const +{ + return myMarkedValue; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::SetIsMarked(const bool theFlag) +{ + myMarked = theFlag; +} + +bool +VISU_ScalarBarCtrl +::GetIsMarked() const +{ + return myMarked; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::Update() +{ + SetVisibility(GetVisibility()); + // + PrepareTables(); + // + if(myBicolor) + UpdateForBicolor(); + else + UpdateForColor(); + // + UpdateMarkValue(); +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::UpdateMarkValue() +{ + if(myMarked){ + if(myMode == eGlobal){ + MarkValueByColor(myGlobalLookupTable, myMarkedValue, myBlack); + }else{ + MarkValueByColor(myLocalLookupTable, myMarkedValue, myBlack); + } + } + if(myGlobalRangeIsDefined){ + float aLocalRange[2]; + myLocalLookupTable->GetTableRange(aLocalRange); + MarkValueByColor(myGlobalLookupTable, aLocalRange[0], myBlack); + MarkValueByColor(myGlobalLookupTable, aLocalRange[1], myBlack); + } +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::PrepareTables(vtkScalarBarActor* theScalarBarActor, + vtkLookupTable *theLookupTable, + vtkIdType theId) +{ + vtkCoordinate * aCoordinate = theScalarBarActor->GetPositionCoordinate(); + aCoordinate->SetCoordinateSystemToNormalizedViewport(); + if(theScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL){ + float aWidth = theScalarBarActor->GetWidth(); + aCoordinate->SetValue(myPosition[0]+theId*(aWidth+myDistance), myPosition[1]); + }else{ + float aHeight = theScalarBarActor->GetHeight(); + aCoordinate->SetValue(myPosition[0], myPosition[1]+theId*(aHeight+myDistance)); + } + // Initialize Lookup Tables and Scalar Bars + theLookupTable->Modified(); + theLookupTable->Build(); +} + + +void +VISU_ScalarBarCtrl +::PrepareTables() +{ + if(myMode != eSimple){ + PrepareTables(myGlobalScalarBar,myGlobalLookupTable,0); + PrepareTables(myLocalScalarBar,myLocalLookupTable,1); + }else{ + PrepareTables(myLocalScalarBar,myLocalLookupTable,0); + } +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::UpdateForColor() +{ + if(myMode == eGlobal){ + FillByColor(myLocalLookupTable,myGrey); + }else if(myMode == eLocal){ + FillByColor(myGlobalLookupTable,myGrey); + } +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarBarCtrl +::UpdateForBicolor() +{ + myLocalLookupTable->Modified(); + myLocalLookupTable->Build(); + + if(myMode == eSimple){ + MakeBiColor(myLocalLookupTable); + return; + } + + if(myMode == eGlobal){ + MakeBiColor(myGlobalLookupTable); + FillByColor(myLocalLookupTable,myGrey); + }else if(myMode == eLocal){ + MakeBiColor(myLocalLookupTable); + FillByColor(myGlobalLookupTable,myGrey); + } +} diff --git a/src/PIPELINE/VISU_ScalarBarCtrl.hxx b/src/PIPELINE/VISU_ScalarBarCtrl.hxx new file mode 100644 index 00000000..c1a2f958 --- /dev/null +++ b/src/PIPELINE/VISU_ScalarBarCtrl.hxx @@ -0,0 +1,138 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_ScalarBarCtrl.hxx +// Author: Peter KURNEV +// Module : VISU + +#ifndef VISU_ScalarBarCtrl_HeaderFile +#define VISU_ScalarBarCtrl_HeaderFile + +#include + +class vtkRenderer; +class vtkLookupTable; +class vtkScalarBarActor; + +class VISU_ScalarBarCtrl : public vtkObject +{ +public: + vtkTypeMacro(VISU_ScalarBarCtrl, vtkObject); + static VISU_ScalarBarCtrl* New(); + + enum EMode {eSimple, eGlobal, eLocal}; + + // Mode + void SetMode(EMode theMode); + EMode GetMode() const; + + // Ranges + void SetRangeGlobal(float theMin, + float theMax); + void SetRangeGlobal(float *theRange); + + void SetGlobalRangeIsDefined(bool theIsDefined); + + void SetRangeLocal(float theMin, + float theMax); + void SetRangeLocal(float *theRange); + + // Selectors + vtkScalarBarActor* GetLocalBar(); + vtkLookupTable* GetLocalTable(); + + vtkScalarBarActor* GetGlobalBar(); + vtkLookupTable* GetGlobalTable(); + // + // Renderer + void AddToRender(vtkRenderer* theRenderer); + void RemoveFromRender(vtkRenderer* theRenderer); + // + // Visibility + void SetVisibility(int theFlag); + int GetVisibility() const; + // + // Visibility + void SetCtrlVisibility(int theFlag); + int GetCtrlVisibility() const; + // + // Build + void Update(); + // + // Position + void SetWidth(const float theWidth); + float GetWidth()const; + void SetHeight(const float theHeight); + float GetHeight()const; + void SetPosition(const float* thePosition); + const float* GetPosition()const; + // + // Spacing + void SetSpacing(const float theSpacing); + float GetSpacing()const; + // + // Rainbow/bicolor + bool GetBicolor() const; + void SetBicolor(const bool theBicolor); + // + // Misc + void SetMarkValue (const float theValue); + float GetMarkValue ()const; + void SetIsMarked(const bool theFlag); + bool GetIsMarked()const; + // +protected: + VISU_ScalarBarCtrl(); + virtual ~VISU_ScalarBarCtrl(); + + void UpdateForBicolor(); + void UpdateForColor(); + void UpdateMarkValue(); + void PrepareTables(); + + void PrepareTables(vtkScalarBarActor* theScalarBarActor, + vtkLookupTable *theLookupTable, + vtkIdType theId); + +protected: + EMode myMode; + bool myGlobalRangeIsDefined; + + float myDistance; + float myPosition[2]; + bool myBicolor; + int myCtrlVisibility; + + unsigned char myBlack[3]; + unsigned char myGrey[3]; + // + bool myMarked; + float myMarkedValue; + // + vtkScalarBarActor *myGlobalScalarBar; + vtkLookupTable *myGlobalLookupTable; + + vtkScalarBarActor *myLocalScalarBar; + vtkLookupTable *myLocalLookupTable; +}; + +#endif diff --git a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx new file mode 100644 index 00000000..0d0ccad5 --- /dev/null +++ b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx @@ -0,0 +1,239 @@ +// VISU ScalarMapOnDeformedShapePL +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_ScalarMapOnDeformedShapePL.cxx +// Author: Eugeny Nikolaev +// Module : VISU + +#include "VISU_ScalarMapOnDeformedShapePL.hxx" +#include "VISU_DeformedShapePL.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "VTKViewer_TransformFilter.h" +#include "VTKViewer_Transform.h" + +#include +#include +#include +#include +#include + +#include + +vtkStandardNewMacro(VISU_ScalarMapOnDeformedShapePL) + +/*! + * Constructor. Creating new instances of vtkWarpVector,vtkMergeFilter,vtkUnstructuredGrid + * Where: + * \li myDeformVectors is vtkWarpVector - deformation vectors data + * \li myMergeFilter is vtkMergeFilter - merge filter. + * Merge filter which unify the deformation and scalars + * \li myScalars is vtk shared pointer to vtkUnstructuredGrid - scalars data +*/ +VISU_ScalarMapOnDeformedShapePL::VISU_ScalarMapOnDeformedShapePL(){ + myDeformVectors = vtkWarpVector::New(); + myMergeFilter = vtkMergeFilter::New(); + myExtractorScalars = VISU_Extractor::New(); + myCellDataToPointData = vtkCellDataToPointData::New(); +} + +/*! + * Destructor. + * Delete all fields. +*/ +VISU_ScalarMapOnDeformedShapePL::~VISU_ScalarMapOnDeformedShapePL(){ + myDeformVectors->UnRegisterAllOutputs(); + myDeformVectors->Delete(); + + myMergeFilter->UnRegisterAllOutputs(); + myMergeFilter->Delete(); + + myExtractorScalars->UnRegisterAllOutputs(); + myExtractorScalars->Delete(); + + myCellDataToPointData->UnRegisterAllOutputs(); + myCellDataToPointData->Delete(); +} + +/*! + * Initial method + */ +void VISU_ScalarMapOnDeformedShapePL::Init(){ + + if (GetScalars() == NULL) SetScalars(GetInput2()); + + Superclass::Init(); + + float aScalarRange[2]; + GetSourceRange(aScalarRange); + static double EPS = 1.0 / VTK_LARGE_FLOAT; + if(aScalarRange[1] > EPS) + SetScale(VISU_DeformedShapePL::GetScaleFactor(GetInput2())/aScalarRange[1]); + else + SetScale(0.0); + + myMapper->SetColorModeToMapScalars(); + myMapper->ScalarVisibilityOn(); + + // Sets input for field transformation filter + myFieldTransform->SetInput(myExtractor->GetOutput()); + +} + +/*! + * Build method + * Building of deformation and puts result to merge filter. + */ +void VISU_ScalarMapOnDeformedShapePL::Build() +{ + // Set input for extractor + myExtractor->SetInput(GetInput2()); + + VISU::CellDataToPoint(myDeformVectors,myCellDataToPointData, + GetInput2(),myFieldTransform); + + // Sets geometry for merge filter + myMergeFilter->SetGeometry(myDeformVectors->GetOutput()); + // Sets data to mapper + myMapper->SetInput(myMergeFilter->GetOutput()); +} + +/*! + * Update method + */ +void VISU_ScalarMapOnDeformedShapePL::Update(){ + this->UpdateScalars(); + + float aRange[2]; + GetSourceRange(aRange); + float aScalarRange[2] = {aRange[0], aRange[1]}; + + if(myBarTable->GetScale() == VTK_SCALE_LOG10) + VISU_LookupTable::ComputeLogRange(aRange,aScalarRange); + myMapperTable->SetRange(aScalarRange); + + myMapperTable->Build(); + myBarTable->Build(); + + myMapper->SetLookupTable(myMapperTable); + myMapper->SetScalarRange(aScalarRange); + + VISU_PipeLine::Update(); +} + +/*! + * Update scalars method. + * Put scalars to merge filter. + */ +void VISU_ScalarMapOnDeformedShapePL::UpdateScalars(){ + if(myScalars->GetCellData()->GetVectors() != NULL || + myScalars->GetPointData()->GetVectors() != NULL) + myMergeFilter->SetScalars(myExtractorScalars->GetOutput()); + else + myMergeFilter->SetScalars(GetScalars()); +} + +/*! + * Copy information about pipline. + * Copy scale and scalars. + */ +void VISU_ScalarMapOnDeformedShapePL::ShallowCopy(VISU_PipeLine *thePipeLine){ + VISU_ScalarMapOnDeformedShapePL *aPipeLine = dynamic_cast(thePipeLine); + if(aPipeLine){ + SetScale(aPipeLine->GetScale()); + SetScalars(aPipeLine->GetScalars()); + float aRange[2]; + aPipeLine->GetSourceRange(aRange); + SetScalarRange(aRange); + } + Superclass::ShallowCopy(thePipeLine); +} + +/*! + * Set scalars. + * Sets vtkDataSet with scalars values to VISU_Extractor filter for scalars extraction. + */ +void VISU_ScalarMapOnDeformedShapePL::SetScalars(vtkDataSet *theScalars){ + myScalars = theScalars; + vtkUnstructuredGrid* aScalars = GetScalars(); + myExtractorScalars->SetInput(aScalars); + Modified(); +} + +/*! + * Get pointer to input scalars. + */ +vtkUnstructuredGrid* VISU_ScalarMapOnDeformedShapePL::GetScalars(){ + return myScalars.GetPointer(); +} + +/*! + * Sets scale for deformed shape + */ +void VISU_ScalarMapOnDeformedShapePL::SetScale(float theScale) { + if(myScaleFactor == theScale) return; + myScaleFactor = theScale; + myDeformVectors->SetScaleFactor(myScaleFactor); + Modified(); +} + +/*! + * Gets scale of deformed shape. + */ +float VISU_ScalarMapOnDeformedShapePL::GetScale() { + float aScale=myDeformVectors->GetScaleFactor(); + return aScale; +} + +/*! + * Set scale factor of deformation. + */ +void VISU_ScalarMapOnDeformedShapePL::SetMapScale(float theMapScale){ + myDeformVectors->SetScaleFactor(myScaleFactor*theMapScale); + Modified(); +} + +/*! + * Gets scalar mode. + */ +int VISU_ScalarMapOnDeformedShapePL::GetScalarMode(){ + int aMode=myExtractorScalars->GetScalarMode(); + return aMode; +} + +/*! + * Sets scalar mode. + */ +void VISU_ScalarMapOnDeformedShapePL::SetScalarMode(int theScalarMode){ + myExtractorScalars->SetScalarMode(theScalarMode); + Modified(); +} + +/*! + * Gets ranges of extracted scalars + * \param theRange[2] - output values + * \li theRange[0] - minimum value + * \li theRange[1] - maximum value + */ +void VISU_ScalarMapOnDeformedShapePL::GetSourceRange(float theRange[2]){ + myExtractorScalars->Update(); + myExtractorScalars->GetUnstructuredGridOutput()->GetScalarRange(theRange); +} diff --git a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx new file mode 100644 index 00000000..6d1ccf9a --- /dev/null +++ b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx @@ -0,0 +1,95 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_ScalarMapOnDeformedShapePL.hxx +// Author: Eugeny Nikolaev +// Module : VISU + +#ifndef VISU_ScalarMapOnDeformedShapePL_HeaderFile +#define VISU_ScalarMapOnDeformedShapePL_HeaderFile + +#include "VISU_ScalarMapPL.hxx" + +class vtkMergeFilter; +class vtkWarpVector; +class vtkUnstructuredGrid; +class vtkCellDataToPointData; +class vtkPointDataToCellData; + +class VISU_ScalarMapOnDeformedShapePL : public VISU_ScalarMapPL +{ +protected: + VISU_ScalarMapOnDeformedShapePL(); + + virtual ~VISU_ScalarMapOnDeformedShapePL(); + + VISU_ScalarMapOnDeformedShapePL(const VISU_ScalarMapOnDeformedShapePL&); +public: + vtkTypeMacro(VISU_ScalarMapOnDeformedShapePL,VISU_ScalarMapPL); + + static VISU_ScalarMapOnDeformedShapePL* New(); + + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + + virtual void SetScale(float theScale); + virtual float GetScale(); + + virtual int GetScalarMode(); + virtual void SetScalarMode(int theScalarMode = 0); + + virtual void GetSourceRange(float theRange[2]); + + virtual void SetScalars(vtkDataSet *theScalars); + virtual vtkUnstructuredGrid* GetScalars(); + +public: + //! Redefined method for initialization of the pipeline. + virtual + void + Init(); + + //! Redefined method for building the pipeline. + virtual + void + Build(); + + //! Redefined method for updating the pipeline. + virtual + void + Update(); + + //! Update scalars. + void + UpdateScalars(); + + virtual void SetMapScale(float theMapScale = 1.0); + +protected: + float myScaleFactor; + vtkWarpVector *myDeformVectors; + vtkMergeFilter *myMergeFilter; + vtkSmartPointer myScalars; + VISU_Extractor* myExtractorScalars; + vtkCellDataToPointData* myCellDataToPointData; +}; + +#endif diff --git a/src/PIPELINE/VISU_ScalarMapPL.cxx b/src/PIPELINE/VISU_ScalarMapPL.cxx index 473d2de8..daaa24e6 100644 --- a/src/PIPELINE/VISU_ScalarMapPL.cxx +++ b/src/PIPELINE/VISU_ScalarMapPL.cxx @@ -28,14 +28,17 @@ #include "VISU_ScalarMapPL.hxx" #include "VISU_PipeLineUtils.hxx" +#include "SALOME_ExtractGeometry.h" -vtkStandardNewMacro(VISU_ScalarMapPL); +//============================================================================ +vtkStandardNewMacro(VISU_ScalarMapPL); -VISU_ScalarMapPL::VISU_ScalarMapPL(){ - myFieldTransform = VISU_FieldTransform::New(); - //myFieldTransform->DebugOn(); +//---------------------------------------------------------------------------- +VISU_ScalarMapPL +::VISU_ScalarMapPL() +{ myMapperTable = VISU_LookupTable::New(); myMapperTable->SetScale(VTK_SCALE_LINEAR); myMapperTable->SetHueRange(0.667,0.0); @@ -45,46 +48,90 @@ VISU_ScalarMapPL::VISU_ScalarMapPL(){ myBarTable->SetHueRange(0.667,0.0); myExtractor = VISU_Extractor::New(); - //myExtractor->DebugOn(); + myExtractor->SetInput(myExtractGeometry->GetOutput()); + + myFieldTransform = VISU_FieldTransform::New(); + myFieldTransform->SetInput(myExtractor->GetOutput()); + myIsShrinkable = true; } -VISU_ScalarMapPL::~VISU_ScalarMapPL(){ - myFieldTransform->UnRegisterAllOutputs(); +VISU_ScalarMapPL +::~VISU_ScalarMapPL() +{ myFieldTransform->Delete(); - myMapperTable->Delete();; + myMapperTable->Delete(); myBarTable->Delete(); - myExtractor->UnRegisterAllOutputs(); myExtractor->Delete(); } -void VISU_ScalarMapPL::ShallowCopy(VISU_PipeLine *thePipeLine){ - VISU_PipeLine::ShallowCopy(thePipeLine); +//---------------------------------------------------------------------------- +void +VISU_ScalarMapPL +::ShallowCopy(VISU_PipeLine *thePipeLine) +{ if(VISU_ScalarMapPL *aPipeLine = dynamic_cast(thePipeLine)){ SetScalarRange(aPipeLine->GetScalarRange()); SetScalarMode(aPipeLine->GetScalarMode()); SetNbColors(aPipeLine->GetNbColors()); SetScaling(aPipeLine->GetScaling()); - //Update(); + SetMapScale(aPipeLine->GetMapScale()); } + Superclass::ShallowCopy(thePipeLine); } -int VISU_ScalarMapPL::GetScalarMode(){ +//---------------------------------------------------------------------------- +int +VISU_ScalarMapPL +::GetScalarMode() +{ return myExtractor->GetScalarMode(); } -void VISU_ScalarMapPL::SetScalarMode(int theScalarMode){ + +void +VISU_ScalarMapPL +::SetScalarMode(int theScalarMode) +{ + vtkDataSet *input = GetInput(); + if (input){ + if(input->GetPointData()->GetNumberOfArrays()){ + vtkPointData *inData = input->GetPointData(); + if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)) { + if (theScalarMode==0){ + return; + } + } + } + else { + vtkCellData *inData = input->GetCellData(); + if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)){ + if (theScalarMode==0){ + return; + } + } + } + } + // myExtractor->SetScalarMode(theScalarMode); Modified(); } -int VISU_ScalarMapPL::GetScaling() { +//---------------------------------------------------------------------------- +int +VISU_ScalarMapPL +::GetScaling() +{ return myBarTable->GetScale(); } -void VISU_ScalarMapPL::SetScaling(int theScaling) { + +void +VISU_ScalarMapPL +::SetScaling(int theScaling) +{ myBarTable->SetScale(theScaling); if(theScaling == VTK_SCALE_LOG10) myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10)); @@ -94,60 +141,94 @@ void VISU_ScalarMapPL::SetScaling(int theScaling) { } -float* VISU_ScalarMapPL::GetScalarRange() { +//---------------------------------------------------------------------------- +float* +VISU_ScalarMapPL +::GetScalarRange() +{ return myFieldTransform->GetScalarRange(); } -void VISU_ScalarMapPL::SetScalarRange(float theRange[2]){ + +void +VISU_ScalarMapPL +::SetScalarRange(float theRange[2]) +{ myFieldTransform->SetScalarRange(theRange); myBarTable->SetRange(theRange); Modified(); } -void VISU_ScalarMapPL::SetScalarMin(float theValue){ + +void +VISU_ScalarMapPL +::SetScalarMin(float theValue) +{ float aScalarRange[2] = {theValue, GetScalarRange()[1]}; SetScalarRange(aScalarRange); } -void VISU_ScalarMapPL::SetScalarMax(float theValue){ + +void +VISU_ScalarMapPL +::SetScalarMax(float theValue) +{ float aScalarRange[2] = {GetScalarRange()[0], theValue}; SetScalarRange(aScalarRange); } -void VISU_ScalarMapPL::SetNbColors(int theNbColors) { +//---------------------------------------------------------------------------- +void +VISU_ScalarMapPL +::SetNbColors(int theNbColors) +{ myMapperTable->SetNumberOfColors(theNbColors); myBarTable->SetNumberOfColors(theNbColors); Modified(); } -int VISU_ScalarMapPL::GetNbColors() { + +int +VISU_ScalarMapPL +::GetNbColors() +{ return myMapperTable->GetNumberOfColors(); } -VISU_ScalarMapPL::THook* VISU_ScalarMapPL::DoHook(){ +//---------------------------------------------------------------------------- +VISU_ScalarMapPL::THook* +VISU_ScalarMapPL +::DoHook() +{ myMapper->SetColorModeToMapScalars(); myMapper->ScalarVisibilityOn(); return myFieldTransform->GetUnstructuredGridOutput(); } -void VISU_ScalarMapPL::Init(){ - //SetSourceRange(); +void +VISU_ScalarMapPL +::Init() +{ + SetScalarMode(0); + SetSourceRange(); } - -void VISU_ScalarMapPL::Build() { - myExtractor->SetInput(GetInput2()); - myFieldTransform->SetInput(myExtractor->GetOutput()); +void +VISU_ScalarMapPL +::Build() +{ myMapper->SetInput(DoHook()); } -void VISU_ScalarMapPL::Update() { +void +VISU_ScalarMapPL +::Update() +{ float *aRange = myFieldTransform->GetScalarRange(); float aScalarRange[2] = {aRange[0], aRange[1]}; if(myBarTable->GetScale() == VTK_SCALE_LOG10) VISU_LookupTable::ComputeLogRange(aRange,aScalarRange); myMapperTable->SetRange(aScalarRange); - myMapperTable->SetMapScale(1.0); myMapperTable->Build(); myBarTable->Build(); @@ -159,21 +240,51 @@ void VISU_ScalarMapPL::Update() { } -void VISU_ScalarMapPL::SetMapScale(float theMapScale){ +//---------------------------------------------------------------------------- +VISU_LookupTable * +VISU_ScalarMapPL +::GetMapperTable() +{ + return myMapperTable; +} + +VISU_LookupTable* +VISU_ScalarMapPL +::GetBarTable() +{ + return myBarTable; +} + + +//---------------------------------------------------------------------------- +void +VISU_ScalarMapPL +::SetMapScale(float theMapScale) +{ myMapperTable->SetMapScale(theMapScale); myMapperTable->Build(); } -float VISU_ScalarMapPL::GetMapScale(){ + +float +VISU_ScalarMapPL::GetMapScale() +{ return myMapperTable->GetMapScale(); } -void VISU_ScalarMapPL::GetSourceRange(float theRange[2]){ +//---------------------------------------------------------------------------- +void +VISU_ScalarMapPL +::GetSourceRange(float theRange[2]) +{ myExtractor->Update(); myExtractor->GetOutput()->GetScalarRange(theRange); } -void VISU_ScalarMapPL::SetSourceRange(){ +void +VISU_ScalarMapPL +::SetSourceRange() +{ float aRange[2]; GetSourceRange(aRange); SetScalarRange(aRange); diff --git a/src/PIPELINE/VISU_ScalarMapPL.hxx b/src/PIPELINE/VISU_ScalarMapPL.hxx index b5358285..1d810fb9 100644 --- a/src/PIPELINE/VISU_ScalarMapPL.hxx +++ b/src/PIPELINE/VISU_ScalarMapPL.hxx @@ -31,55 +31,121 @@ #include "VISU_PipeLine.hxx" #include "VISU_ScalarBarActor.hxx" +class vtkCell; class vtkDataSet; class VISU_Extractor; class VISU_FieldTransform; -class VISU_ScalarMapPL : public VISU_PipeLine{ + +//============================================================================ +class VISU_ScalarMapPL : public VISU_PipeLine +{ protected: VISU_ScalarMapPL(); VISU_ScalarMapPL(const VISU_ScalarMapPL&); + + virtual + ~VISU_ScalarMapPL(); + public: + //---------------------------------------------------------------------------- vtkTypeMacro(VISU_ScalarMapPL,VISU_PipeLine); - static VISU_ScalarMapPL* New(); - virtual ~VISU_ScalarMapPL(); - virtual void ShallowCopy(VISU_PipeLine *thePipeLine); - virtual int GetScalarMode(); - virtual void SetScalarMode(int theScalarMode = 0); + static + VISU_ScalarMapPL* + New(); + + virtual + void + ShallowCopy(VISU_PipeLine *thePipeLine); + + //---------------------------------------------------------------------------- + virtual + int + GetScalarMode(); + + virtual + void + SetScalarMode(int theScalarMode = 0); - virtual int GetScaling(); - virtual void SetScaling(int theScaling = VTK_SCALE_LINEAR); + virtual + int + GetScaling(); + virtual + void + SetScaling(int theScaling = VTK_SCALE_LINEAR); - virtual float* GetScalarRange(); - virtual void SetScalarRange(float theRange[2]); - virtual void SetScalarMin(float theValue); - virtual void SetScalarMax(float theValue); + virtual + float* + GetScalarRange(); + + virtual + void + SetScalarRange(float theRange[2]); + + virtual + void + SetScalarMin(float theValue); + + virtual + void + SetScalarMax(float theValue); - virtual void SetNbColors(int theNbColors = 16); - virtual int GetNbColors(); + virtual + void + SetNbColors(int theNbColors = 16); + + virtual + int + GetNbColors(); + //---------------------------------------------------------------------------- public: - virtual void Init(); - virtual void Build(); - virtual void Update(); + virtual + void + Init(); + + virtual + void + Build(); + + virtual + void + Update(); - virtual VISU_LookupTable *GetMapperTable(){ return myMapperTable;} - virtual VISU_LookupTable *GetBarTable(){ return myBarTable;} + virtual + VISU_LookupTable* + GetMapperTable(); + + virtual + VISU_LookupTable* + GetBarTable(); + + virtual + void + SetMapScale(float theMapScale = 1.0); + + virtual + float + GetMapScale(); - virtual void SetMapScale(float theMapScale = 1.0); - virtual float GetMapScale(); + virtual + void + GetSourceRange(float theRange[2]); - virtual void GetSourceRange(float theRange[2]); - virtual void SetSourceRange(); + virtual + void + SetSourceRange(); + //---------------------------------------------------------------------------- protected: typedef vtkDataSet THook; virtual THook* DoHook(); - VISU_LookupTable *myMapperTable, *myBarTable; - VISU_FieldTransform *myFieldTransform; + VISU_LookupTable* myMapperTable; + VISU_LookupTable* myBarTable; + VISU_FieldTransform* myFieldTransform; VISU_Extractor* myExtractor; }; diff --git a/src/PIPELINE/VISU_SphereWidget.cxx b/src/PIPELINE/VISU_SphereWidget.cxx new file mode 100755 index 00000000..2134aeb7 --- /dev/null +++ b/src/PIPELINE/VISU_SphereWidget.cxx @@ -0,0 +1,622 @@ +#include "VISU_SphereWidget.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +vtkCxxRevisionMacro(VISU_SphereWidget, "$Revision$"); +vtkStandardNewMacro(VISU_SphereWidget); +//==================================================================== +// function: +// purpose: +//==================================================================== +VISU_SphereWidget::VISU_SphereWidget() +{ + myState = VISU_SphereWidget::Start; + this->EventCallbackCommand->SetCallback(VISU_SphereWidget::ProcessEvents); + + //Build the representation of the widget + mySphereSource = vtkSphereSource::New(); + mySphereSource->SetThetaResolution(16); + mySphereSource->SetPhiResolution(15); + mySphereSource->LatLongTessellationOn(); + mySphereMapper = vtkPolyDataMapper::New(); + mySphereMapper->SetInput(mySphereSource->GetOutput()); + mySphereActor = vtkActor::New(); + mySphereActor->SetMapper(mySphereMapper); + // + // Define the point coordinates + float bounds[6]; + for(int i = 0; i < 6; i += 2){ + bounds[i]=-.5; + bounds[i+1]=-bounds[i]; + } + // Initial creation of the widget, serves to initialize it + PlaceWidget(bounds); + + //Manage the picking stuff + myPicker = vtkCellPicker::New(); + myPicker->SetTolerance(0.005); //need some fluff + myPicker->AddPickList(mySphereActor); + myPicker->PickFromListOn(); + + // Set up the initial properties + mySphereProperty = NULL; + mySelectedSphereProperty = NULL; + CreateDefaultProperties(); + myRmin=1.e-7; + + mySphere=vtkSphere::New(); + myImplicitSum=vtkImplicitSum::New(); + myImplicitSum->AddFunction(mySphere,-1.0); + + myRatio = 2.0; +} +//==================================================================== +// function: ~ +// purpose: +//==================================================================== +VISU_SphereWidget::~VISU_SphereWidget() +{ + mySphereActor->Delete(); + mySphereMapper->Delete(); + mySphereSource->Delete(); + + myPicker->Delete(); + + if ( mySphereProperty ) { + mySphereProperty->Delete(); + } + if ( mySelectedSphereProperty ) { + mySelectedSphereProperty->Delete(); + } + mySphere->Delete(); + myImplicitSum->Delete(); +} +//==================================================================== +// function: SetThetaResolution +// purpose : +//==================================================================== +void VISU_SphereWidget::SetThetaResolution(int r) +{ + mySphereSource->SetThetaResolution(r); +} +//==================================================================== +// function: GetThetaResolution +// purpose : +//==================================================================== +int VISU_SphereWidget::GetThetaResolution() +{ + return mySphereSource->GetThetaResolution(); +} +//==================================================================== +// function: SetPhiResolution +// purpose : +//==================================================================== +void VISU_SphereWidget::SetPhiResolution(int r) +{ + mySphereSource->SetPhiResolution(r); +} +//==================================================================== +// function: SetPhiResolution +// purpose : +//==================================================================== +int VISU_SphereWidget::GetPhiResolution() +{ + return mySphereSource->GetPhiResolution(); +} +//==================================================================== +// function: SetRadius +// purpose : +//==================================================================== +void VISU_SphereWidget::SetRadius(float theRadius) +{ + if ( theRadius <= myRmin ) { + theRadius = myRmin; + } + mySphereSource->SetRadius(theRadius); + mySphere->SetRadius(theRadius); +} +//==================================================================== +// function: GetRadius +// purpose : +//==================================================================== +float VISU_SphereWidget::GetRadius() +{ + return mySphereSource->GetRadius(); +} +//==================================================================== +// function: SetCenter +// purpose : +//==================================================================== +void VISU_SphereWidget::SetCenter(float theCenter[3]) +{ + mySphereSource->SetCenter(theCenter); + mySphere->SetCenter(theCenter); +} +//==================================================================== +// function: SetCenter +// purpose : +//==================================================================== +void VISU_SphereWidget::SetCenter(float theX, float theY, float theZ) +{ + float aCenter[3] = {theX, theY, theZ}; + SetCenter(aCenter); +} + +//==================================================================== +// function: GetCenter +// purpose : +//==================================================================== +float* VISU_SphereWidget::GetCenter() +{ + return mySphereSource->GetCenter(); +} +//==================================================================== +// function: GetCenter +// purpose : +//==================================================================== +void VISU_SphereWidget::GetCenter(float theCenter[3]) +{ + mySphereSource->GetCenter(theCenter); +} +//==================================================================== +// function: GetSphereProperty +// purpose : +//==================================================================== +vtkProperty* VISU_SphereWidget::GetSphereProperty () +{ + return mySphereProperty; +} +//==================================================================== +// function: GetSelectedSphereProperty +// purpose : +//==================================================================== +vtkProperty* VISU_SphereWidget::GetSelectedSphereProperty () +{ + return mySelectedSphereProperty; +} +//==================================================================== +// function: ImplicitFunction +// purpose : +//==================================================================== +vtkImplicitFunction* VISU_SphereWidget::ImplicitFunction() +{ + return myImplicitSum; +} +//==================================================================== +// function: SetEnabled +// purpose : +//==================================================================== +void VISU_SphereWidget::SetEnabled(int enabling) +{ + if ( !Interactor ) { + vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget"); + return; + } + + if ( enabling ) { + vtkDebugMacro(<<"Enabling sphere widget"); + if ( Enabled ) {//already enabled, just return + return; + } + + if ( ! CurrentRenderer ) { + int aPos[2]; + Interactor->GetLastEventPosition(aPos); + CurrentRenderer=Interactor->FindPokedRenderer(aPos[0], aPos[1]); + if (!CurrentRenderer) { + return; + } + } + + Enabled = 1; + + // listen for the following events + Interactor->AddObserver(vtkCommand::MouseMoveEvent, + EventCallbackCommand, + Priority); + Interactor->AddObserver(vtkCommand::LeftButtonPressEvent, + EventCallbackCommand, + Priority); + Interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, + EventCallbackCommand, + Priority); + Interactor->AddObserver(vtkCommand::MiddleButtonPressEvent, + EventCallbackCommand, + Priority); + Interactor->AddObserver(vtkCommand::MiddleButtonReleaseEvent, + EventCallbackCommand, + Priority); + + // Add the sphere + CurrentRenderer->AddActor(mySphereActor); + mySphereActor->SetProperty(mySphereProperty); + mySphere->SetCenter(mySphereSource->GetCenter()); + mySphere->SetRadius(mySphereSource->GetRadius()); + + InvokeEvent(vtkCommand::EnableEvent,NULL); //!!!see what will be done + } + //disabling---------------------------------------------------------- + else { + vtkDebugMacro(<<"Disabling sphere widget"); + + if ( !Enabled ){ //already disabled, just return + return; + } + + Enabled = 0; + + // don't listen for events any more + Interactor->RemoveObserver(EventCallbackCommand); + + // turn off the sphere + CurrentRenderer->RemoveActor(mySphereActor); + InvokeEvent(vtkCommand::DisableEvent,NULL); + CurrentRenderer = NULL; + } + + Interactor->Render(); +} +//==================================================================== +// function:ProcessEvents +// purpose: +//==================================================================== +void VISU_SphereWidget::ProcessEvents(vtkObject* vtkNotUsed(object), + unsigned long event, + void* clientdata, + void* vtkNotUsed(calldata)) +{ + VISU_SphereWidget* self = reinterpret_cast( clientdata ); + + switch(event) { + case vtkCommand::LeftButtonPressEvent: + self->OnLeftButtonDown(); + break; + case vtkCommand::LeftButtonReleaseEvent: + self->OnLeftButtonUp(); + break; + case vtkCommand::MiddleButtonPressEvent: + self->OnMiddleButtonDown(); + break; + case vtkCommand::MiddleButtonReleaseEvent: + self->OnMiddleButtonUp(); + break; + case vtkCommand::MouseMoveEvent: + self->OnMouseMove(); + break; + default: + break; + } +} +//==================================================================== +// function:OnLeftButtonDown +// purpose: +//==================================================================== +void VISU_SphereWidget::OnLeftButtonDown() +{ + int X = Interactor->GetEventPosition()[0]; + int Y = Interactor->GetEventPosition()[1]; + + // Okay, make sure that the pick is in the current renderer + vtkRenderer *aRenderer = Interactor->FindPokedRenderer(X,Y); + // + if (aRenderer != CurrentRenderer) { + myState = VISU_SphereWidget::Outside; + return; + } + // Okay, we can process this. Try to pick handles first; + // if no places picked, then try to pick the sphere. + myPicker->Pick(X, Y, 0., CurrentRenderer); + if(vtkAssemblyPath *aPath = myPicker->GetPath()){ + if(aPath->GetFirstNode()->GetProp() == mySphereActor){ + myState = VISU_SphereWidget::Moving; + HighlightSphere(1); + } + }else{ + myState = VISU_SphereWidget::Outside; + return; + } + // + EventCallbackCommand->SetAbortFlag(1); + StartInteraction(); + InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + Interactor->Render(); +} +//==================================================================== +// function:OnMouseMove +// purpose: +//==================================================================== +void VISU_SphereWidget::OnMouseMove() +{ + // See whether we're active + if ( myState == VISU_SphereWidget::Outside || + myState == VISU_SphereWidget::Start ) { + return; + } + + int X = Interactor->GetEventPosition()[0]; + int Y = Interactor->GetEventPosition()[1]; + + // Do different things depending on state + // Calculations everybody does + double focalPoint[4], pickPoint[4], prevPickPoint[4], z; + + vtkRenderer *aRenderer=Interactor->FindPokedRenderer(X, Y); + vtkCamera *aCamera=aRenderer->GetActiveCamera(); + if (!aCamera ) { + return; + } + // Compute the two points defining the motion vector + aCamera->GetFocalPoint(focalPoint); + ComputeWorldToDisplay(focalPoint[0], + focalPoint[1], + focalPoint[2], + focalPoint); + z = focalPoint[2]; + ComputeDisplayToWorld(double(Interactor->GetLastEventPosition()[0]), + double(Interactor->GetLastEventPosition()[1]), + z, + prevPickPoint); + ComputeDisplayToWorld(double(X), double(Y), z, pickPoint); + + // Process the motion + if ( myState == VISU_SphereWidget::Moving ) { + Translate(prevPickPoint, pickPoint); + } + else if ( myState == VISU_SphereWidget::Scaling ) { + Scale(prevPickPoint, pickPoint, X, Y); + } + // Interact, if desired + EventCallbackCommand->SetAbortFlag(1); + InvokeEvent(vtkCommand::InteractionEvent,NULL); + // + Interactor->Render(); +} +//==================================================================== +// function:OnLeftButtonUp +// purpose: +//==================================================================== +void VISU_SphereWidget::OnLeftButtonUp() +{ + if ( myState == VISU_SphereWidget::Outside ) { + return; + } + + myState = VISU_SphereWidget::Start; + HighlightSphere(0); + + EventCallbackCommand->SetAbortFlag(1); + EndInteraction(); + InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + + Interactor->Render(); +} +//==================================================================== +// function:OnMiddleButtonDown +// purpose: +//==================================================================== +void VISU_SphereWidget::OnMiddleButtonDown() +{ + myState = VISU_SphereWidget::Scaling; + + int X = Interactor->GetEventPosition()[0]; + int Y = Interactor->GetEventPosition()[1]; + + // Okay, make sure that the pick is in the current renderer + vtkRenderer *aRenderer = Interactor->FindPokedRenderer(X,Y); + if (aRenderer!=CurrentRenderer) { + myState = VISU_SphereWidget::Outside; + return; + } + + // Okay, we can process this. Try to pick handles first; + // if no handles picked, then pick the bounding box. + myPicker->Pick(X, Y, 0., CurrentRenderer); + vtkAssemblyPath *aPath = myPicker->GetPath(); + if ( !aPath ) { + myState=VISU_SphereWidget::Outside; + HighlightSphere(0); + return; + } + + HighlightSphere(1); + + EventCallbackCommand->SetAbortFlag(1); + StartInteraction(); + InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + // + Interactor->Render(); +} +//==================================================================== +// function:OnMiddleButtonUp +// purpose: +//==================================================================== +void VISU_SphereWidget::OnMiddleButtonUp() +{ + if ( myState == VISU_SphereWidget::Outside ) { + return; + } + myState = VISU_SphereWidget::Start; + HighlightSphere(0); + + EventCallbackCommand->SetAbortFlag(1); + EndInteraction(); + InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + // + Interactor->Render(); +} +//==================================================================== +// function:Translate +// purpose: +//==================================================================== +void VISU_SphereWidget::Translate(double *p1, double *p2) +{ + float v[3], aC[3], aC1[3]; + // + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + // + mySphereSource->GetCenter(aC); + aC1[0] = aC[0] + v[0]; + aC1[1] = aC[1] + v[1]; + aC1[2] = aC[2] + v[2]; + mySphereSource->SetCenter(aC1); + mySphere->SetCenter(mySphereSource->GetCenter()); + mySphere->SetRadius(mySphereSource->GetRadius()); +} +//==================================================================== +// function:Scale +// purpose: +//==================================================================== +void VISU_SphereWidget::Scale(double *p1, double *p2, + int aX, int aY) +{ + double v[3]; + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + // + float aC[3], aR, sf, aR1; + aR=mySphereSource->GetRadius(); + mySphereSource->GetCenter(aC); + sf=vtkMath::Norm(v)/aR; + int aCoordLast[2], iDX, iDY, iSign; + Interactor->GetLastEventPosition(aCoordLast); + // + iDX=aX-aCoordLast[0]; + iDY=aCoordLast[1]-aY; + iSign=(iDX+iDY>0)? 1 : -1; + sf=1.+iSign*sf; + aR1=sf*aR; + if (aR1SetRadius(aR1); + mySphere->SetCenter(mySphereSource->GetCenter()); + mySphere->SetRadius(mySphereSource->GetRadius()); +} +//==================================================================== +// function:GetSphere +// purpose: +//==================================================================== +void VISU_SphereWidget::GetSphere(vtkSphere *sphere) +{ + sphere->SetRadius(mySphereSource->GetRadius()); + sphere->SetCenter(mySphereSource->GetCenter()); +} +//==================================================================== +// function:HighlightSphere +// purpose: +//==================================================================== +void VISU_SphereWidget::HighlightSphere(int highlight) +{ + if ( highlight ) { + this->ValidPick = 1; + myPicker->GetPickPosition(this->LastPickPosition);// -> def in vtk3DWidget + mySphereActor->SetProperty(mySelectedSphereProperty); + } + else { + mySphereActor->SetProperty(mySphereProperty); + } +} +//==================================================================== +// function:CreateDefaultProperties +// purpose: +//==================================================================== +void VISU_SphereWidget::CreateDefaultProperties() +{ + if (!mySphereProperty) { + mySphereProperty = vtkProperty::New(); + mySphereProperty->SetColor(0.,.5, .7); + mySphereProperty->SetSpecular(0.5); + mySphereProperty->SetRepresentationToWireframe(); + } + if (!mySelectedSphereProperty) { + mySelectedSphereProperty = vtkProperty::New(); + mySelectedSphereProperty->SetColor(0.5, 0.5, 0.); + mySelectedSphereProperty->SetSpecular(1.); + mySelectedSphereProperty->SetRepresentationToWireframe(); + } +} +//==================================================================== +// function:PlaceWidget +// purpose: +//==================================================================== +void VISU_SphereWidget::PlaceWidget(float bds[6]) +{ + float bounds[6], center[3], radius; + + this->AdjustBounds(bds, bounds, center); + float dX, dY, dZ; + // + dX=bounds[1]-bounds[0]; + dY=bounds[3]-bounds[2]; + dZ=bounds[5]-bounds[4]; + radius = dX; + if (radius>dY){ + radius = dY; + } + if (radius>dZ) { + radius=dZ; + } + radius*=0.5; + + mySphereSource->SetCenter(center); + mySphereSource->SetRadius(radius); + mySphereSource->Update(); + // + for (int i=0; i<6; i++) { + InitialBounds[i]=bounds[i]; + } + InitialLength = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) + + (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) + + (bounds[5]-bounds[4])*(bounds[5]-bounds[4])); + + static float EPS = 1.0E-1; + myRmin = EPS*InitialLength; + +} + +//==================================================================== +// function:ChangeRadius +// purpose: +//==================================================================== +void VISU_SphereWidget::ChangeRadius(bool up) +{ + SetRadius( GetRadius() * ( up ? myRatio : 1 / myRatio ) ); +} +//==================================================================== +// function:GetPolyData +// purpose: +//==================================================================== +void VISU_SphereWidget::GetPolyData(vtkPolyData *pd) +{ + pd->ShallowCopy(mySphereSource->GetOutput()); +} +//==================================================================== +// function:PrintSelf +// purpose: +//==================================================================== +void VISU_SphereWidget::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); +} diff --git a/src/PIPELINE/VISU_SphereWidget.hxx b/src/PIPELINE/VISU_SphereWidget.hxx new file mode 100755 index 00000000..040a4180 --- /dev/null +++ b/src/PIPELINE/VISU_SphereWidget.hxx @@ -0,0 +1,134 @@ +#ifndef __VISU_SphereWidget_h +#define __VISU_SphereWidget_h + +#include "VISU_ImplicitFunctionWidget.hxx" + +class VISU_UnScaledActor; + +class vtkActor; +class vtkPolyDataMapper; +class vtkPoints; +class vtkPolyData; +class vtkSphereSource; +class vtkSphere; +class vtkCellPicker; +class vtkProperty; +class vtkSphere; +class vtkImplicitSum; +class vtkImplicitFunction; +// +class VISU_SphereWidget : public VISU_ImplicitFunctionWidget +{ +public: + // Description: + // Instantiate the object. + static VISU_SphereWidget *New(); + vtkTypeRevisionMacro(VISU_SphereWidget,VISU_ImplicitFunctionWidget); + void PrintSelf(ostream& os, vtkIndent indent); + + virtual vtkImplicitFunction* ImplicitFunction(); + + // Description: + // Methods that satisfy the superclass' API. + virtual void SetEnabled(int); + // + //PlaceWidget + virtual void PlaceWidget(float bounds[6]); + // + // Description: + // Set/Get the resolution of the sphere in the Theta direction. + void SetThetaResolution(int r); + int GetThetaResolution(); + // Description: + // Set/Get the resolution of the sphere in the Phi direction. + void SetPhiResolution(int r); + int GetPhiResolution(); + + // Description: + // Set/Get the radius of sphere. Default is .5. + void SetRadius(float r); + float GetRadius(); + + + // Description: + // Set/Get the center of the sphere. + void SetCenter(float x, float y, float z); + void SetCenter(float x[3]); + + float* GetCenter(); + void GetCenter(float xyz[3]); + + // Description: + // Set the ratio of the radius changing. + void SetRatio(float r) { myRatio = r; } + float GetRatio() { return myRatio; } + + void ChangeRadius(bool up); + + void GetPolyData(vtkPolyData *pd); + + void GetSphere(vtkSphere *sphere); + + + vtkProperty* GetSphereProperty (); + vtkProperty* GetSelectedSphereProperty (); + + +protected: + VISU_SphereWidget(); + ~VISU_SphereWidget(); + + //handles the events + static void ProcessEvents(vtkObject* object, + unsigned long event, + void* clientdata, + void* calldata); + + // ProcessEvents() dispatches to these methods. + void OnLeftButtonDown(); + void OnLeftButtonUp(); + void OnMiddleButtonDown(); + void OnMiddleButtonUp(); + void OnMouseMove(); + + void HighlightSphere(int highlight); + + // Methods to manipulate the sphere widget + void Translate(double *p1, double *p2); + void Scale(double *p1, double *p2, int X, int Y); + + //virtual void SizeHandles(); + void CreateDefaultProperties(); + + //BTX - manage the state of the widget + int myState; + enum WidgetState + { + Start=0, + Moving, + Scaling, + Positioning, + Outside + }; + //ETX + // the sphere + vtkActor *mySphereActor; + vtkPolyDataMapper *mySphereMapper; + vtkSphereSource *mySphereSource; + // + // the Picker + vtkCellPicker *myPicker; + // Properties used to control the appearance of selected objects and + // the manipulator in general. + vtkProperty *mySphereProperty; + vtkProperty *mySelectedSphereProperty; + float myRmin; + vtkSphere *mySphere; + vtkImplicitSum* myImplicitSum; + float myRatio; +private: + VISU_SphereWidget(const VISU_SphereWidget&); //Not implemented + void operator=(const VISU_SphereWidget&); //Not implemented +}; + +#endif diff --git a/src/PIPELINE/VISU_StreamLinesPL.cxx b/src/PIPELINE/VISU_StreamLinesPL.cxx index 9b9f781e..509074a9 100644 --- a/src/PIPELINE/VISU_StreamLinesPL.cxx +++ b/src/PIPELINE/VISU_StreamLinesPL.cxx @@ -37,7 +37,7 @@ #include #ifdef _DEBUG_ -static int MYDEBUG = 1; +static int MYDEBUG = 0; #else static int MYDEBUG = 0; #endif @@ -74,14 +74,15 @@ VISU_StreamLinesPL::~VISU_StreamLinesPL(){ } void VISU_StreamLinesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ - VISU_DeformedShapePL::ShallowCopy(thePipeLine); - if(VISU_StreamLinesPL *aPipeLine = dynamic_cast(thePipeLine)) + if(VISU_StreamLinesPL *aPipeLine = dynamic_cast(thePipeLine)){ SetParams(aPipeLine->GetIntegrationStep(), aPipeLine->GetPropagationTime(), aPipeLine->GetStepLength(), aPipeLine->GetSource(), aPipeLine->GetUsedPoints(), aPipeLine->GetDirection()); + } + VISU_DeformedShapePL::ShallowCopy(thePipeLine); } diff --git a/src/PIPELINE/VISU_VectorsPL.cxx b/src/PIPELINE/VISU_VectorsPL.cxx index c34d36d9..92a5e575 100644 --- a/src/PIPELINE/VISU_VectorsPL.cxx +++ b/src/PIPELINE/VISU_VectorsPL.cxx @@ -34,11 +34,15 @@ #include #include #include +#include vtkStandardNewMacro(VISU_VectorsPL); -VISU_VectorsPL::VISU_VectorsPL(){ - myGlyph = vtkGlyph3D::New(); +VISU_VectorsPL +::VISU_VectorsPL() +{ + myBaseGlyph = vtkGlyph3D::New(); + myTransformedGlyph = vtkGlyph3D::New(); myGlyphSource = vtkGlyphSource2D::New(); myConeSource = vtkConeSource::New(); @@ -49,75 +53,118 @@ VISU_VectorsPL::VISU_VectorsPL(){ myIsShrinkable = false; } -VISU_VectorsPL::~VISU_VectorsPL(){ - myGlyph->UnRegisterAllOutputs(); - myGlyph->Delete(); +VISU_VectorsPL +::~VISU_VectorsPL() +{ + myBaseGlyph->Delete(); + myTransformedGlyph->Delete(); - myCenters->UnRegisterAllOutputs(); myCenters->Delete(); - myGlyphSource->UnRegisterAllOutputs(); myGlyphSource->Delete(); - myConeSource->UnRegisterAllOutputs(); myConeSource->Delete(); - myLineSource->UnRegisterAllOutputs(); myLineSource->Delete(); - myTransformFilter->UnRegisterAllOutputs(); myTransformFilter->Delete(); } -void VISU_VectorsPL::ShallowCopy(VISU_PipeLine *thePipeLine){ - VISU_DeformedShapePL::ShallowCopy(thePipeLine); +void +VISU_VectorsPL +::ShallowCopy(VISU_PipeLine *thePipeLine) +{ if(VISU_VectorsPL *aPipeLine = dynamic_cast(thePipeLine)){ SetGlyphType(aPipeLine->GetGlyphType()); SetGlyphPos(aPipeLine->GetGlyphPos()); } + Superclass::ShallowCopy(thePipeLine); } -void VISU_VectorsPL::SetTransform(VTKViewer_Transform* theTransform){ +void +VISU_VectorsPL +::SetTransform(VTKViewer_Transform* theTransform) +{ myFieldTransform->SetSpaceTransform(theTransform); myTransformFilter->SetTransform(theTransform); myTransformFilter->Modified(); } -VTKViewer_Transform* VISU_VectorsPL::GetTransform(){ + +VTKViewer_Transform* +VISU_VectorsPL +::GetTransform() +{ return myFieldTransform->GetSpaceTransform(); } -void VISU_VectorsPL::SetScale(float theScale) { - if(myScaleFactor == theScale) return; +void +VISU_VectorsPL +::SetScale(float theScale) +{ + if(myScaleFactor == theScale) + return; + myScaleFactor = theScale; - myGlyph->SetScaleFactor(myScaleFactor); + + myBaseGlyph->SetScaleFactor(myScaleFactor); + myTransformedGlyph->SetScaleFactor(myScaleFactor); + Modified(); } -float VISU_VectorsPL::GetScale() { - return myGlyph->GetScaleFactor(); + +float +VISU_VectorsPL +::GetScale() +{ + return myTransformedGlyph->GetScaleFactor(); } -void VISU_VectorsPL::Init(){ - VISU_DeformedShapePL::Init(); +void +VISU_VectorsPL +::Init() +{ + Superclass::Init(); myTypeGlyph = ARROW; myPosGlyph = TAIL; } -VISU_ScalarMapPL::THook* VISU_VectorsPL::DoHook(){ +vtkDataSet* +VISU_VectorsPL +::GetOutput() +{ + myBaseGlyph->Update(); + return myBaseGlyph->GetOutput(); +} + + +VISU_ScalarMapPL::THook* +VISU_VectorsPL +::DoHook() +{ + VISU::ToCellCenters(myBaseGlyph,myCenters,GetInput2(),myFieldTransform); + myBaseGlyph->SetVectorModeToUseVector(); + myBaseGlyph->SetScaleModeToScaleByVector(); + myBaseGlyph->SetColorModeToColorByScalar(); + VISU::ToCellCenters(myTransformFilter,myCenters,GetInput2(),myFieldTransform); - myGlyph->SetInput(myTransformFilter->GetOutput()); - myGlyph->SetVectorModeToUseVector(); - myGlyph->SetScaleModeToScaleByVector(); - myGlyph->SetColorModeToColorByScalar(); - return myGlyph->GetOutput(); + myTransformedGlyph->SetInput(myTransformFilter->GetOutput()); + myTransformedGlyph->SetVectorModeToUseVector(); + myTransformedGlyph->SetScaleModeToScaleByVector(); + myTransformedGlyph->SetColorModeToColorByScalar(); + + return myTransformedGlyph->GetOutput(); } -void VISU_VectorsPL::Update(){ +void +VISU_VectorsPL +::Update() +{ switch (myTypeGlyph) { case ARROW: { myGlyphSource->SetGlyphTypeToArrow(); @@ -132,11 +179,8 @@ void VISU_VectorsPL::Update(){ case CENTER: myGlyphSource->SetCenter(0.0, 0.0, 0.0); } -// if(myPosGlyph == TAIL) -// myGlyphSource->SetCenter(0.5, 0.0, 0.0); -// else if(myPosGlyph == HEAD) -// myGlyphSource->SetCenter(-0.5, 0.0, 0.0); - myGlyph->SetSource(myGlyphSource->GetOutput()); + myBaseGlyph->SetSource(myGlyphSource->GetOutput()); + myTransformedGlyph->SetSource(myGlyphSource->GetOutput()); } break; case CONE2: @@ -158,26 +202,29 @@ void VISU_VectorsPL::Update(){ case CENTER: myConeSource->SetCenter(0.0, 0.0, 0.0); } -// if(myPosGlyph == TAIL) -// myConeSource->SetCenter(0.5, 0.0, 0.0); -// else if(myPosGlyph == HEAD) -// myConeSource->SetCenter(-0.5, 0.0, 0.0); - myGlyph->SetSource(myConeSource->GetOutput()); + myBaseGlyph->SetSource(myConeSource->GetOutput()); + myTransformedGlyph->SetSource(myConeSource->GetOutput()); } break; case NONE: default: { - myGlyph->SetSource(myLineSource->GetOutput()); + myBaseGlyph->SetSource(myLineSource->GetOutput()); + myTransformedGlyph->SetSource(myLineSource->GetOutput()); } } - VISU_DeformedShapePL::Update(); + Superclass::Update(); } -void VISU_VectorsPL::SetMapScale(float theMapScale){ +void +VISU_VectorsPL +::SetMapScale(float theMapScale) +{ VISU_ScalarMapPL::SetMapScale(theMapScale); - myGlyph->SetScaleFactor(myScaleFactor*theMapScale); - myGlyph->Modified(); + myBaseGlyph->SetScaleFactor(myScaleFactor*theMapScale); + myTransformedGlyph->SetScaleFactor(myScaleFactor*theMapScale); + + Modified(); } diff --git a/src/PIPELINE/VISU_VectorsPL.hxx b/src/PIPELINE/VISU_VectorsPL.hxx index 8b24ece6..312d56fc 100644 --- a/src/PIPELINE/VISU_VectorsPL.hxx +++ b/src/PIPELINE/VISU_VectorsPL.hxx @@ -61,19 +61,24 @@ public: virtual GlyphPos GetGlyphPos() { return myPosGlyph;} public: - virtual THook* DoHook(); virtual void Init(); virtual void Update(); + vtkDataSet* + GetOutput(); + virtual void SetTransform(VTKViewer_Transform* theTransform); virtual VTKViewer_Transform* GetTransform(); virtual void SetMapScale(float theMapScale = 1.0); protected: + virtual THook* DoHook(); + GlyphType myTypeGlyph; GlyphPos myPosGlyph; - vtkGlyph3D *myGlyph; + vtkGlyph3D *myBaseGlyph; + vtkGlyph3D *myTransformedGlyph; vtkGlyphSource2D *myGlyphSource; vtkLineSource *myLineSource; diff --git a/src/PIPELINE/VISU_WidgetCtrl.cxx b/src/PIPELINE/VISU_WidgetCtrl.cxx new file mode 100644 index 00000000..bb62dc63 --- /dev/null +++ b/src/PIPELINE/VISU_WidgetCtrl.cxx @@ -0,0 +1,364 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_WidgetCtrl.cxx +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#include "VISU_WidgetCtrl.hxx" +// +#include "VISU_ImplicitFunctionWidget.hxx" +#include "VISU_PlanesWidget.hxx" +#include "VISU_SphereWidget.hxx" +// +#include +// +#include +#include +#include +#include +#include +#include +// +vtkCxxRevisionMacro(VISU_WidgetCtrl,"$Revision$"); +vtkStandardNewMacro(VISU_WidgetCtrl); + +//================================================================== +// function: VISU_WidgetCtrl +// purpose : +//================================================================== +VISU_WidgetCtrl::VISU_WidgetCtrl() +{ + myDummyWidget=NULL; + myDisableAll=0; + myNbWidgets=2; + myActiveIndex=-1;// 0 - PlanesWidget; 1 - SphereWidget + myPriority=0.; + // + myPlanesWidget=VISU_PlanesWidget::New(); + mySphereWidget=VISU_SphereWidget::New(); + // + myWidgets[0]=myPlanesWidget; + myWidgets[1]=mySphereWidget; + // + myEventCallbackCommand=vtkCallbackCommand::New(); + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(VISU_WidgetCtrl::ProcessEvents); + // + int i; + for (i=0; iAddObserver(vtkCommand::EnableEvent, + myEventCallbackCommand, + myPriority); + myWidgets[i]->AddObserver(vtkCommand::DisableEvent, + myEventCallbackCommand, + myPriority); + myWidgets[i]->AddObserver(vtkCommand::EndInteractionEvent, + myEventCallbackCommand, + myPriority); + myWidgets[i]->AddObserver(vtkCommand::StartInteractionEvent, + myEventCallbackCommand, + myPriority); + + myWidgets[i]->AddObserver(vtkCommand::InteractionEvent, + myEventCallbackCommand, + myPriority); + } +} +//================================================================== +// function: ~ +// purpose : +//================================================================== +VISU_WidgetCtrl::~VISU_WidgetCtrl() +{ + + myPlanesWidget->Delete(); + mySphereWidget->Delete(); + // + for (int i=0; iRemoveObserver(myEventCallbackCommand); + } + // + myEventCallbackCommand->Delete(); +} +//================================================================== +// function: GetEnabled +// purpose : +//================================================================== +int VISU_WidgetCtrl::GetEnabled() +{ + if (HasActiveIndex()) { + return GetActiveWidget()->GetEnabled(); + } + return 0; +} +//================================================================== +// function: SetEnabled +// purpose : +//================================================================== +void VISU_WidgetCtrl::SetEnabled(int theFlag) +{ + int iFlag, i; + // + myDisableAll=0; + // + iFlag=GetEnabled(); + if (iFlag==theFlag) { + return; + } + // + if (theFlag) {//enabling + if (HasActiveIndex()) { + for (i=0; iSetEnabled(iFlag); + } + } + } + else {//disabling + myDisableAll=1; + for (i=0; iSetEnabled(0); + } + } + + Modified(); +} +//================================================================== +// function: ProcessEvents +// purpose : +//================================================================== +void VISU_WidgetCtrl::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + VISU_WidgetCtrl *aSelf = reinterpret_cast(theClientData); + switch(theEvent){ + case vtkCommand::DisableEvent: + if(aSelf->GetDisableAll()) + aSelf->InvokeEvent(theEvent, NULL); + default: + aSelf->InvokeEvent(theEvent, NULL); + break; + } +} + +//================================================================== +// function: GetNbWidgets +// purpose : +//================================================================== +int VISU_WidgetCtrl::GetNbWidgets()const +{ + return myNbWidgets; +} +//================================================================== +// function: GetDisableAll +// purpose : +//================================================================== +int VISU_WidgetCtrl::GetDisableAll()const +{ + return myDisableAll; +} +//================================================================== +// function: SetActiveIndex +// purpose : +//================================================================== +void VISU_WidgetCtrl::SetActiveIndex(const int theIndex) +{ + myActiveIndex=-1; + if (theIndex>=0 && theIndex=0 && myActiveIndex=0 && theIndexPlaceWidget(theBounds); + } +} +//================================================================== +// function: SetInteractor +// purpose : +//================================================================== +void VISU_WidgetCtrl::SetInteractor(vtkRenderWindowInteractor* theRWI) +{ + for (int i=0; iSetInteractor(theRWI); + } + + Modified(); +} +//================================================================== +// function: GetInteractor +// purpose : +//================================================================== +vtkRenderWindowInteractor* VISU_WidgetCtrl::GetInteractor() +{ + return myWidgets[0]->GetInteractor(); +} +//================================================================== +// function: SetPlaceFactor +// purpose : +//================================================================== +void VISU_WidgetCtrl::SetPlaceFactor(float theFactor) +{ + for (int i=0; iSetPlaceFactor(theFactor); + } + + Modified(); +} +//================================================================== +// function: GetPlaceFactor +// purpose : +//================================================================== +float VISU_WidgetCtrl::GetPlaceFactor() +{ + return myWidgets[0]->GetPlaceFactor(); +} +//================================================================== +// function: ImplicitFunction +// purpose : +//================================================================== +vtkImplicitFunction* VISU_WidgetCtrl::ImplicitFunction() +{ + return this; +} + +//================================================================== +float +VISU_WidgetCtrl +::EvaluateFunction(float theX[3]) +{ + if(VISU_ImplicitFunctionWidget* aWidget = GetActiveWidget()){ + if(vtkImplicitFunction* aFunction = aWidget->ImplicitFunction()) + return aFunction->EvaluateFunction(theX[0],theX[1],theX[2]); + } + return 1.0; +} + +//================================================================== +void +VISU_WidgetCtrl +::EvaluateGradient(float theX[3], float theG[3]) +{ + theG[0] = theG[1] = theG[2] = 0.0; + if(VISU_ImplicitFunctionWidget* aWidget = GetActiveWidget()){ + if(vtkImplicitFunction* aFunction = aWidget->ImplicitFunction()) + aFunction->EvaluateGradient(theX,theG); + } +} + +//================================================================== +unsigned long +VISU_WidgetCtrl +::GetMTime() +{ + unsigned long aTime = Superclass::GetMTime(); + + if(vtkImplicitFunction* aFunction = myPlanesWidget->ImplicitFunction()) + aTime = std::max(aTime,aFunction->GetMTime()); + + if(vtkImplicitFunction* aFunction = mySphereWidget->ImplicitFunction()) + aTime = std::max(aTime,aFunction->GetMTime()); + + return aTime; +} diff --git a/src/PIPELINE/VISU_WidgetCtrl.hxx b/src/PIPELINE/VISU_WidgetCtrl.hxx new file mode 100644 index 00000000..8737b5dc --- /dev/null +++ b/src/PIPELINE/VISU_WidgetCtrl.hxx @@ -0,0 +1,120 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VISU_WidgetCtrl.hxx +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#ifndef __VISU_WidgetCtrl_hxx +#define __VISU_WidgetCtrl_hxx + + +#include + +class vtkImplicitFunction; +class vtkObject; +class vtkRenderWindowInteractor; +class vtkCommand; +class vtkCallbackCommand; + +class VISU_PlanesWidget; +class VISU_SphereWidget; +class VISU_ImplicitFunctionWidget; + +class VISU_WidgetCtrl : public vtkImplicitFunction +{ +public: + static VISU_WidgetCtrl *New(); + vtkTypeRevisionMacro(VISU_WidgetCtrl,vtkObject); + + vtkImplicitFunction* ImplicitFunction(); + + virtual + float + EvaluateFunction(float theX[3]); + + virtual + void + EvaluateGradient(float theX[3], float theG[3]); + + virtual + unsigned long + GetMTime(); + + void PlaceWidget(float theBounds[6]); + void SetEnabled(int theFlag); + int GetEnabled(); + void On() {SetEnabled(1);} + void Off(){SetEnabled(0);} + + void SetInteractor(vtkRenderWindowInteractor* theRWI); + vtkRenderWindowInteractor* GetInteractor(); + // + void SetPlaceFactor(float theFactor); + float GetPlaceFactor(); + // + void SetActiveIndex(const int theFlag); + int GetActiveIndex()const; + bool HasActiveIndex()const; + bool IsPlanesActive()const; + bool IsSphereActive()const; + + + VISU_ImplicitFunctionWidget* GetActiveWidget(); + VISU_ImplicitFunctionWidget* GetWidget(const int); + + int GetNbWidgets()const; + int GetDisableAll()const; + + // + VISU_PlanesWidget * GetPlanesWidget(); + VISU_SphereWidget * GetSphereWidget(); + // + static void ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCalldata); + // +protected: + VISU_WidgetCtrl(); + ~VISU_WidgetCtrl(); + +protected: + int myNbWidgets; + int myActiveIndex; + int myCounter; + int myDisableAll; + float myPriority; + VISU_ImplicitFunctionWidget *myWidgets[2]; + VISU_ImplicitFunctionWidget *myDummyWidget; + VISU_PlanesWidget *myPlanesWidget; + VISU_SphereWidget *mySphereWidget; + vtkCallbackCommand *myEventCallbackCommand; + +private: + VISU_WidgetCtrl(const VISU_WidgetCtrl&); //Not implemented + void operator=(const VISU_WidgetCtrl&); //Not implemented +}; + +#endif diff --git a/src/PIPELINE/VISU_img2vti.cxx b/src/PIPELINE/VISU_img2vti.cxx new file mode 100644 index 00000000..8cc0a475 --- /dev/null +++ b/src/PIPELINE/VISU_img2vti.cxx @@ -0,0 +1,88 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_img2vti.cxx +// Author: Oleg UVAROV +// Module : VISU + +#include +#include +#include +#include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +int main( int argc, char** argv ) +{ + if(MYDEBUG) std::cout << "Converting the image to VTI format" << std::endl; + + if( argc != 4 ) + { + std::cout << "Usage : VISU_img2vti ImageFormat InputFileName OutputFileName" << std::endl; + return 1; + } + + if(MYDEBUG){ + std::cout << argv[1] << std::endl; + std::cout << argv[2] << std::endl; + std::cout << argv[3] << std::endl; + } + + vtkImageReader2* aReader = NULL; + if( !strcmp( argv[1], "BMP" ) || !strcmp( argv[1], "bmp" ) ) + { + if(MYDEBUG) std::cout << "Input image format - BMP" << std::endl; + aReader = vtkBMPReader::New(); + } + else if( !strcmp( argv[1], "PNG" ) || !strcmp( argv[1], "png" ) ) + { + if(MYDEBUG) std::cout << "Input image format - PNG" << std::endl; + aReader = vtkPNGReader::New(); + } + else if( !strcmp( argv[1], "JPG" ) || !strcmp( argv[1], "jpg" ) ) + { + if(MYDEBUG) std::cout << "Input image format - JPG" << std::endl; + aReader = vtkJPEGReader::New(); + } + else + { + std::cout << "Unknown input image format... Must be BMP, PNG or JPG." << std::endl; + return 1; + } + aReader->SetFileName( argv[2] ); + aReader->Update(); + + vtkXMLImageDataWriter* aWriter = vtkXMLImageDataWriter::New(); + aWriter->SetInput( aReader->GetOutput() ); + aWriter->SetFileName( argv[3] ); + aWriter->Write(); + + aWriter->Delete(); + aReader->Delete(); + + return 0; +} diff --git a/src/VISUGUI/Makefile.in b/src/VISUGUI/Makefile.in index 805e6928..1c2f20f1 100644 --- a/src/VISUGUI/Makefile.in +++ b/src/VISUGUI/Makefile.in @@ -35,12 +35,11 @@ VPATH=.:@srcdir@ # header files EXPORT_HEADERS= \ - VisuGUI_NonIsometricDlg.h \ VisuGUI_Tools.h # .po files to transform in .qm PO_FILES = \ - VISU_msg_en.po VISU_images.po + VISU_msg_en.po VISU_images.po VISUM_msg_en.po VISUM_images.po # Libraries targets LIB = libVISU.la @@ -49,8 +48,10 @@ LIB = libVISU.la LIB_SRC = VisuGUI.cxx \ VisuGUI_Factory.cxx \ + VisuGUI_Module.cxx \ VisuGUI_Selection.cxx \ VisuGUI_Tools.cxx \ + VisuGUI_ViewTools.cxx \ VisuGUI_PopupTools.cxx \ VisuGUI_NameDlg.cxx \ VisuGUI_FileDlg.cxx \ @@ -58,23 +59,26 @@ LIB_SRC = VisuGUI.cxx \ VisuGUI_TimeAnimation.cxx \ VisuGUI_EditContainerDlg.cxx \ VisuGUI_ClippingDlg.cxx \ - VisuGUI_CubeAxesDlg.cxx \ - VisuGUI_FontWg.cxx \ + VisuGUI_DialogRunner.cxx \ VisuGUI_OffsetDlg.cxx \ VisuGUI_Plot3DDlg.cxx \ - VisuGUI_NonIsometricDlg.cxx \ VisuGUI_ScalarBarDlg.cxx \ + VisuGUI_GaussPointsDlg.cxx \ VisuGUI_DeformedShapeDlg.cxx \ VisuGUI_IsoSurfacesDlg.cxx \ VisuGUI_CutLinesDlg.cxx \ VisuGUI_CutPlanesDlg.cxx \ VisuGUI_StreamLinesDlg.cxx \ VisuGUI_VectorsDlg.cxx \ - VisuGUI_DialogRunner.cxx \ VisuGUI_Displayer.cxx \ - VisuGUI_SetupPlot2dDlg.cxx + VisuGUI_ScalarMapOnDeformedShapeDlg.cxx \ + VisuGUI_SetupPlot2dDlg.cxx \ + VisuGUI_BuildProgressDlg.cxx \ + VisuGUI_TransparencyDlg.cxx \ + VisuGUI_Timer.cxx LIB_MOC = VisuGUI.h \ + VisuGUI_Module.h \ VisuGUI_Selection.h \ VisuGUI_NameDlg.h \ VisuGUI_FileDlg.h \ @@ -82,20 +86,21 @@ LIB_MOC = VisuGUI.h \ VisuGUI_TimeAnimation.h \ VisuGUI_EditContainerDlg.h \ VisuGUI_ClippingDlg.h \ - VisuGUI_CubeAxesDlg.h \ - VisuGUI_FontWg.h \ + VisuGUI_DialogRunner.h \ VisuGUI_OffsetDlg.h \ VisuGUI_Plot3DDlg.h \ - VisuGUI_NonIsometricDlg.h \ VisuGUI_ScalarBarDlg.h \ + VisuGUI_GaussPointsDlg.h \ VisuGUI_DeformedShapeDlg.h \ VisuGUI_IsoSurfacesDlg.h \ VisuGUI_CutLinesDlg.h \ VisuGUI_CutPlanesDlg.h \ VisuGUI_StreamLinesDlg.h \ VisuGUI_VectorsDlg.h \ - VisuGUI_DialogRunner.h \ - VisuGUI_SetupPlot2dDlg.h + VisuGUI_ScalarMapOnDeformedShapeDlg.h \ + VisuGUI_SetupPlot2dDlg.h \ + VisuGUI_BuildProgressDlg.h \ + VisuGUI_TransparencyDlg.h LIB_CLIENT_IDL = SALOME_Exception.idl \ VISU_Gen.idl \ @@ -114,13 +119,17 @@ LIB_SERVER_IDL = CPPFLAGS += -ftemplate-depth-32 $(QT_INCLUDES) $(VTK_INCLUDES) $(OCC_INCLUDES) \ $(PYTHON_INCLUDES) $(HDF5_INCLUDES) $(QWT_INCLUDES) \ - -I${KERNEL_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) + -I${KERNEL_ROOT_DIR}/include/salome \ + -I${MED_ROOT_DIR}/include/salome \ + $(BOOST_CPPFLAGS) CXXFLAGS += -ftemplate-depth-32 $(OCC_CXXFLAGS) \ - -I${KERNEL_ROOT_DIR}/include/salome -I${GUI_ROOT_DIR}/include/salome + -I${KERNEL_ROOT_DIR}/include/salome \ + -I${GUI_ROOT_DIR}/include/salome LDFLAGS += $(QWT_LIBS) -lSalomeNS \ - -lSVTK -lSPlot2d -lVisuObject -lVISUEngineImpl -lVISUGUITOOLS \ - -L${KERNEL_ROOT_DIR}/lib/salome -L${GUI_ROOT_DIR}/lib/salome + -lSVTK -lVVTK -lSPlot2d -lVisuObject -lVISUEngineImpl -lVISUGUITOOLS \ + -L${KERNEL_ROOT_DIR}/lib/salome \ + -L${GUI_ROOT_DIR}/lib/salome @CONCLUDE@ diff --git a/src/VISUGUI/VISUM_images.po b/src/VISUGUI/VISUM_images.po new file mode 100644 index 00000000..24d00e85 --- /dev/null +++ b/src/VISUGUI/VISUM_images.po @@ -0,0 +1,67 @@ +# VISU VISUGUI : GUI of VISU component +# +# Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : VisuGUI_icons.po +# Module : VISU + +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2002-05-28 10:57:43 AM CEST\n" +"PO-Revision-Date: 2005-05-10 15:20+0400\n" +"Last-Translator: FULLNAME \n" +"Content-Type: text/plain; charset=iso-8859-1\n" + + +msgid "ICON_GAUSS_NEW_VIEWER" +msgstr "Visu_points.png" + +msgid "ICON_GAUSS_POINTS" +msgstr "Visu_gauss_points.png" + +msgid "ICON_VVTK_INTERACTOR_STYLE_SWITCH" +msgstr "Visu_vvtk_switch.png" + +msgid "ICON_VVTK_SELECTION_MODE_SWITCH" +msgstr "Visu_points.png" + +msgid "ICON_VVTK_PLANE_SEGMENTATION_SWITCH" +msgstr "Visu_PlaneSegmentation.png" + +msgid "ICON_VVTK_SPHERE_SEGMENTATION_SWITCH" +msgstr "Visu_SphereSegmentation.png" + +msgid "ICON_VVTK_RECORDING_START" +msgstr "Visu_recording_start.png" + +msgid "ICON_VVTK_RECORDING_PLAY" +msgstr "Visu_recording_play.png" + +msgid "ICON_VVTK_RECORDING_PAUSE" +msgstr "Visu_recording_pause.png" + +msgid "ICON_VVTK_RECORDING_STOP" +msgstr "Visu_recording_stop.png" + +msgid "ICON_LOAD_TEXTURE" +msgstr "Visu_load_texture.png" diff --git a/src/VISUGUI/VISUM_msg_en.po b/src/VISUGUI/VISUM_msg_en.po new file mode 100644 index 00000000..e9676f43 --- /dev/null +++ b/src/VISUGUI/VISUM_msg_en.po @@ -0,0 +1,757 @@ +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2002-02-22 16:56:46 CET\n" +"PO-Revision-Date: 2005-06-27 12:38+0400\n" +"Last-Translator: FULLNAME \n" +"Content-Type: text/plain; charset=iso-8859-1\n" + +msgid "INF_VISU" +msgstr "Post-Pro Info" + +msgid "IMPORT_DONE" +msgstr "Importing is done" + +msgid "VisuGUI_Module::MEN_VISUALISATION" +msgstr "Visualization" + +msgid "VisuGUI_Module::TOOL_VISUALISATION" +msgstr "Visualization Toolbar" + +msgid "VisuGUI_Module::MEN_SAVE_CONFIGURATION" +msgstr "Store current configuration" + +msgid "VisuGUI_Module::MEN_OVERWRITE_CONFIGURATION" +msgstr "Overwrite current configuration" + +msgid "VisuGUI_Module::MEN_RESTORE_CONFIGURATION" +msgstr "Restore current configuration" + +msgid "VisuGUI_Module::MEN_GAUSS" +msgstr "Gauss" + +msgid "VisuGUI_Module::MEN_GAUSS_NEW_VIEWER" +msgstr "Points view" + +msgid "VisuGUI_Module::MEN_GAUSS_CREATE_PRS" +msgstr "Gauss Points" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_TAB_TTL" +msgstr "Gauss Points" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" +msgstr "Primitive" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_PRIMITIVE_TYPE" +msgstr "Primitive Type" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_POINTSPRITE" +msgstr "Point sprite" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_OPENGLPOINT" +msgstr "OpenGL point" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_GEOMSPHERE" +msgstr "Geometrical sphere" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_CLAMP" +msgstr "Maximum Size (Clamp)" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_MAIN_TEXTURE" +msgstr "Main Texture (16x16)" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_ALPHA_TEXTURE" +msgstr "Alpha Channel Texture (16x16)" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_ALPHA_THRESHOLD" +msgstr "Alpha Channel Threshold" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_RESOLUTION" +msgstr "Geometrical sphere resolution" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_FACE_LIMIT" +msgstr "Notify when number of faces exceeds" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_SIZE_GROUP_TTL" +msgstr "Size" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_MIN_SIZE" +msgstr "Range value for min size (%)" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_MAX_SIZE" +msgstr "Range value for max size (%)" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_MAGNIFICATION" +msgstr "Magnification (%)" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_INCREMENT" +msgstr "+/- Ratio" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_GEOM_GROUP_TTL" +msgstr "Geometry" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_SIZE" +msgstr "Size of points (%)" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_COLOR" +msgstr "Color" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_DEFORMED_SHAPE_GROUP_TTL" +msgstr "Deformed Shape" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_SCALE_FACTOR" +msgstr "Scale factor" + +msgid "VisuGUI_Module::VISU_GAUSS_SCALAR_BAR_PREF_TAB_TTL" +msgstr "Gauss Points Scalar Bar" + +msgid "VisuGUI_Module::VISU_GAUSS_SCALAR_BAR_PREF_GROUP_TTL" +msgstr "Gauss Points Scalar Bar" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_ACTIVE_BAR" +msgstr "Active bar" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_LOCAL" +msgstr "Local" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_GLOBAL" +msgstr "Global" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_DISPLAY_GLOBAL" +msgstr "Display global bar" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_SCALAR_BAR_MODE" +msgstr "Scalar bar mode" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_BICOLOR" +msgstr "Bicolor" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_RAINBOW" +msgstr "Rainbow" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_SPACING" +msgstr "Spacing" + +msgid "VisuGUI_Module::VISU_GAUSS_INSIDE_CURSOR_PREF_TAB_TTL" +msgstr "Inside Cursor" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_MAGNIFICATION_GROUP_TTL" +msgstr "Magnification (Inside and Outside)" + +msgid "VisuGUI_Module::VISU_GAUSS_OUTSIDE_CURSOR_PREF_TAB_TTL" +msgstr "Outside Cursor" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_UNIFORM_COLOR" +msgstr "Uniform Color" + +msgid "VisuGUI_Module::VISU_GAUSS_PREF_COLOR_GROUP_TTL" +msgstr "Color" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_TAB_TTL" +msgstr "Picking" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_CURSOR_GROUP_TTL" +msgstr "Cursor" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_CURSOR_SIZE" +msgstr "Size of the cursor" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_PYRAMID_HEIGHT" +msgstr "Height of the pyramids" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_SELECTION_COLOR" +msgstr "Selection cursor color" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_TOLERANCE_GROUP_TTL" +msgstr "Tolerance" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_POINT_SELECTION_TOLERANCE" +msgstr "Point selection tolerance" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_INFO_WINDOW_GROUP_TTL" +msgstr "Information window" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_TRANSPARENCY" +msgstr "Transparency" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_POSITION" +msgstr "Position" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_BELOW_POINT" +msgstr "Centered below the point" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_TOP_LEFT_CORNER" +msgstr "Top-left corner of the 3D view" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_CAMERA_GROUP_TTL" +msgstr "Movement of the camera" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_ZOOM_FACTOR" +msgstr "Zoom at first selected point (ratio)" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_STEP_NUMBER" +msgstr "Number of steps between two positions" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_PARENT_MESH_TTL" +msgstr "Parent mesh element" + +msgid "VisuGUI_Module::VISU_PICKING_PREF_DISPLAY_PARENT_MESH" +msgstr "Display parent mesh element" + +msgid "VisuGUI_Module::VISU_MOUSE_PREF_TAB_TLT" +msgstr "Navigation" + +msgid "VisuGUI_Module::VISU_MOUSE_PREF_GROUP_TLT" +msgstr "Mouse" + +msgid "VisuGUI_Module::VISU_MOUSE_PREF" +msgstr "Mouse behaviour" + +msgid "VisuGUI_Module::VISU_MOUSE_PREF_STANDARD" +msgstr "Salome standard controls" + +msgid "VisuGUI_Module::VISU_MOUSE_PREF_KEYBOARD_FREE" +msgstr "Keyboard free" + +msgid "VisuGUI_Module::VISU_KEYBOARD_PREF_GROUP_TTL" +msgstr "Keyboard" + +msgid "VisuGUI_Module::VISU_KEYBOARD_PREF" +msgstr "[+]/[-] Speed increment" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF" +msgstr "Spacemouse" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_1" +msgstr "Decrease speed increment" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_2" +msgstr "Increase speed increment" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_3" +msgstr "Decrease Gauss points magnification" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_4" +msgstr "Increase Gauss points magnification" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_5" +msgstr "Dominant / combined switch" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_1" +msgstr "Button 1" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_2" +msgstr "Button 2" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_3" +msgstr "Button 3" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_4" +msgstr "Button 4" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_5" +msgstr "Button 5" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_6" +msgstr "Button 6" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_7" +msgstr "Button 7" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_8" +msgstr "Button 8" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_10" +msgstr "Button 10" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_11" +msgstr "Button 11" + +msgid "VisuGUI_Module::VISU_SPACEMOUSE_PREF_BTN_*" +msgstr "Button *" + +msgid "VisuGUI_Module::VISU_CAMERA_PREF_GROUP_TTL" +msgstr "Camera movements" + +msgid "VisuGUI_Module::VISU_CAMERA_MOVE_PREF" +msgstr "Number of steps between two positions" + +msgid "VisuGUI_Module::VISU_RECORDER_PREF_TAB_TTL" +msgstr "Recorder" + +msgid "VisuGUI_Module::VISU_RECORDER_PREF_GROUP_TTL" +msgstr "Settings" + +msgid "VisuGUI_Module::VISU_RECORDER_PREF_RECORDING_MODE" +msgstr "Mode" + +msgid "VisuGUI_Module::VISU_RECORDER_PREF_SKIPPED_FRAMES" +msgstr "Recording at a given FPS" + +msgid "VisuGUI_Module::VISU_RECORDER_PREF_ALL_DISLPAYED_FRAMES" +msgstr "Recording all displayed frames" + +msgid "VisuGUI_Module::VISU_RECORDER_PREF_FPS" +msgstr "FPS" + +msgid "VisuGUI_Module::VISU_RECORDER_PREF_QUALITY" +msgstr "Quality" + +msgid "VisuGUI_Module::VISU_RECORDER_PREF_PROGRESSIVE" +msgstr "Progressive" + +msgid "VisuGUI_GaussPointsDlg::DLG_PREF_TITLE" +msgstr "Gauss Points Preferences" + +msgid "VisuGUI_GaussPointsDlg::DLG_PROP_TITLE" +msgstr "Gauss Points Properties" + +msgid "VisuGUI_BuildProgressDlg::DLG_BUILD_PROGRESS_TITLE" +msgstr "Build progress" + +msgid "VisuGUI_BuildProgressDlg::IMPORT_SETTINGS" +msgstr "Settings" + +msgid "VisuGUI_BuildProgressDlg::FILE_NAME" +msgstr "Import file : " + +msgid "VisuGUI_BuildProgressDlg::BUILD_AT_ONCE" +msgstr "Build at once" + +msgid "VisuGUI_BuildProgressDlg::BUILD_ALL" +msgstr "Build all" + +msgid "VisuGUI_BuildProgressDlg::IMPORT_PROGRESS" +msgstr "Import progress" + +msgid "VisuGUI_BuildProgressDlg::BUILD_ENTITIES" +msgstr "Build entities" + +msgid "VisuGUI_BuildProgressDlg::BUILD_FIELDS" +msgstr "Build fields" + +msgid "VisuGUI_BuildProgressDlg::BUILD_GROUPS" +msgstr "Build groups" + +msgid "VisuGUI_BuildProgressDlg::BUILD_MINMAX" +msgstr "Build min/max" + +msgid "VisuGUI_BuildProgressDlg::IMPORT_TIME" +msgstr "Time" + +msgid "VisuGUI_BuildProgressDlg::TIME" +msgstr "Elapsed time : " + +msgid "VisuGUI_BuildProgressDlg::IMPORT_FROM_FILE" +msgstr "Import from File" + +msgid "VisuGUI_BuildProgressDlg::FLT_ALL_FILES" +msgstr "All Files (*.*)" + +msgid "VisuGUI_BuildProgressDlg::FLT_MED_FILES" +msgstr "MED Files (*.med)" + +msgid "VisuGUI_BuildProgressDlg::CLOSE_AT_FINISH" +msgstr "Close dialog at finish" + +msgid "VisuGUI_BuildProgressDlg::START" +msgstr "Start" + +msgid "VisuGUI_BuildProgressDlg::CLOSE" +msgstr "Close" + +msgid "VVTK_RecorderDlg::DLG_RECORDER_TITLE" +msgstr "Recorder" + +msgid "VVTK_RecorderDlg::SETTINGS" +msgstr "Settings" + +msgid "VVTK_RecorderDlg::FILE_NAME" +msgstr "Save to file : " + +msgid "VVTK_RecorderDlg::FLT_ALL_FILES" +msgstr "All Files (*.*)" + +msgid "VVTK_RecorderDlg::FLT_AVI_FILES" +msgstr "AVI Files (*.avi)" + +msgid "VVTK_RecorderDlg::RECORDING_MODE" +msgstr "Mode : " + +msgid "VVTK_RecorderDlg::SKIPPED_FRAMES" +msgstr "Recording at a given FPS" + +msgid "VVTK_RecorderDlg::ALL_DISLPAYED_FRAMES" +msgstr "Recording all displayed frames" + +msgid "VVTK_RecorderDlg::FPS" +msgstr "FPS : " + +msgid "VVTK_RecorderDlg::QUALITY" +msgstr "Quality : " + +msgid "VVTK_RecorderDlg::PROGRESSIVE" +msgstr "Progressive" + +msgid "VVTK_RecorderDlg::START" +msgstr "Start" + +msgid "VVTK_RecorderDlg::CLOSE" +msgstr "Close" + +msgid "VisuGUI_TransparencyDlg::TRANSPARENCY_TITLE" +msgstr "Change Transparency" + +msgid "VisuGUI_TransparencyDlg::TRANSPARENCY_TRANSPARENT" +msgstr "Transparent" + +msgid "VisuGUI_TransparencyDlg::TRANSPARENCY_OPAQUE" +msgstr "Opaque" + +msgid "VisuGUI_TransparencyDlg::BUT_CLOSE" +msgstr "Close" + +msgid "VVTK_ViewManager::VTK_VIEW_TITLE" +msgstr "VISU scene:%1 - viewer:%2" + +msgid "VVTK_MainWindow::MNU_VVTK_RECORDING_START" +msgstr "Start recording" + +msgid "VVTK_MainWindow::DSC_VVTK_RECORDING_START" +msgstr "Start recording" + +msgid "VVTK_MainWindow::MNU_VVTK_RECORDING_PLAY" +msgstr "Play recording" + +msgid "VVTK_MainWindow::DSC_VVTK_RECORDING_PLAY" +msgstr "Play recording" + +msgid "VVTK_MainWindow::MNU_VVTK_RECORDING_PAUSE" +msgstr "Pause recording" + +msgid "VVTK_MainWindow::DSC_VVTK_RECORDING_PAUSE" +msgstr "Pause recording" + +msgid "VVTK_MainWindow::MNU_VVTK_RECORDING_STOP" +msgstr "Stop recording" + +msgid "VVTK_MainWindow::DSC_VVTK_RECORDING_STOP" +msgstr "Stop recording" + +msgid "VVTK_MainWindow1::MNU_VVTK_INTERACTOR_STYLE_SWITCH" +msgstr "Interaction Style Switch" + +msgid "VVTK_MainWindow1::DSC_VVTK_INTERACTOR_STYLE_SWITCH" +msgstr "Interaction Style Switch" + +msgid "VVTK_MainWindow1::MNU_VVTK_SELECTION_MODE_SWITCH" +msgstr "Selection Mode Switch" + +msgid "VVTK_MainWindow1::DSC_VVTK_SELECTION_MODE_SWITCH" +msgstr "Selection Mode Switch" + +msgid "VVTK_MainWindow1::MNU_VVTK_PLANE_SEGMENTATION_SWITCH" +msgstr "Plane Segmentation" + +msgid "VVTK_MainWindow1::DSC_VVTK_PLANE_SEGMENTATION_SWITCH" +msgstr "Plane Segmentation" + +msgid "VVTK_MainWindow1::MNU_VVTK_SPHERE_SEGMENTATION_SWITCH" +msgstr "Sphere Segmentation" + +msgid "VVTK_MainWindow1::DSC_VVTK_SPHERE_SEGMENTATION_SWITCH" +msgstr "Sphere Segmentation" + +msgid "VVTK_PrimitiveBox::PRIMITIVE_TITLE" +msgstr "Primitive" + +msgid "VVTK_PrimitiveBox::POINT_SPRITE" +msgstr "Point Sprite" + +msgid "VVTK_PrimitiveBox::OPENGL_POINT" +msgstr "OpenGL Point" + +msgid "VVTK_PrimitiveBox::GEOMETRICAL_SPHERE" +msgstr "Geometrical Sphere" + +msgid "VVTK_PrimitiveBox::CLAMP" +msgstr "Maximum Size (Clamp) : " + +msgid "VVTK_PrimitiveBox::MAIN_TEXTURE" +msgstr "Main Texture (16x16) : " + +msgid "VVTK_PrimitiveBox::ALPHA_TEXTURE" +msgstr "Alpha Channel Texture (16x16) : " + +msgid "VVTK_PrimitiveBox::ALPHA_THRESHOLD" +msgstr "Alpha Channel Threshold : " + +msgid "VVTK_PrimitiveBox::RESOLUTION" +msgstr "Resolution : " + +msgid "VVTK_PrimitiveBox::FACE_NUMBER" +msgstr "Number of faces : " + +msgid "VVTK_PrimitiveBox::FACE_LIMIT" +msgstr "Notify when number of faces exceeds : " + +msgid "VVTK_SizeBox::SIZE_TITLE" +msgstr "Size" + +msgid "VVTK_SizeBox::OUTSIDE_SIZE" +msgstr "Percentage of normal size(%) : " + +msgid "VVTK_SizeBox::GEOM_SIZE" +msgstr "Size of points (%) : " + +msgid "VVTK_SizeBox::MIN_SIZE" +msgstr "Range values for min size (%) : " + +msgid "VVTK_SizeBox::MAX_SIZE" +msgstr "max size (%) : " + +msgid "VVTK_SizeBox::MAGNIFICATION" +msgstr "Magnification (%) : " + +msgid "VVTK_SizeBox::INCREMENT" +msgstr "+/- Ratio : " + +msgid "VVTK_SizeBox::COLOR_TITLE" +msgstr "Color" + +msgid "VVTK_SizeBox::UNIFORM_COLOR" +msgstr "Uniform Color" + +msgid "VVTK_SizeBox::COLOR" +msgstr "Color : " + +msgid "VisuGUI_GaussPointsDlg::&Cancel" +msgstr "" + +msgid "VisuGUI_GaussPointsDlg::&OK" +msgstr "" + +msgid "VisuGUI_GaussPointsDlg::WARNING" +msgstr "Warning" + +msgid "VisuGUI_GaussPointsDlg::DLG_TITLE" +msgstr "Gauss Points" + +msgid "VisuGUI_GaussPointsDlg::GAUSS_POINTS_TAB" +msgstr "Gauss Points" + +msgid "VisuGUI_GaussPointsDlg::SCALAR_BAR_TAB" +msgstr "Scalar Bar" + +msgid "VisuGUI_GaussPointsDlg::PRS_TITLE" +msgstr "Presentation" + +msgid "VisuGUI_GaussPointsDlg::RESULTS" +msgstr "Results" + +msgid "VisuGUI_GaussPointsDlg::GEOMETRY" +msgstr "Geometry" + +msgid "VisuGUI_GaussPointsDlg::DEFORMED_SHAPE" +msgstr "Deformed Shape" + +msgid "VisuGUI_GaussPointsDlg::DEFORMED_SHAPE_TITLE" +msgstr "Deformed Shape" + +msgid "VisuGUI_GaussPointsDlg::SCALE_FACTOR" +msgstr "Scale Factor :" + +msgid "VisuGUI_GaussScalarBarPane::ACTIVE_BAR_GRP" +msgstr "Active bar" + +msgid "VisuGUI_GaussScalarBarPane::LOCAL" +msgstr "Local" + +msgid "VisuGUI_GaussScalarBarPane::GLOBAL" +msgstr "Global" + +msgid "VisuGUI_GaussScalarBarPane::DISPLAYED" +msgstr "Displayed" + +msgid "VisuGUI_GaussScalarBarPane::SCALAR_RANGE_GRP" +msgstr "Scalar range" + +msgid "VisuGUI_GaussScalarBarPane::LOGARITHMIC_SCALING" +msgstr "Logarithmic scaling" + +msgid "VisuGUI_GaussScalarBarPane::FIELD_RANGE_BTN" +msgstr "Use field range" + +msgid "VisuGUI_GaussScalarBarPane::IMPOSED_RANGE_BTN" +msgstr "Use imposed range" + +msgid "VisuGUI_GaussScalarBarPane::LBL_MIN" +msgstr "Min:" + +msgid "VisuGUI_GaussScalarBarPane::LBL_MAX" +msgstr "Max:" + +msgid "VisuGUI_GaussScalarBarPane::COLORS_LABELS_GRP" +msgstr "Colors and labels" + +msgid "VisuGUI_GaussScalarBarPane::BICOLOR" +msgstr "Bicolor" + +msgid "VisuGUI_GaussScalarBarPane::RAINBOW" +msgstr "Rainbow" + +msgid "VisuGUI_GaussScalarBarPane::LBL_NB_COLORS" +msgstr "Nb. of colors:" + +msgid "VisuGUI_GaussScalarBarPane::LBL_NB_LABELS" +msgstr "Nb. of labels:" + +msgid "VisuGUI_GaussScalarBarPane::ORIENTATION_GRP" +msgstr "Orientation" + +msgid "VisuGUI_GaussScalarBarPane::VERTICAL_BTN" +msgstr "Vertical" + +msgid "VisuGUI_GaussScalarBarPane::HORIZONTAL_BTN" +msgstr "Horizontal" + +msgid "VisuGUI_GaussScalarBarPane::ORIGIN_GRP" +msgstr "Origin" + +msgid "VisuGUI_GaussScalarBarPane::LBL_X" +msgstr "X:" + +msgid "VisuGUI_GaussScalarBarPane::LBL_Y" +msgstr "Y:" + +msgid "VisuGUI_GaussScalarBarPane::DIMENSIONS_GRP" +msgstr "Dimensions" + +msgid "VisuGUI_GaussScalarBarPane::LBL_WIDTH" +msgstr "Width:" + +msgid "VisuGUI_GaussScalarBarPane::LBL_HEIGHT" +msgstr "Height:" + +msgid "VisuGUI_GaussScalarBarPane::LBL_SPACING" +msgstr "Spacing:" + +msgid "VisuGUI_GaussScalarBarPane::SAVE_DEFAULT_CHK" +msgstr "Save as default values" + +msgid "VVTK_ViewWindow::LBL_TOOLBAR_LABEL" +msgstr "GAUSS viewer tools" + +msgid "VVTK_SegmentationCursorDlg::SEGMENTATION_CURSOR_DLG_TITLE" +msgstr "Segmentation Cursor" + +msgid "VVTK_SegmentationCursorDlg::ORIGIN_TITLE" +msgstr "Origin" + +msgid "VVTK_SegmentationCursorDlg::ORIGIN_X" +msgstr "X: " + +msgid "VVTK_SegmentationCursorDlg::ORIGIN_Y" +msgstr "Y: " + +msgid "VVTK_SegmentationCursorDlg::ORIGIN_Z" +msgstr "Z: " + +msgid "VVTK_SegmentationCursorDlg::DIRECTION_TITLE" +msgstr "Direction" + +msgid "VVTK_SegmentationCursorDlg::DIRECTION_DX" +msgstr "DX: " + +msgid "VVTK_SegmentationCursorDlg::DIRECTION_DY" +msgstr "DY: " + +msgid "VVTK_SegmentationCursorDlg::DIRECTION_DZ" +msgstr "DZ: " + +msgid "VVTK_SegmentationCursorDlg::DEPTH_TITLE" +msgstr "Depth" + +msgid "VVTK_SegmentationCursorDlg::DEPTH" +msgstr "Depth of the cursor: " + +msgid "VVTK_SegmentationCursorDlg::RADIUS_TITLE" +msgstr "Radius" + +msgid "VVTK_SegmentationCursorDlg::RADIUS" +msgstr "Radius of the cursor :" + +msgid "VVTK_SegmentationCursorDlg::RATIO" +msgstr "+/- Ratio :" + +msgid "VVTK_SegmentationCursorDlg::SEGMENTATION_CURSOR_TAB" +msgstr "Segmentation Cursor" + +msgid "VVTK_SegmentationCursorDlg::GAUSS_POINTS_TAB" +msgstr "Gauss Points" + +msgid "VVTK_SegmentationCursorDlg::INSIDE_GAUSS_POINTS" +msgstr "Inside Cursor Gauss Points Presentation" + +msgid "VVTK_SegmentationCursorDlg::OUTSIDE_GAUSS_POINTS" +msgstr "Outside Cursor Gauss Points Presentation" + +msgid "VVTK_SegmentationCursorDlg::MAGNIFICATION_TITLE" +msgstr "Magnification" + +msgid "VVTK_SegmentationCursorDlg::MAGNIFICATION" +msgstr "Magnification (%) : " + +msgid "VVTK_SegmentationCursorDlg::INCREMENT" +msgstr "+/- Ratio : " + +msgid "VVTK_PickingDlg::PICKING_DLG_TITLE" +msgstr "Picking" + +msgid "VVTK_PickingDlg::CURSOR_TITLE" +msgstr "Cursor" + +msgid "VVTK_PickingDlg::CURSOR_SIZE" +msgstr "Size of the cursor :" + +msgid "VVTK_PickingDlg::PYRAMID_HEIGHT" +msgstr "Height of the pyramids :" + +msgid "VVTK_PickingDlg::SELECTION_COLOR" +msgstr "Selection cursor color :" + +msgid "VVTK_PickingDlg::TOLERANCE_TITLE" +msgstr "Tolerance" + +msgid "VVTK_PickingDlg::POINT_TOLERANCE" +msgstr "Point tolerance :" + +msgid "VVTK_PickingDlg::INFO_WINDOW_TITLE" +msgstr "Information window" + +msgid "VVTK_PickingDlg::TRANSPARENCY" +msgstr "Transparency :" + +msgid "VVTK_PickingDlg::POSITION" +msgstr "Position :" + +msgid "VVTK_PickingDlg::BELOW_POINT" +msgstr "Centered below the point" + +msgid "VVTK_PickingDlg::TOP_LEFT_CORNER" +msgstr "Top-left corner of the 3D view" + +msgid "VVTK_PickingDlg::CAMERA_TITLE" +msgstr "Movement of the camera" + +msgid "VVTK_PickingDlg::ZOOM_FACTOR" +msgstr "Zoom at first selected point (ratio) :" + +msgid "VVTK_PickingDlg::STEP_NUMBER" +msgstr "Number of steps between two positions :" + +msgid "VVTK_PickingDlg::PARENT_MESH_TITLE" +msgstr "Parent mesh element" + +msgid "VVTK_PickingDlg::DISPLAY_PARENT_MESH" +msgstr "Display parent mesh element" \ No newline at end of file diff --git a/src/VISUGUI/VISU_icons.po b/src/VISUGUI/VISU_icons.po index 4422d48d..525994aa 100644 --- a/src/VISUGUI/VISU_icons.po +++ b/src/VISUGUI/VISU_icons.po @@ -42,6 +42,9 @@ msgstr "Visu_scalars.png" msgid "ICON_DEFORMED_SHAPE" msgstr "Visu_deformed.png" +msgid "ICON_SCALAR_MAP_ON_DEFORMED_SHAPE" +msgstr "Visu_scalarmapondeformedshape.png" + msgid "ICON_VECTORS" msgstr "Visu_vectors.png" diff --git a/src/VISUGUI/VISU_images.po b/src/VISUGUI/VISU_images.po index 0f7909b9..7357d06a 100644 --- a/src/VISUGUI/VISU_images.po +++ b/src/VISUGUI/VISU_images.po @@ -42,6 +42,9 @@ msgstr "Visu_scalars.png" msgid "ICON_DEFORMED_SHAPE" msgstr "Visu_deformed.png" +msgid "ICON_SCALAR_MAP_ON_DEFORMED_SHAPE" +msgstr "Visu_scalarmapondeformedshape.png" + msgid "ICON_VECTORS" msgstr "Visu_vectors.png" diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index e25236e9..eb50916f 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -178,6 +178,9 @@ msgstr "Scalar Map" msgid "VisuGUI::MEN_DEFORMED_SHAPE" msgstr "Deformed Shape" +msgid "VisuGUI::MEN_SCALAR_MAP_ON_DEFORMED_SHAPE" +msgstr "Scalar Map on Deformed Shape" + msgid "VisuGUI::MEN_VISUALIZATION" msgstr "Visualization" @@ -386,6 +389,8 @@ msgstr "Error has been occured during exporting to file" msgid "VisuGUI::ERR_ACTIVATE_VIEW3D" msgstr "Please activate 3D view before" +msgid "VisuGUI::ERR_SCALARBAR_PARAMS" +msgstr "Warning! The parameters is incorrect" msgid "VisuGUI::FLT_ALL_FILES" msgstr "All Files (*.*)" @@ -555,6 +560,32 @@ msgid "VisuGUI_DeformedShapeDlg::SCALE_FACTOR" msgstr "Scale Factor:" +#: VisuGUI_ScalarMapOnDeformedShapeDlg.cxx + +msgid "VisuGUI_ScalarMapOnDeformedShapeDlg::DLG_TITLE" +msgstr "Scalar Map on Deformed Shape" + +msgid "VisuGUI_ScalarMapOnDeformedShapeDlg::&Cancel" +msgstr "" + +msgid "VisuGUI_ScalarMapOnDeformedShapeDlg::&OK" +msgstr "" + +msgid "VisuGUI_ScalarMapOnDeformedShapeDlg::SCALAR_MAP_ON_DEFORMED_SHAPE_TAB" +msgstr "Scalar Map on Deformed Shape" + +msgid "VisuGUI_ScalarMapOnDeformedShapeDlg::SCALAR_BAR_TAB" +msgstr "Scalar Bar" + +msgid "VisuGUI_ScalarMapOnDeformedShapeDlg::SCALE_FACTOR" +msgstr "Scale Factor:" + +msgid "VisuGUI_ScalarMapOnDeformedShapeDlg::FIELD_ITEM" +msgstr "Fields" + +msgid "VisuGUI_ScalarMapOnDeformedShapeDlg::TIMESTAMP_ITEM" +msgstr "Time stamp" + #: VisuGUI_EditContainerDlg.cxx msgid "VisuGUI_EditContainerDlg::&Cancel" diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index c70253e2..3128e69f 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -22,7 +22,7 @@ // // // File : VisuGUI.cxx -// Author : Laurent CORNABE +// Author : // Module : VISU // $Header$ @@ -37,11 +37,13 @@ #include #include #include +#include // VTK Includes #include #include #include +#include // SALOME Includes #include "SALOME_LifeCycleCORBA.hxx" @@ -54,7 +56,6 @@ #include "CAM_Module.h" -#include "SVTK_RenderWindow.h" #include "SVTK_ViewWindow.h" #include "SVTK_ViewModel.h" #include "SVTK_Functor.h" @@ -99,12 +100,12 @@ #include "VisuGUI_Selection.h" #include "VisuGUI_TimeAnimation.h" #include "VisuGUI_EditContainerDlg.h" -#include "VisuGUI_NonIsometricDlg.h" #include "VisuGUI_ClippingDlg.h" #include "VisuGUI_Plot3DDlg.h" -#include "VisuGUI_CubeAxesDlg.h" #include "VisuGUI_OffsetDlg.h" #include "VisuGUI_Displayer.h" +#include "VisuGUI_BuildProgressDlg.h" +#include "VisuGUI_TransparencyDlg.h" #include "VISU_ScalarMap_i.hh" #include "VisuGUI_ScalarBarDlg.h" @@ -112,6 +113,9 @@ #include "VISU_DeformedShape_i.hh" #include "VisuGUI_DeformedShapeDlg.h" +#include "VISU_ScalarMapOnDeformedShape_i.hh" +#include "VisuGUI_ScalarMapOnDeformedShapeDlg.h" + #include "VISU_IsoSurfaces_i.hh" #include "VisuGUI_IsoSurfacesDlg.h" @@ -136,6 +140,8 @@ #include "VisuGUI_ActionsDef.h" +#include "VisuGUI_Timer.h" + using namespace VISU; #ifdef _DEBUG_ @@ -159,59 +165,17 @@ VisuGUI::~VisuGUI() { } - void VisuGUI:: OnImportFromFile() { if(MYDEBUG) MESSAGE("VisuGUI::OnImportFromFile()"); - if ( CheckLock(GetCStudy(GetAppStudy(this))) ) + if ( CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this)) ) return; - SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); - QStringList aFilter; - aFilter.append( tr("FLT_MED_FILES") ); - aFilter.append( tr("FLT_ALL_FILES") ); - - QFileInfo aFileInfo = - SUIT_FileDlg::getFileName(GetDesktop(this), - "", - aFilter, - tr("MEN_IMPORT_FROM_FILE"), - true); - if(aFileInfo.exists()) { - application()->putInfo( "Importing From File " + aFileInfo.filePath() + "..." ); - - VISU::Result_var aResult; - bool anIsBuild = aResourceMgr->booleanValue("VISU", "full_med_loading", false); - if (VisuGUI_FileDlg::IsBuild) { - aResult = GetVisuGen(this)->ImportFile(aFileInfo.filePath()); - if (!CORBA::is_nil(aResult.in())) - if (Result_i* aRes = dynamic_cast(GetServant(aResult).in())) { - if (!aRes->IsPossible()) - SUIT_MessageBox::warn1(GetDesktop(this), - tr("WRN_VISU"), - tr("ERR_CANT_BUILD_PRESENTATION"), - tr("BUT_OK")); - else - aRes->BuildAll(); - } - } else { - aResourceMgr->setValue("VISU", "full_med_loading", false); - aResult = GetVisuGen(this)->ImportFile(aFileInfo.filePath()); - aResourceMgr->setValue("VISU", "full_med_loading", anIsBuild); - } - - if (CORBA::is_nil(aResult.in())) { - SUIT_MessageBox::warn1(GetDesktop(this), - tr("WRN_VISU"), - tr("ERR_ERROR_IN_THE_FILE"), - tr("BUT_OK")); - }else{ - application()->putInfo(aFileInfo.filePath() + tr("INF_DONE")); - UpdateObjBrowser(this); - } - } + VisuGUI_BuildProgressDlg* aBuildProgressDlg = new VisuGUI_BuildProgressDlg( GetDesktop(this) ); + aBuildProgressDlg->setGenerator( GetVisuGen(this) ); + aBuildProgressDlg->show(); } @@ -221,7 +185,7 @@ OnExploreMEDFile() { if(MYDEBUG) MESSAGE("VisuGUI::OnExploreMEDFile()"); _PTR(Study) aStudy = GetCStudy(GetAppStudy(this)); - if ( CheckLock(aStudy) ) + if ( CheckLock(aStudy,GetDesktop(this)) ) return; SALOME_MED::MED_Gen_var aGen = GetMEDEngine(); @@ -262,7 +226,7 @@ VisuGUI:: OnImportTableFromFile() { if(MYDEBUG) MESSAGE("VisuGUI::OnImportTableFromFile()"); - if ( CheckLock(GetCStudy(GetAppStudy(this))) ) + if ( CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this)) ) return; QStringList aFilter; @@ -377,11 +341,11 @@ OnExportTableToFile() try { GetVisuGen(this)->ExportTableToFile(GetSObject(aSObj), aFile.latin1()); application()->putInfo(aFile + " " + tr("INF_DONE")); - } catch(std::exception& ex) { - INFOS(ex.what()); + } catch(std::exception& exc) { + INFOS(exc.what()); SUIT_MessageBox::warn1(GetDesktop(this), tr("WRN_VISU"), - tr("ERR_ERROR_DURING_EXPORT") + " " + tr(ex.what()), + tr("ERR_ERROR_DURING_EXPORT") + " " + tr(exc.what()), tr("BUT_OK")); } catch(...) { INFOS(tr("ERR_ERROR_DURING_EXPORT")); @@ -400,7 +364,7 @@ VisuGUI:: OnImportMedField() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aCStudy)) + if (CheckLock(aCStudy,GetDesktop(this))) return; SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy); @@ -461,7 +425,8 @@ CreateCurves( SalomeApp_Module* theModule, if ( aTblObj ) { _PTR(GenericAttribute) anAttr; if (aTblObj->FindAttribute( anAttr, "AttributeName" ) ) { - aBuilder->RemoveObjectWithChildren( aIter->Value() ); // We should have only one child + aBuilder->RemoveObjectWithChildren( aTblObj ); // We should have only one child + UpdateObjBrowser(theModule,true,aTblObj); break; } } @@ -497,7 +462,7 @@ VisuGUI:: OnCreateMesh() { _PTR(Study) aStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aStudy)) + if (CheckLock(aStudy,GetDesktop(this))) return; // Get selected SObject @@ -517,7 +482,7 @@ VisuGUI:: OnCreateManyMesh() { _PTR(Study) aStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aStudy)) + if (CheckLock(aStudy,GetDesktop(this))) return; // create a VTK view window if it does not exist @@ -552,6 +517,13 @@ OnCreateDeformedShape() CreatePrs3d(this); } +void +VisuGUI:: +OnCreateScalarMapOnDeformedShape() +{ + CreatePrs3d(this); +} + void VisuGUI:: OnCreateVectors() @@ -598,7 +570,7 @@ void VisuGUI:: OnCreatePlot2dView() { - CheckLock(GetCStudy(GetAppStudy(this))); + CheckLock(GetCStudy(GetAppStudy(this)),GetDesktop(this)); GetVisuGen( this )->CreateContainer(); UpdateObjBrowser(this); } @@ -709,6 +681,30 @@ OnErasePrs() QApplication::restoreOverrideCursor(); } +void +VisuGUI:: +OnEraseAll() +{ + startOperation( myEraseAll ); + if (SVTK_ViewWindow* vw = GetViewWindow(this)) { + vw->unHighlightAll(); + if (vtkRenderer *aRen = vw->getRenderer()) { + vtkActor *anActor; + vtkActorCollection *anActColl = aRen->GetActors(); + for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ) { + if (anActor->GetVisibility() > 0) + if (VISU_Actor* anVISUActor = VISU_Actor::SafeDownCast(anActor)) { + RemoveScalarBarPosition(this,anVISUActor->GetPrs3d()); + anVISUActor->VisibilityOff(); + } + } + vw->Repaint(); + } + } else if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(this, false)) { + aPlot2d->EraseAll(); + } +} + void VisuGUI:: @@ -717,7 +713,7 @@ OnEditScalarMap() Handle(SALOME_InteractiveObject) anIO; if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ EditPrs3d(this, aPrs3d); - if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){ aViewWindow->highlight(anIO, 1); } } @@ -731,12 +727,24 @@ OnEditDeformedShape() Handle(SALOME_InteractiveObject) anIO; if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ EditPrs3d(this, aPrs3d); - if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){ aViewWindow->highlight(anIO, 1); } } } +void +VisuGUI:: +OnEditScalarMapOnDeformedShape() +{ + Handle(SALOME_InteractiveObject) anIO; + if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ + EditPrs3d(this, aPrs3d); + if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + aViewWindow->highlight(anIO, 1); + } + } +} void VisuGUI:: @@ -745,7 +753,7 @@ OnEditCutPlanes() Handle(SALOME_InteractiveObject) anIO; if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ EditPrs3d(this, aPrs3d); - if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){ aViewWindow->highlight(anIO, 1); } } @@ -759,7 +767,7 @@ OnEditCutLines() Handle(SALOME_InteractiveObject) anIO; if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ EditPrs3d(this, aPrs3d); - if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){ aViewWindow->highlight(anIO, 1); } } @@ -773,7 +781,7 @@ OnEditIsoSurfaces() Handle(SALOME_InteractiveObject) anIO; if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ EditPrs3d(this, aPrs3d); - if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){ aViewWindow->highlight(anIO, 1); } } @@ -787,7 +795,7 @@ OnEditVectors() Handle(SALOME_InteractiveObject) anIO; if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ EditPrs3d(this, aPrs3d); - if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){ aViewWindow->highlight(anIO, 1); } } @@ -801,7 +809,7 @@ OnEditStreamLines() Handle(SALOME_InteractiveObject) anIO; if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ EditPrs3d(this, aPrs3d); - if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){ aViewWindow->highlight(anIO, 1); } } @@ -815,39 +823,13 @@ OnEditPlot3D() Handle(SALOME_InteractiveObject) anIO; if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ EditPrs3d(this, aPrs3d); - if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){ + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this)){ aViewWindow->highlight(anIO, 1); } } } -void -VisuGUI:: -OnEraseAll() -{ - startOperation( myEraseAll ); - if (SVTK_ViewWindow* vw = GetViewWindow()) { - vw->unHighlightAll(); - if (vtkRenderer *aRen = vw->getRenderer()) { - vtkActor *anActor; - vtkActorCollection *anActColl = aRen->GetActors(); - for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ) { - if (anActor->GetVisibility() > 0) - if (VISU_Actor* anVISUActor = VISU_Actor::SafeDownCast(anActor)) { - RemoveScalarBarPosition(this,anVISUActor->GetPrs3d()); - anVISUActor = anVISUActor->GetParent(); - RemoveScalarBarPosition(this,anVISUActor->GetPrs3d()); - anVISUActor->VisibilityOff(); - } - } - vw->Repaint(); - } - } else if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(this, false)) { - aPlot2d->EraseAll(); - } -} - void VisuGUI:: OnMakeSurfaceframe() @@ -917,7 +899,7 @@ OnChangeColor() VISU::Prs3d_i* aPrs3d = dynamic_cast(aServant.in()); if (!aPrs3d) return; - SVTK_ViewWindow* vw = GetViewWindow(); + SVTK_ViewWindow* vw = GetViewWindow(this); if (!vw) return; VISU_Actor* anActor = GetActor(aPrs3d, vw); @@ -989,7 +971,7 @@ OnChangeWireframeColor() VISU::Prs3d_i* aPrs3d = dynamic_cast(aServant.in()); if (!aPrs3d) return; - SVTK_ViewWindow* vw = GetViewWindow(); + SVTK_ViewWindow* vw = GetViewWindow(this); if (!vw) return; VISU_Actor* anActor = GetActor(aPrs3d, vw); @@ -1024,31 +1006,14 @@ OnChangeOpacity() VISU::Prs3d_i* aPrsObject = dynamic_cast(aServant.in()); if (!aPrsObject) return; - SVTK_ViewWindow* vw = GetViewWindow(); + SVTK_ViewWindow* vw = GetViewWindow(this); if (!vw) return; VISU_Actor* anActor = GetActor(aPrsObject, vw); if (!anActor) return; - VisuGUI_CursorDlg* CursorDlg = - new VisuGUI_CursorDlg (GetDesktop(this), tr("DLG_OPACITY_TITLE"), TRUE); - - CursorDlg->Comment1->setText(tr("DLG_OPACITY_CMT1")); - CursorDlg->Comment2->setText(tr("DLG_OPACITY_CMT2")); - CursorDlg->SpinBox1->setMinValue(0); - CursorDlg->SpinBox1->setMaxValue(100); - - float oldopac = anActor->GetOpacity(); - int intopac = int(oldopac*100. + 0.5); - CursorDlg->SpinBox1->setValue(intopac); - - int ret = CursorDlg->exec(); - if (ret == 1) { - intopac = CursorDlg->SpinBox1->value(); - float newopac = intopac/100.; - anActor->SetOpacity(newopac); - } - delete CursorDlg; + VisuGUI_TransparencyDlg* aTransparencyDlg = new VisuGUI_TransparencyDlg( this ); + aTransparencyDlg->show(); } void @@ -1064,7 +1029,7 @@ OnChangeLines() VISU::Prs3d_i* aPrsObject = dynamic_cast(aServant.in()); if (!aPrsObject) return; - SVTK_ViewWindow* vw = GetViewWindow(); + SVTK_ViewWindow* vw = GetViewWindow(this); if (!vw) return; VISU_Actor* anActor = GetActor(aPrsObject, vw); @@ -1146,7 +1111,7 @@ VisuGUI:: OnDeleteObjects() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aCStudy)) + if (CheckLock(aCStudy,GetDesktop(this))) return; SALOME_ListIO aList; @@ -1173,14 +1138,12 @@ OnDeleteObjects() _PTR(SObject) aSObject = aCStudy->FindObjectID(entries[i]); if (aSObject) { DeleteSObject(this, aCStudy, aSObject); + UpdateObjBrowser(this, true, aSObject); } } // Finish transaction aStudyBuilder->CommitCommand(); - - //GetActiveStudy()->unHighlightAll(); - UpdateObjBrowser(this, true); } void @@ -1386,7 +1349,7 @@ VisuGUI:: OnClearContainer() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aCStudy)) + if (CheckLock(aCStudy,GetDesktop(this))) return; Handle(SALOME_InteractiveObject) anIO; CORBA::Object_var anObject = GetSelectedObj(this, &anIO); @@ -1434,7 +1397,7 @@ VisuGUI:: OnSaveViewParams() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aCStudy)) + if (CheckLock(aCStudy,GetDesktop(this))) return; SUIT_ViewManager* aViewMgr = getApp()->activeViewManager(); @@ -1482,7 +1445,7 @@ VisuGUI:: OnRename() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aCStudy)) + if (CheckLock(aCStudy,GetDesktop(this))) return; Handle(SALOME_InteractiveObject) anIO; @@ -1590,7 +1553,7 @@ OnSweep() VISU::ScalarMap_i* aPrsObject = dynamic_cast(aServant.in()); if (!aPrsObject) return; - SVTK_ViewWindow* vw = GetViewWindow(); + SVTK_ViewWindow* vw = GetViewWindow(this); if (!vw) return; VISU_Actor* aActor = GetActor(aPrsObject, vw); @@ -1617,7 +1580,7 @@ OnSweep() float aPercents = float(i)/aSteps; aPrsObject->SetMapScale(aPercents); aPrsObject->UpdateActor(aActor); - vw->getRenderWindow()->getRenderWindow()->Render(); + vw->getRenderWindow()->Render(); usleep(aTemp); } catch (std::exception& exc) { INFOS("Follow exception was occured :\n" << exc.what()); @@ -1633,9 +1596,11 @@ void VisuGUI:: OnTimeAnimation() { + if(!VISU::GetViewWindow(this)) + return; + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); VisuGUI_TimeAnimationDlg* aAnimationDlg = -// new VisuGUI_TimeAnimationDlg(GetDesktop(this), aCStudy); new VisuGUI_TimeAnimationDlg (this, aCStudy); LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this); @@ -1670,6 +1635,9 @@ void VisuGUI:: OnShowAnimation() { + if(!VISU::GetViewWindow(this)) + return; + LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this); SALOME_ListIO aListIO; aSelectionMgr->selectedObjects(aListIO); @@ -1707,7 +1675,7 @@ VisuGUI:: OnCopyPresentation() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aCStudy)) + if (CheckLock(aCStudy,GetDesktop(this))) return; Handle(SALOME_InteractiveObject) anIO; @@ -1744,6 +1712,14 @@ OnCopyPresentation() UpdateViewer(this, aSameDeformed); } break; + case VISU::TSCALARMAPONDEFORMEDSHAPE: + { + VISU::ScalarMapOnDeformedShape_i* aDefPrs = dynamic_cast(aPrsObject); + VISU::ScalarMapOnDeformedShape_i* aSameScalarMapOnDeformed = new VISU::ScalarMapOnDeformedShape_i(aDefPrs->GetResult(),true); + aSameScalarMapOnDeformed->SameAs(aDefPrs); + UpdateViewer(this, aSameScalarMapOnDeformed); + } + break; case VISU::TCUTPLANES: { VISU::CutPlanes_i* aCutPrs = dynamic_cast(aPrsObject); @@ -1800,8 +1776,8 @@ void VisuGUI:: OnSelectionInfo() { - if (GetViewWindow()) - (new VisuGUI_SelectionDlg(GetDesktop(this)))->show(); + if (GetViewWindow(this)) + (new VisuGUI_SelectionDlg(this))->show(); else SUIT_MessageBox::warn1(GetDesktop(this), tr("WRN_VISU"), @@ -1809,25 +1785,6 @@ OnSelectionInfo() tr("BUT_OK") ); } -void -VisuGUI:: -OnScaling() -{ - VisuGUI_NonIsometricDlg* m_NonIsoDlg = - new VisuGUI_NonIsometricDlg (GetDesktop(this), "m_NonIsoDlg", - false, Qt::WDestructiveClose); - m_NonIsoDlg->show(); -} - -void -VisuGUI:: -OnCubeAxes() -{ - //Show dialog that allows to select scale function and corresponding scale factor - VisuGUI_CubeAxesDlg* aDlg = new VisuGUI_CubeAxesDlg (GetDesktop(this)); - aDlg->show(); -} - void VisuGUI:: OnMergeScalarBars() @@ -1969,7 +1926,7 @@ void VisuGUI:: OnArrangeActors() { - SVTK_ViewWindow* vw = GetViewWindow(); + SVTK_ViewWindow* vw = GetViewWindow(this); if (vw) { ArrangeDlg* aDlg = new ArrangeDlg (GetDesktop(this), vw); aDlg->exec(); @@ -2021,6 +1978,11 @@ createActions() tr("MEN_DEFORMED_SHAPE"), "", 0, aParent, false, this, SLOT(OnCreateDeformedShape())); + aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_SCALAR_MAP_ON_DEFORMED_SHAPE")); + createAction( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE, tr("MEN_SCALAR_MAP_ON_DEFORMED_SHAPE"), QIconSet(aPixmap), + tr("MEN_SCALAR_MAP_ON_DEFORMED_SHAPE"), "", 0, aParent, false, + this, SLOT(OnCreateScalarMapOnDeformedShape())); + aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_VECTORS")); createAction( VISU_VECTORS, tr("MEN_VECTORS"), QIconSet(aPixmap), tr("MEN_VECTORS"), "", 0, aParent, false, @@ -2246,6 +2208,10 @@ createActions() tr("MEN_EDIT_PRS"), "", 0, aParent, false, this, SLOT(OnEditPlot3D())); + createAction( VISU_EDIT_SCALARMAPONDEFORMEDSHAPE, tr("MEN_EDIT_PRS"), QIconSet(), + tr("MEN_EDIT_PRS"), "", 0, aParent, false, + this, SLOT(OnEditScalarMapOnDeformedShape())); + createAction( VISU_CREATE_TABLE, tr("MEN_CREATE_TABLE"), QIconSet(), tr("MEN_CREATE_TABLE"), "", 0, aParent, false, @@ -2286,16 +2252,6 @@ createActions() //this, SLOT(OnEraseAll())); this); - aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_SCALING")); - createAction( VISU_SCALING, tr("MEN_SCALING"), QIconSet(aPixmap), - tr("MEN_SCALING"), "", 0, aParent, false, - this, SLOT(OnScaling())); - - aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_CUBE_AXES")); - createAction( VISU_CUBE_AXES, tr("MEN_CUBE_AXES"), QIconSet(aPixmap), - tr("MEN_CUBE_AXES"), "", 0, aParent, false, - this, SLOT(OnCubeAxes())); - createAction( VISU_SHOW_ANIMATION, tr("MEN_SHOW_ANIMATION"), QIconSet(), tr("MEN_SHOW_ANIMATION"), "", 0, aParent, false, this, SLOT(OnShowAnimation())); @@ -2322,6 +2278,7 @@ createMenus() createMenu( VISU_CUT_LINES, aMenuId, 10 ); // cut lines createMenu( VISU_STREAM_LINES, aMenuId, 10 ); // stream lines createMenu( VISU_PLOT_3D, aMenuId, 10 ); // Plot3d + createMenu( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE, aMenuId, 10 ); // scalar map on deformed shape aMenuId = createMenu( tr( "MEN_SELECTION" ), -1, -1, 30 ); createMenu( VISU_SELECTION_INFO, aMenuId, 10 ); // selection info @@ -2335,8 +2292,6 @@ createMenus() createMenu( VISU_ERASE_ALL, aMenuId, 10 ); // erase all createMenu( VISU_GLOBAL_SELECTION, aMenuId, 10 ); // global selection createMenu( VISU_PARTIAL_SELECTION, aMenuId, 10 ); // partial selection - createMenu( VISU_SCALING, aMenuId, 10 ); // scaling - createMenu( VISU_CUBE_AXES, aMenuId, 10 ); // scaling } void @@ -2352,6 +2307,7 @@ createToolBars() createTool( VISU_CUT_LINES, aToolId ); createTool( VISU_STREAM_LINES, aToolId ); createTool( VISU_PLOT_3D, aToolId ); + createTool( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE, aToolId ); aToolId = createTool(tr("TOOL_REPRESENTATION")); createTool( VISU_POINTS, aToolId ); @@ -2360,8 +2316,6 @@ createToolBars() createTool( VISU_ERASE_ALL, aToolId ); createTool( VISU_GLOBAL_SELECTION, aToolId ); createTool( VISU_PARTIAL_SELECTION, aToolId ); - createTool( VISU_SCALING, aToolId ); - createTool( VISU_CUBE_AXES, aToolId ); } void @@ -2387,6 +2341,7 @@ createPopupMenus() mgr->insert( action( VISU_VECTORS ), -1, -1, -1 ); // vectors mgr->insert( action( VISU_STREAM_LINES ), -1, -1, -1 ); // stream lines mgr->insert( action( VISU_PLOT_3D ), -1, -1, -1 ); // Plot3d + mgr->insert( action( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE ), -1, -1, -1 ); // scalar map on deformed shape mgr->insert( action( VISU_CREATE_PRS ), -1, -1, -1 ); // create presentation mgr->insert( action( VISU_CREATE_MANY_PRS ), -1, -1, -1 ); // create presentations @@ -2402,6 +2357,7 @@ createPopupMenus() mgr->insert( action( VISU_EDIT_VECTORS ), -1, -1, -1 ); mgr->insert( action( VISU_EDIT_STREAMLINES ), -1, -1, -1 ); mgr->insert( action( VISU_EDIT_PLOT3D ), -1, -1, -1 ); + mgr->insert( action( VISU_EDIT_SCALARMAPONDEFORMEDSHAPE ), -1, -1, -1 ); mgr->insert( action( VISU_EDIT_CONTAINER ), -1, -1, -1 ); // rename @@ -2474,7 +2430,7 @@ createPopupMenus() // Rules QString aPrsAll ("'VISU::TSCALARMAP' 'VISU::TISOSURFACE' 'VISU::TDEFORMEDSHAPE' 'VISU::TCUTPLANES' " - "'VISU::TCUTLINES' 'VISU::TVECTORS' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D'"); + "'VISU::TCUTLINES' 'VISU::TVECTORS' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D' 'VISU::TSCALARMAPONDEFORMEDSHAPE'"); // VISU root commands QString aRule = "client='ObjectBrowser' and selcount=1 and type='VISU::TVISUGEN'"; @@ -2493,6 +2449,7 @@ createPopupMenus() mgr->setRule( action( VISU_DEFORMED_SHAPE ), aRule, true ); mgr->setRule( action( VISU_VECTORS ), aRule, true ); mgr->setRule( action( VISU_STREAM_LINES ), aRule, true ); + mgr->setRule( action( VISU_SCALAR_MAP_ON_DEFORMED_SHAPE ), aRule, true ); // display/erase commands QString andInvisible = " and (((not isVisible) and isActiveView) or (not isActiveView))"; @@ -2501,7 +2458,7 @@ createPopupMenus() QString orCurveInvisible = "or (type='VISU::TCURVE'" + andInvisible + ")"; QString aPrsVisible = "(($type in {'VISU::TMESH' " + aPrsAll + "}) and isVisible)"; QString aPrsInvisible = "(($type in {'VISU::TMESH' " + aPrsAll + "})" + andInvisible + ")"; - QString aComponent = "( selcount=1 and canBeDisplayed )"; + QString aComponent = "( selcount=1 and canBeDisplayed and isComponent )"; QString anEraseRule = "( selcount>0 and ({true} in $canBeDisplayed) and (" + aPrsVisible + " or (client='ObjectBrowser' and (" + aTableOrCont + orCurveVisible + "))) ) or " + aComponent; @@ -2525,10 +2482,10 @@ createPopupMenus() mgr->setRule( action( VISU_FREE_SCALAR_BARS ), aRule, true ); // view parameters - aRule = "selcount=1 and type='VISU::TVIEW3D'"; + aRule = "selcount=1 and type='VISU::TVIEW3D' and activeView='VTKViewer'"; mgr->setRule( action( VISU_SAVE_VIEW_PARAMS_1 ), aRule, true ); - mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "client='VTKViewer' and selcount=0", true ); - mgr->setRule( action( VISU_RESTORE_VIEW_PARAMS ), "selcount=1 and type='VISU::TVIEW3D'", true ); + mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "client='VTKViewer' and selcount=0 and activeView='VTKViewer'", true ); + mgr->setRule( action( VISU_RESTORE_VIEW_PARAMS ), "selcount=1 and type='VISU::TVIEW3D' and activeView='VTKViewer'", true ); //mgr->setRule( action( VISU_DELETE_VIEW_PARAMS ), "selcount=1 and type='VISU::TVIEW3D'", true ); mgr->setRule( action( VISU_ARRANGE_ACTORS ), "client='VTKViewer' and selcount=0", true ); @@ -2538,9 +2495,9 @@ createPopupMenus() QString aInsideType = " and $type in {'VISU::TMESH' 'VISU::TSCALARMAP' 'VISU::TDEFORMEDSHAPE'}"; QString aSurfType = " and $type in {'VISU::TMESH'}"; QString aShrinkType = " and $type in {'VISU::TMESH' 'VISU::TSCALARMAP' 'VISU::TISOSURFACE' " - "'VISU::TDEFORMEDSHAPE' 'VISU::TCUTPLANES' 'VISU::TCUTLINES' 'VISU::TPLOT3D'}"; + "'VISU::TDEFORMEDSHAPE' 'VISU::TCUTPLANES' 'VISU::TCUTLINES' 'VISU::TPLOT3D' 'VISU::TSCALARMAPONDEFORMEDSHAPE'}"; QString aLineType = " and $type in {'VISU::TMESH' 'VISU::TSCALARMAP' 'VISU::TISOSURFACE' 'VISU::TDEFORMEDSHAPE' " - "'VISU::TCUTPLANES' 'VISU::TCUTLINES' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D'}"; + "'VISU::TCUTPLANES' 'VISU::TCUTLINES' 'VISU::TSTREAMLINES' 'VISU::TPLOT3D' 'VISU::TSCALARMAPONDEFORMEDSHAPE' }"; aRule = "selcount=1"; mgr->setRule( action( VISU_CLIPPING ), aRule + aPrsType, true ); @@ -2596,6 +2553,8 @@ createPopupMenus() "selcount=1 and type='VISU::TSCALARMAP'", true ); mgr->setRule( action( VISU_EDIT_DEFORMEDSHAPE ), "selcount=1 and type='VISU::TDEFORMEDSHAPE'", true ); + mgr->setRule( action( VISU_EDIT_SCALARMAPONDEFORMEDSHAPE ), + "selcount=1 and type='VISU::TSCALARMAPONDEFORMEDSHAPE'", true ); mgr->setRule( action( VISU_EDIT_CUTPLANES ), "selcount=1 and type='VISU::TCUTPLANES'", true ); mgr->setRule( action( VISU_EDIT_CUTLINES ), @@ -2619,7 +2578,10 @@ createPopupMenus() aRule = "client='VTKViewer' and selcount=1" + aInsideType; mgr->setRule( action( VISU_SELECTION_INFO ), aRule, true ); - aRule = "client='ObjectBrowser' and selcount>0 and $type in {'VISU::TFIELD'} and nbTimeStamps>1"; + aRule = "client='ObjectBrowser' and selcount>0"; + aRule += " and $type in {'VISU::TFIELD'}"; + aRule += " and nbTimeStamps>1"; + aRule += " and activeView in {'VTKViewer' 'VVTK'}"; mgr->setRule( action( VISU_ANIMATION ), aRule, true ); aRule = "client='ObjectBrowser' and $type in {'VISU::TENTITY' 'VISU::TFAMILY' 'VISU::TGROUP'}"; @@ -2853,6 +2815,42 @@ void VisuGUI::createPreferences() // TAB: "Scalar Bar" int sbarTab = addPreference( tr( "VISU_SCALAR_BAR" ) ); + int rangeGr = addPreference( tr( "VISU_SCALAR_RANGE" ), sbarTab ); + setPreferenceProperty( rangeGr, "columns", 1 ); + + int mode = addPreference( tr( "VISU_SCALAR_MODE" ), rangeGr, LightApp_Preferences::Selector, "VISU", "scalar_bar_mode" ); + QStringList modes; + modes.append( tr( "VISU_MODULUS" ) ); + modes.append( tr( "VISU_COMPONENT" ) + tr("1") ); + modes.append( tr( "VISU_COMPONENT" ) + tr("2") ); + modes.append( tr( "VISU_COMPONENT" ) + tr("3") ); + QValueList indices; + indices.append( 0 ); + indices.append( 1 ); + indices.append( 2 ); + indices.append( 3 ); + setPreferenceProperty( mode, "strings", modes ); + setPreferenceProperty( mode, "indexes", indices ); + + addPreference( tr( "VISU_LOGARITHMIC_SCALING" ), rangeGr, LightApp_Preferences::Bool, "VISU", "scalar_bar_logarithmic" ); + + int rangetype = addPreference( tr( "VISU_RANGE_TO_USE" ), rangeGr, LightApp_Preferences::Selector, "VISU", "scalar_range_type" ); + QStringList types; + types.append( tr( "VISU_FIELD_RANGE" ) ); + types.append( tr( "VISU_IMPOSED_RANGE" ) ); + indices.clear(); + indices.append( 0 ); + indices.append( 1 ); + setPreferenceProperty( rangetype, "strings", types ); + setPreferenceProperty( rangetype, "indexes", indices ); + + int imposedGr = addPreference( tr( "VISU_MINMAX_IMPOSED_RANGE" ), sbarTab ); + + int min = addPreference( tr( "VISU_MIN" ), imposedGr, LightApp_Preferences::DblSpin, "VISU", "scalar_range_min" ); + int max = addPreference( tr( "VISU_MAX" ), imposedGr, LightApp_Preferences::DblSpin, "VISU", "scalar_range_max" ); + setPreferenceProperty( min, "step", 0.1 ); + setPreferenceProperty( max, "step", 0.1 ); + // group: "Font" int fontGr = addPreference( tr( "VISU_FONT" ), sbarTab ); int tfont = addPreference( tr( "VISU_TITLE" ), fontGr, @@ -2885,7 +2883,7 @@ void VisuGUI::createPreferences() int numcol = addPreference( tr( "VISU_NB_COLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "VISU", "scalar_bar_num_colors" ); setPreferenceProperty( numcol, "min", 2 ); - setPreferenceProperty( numcol, "max", 64 ); + setPreferenceProperty( numcol, "max", 256 ); int numlab = addPreference( tr( "VISU_NB_LABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "VISU", "scalar_bar_num_labels" ); @@ -2899,7 +2897,7 @@ void VisuGUI::createPreferences() QStringList orients; orients.append( tr( "VISU_VERTICAL" ) ); orients.append( tr( "VISU_HORIZONTAL" ) ); - QValueList indices; + indices.clear(); indices.append( 0 ); indices.append( 1 ); setPreferenceProperty( orient, "strings", orients ); @@ -2953,54 +2951,9 @@ void VisuGUI::createPreferences() // group: "Scalar bars default position" int scalarBarGr = addPreference( tr( "Scalar bars default position" ), sbarTab ); - addPreference( tr( "Arrange Scalar Bars" ), scalarBarGr, - LightApp_Preferences::Bool, "VISU", "scalar_bars_default_position" ); - - // TAB: "Scalar range, Sweep, MED import, Shading" - int srangeTab = addPreference( tr( "VISU_PREF_SECOND_TAB" ) ); - - // group: "Scalar range" - int rangeGr = addPreference( tr( "VISU_SCALAR_RANGE" ), srangeTab ); - setPreferenceProperty( rangeGr, "columns", 1 ); - - int mode = addPreference( tr( "VISU_SCALAR_MODE" ), rangeGr, - LightApp_Preferences::Selector, "VISU", "scalar_bar_mode" ); - QStringList modes; - modes.append( tr( "VISU_MODULUS" ) ); - modes.append( tr( "VISU_COMPONENT" ) + tr("1") ); - modes.append( tr( "VISU_COMPONENT" ) + tr("2") ); - modes.append( tr( "VISU_COMPONENT" ) + tr("3") ); - indices.clear(); - indices.append( 0 ); - indices.append( 1 ); - indices.append( 2 ); - indices.append( 3 ); - setPreferenceProperty( mode, "strings", modes ); - setPreferenceProperty( mode, "indexes", indices ); - - addPreference( tr( "VISU_LOGARITHMIC_SCALING" ), rangeGr, - LightApp_Preferences::Bool, "VISU", "scalar_bar_logarithmic" ); - - int rangetype = addPreference( tr( "VISU_RANGE_TO_USE" ), rangeGr, - LightApp_Preferences::Selector, "VISU", "scalar_range_type" ); - QStringList types; - types.append( tr( "VISU_FIELD_RANGE" ) ); - types.append( tr( "VISU_IMPOSED_RANGE" ) ); - indices.clear(); - indices.append( 0 ); - indices.append( 1 ); - setPreferenceProperty( rangetype, "strings", types ); - setPreferenceProperty( rangetype, "indexes", indices ); + addPreference( tr( "Arrange Scalar Bars" ), scalarBarGr, LightApp_Preferences::Bool, "VISU", "scalar_bars_default_position" ); - // group: "Min and max for imposed range" - int imposedGr = addPreference( tr( "VISU_MINMAX_IMPOSED_RANGE" ), srangeTab ); - - int min = addPreference( tr( "VISU_MIN" ), imposedGr, - LightApp_Preferences::DblSpin, "VISU", "scalar_range_min" ); - int max = addPreference( tr( "VISU_MAX" ), imposedGr, - LightApp_Preferences::DblSpin, "VISU", "scalar_range_max" ); - setPreferenceProperty( min, "step", 0.1 ); - setPreferenceProperty( max, "step", 0.1 ); + int srangeTab = addPreference( tr( "Sweep, MED import" ) ); // group: "Sweeping preferences" int sweepGr = addPreference( tr( "VISU_SWEEPING_PREF" ), srangeTab ); @@ -3019,9 +2972,14 @@ void VisuGUI::createPreferences() setPreferenceProperty( nbsteps, "max", 200 ); // group: "MED files import" - int importGr = addPreference( tr( "VISU_PREF_MED_IMPORT" ), srangeTab ); - addPreference( tr( "VISU_PREF_MED_FULL_LOAD" ), importGr, - LightApp_Preferences::Bool, "VISU", "full_med_loading" ); + int importGr = addPreference( tr( "MED files import" ), srangeTab ); + setPreferenceProperty( importGr, "columns", 1 ); + addPreference( tr( "Full MED loading" ), importGr, LightApp_Preferences::Bool, "VISU", "full_med_loading" ); + addPreference( tr( "Build at once" ), importGr, LightApp_Preferences::Bool, "VISU", "build_at_once" ); + addPreference( tr( "Build fields" ), importGr, LightApp_Preferences::Bool, "VISU", "build_fields" ); + addPreference( tr( "Build min/max" ), importGr, LightApp_Preferences::Bool, "VISU", "build_min_max" ); + addPreference( tr( "Build groups" ), importGr, LightApp_Preferences::Bool, "VISU", "build_groups" ); + addPreference( tr( "Close dialog at finish" ), importGr, LightApp_Preferences::Bool, "VISU", "close_at_finish" ); // group: "Representation properties" int representGr = addPreference( tr( "VISU_PREF_REPRESENT_PROPS" ), srangeTab ); @@ -3035,10 +2993,12 @@ void VisuGUI::preferencesChanged( const QString& a, const QString& b) if (b == QString("scalar_bar_orientation")) return; SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); float sbX1,sbY1,sbW,sbH; + std::string aWarning; if(b == QString("scalar_bar_vertical_x") || b == QString("scalar_bar_vertical_width")){ sbX1 = aResourceMgr->doubleValue("VISU", "scalar_bar_vertical_x", sbX1); sbW = aResourceMgr->doubleValue("VISU", "scalar_bar_vertical_width", sbW); if(sbX1+sbW > 1.0){ + aWarning = "Origin and Size Vertical: X+Width > 1\n"; sbX1=0.01; sbW=0.05; aResourceMgr->setValue("VISU", "scalar_bar_vertical_x", sbX1); @@ -3049,6 +3009,7 @@ void VisuGUI::preferencesChanged( const QString& a, const QString& b) sbY1 = aResourceMgr->doubleValue("VISU", "scalar_bar_vertical_y", sbY1); sbH = aResourceMgr->doubleValue("VISU", "scalar_bar_vertical_height",sbH); if(sbY1+sbH > 1.0){ + aWarning = "Origin and Size Vertical: Y+Height > 1\n"; sbY1=0.01; sbH=0.5; aResourceMgr->setValue("VISU", "scalar_bar_vertical_y", sbY1); @@ -3059,6 +3020,7 @@ void VisuGUI::preferencesChanged( const QString& a, const QString& b) sbX1 = aResourceMgr->doubleValue("VISU", "scalar_bar_horizontal_x", sbX1); sbW = aResourceMgr->doubleValue("VISU", "scalar_bar_horizontal_width", sbW); if(sbX1+sbW > 1.0){ + aWarning = "Origin and Size Horizontal: X+Width > 1\n"; sbX1=0.2; sbW=0.6; aResourceMgr->setValue("VISU", "scalar_bar_horizontal_x", sbX1); @@ -3069,12 +3031,20 @@ void VisuGUI::preferencesChanged( const QString& a, const QString& b) sbY1 = aResourceMgr->doubleValue("VISU", "scalar_bar_horizontal_y", sbY1); sbH = aResourceMgr->doubleValue("VISU", "scalar_bar_horizontal_height",sbH); if(sbY1+sbH > 1.0){ + aWarning = "Origin and Size Horizontal: Y+Height > 1\n"; sbY1=0.01; sbH=0.12; aResourceMgr->setValue("VISU", "scalar_bar_horizontal_y", sbY1); aResourceMgr->setValue("VISU", "scalar_bar_horizontal_height",sbH); } } + if (aWarning.size() != 0){ + aWarning += "The default values are applied instead."; + SUIT_MessageBox::warn1(GetDesktop(this), + tr("ERR_SCALARBAR_PARAMS"), + tr(aWarning.c_str()), + tr("BUT_OK") ); + } } SUIT_ViewManager* @@ -3098,12 +3068,3 @@ LightApp_Displayer* VisuGUI::displayer() return myDisplayer; } - -void VisuGUI::storeVisualParameters(int savePoint) -{ -} - -void VisuGUI::restoreVisualParameters(int savePoint) -{ -} - diff --git a/src/VISUGUI/VisuGUI.h b/src/VISUGUI/VisuGUI.h index 0fbbcbb4..22224d72 100644 --- a/src/VISUGUI/VisuGUI.h +++ b/src/VISUGUI/VisuGUI.h @@ -74,9 +74,6 @@ public: VISU::TViewToPrs3d getScalarBarsMap(); VISU::TViewToPrs3d myScalarBarsMap; - - virtual void storeVisualParameters(int savePoint); - virtual void restoreVisualParameters(int savePoint); public slots: virtual bool deactivateModule( SUIT_Study* ); @@ -100,6 +97,7 @@ protected slots: void OnCreatePlot3D(); void OnCreateManyMesh(); void OnCreatePlot2dView(); + void OnCreateScalarMapOnDeformedShape(); void OnEditScalarMap(); void OnEditDeformedShape(); @@ -109,6 +107,7 @@ protected slots: void OnEditVectors(); void OnEditStreamLines(); void OnEditPlot3D(); + void OnEditScalarMapOnDeformedShape(); virtual void OnDisplayPrs(); virtual void OnDisplayOnlyPrs(); @@ -141,8 +140,8 @@ protected slots: void OnMergeScalarBars(); void OnFreeScalarBars(); - void OnSaveViewParams(); - void OnRestoreViewParams(); + virtual void OnSaveViewParams(); + virtual void OnRestoreViewParams(); void OnRename(); void OnClippingPlanes(); @@ -157,9 +156,6 @@ protected slots: void OnTranslatePrs(); void OnArrangeActors(); - void OnScaling(); - void OnCubeAxes(); - protected: virtual LightApp_Selection* createSelection() const; diff --git a/src/VISUGUI/VisuGUI_ActionsDef.h b/src/VISUGUI/VisuGUI_ActionsDef.h index 923247d8..1fe7a7b2 100644 --- a/src/VISUGUI/VisuGUI_ActionsDef.h +++ b/src/VISUGUI/VisuGUI_ActionsDef.h @@ -40,6 +40,7 @@ #define VISU_CUT_LINES 4017 #define VISU_PLOT2D 4018 #define VISU_PLOT_3D 4019 +#define VISU_SCALAR_MAP_ON_DEFORMED_SHAPE 40110 //#define VISU_DELETE 4021 #define VISU_DELETE_OBJS 4022 @@ -91,6 +92,7 @@ #define VISU_EDIT_VECTORS 40625 #define VISU_EDIT_STREAMLINES 40626 #define VISU_EDIT_PLOT3D 40627 +#define VISU_EDIT_SCALARMAPONDEFORMEDSHAPE 40628 #define VISU_EDIT_PRS 4062 #define VISU_CREATE_TABLE 4063 diff --git a/src/VISUGUI/VisuGUI_BuildProgressDlg.cxx b/src/VISUGUI/VisuGUI_BuildProgressDlg.cxx new file mode 100644 index 00000000..7705f32d --- /dev/null +++ b/src/VISUGUI/VisuGUI_BuildProgressDlg.cxx @@ -0,0 +1,392 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_BuildProgressDlg.cxx +// Author : Oleg UVAROV +// Module : VISU + +#include "VisuGUI_BuildProgressDlg.h" + +#include "VisuGUI_Tools.h" + +#include "SUIT_FileDlg.h" +#include "SUIT_MessageBox.h" +#include "SUIT_ResourceMgr.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +/*! + * Constructor + */ +VisuGUI_BuildProgressDlg::VisuGUI_BuildProgressDlg( QWidget* theParent ): + QDialog( theParent, "VisuGUI_BuildProgressBar", false ), + myIsRaiseColor( false ) +{ + setCaption( tr( "DLG_BUILD_PROGRESS_TITLE" ) ); + + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + + QVBoxLayout* aTopLayout = new QVBoxLayout( this ); + aTopLayout->setSpacing( 6 ); + aTopLayout->setMargin( 6 ); + aTopLayout->setAutoAdd( true ); + + // Settings + mySettingsBox = new QGroupBox( tr( "IMPORT_SETTINGS" ), this ); + mySettingsBox->setColumnLayout( 0, Qt::Vertical ); + mySettingsBox->layout()->setSpacing( 0 ); + mySettingsBox->layout()->setMargin( 0 ); + + QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox->layout() ); + aSettingsLayout->setSpacing( 6 ); + aSettingsLayout->setMargin( 11 ); + + QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox ); + myFileNameLineEdit = new QLineEdit( mySettingsBox ); + myFileNameLineEdit->setMinimumWidth( 250 ); + myFileNameLineEdit->setReadOnly( true ); + /* + QPushButton* aFileNameButton = new QPushButton( mySettingsBox ); + aFileNameButton->setAutoDefault( false ); + aFileNameButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) ); + connect( aFileNameButton, SIGNAL( clicked() ), this, SLOT( onBrowseFile() ) ); + */ + myBuildAllCheckBox = new QCheckBox( tr( "BUILD_ALL" ), mySettingsBox ); + myBuildAllCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "full_med_loading", false ) ); + connect( myBuildAllCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) ); + + myBuildAtOnceCheckBox = new QCheckBox( tr( "BUILD_AT_ONCE" ), mySettingsBox ); + myBuildAtOnceCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_at_once", false ) ); + connect( myBuildAtOnceCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) ); + + myCloseCheckBox = new QCheckBox( tr( "CLOSE_AT_FINISH" ), mySettingsBox ); + myCloseCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "close_at_finish", true ) ); + + aSettingsLayout->addWidget( aFileNameLabel, 0, 0 ); + aSettingsLayout->addMultiCellWidget( myFileNameLineEdit, 1, 1, 0, 1 ); + //aSettingsLayout->addWidget( aFileNameButton, 1, 2 ); + aSettingsLayout->addWidget( myBuildAllCheckBox, 2, 0 ); + aSettingsLayout->addWidget( myBuildAtOnceCheckBox, 3, 0 ); + aSettingsLayout->addWidget( myCloseCheckBox, 4, 0 ); + + // Progress + myProgressBox = new QGroupBox( tr( "IMPORT_PROGRESS" ), this ); + myProgressBox->setColumnLayout( 0, Qt::Vertical ); + myProgressBox->layout()->setSpacing( 0 ); + myProgressBox->layout()->setMargin( 0 ); + + QGridLayout* aProgressLayout = new QGridLayout( myProgressBox->layout() ); + aProgressLayout->setSpacing( 6 ); + aProgressLayout->setMargin( 11 ); + + myBuildEntitiesCheckBox = new QCheckBox( tr( "BUILD_ENTITIES" ), myProgressBox ); + myBuildEntitiesCheckBox->setChecked( true ); + myBuildEntitiesCheckBox->setEnabled( false ); + myBuildEntitiesButton = new QPushButton( myProgressBox ); + myBuildEntitiesButton->setEnabled( false ); + myBuildEntitiesButton->setFixedSize( 30, 30 ); + myBuildEntitiesButton->setPaletteBackgroundColor( Qt::red ); + connect( myBuildEntitiesCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) ); + + myBuildFieldsCheckBox = new QCheckBox( tr( "BUILD_FIELDS" ), myProgressBox ); + myBuildFieldsCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_fields", true ) ); + myBuildFieldsButton = new QPushButton( myProgressBox ); + myBuildFieldsButton->setEnabled( false ); + myBuildFieldsButton->setFixedSize( 30, 30 ); + myBuildFieldsButton->setPaletteBackgroundColor( Qt::red ); + connect( myBuildFieldsCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) ); + + myBuildMinMaxCheckBox = new QCheckBox( tr( "BUILD_MINMAX" ), myProgressBox ); + myBuildMinMaxCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_min_max", true ) ); + myBuildMinMaxButton = new QPushButton( myProgressBox ); + myBuildMinMaxButton->setEnabled( false ); + myBuildMinMaxButton->setFixedSize( 30, 30 ); + myBuildMinMaxButton->setPaletteBackgroundColor( Qt::red ); + connect( myBuildMinMaxCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) ); + + myBuildGroupsCheckBox = new QCheckBox( tr( "BUILD_GROUPS" ), myProgressBox ); + myBuildGroupsCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_groups", true ) ); + myBuildGroupsButton = new QPushButton( myProgressBox ); + myBuildGroupsButton->setEnabled( false ); + myBuildGroupsButton->setFixedSize( 30, 30 ); + myBuildGroupsButton->setPaletteBackgroundColor( Qt::red ); + connect( myBuildGroupsCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) ); + + aProgressLayout->addWidget( myBuildEntitiesCheckBox, 0, 0 ); + aProgressLayout->addWidget( myBuildEntitiesButton, 0, 1 ); + aProgressLayout->addWidget( myBuildFieldsCheckBox, 1, 0 ); + aProgressLayout->addWidget( myBuildFieldsButton, 1, 1 ); + aProgressLayout->addWidget( myBuildMinMaxCheckBox, 2, 0 ); + aProgressLayout->addWidget( myBuildMinMaxButton, 2, 1 ); + aProgressLayout->addWidget( myBuildGroupsCheckBox, 3, 0 ); + aProgressLayout->addWidget( myBuildGroupsButton, 3, 1 ); + + // Time + myTimeBox = new QGroupBox( tr( "IMPORT_TIME" ), this ); + myTimeBox->setColumnLayout( 0, Qt::Vertical ); + myTimeBox->layout()->setSpacing( 0 ); + myTimeBox->layout()->setMargin( 0 ); + + QGridLayout* aTimeLayout = new QGridLayout( myTimeBox->layout() ); + aTimeLayout->setSpacing( 6 ); + aTimeLayout->setMargin( 11 ); + + QLabel* aTimeLabel = new QLabel( tr( "TIME" ), myTimeBox ); + + myTimeLCDNumber = new QLCDNumber( myTimeBox ); + myTimeLCDNumber->setSegmentStyle( QLCDNumber::Filled ); + myTimeLCDNumber->setPaletteBackgroundColor( Qt::black ); + myTimeLCDNumber->setPaletteForegroundColor( Qt::white ); + myTimeLCDNumber->setNumDigits( 8 ); + myTimeLCDNumber->display( myTime.toString( "hh:mm:ss.zzz" ) ); + + aTimeLayout->addWidget( aTimeLabel, 0, 0 ); + aTimeLayout->addWidget( myTimeLCDNumber, 0, 1 ); + + // Start / Close + QGroupBox* CommonGroup = new QGroupBox( this ); + CommonGroup->setColumnLayout(0, Qt::Vertical ); + CommonGroup->layout()->setSpacing( 0 ); + CommonGroup->layout()->setMargin( 0 ); + QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup->layout() ); + CommonGroupLayout->setAlignment( Qt::AlignTop ); + CommonGroupLayout->setSpacing( 6 ); + CommonGroupLayout->setMargin( 11 ); + + myStartButton = new QPushButton( tr( "START" ), CommonGroup ); + myStartButton->setAutoDefault( true ); + myStartButton->setDefault( true ); + CommonGroupLayout->addWidget( myStartButton, 0, 0 ); + CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup ); + aCloseButton->setAutoDefault( true ); + CommonGroupLayout->addWidget( aCloseButton, 0, 2 ); + + connect( myStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) ); + connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) ); + + myTimer = new QTimer( this ); + connect( myTimer, SIGNAL( timeout() ), this, SLOT( onTimer() ) ); +} + +VisuGUI_BuildProgressDlg::~VisuGUI_BuildProgressDlg() +{ +} + +void VisuGUI_BuildProgressDlg::show() +{ + if( onBrowseFile() ) + QWidget::show(); +} + +void VisuGUI_BuildProgressDlg::onStart() +{ + if( myFileName.isNull() ) + return; + + bool aBuildAll = myBuildAllCheckBox->isChecked(); + bool aBuildAtOnce = myBuildAtOnceCheckBox->isChecked(); + + myResult = myGenerator->CreateResult( myFileName ); + + myResult->SetBuildFields( myBuildFieldsCheckBox->isChecked(), myBuildMinMaxCheckBox->isChecked() ); + myResult->SetBuildGroups( myBuildGroupsCheckBox->isChecked() ); + + //setModal( false ); + myFileNameLineEdit->setReadOnly( true ); + /* + myBuildAllCheckBox->setNoChange(); + myBuildAtOnceCheckBox->setNoChange(); + myBuildEntitiesCheckBox->setNoChange(); + myBuildFieldsCheckBox->setNoChange(); + myBuildMinMaxCheckBox->setNoChange(); + myBuildGroupsCheckBox->setNoChange(); + */ + + myStartButton->setEnabled( false ); + + if( aBuildAtOnce ) + { + QApplication::setOverrideCursor( Qt::waitCursor ); + myCurrentTime = vtkTimerLog::GetCurrentTime(); + } + + myTime.setHMS( 0, 0, 0 ); + myTimer->start( 100 ); + + myResult->Build( aBuildAll, aBuildAtOnce ); +} + +void VisuGUI_BuildProgressDlg::onClose() +{ + done( 0 ); +} + +bool VisuGUI_BuildProgressDlg::onBrowseFile() +{ + QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ); + + QStringList aFilter; + aFilter.append( tr( "FLT_MED_FILES" ) ); + aFilter.append( tr( "FLT_ALL_FILES" ) ); + + QFileInfo aFileInfo = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_FROM_FILE" ), true ); + QString aFileName = aFileInfo.filePath(); + + if( aFileName.isNull() ) + return false; + + myFileName = aFileName; + myFileNameLineEdit->setText( aFileName.section( '/', -1 ) ); + + return true; +} + +void VisuGUI_BuildProgressDlg::onTimer() +{ + try { + bool aBuildAtOnce = myBuildAtOnceCheckBox->isChecked(); + + if( !aBuildAtOnce ) + { + myTime = myTime.addMSecs( 100 ); + if( myTime.minute() > 9 && myTimeLCDNumber->numDigits() < 9 ) + myTimeLCDNumber->setNumDigits( 9 ); + myTimeLCDNumber->display( myTime.toString( "m:ss.zzz" ) ); + + bool isEntitiesDone = myResult->IsEntitiesDone(); + bool isFieldsDone = myResult->IsFieldsDone(); + bool isMinMaxDone = myResult->IsMinMaxDone(); + bool isGroupsDone = myResult->IsGroupsDone(); + + updateButton( myBuildEntitiesButton, isEntitiesDone ); + updateButton( myBuildFieldsButton, isFieldsDone ); + updateButton( myBuildMinMaxButton, isMinMaxDone ); + updateButton( myBuildGroupsButton, isGroupsDone ); + } + + if( myResult->IsDone() ) + { + myTimer->stop(); + + if( aBuildAtOnce ) + { + QApplication::restoreOverrideCursor(); + + QTime aTime; + int mSecs = ( int )( 1000 * ( vtkTimerLog::GetCurrentTime() - myCurrentTime ) ); + aTime = aTime.addMSecs( mSecs ); + if( aTime.minute() > 9 ) + myTimeLCDNumber->setNumDigits( 9 ); + myTimeLCDNumber->display( aTime.toString( "m:ss.zzz" ) ); + } + + if( myCloseCheckBox->isChecked() ) + done( 0 ); + else + SUIT_MessageBox::warn1( this, tr( "INF_VISU" ), tr( "IMPORT_DONE" ), tr( "BUT_OK" ) ); + } + } + catch( ... ) { + done( 1 ); + } +} + +void VisuGUI_BuildProgressDlg::updateButton( QPushButton* theButton, bool theIsDone ) +{ + QColor aCurrentColor = theButton->paletteBackgroundColor(); + if( aCurrentColor == Qt::gray || aCurrentColor == Qt::green ) + return; + + QColor aNewColor = Qt::green; + + if( !theIsDone ) + { + int r, g, b; + aCurrentColor.getRgb( &r, &g, &b ); + if( g == 0 ) + myIsRaiseColor = true; + else if( g == 255 ) + myIsRaiseColor = false; + + int gNew = g + ( myIsRaiseColor ? 1 : -1 ) * 51; + + aNewColor.setRgb( 255, gNew, 0 ); + } + + theButton->setPaletteBackgroundColor( aNewColor ); +} + +void VisuGUI_BuildProgressDlg::done( int r ) +{ + QApplication::restoreOverrideCursor(); + myTimer->stop(); + QDialog::done( r ); +} + +void VisuGUI_BuildProgressDlg::onBuildCheckBoxClicked() +{ + QCheckBox* aCheckBox = ( QCheckBox* )sender(); + if( !aCheckBox ) + return; + + bool anIsChecked = aCheckBox->isChecked(); + + QColor aColor = anIsChecked ? Qt::red : Qt::gray; + + if( aCheckBox == myBuildAllCheckBox ) + { + if( anIsChecked && !myBuildAtOnceCheckBox->isChecked() ) + myBuildAtOnceCheckBox->animateClick(); + } + else if( aCheckBox == myBuildAtOnceCheckBox ) + { + if( !anIsChecked && myBuildAllCheckBox->isChecked() ) + myBuildAllCheckBox->animateClick(); + } + else if( aCheckBox == myBuildFieldsCheckBox ) + { + myBuildFieldsButton->setPaletteBackgroundColor( aColor ); + if( !anIsChecked && myBuildMinMaxCheckBox->isChecked() ) + myBuildMinMaxCheckBox->animateClick(); + } + else if( aCheckBox == myBuildMinMaxCheckBox ) + { + myBuildMinMaxButton->setPaletteBackgroundColor( aColor ); + if( anIsChecked && !myBuildFieldsCheckBox->isChecked() ) + myBuildFieldsCheckBox->animateClick(); + } + else if( aCheckBox == myBuildGroupsCheckBox ) + myBuildGroupsButton->setPaletteBackgroundColor( aColor ); + +} diff --git a/src/VISUGUI/VisuGUI_BuildProgressDlg.h b/src/VISUGUI/VisuGUI_BuildProgressDlg.h new file mode 100644 index 00000000..4d880596 --- /dev/null +++ b/src/VISUGUI/VisuGUI_BuildProgressDlg.h @@ -0,0 +1,111 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_BuildProgressDlg.h +// Author : Oleg UVAROV +// Module : VISU +// $Header$ + +#ifndef VISUGUI_BUILDPROGRESSDLG_H +#define VISUGUI_BUILDPROGRESSDLG_H + +#include "VISU_Gen_i.hh" + +#include +#include + +class QCheckBox; +class QGroupBox; +class QLCDNumber; +class QLineEdit; +class QPushButton; +class QTimer; + +//! Build Progress Dialog. +class VisuGUI_BuildProgressDlg : public QDialog +{ + Q_OBJECT + +public: + VisuGUI_BuildProgressDlg( QWidget* ); + ~VisuGUI_BuildProgressDlg(); + + virtual void setGenerator( VISU::VISU_Gen_i* theGenerator ) { myGenerator = theGenerator; } + virtual void show(); + + QString fileName() const { return myFileName; } + +protected slots: + void done( int ); + + void onStart(); + void onClose(); + + bool onBrowseFile(); + void onTimer(); + + void onBuildCheckBoxClicked(); + +private: + void updateButton( QPushButton*, bool ); + +private: + VISU::Result_var myResult; + VISU::VISU_Gen_i* myGenerator; + + QString myFileName; + QTime myTime; + QTimer* myTimer; + + QGroupBox* mySettingsBox; + + QLineEdit* myFileNameLineEdit; + QCheckBox* myBuildAllCheckBox; + QCheckBox* myBuildAtOnceCheckBox; + + QGroupBox* myProgressBox; + + QCheckBox* myBuildEntitiesCheckBox; + QPushButton* myBuildEntitiesButton; + + QCheckBox* myBuildFieldsCheckBox; + QPushButton* myBuildFieldsButton; + + QCheckBox* myBuildMinMaxCheckBox; + QPushButton* myBuildMinMaxButton; + + QCheckBox* myBuildGroupsCheckBox; + QPushButton* myBuildGroupsButton; + + QGroupBox* myTimeBox; + QLCDNumber* myTimeLCDNumber; + + QCheckBox* myCloseCheckBox; + + QPushButton* myStartButton; + + double myCurrentTime; + bool myIsRaiseColor; +}; + +#endif diff --git a/src/VISUGUI/VisuGUI_ClippingDlg.cxx b/src/VISUGUI/VisuGUI_ClippingDlg.cxx index c2bd7a5c..2c9f7f1b 100644 --- a/src/VISUGUI/VisuGUI_ClippingDlg.cxx +++ b/src/VISUGUI/VisuGUI_ClippingDlg.cxx @@ -63,6 +63,7 @@ #include #include #include +#include // OCCT Includes #include diff --git a/src/VISUGUI/VisuGUI_CubeAxesDlg.cxx b/src/VISUGUI/VisuGUI_CubeAxesDlg.cxx deleted file mode 100755 index 97640bd6..00000000 --- a/src/VISUGUI/VisuGUI_CubeAxesDlg.cxx +++ /dev/null @@ -1,594 +0,0 @@ -// VISU VISUGUI : GUI for SMESH component -// -// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : VisuGUI_CubeAxesDlg.cxx -// Author : Sergey LITONIN -// Module : VISU - -#include "VisuGUI_CubeAxesDlg.h" - -#include "VisuGUI.h" -#include "VisuGUI_Tools.h" -#include "VisuGUI_FontWg.h" - -#include "SVTK_ViewWindow.h" -#include "SVTK_CubeAxesActor2D.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -/*! - * Class : AxisWg - * Description : Tab of dialog - */ - -//======================================================================= -// name : VisuGUI_AxisWg::AxisWg -// Purpose : Constructor -//======================================================================= -VisuGUI_AxisWg::VisuGUI_AxisWg (QWidget* theParent) -: QFrame(theParent) -{ - QValueList< QLabel* > aLabels; - - // "Name" grp - - myNameGrp = new QGroupBox(3, Qt::Vertical, tr("AXIS_NAME"), this); - myIsNameVisible = new QCheckBox(tr("IS_VISIBLE"), myNameGrp); - - QHBox* aHBox = new QHBox(myNameGrp); - aHBox->setSpacing(5); - QLabel* aLabel = new QLabel(tr("NAME"), aHBox); - myAxisName = new QLineEdit(aHBox); - aLabels.append(aLabel); - - aHBox = new QHBox(myNameGrp); - aHBox->setSpacing(5); - aLabel = new QLabel(tr("FONT"), aHBox); - myNameFont = new VisuGUI_FontWg(aHBox); - aLabels.append(aLabel); - - - // "Labels" grp - - myLabelsGrp = new QGroupBox(4, Qt::Vertical, tr("LABELS"), this); - myIsLabelsVisible = new QCheckBox(tr("IS_VISIBLE"), myLabelsGrp); - - aHBox = new QHBox(myLabelsGrp); - aHBox->setSpacing(5); - aLabel = new QLabel(tr("NUMBER"), aHBox); - myLabelNumber = new QLineEdit(aHBox); - myLabelNumber->setValidator(new QIntValidator(0, 25, this)); - myLabelNumber->installEventFilter(this); - aLabels.append(aLabel); - - aHBox = new QHBox(myLabelsGrp); - aHBox->setSpacing(5); - aLabel = new QLabel(tr("OFFSET"), aHBox); - myLabelOffset = new QLineEdit(aHBox); - aLabels.append(aLabel); - - aHBox = new QHBox(myLabelsGrp); - aHBox->setSpacing(5); - aLabel = new QLabel(tr("FONT"), aHBox); - myLabelsFont = new VisuGUI_FontWg(aHBox); - aLabels.append(aLabel); - - // "Tick marks" grp - - myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this); - myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp); - - aHBox = new QHBox(myTicksGrp); - aHBox->setSpacing(5); - aLabel = new QLabel(tr("LENGTH"), aHBox); - myTickLength = new QLineEdit(aHBox); - aLabels.append(aLabel); - - // Layout - - QVBoxLayout* aLay = new QVBoxLayout(this, 0, 5); - aLay->addWidget(myNameGrp); - aLay->addWidget(myLabelsGrp); - aLay->addWidget(myTicksGrp); - - // init - myIsNameVisible->setChecked(true); - myIsLabelsVisible->setChecked(true); - myIsTicksVisible->setChecked(true); - updateControlState(); - - // Adjust label widths - QValueList< QLabel* >::iterator anIter; - int aMaxWidth = 0; - for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++) - aMaxWidth = QMAX(aMaxWidth, (*anIter)->sizeHint().width()); - for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++) - (*anIter)->setFixedWidth(aMaxWidth); - - // connect signals and slots - connect(myIsNameVisible, SIGNAL(stateChanged(int)), SLOT(onNameChecked())); - connect(myIsLabelsVisible, SIGNAL(stateChanged(int)), SLOT(onLabelsChecked())); - connect(myIsTicksVisible, SIGNAL(stateChanged(int)), SLOT(onTicksChecked())); -} - -VisuGUI_AxisWg::~VisuGUI_AxisWg() -{ -} - -void VisuGUI_AxisWg::updateControlState() -{ - onNameChecked(); - onLabelsChecked(); - onTicksChecked(); -} - -bool VisuGUI_AxisWg::eventFilter(QObject* o, QEvent* e) -{ - if (e->type() == QEvent::FocusOut) { - bool isOK = false; - int k = myLabelNumber->text().toInt(&isOK); - if (isOK && k > 25) myLabelNumber->setText("25"); - } - return false; -} - -//======================================================================= -// name : VisuGUI_AxisWg::onNameChecked -// Purpose : -//======================================================================= -void VisuGUI_AxisWg::setEnabled(QGroupBox* theGrp, const bool theState) -{ - QObjectList aChildren(*theGrp->children()); - QObject* anObj; - for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next()) - if (anObj !=0 && anObj->inherits("QHBox")) - ((QHBox*)anObj)->setEnabled(theState); -} - -//======================================================================= -// Labels : VisuGUI_AxisWg::onLabelsChecked -// Purpose : -//======================================================================= -void VisuGUI_AxisWg::onLabelsChecked() -{ - setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked()); -} - -//======================================================================= -// Labels : VisuGUI_AxisWg::onTicksChecked -// Purpose : -//======================================================================= -void VisuGUI_AxisWg::onTicksChecked() -{ - setEnabled(myTicksGrp, myIsTicksVisible->isChecked()); -} - -//======================================================================= -// name : VisuGUI_AxisWg::onNameChecked -// Purpose : -//======================================================================= -void VisuGUI_AxisWg::onNameChecked() -{ - setEnabled(myNameGrp, myIsNameVisible->isChecked()); -} - -//======================================================================= -// name : VisuGUI_AxisWg::UseName -// Purpose : -//======================================================================= -void VisuGUI_AxisWg::UseName(const bool toUse) -{ - myIsNameVisible->setChecked(toUse); -} - -//======================================================================= -// name : VisuGUI_AxisWg::SetName -// Purpose : -//================================================== ===================== -void VisuGUI_AxisWg::SetName(const QString& theName) -{ - myAxisName->setText(theName); -} - -//======================================================================= -// name : VisuGUI_AxisWg::SetNameFont -// Purpose : -//======================================================================= -void VisuGUI_AxisWg::SetNameFont(const QColor& theColor, - const int theFont, - const bool theIsBold, - const bool theIsItalic, - const bool theIsShadow) -{ - myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow); -} - -//======================================================================= -// name : VisuGUI_AxisWg::SetNameFont -// Purpose : -//======================================================================= -bool VisuGUI_AxisWg::ReadData(vtkAxisActor2D* theActor) -{ - if (theActor == 0) - return false; - - // Name - - bool useName = theActor->GetTitleVisibility(); - QString aTitle(theActor->GetTitle()); - - QColor aTitleColor(255, 255, 255); - int aTitleFontFamily = VTK_ARIAL; - bool isTitleBold = false; - bool isTitleItalic = false; - bool isTitleShadow = false; - - vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty(); - if (aTitleProp !=0) - { - float c[ 3 ]; - aTitleProp->GetColor(c); - aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255)); - aTitleFontFamily = aTitleProp->GetFontFamily(); - isTitleBold = aTitleProp->GetBold() ? true : false; - isTitleItalic = aTitleProp->GetItalic() ? true : false; - isTitleShadow = aTitleProp->GetShadow() ? true : false; - } - - myIsNameVisible->setChecked(useName); - myAxisName->setText(aTitle); - myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow); - - // Labels - - bool useLabels = theActor->GetLabelVisibility(); - int nbLabels = theActor->GetNumberOfLabels(); - int anOffset = theActor->GetTickOffset(); - - QColor aLabelsColor(255, 255, 255); - int aLabelsFontFamily = VTK_ARIAL; - bool isLabelsBold = false; - bool isLabelsItalic = false; - bool isLabelsShadow = false; - - vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty(); - if (aLabelsProp !=0) - { - float c[ 3 ]; - aLabelsProp->GetColor(c); - aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255)); - aLabelsFontFamily = aLabelsProp->GetFontFamily(); - isLabelsBold = aLabelsProp->GetBold() ? true : false; - isLabelsItalic = aLabelsProp->GetItalic() ? true : false; - isLabelsShadow = aLabelsProp->GetShadow() ? true : false; - } - - myIsLabelsVisible->setChecked(useLabels); - myLabelNumber->setText(QString("%1").arg(nbLabels)); - myLabelOffset->setText(QString("%1").arg(anOffset)); - myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow); - - // Tick marks - bool useTickMarks = theActor->GetTickVisibility(); - int aTickLength = theActor->GetTickLength(); - - myIsTicksVisible->setChecked(useTickMarks); - myTickLength->setText(QString("%1").arg(aTickLength)); - - return true; -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::Apply -// Purpose : -//======================================================================= -bool VisuGUI_AxisWg::Apply(vtkAxisActor2D* theActor) -{ - if (theActor == 0) - return false; - - // Name - - theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0); - theActor->SetTitle(myAxisName->text().latin1()); - - QColor aTitleColor(255, 255, 255); - int aTitleFontFamily = VTK_ARIAL; - bool isTitleBold = false; - bool isTitleItalic = false; - bool isTitleShadow = false; - - myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow); - vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty(); - if (aTitleProp) - { - aTitleProp->SetColor(aTitleColor.red() / 255., - aTitleColor.green() / 255., - aTitleColor.blue() / 255.); - aTitleProp->SetFontFamily(aTitleFontFamily); - - aTitleProp->SetBold(isTitleBold ? 1 : 0); - aTitleProp->SetItalic(isTitleItalic ? 1 : 0); - aTitleProp->SetShadow(isTitleShadow ? 1 : 0); - - theActor->SetTitleTextProperty(aTitleProp); - } - - // Labels - - theActor->SetLabelVisibility(myIsLabelsVisible->isChecked() ? 1 : 0); - - bool isOk = false; - int nbLabels = myLabelNumber->text().toInt(&isOk); - if (isOk) - theActor->SetNumberOfLabels(nbLabels); - - int anOffset = myLabelOffset->text().toInt(&isOk); - if (isOk) - theActor->SetTickOffset(anOffset); - - QColor aLabelsColor(255, 255, 255); - int aLabelsFontFamily = VTK_ARIAL; - bool isLabelsBold = false; - bool isLabelsItalic = false; - bool isLabelsShadow = false; - - myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow); - vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty(); - if (aLabelsProp) - { - aLabelsProp->SetColor(aLabelsColor.red() / 255., - aLabelsColor.green() / 255., - aLabelsColor.blue() / 255.); - aLabelsProp->SetFontFamily(aLabelsFontFamily); - - aLabelsProp->SetBold(isLabelsBold ? 1 : 0); - aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0); - aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0); - - aLabelsProp->Modified(); - theActor->SetLabelTextProperty(aLabelsProp); - } - - - // Tick marks - theActor->SetTickVisibility(myIsTicksVisible->isChecked()); - int aTickLength = myTickLength->text().toInt(&isOk); - if (isOk) - theActor->SetTickLength(aTickLength); - - return true; -} - -/* - Class : VisuGUI_CubeAxesDlg - Description : Dialog for specifynig cube axes properties -*/ - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::VisuGUI_CubeAxesDlg -// Purpose : Constructor -//======================================================================= -VisuGUI_CubeAxesDlg::VisuGUI_CubeAxesDlg(QWidget* theParent) -: QDialog(theParent, "VisuGUI_CubeAxesDlg", false, - WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose) -{ - setCaption(tr("CAPTION")); - - QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5); - aLay->addWidget(createMainFrame(this)); - aLay->addWidget(createButtonFrame(this)); - - Init(); - -//if (VISU::GetDesktop()->getMainFrame()) -// connect(VISU::GetDesktop()->getMainFrame(), SIGNAL(windowActivated(QWidget*)), -// SLOT(onWindowActivated(QWidget*))); -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::createMainFrame -// Purpose : Create frame containing dialog's input fields -//======================================================================= -QWidget* VisuGUI_CubeAxesDlg::createMainFrame(QWidget* theParent) -{ - QFrame* aFrame = new QFrame(theParent); - - myTabWg = new QTabWidget(aFrame); - - myAxes[ 0 ] = new VisuGUI_AxisWg(myTabWg); - myAxes[ 1 ] = new VisuGUI_AxisWg(myTabWg); - myAxes[ 2 ] = new VisuGUI_AxisWg(myTabWg); - - myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS")); - myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS")); - myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS")); - - myTabWg->setMargin(5); - - myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame); - - QVBoxLayout* aLay = new QVBoxLayout(aFrame, 0, 5); - aLay->addWidget(myTabWg); - aLay->addWidget(myIsVisible); - - return aFrame; -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::createButtonFrame -// Purpose : Create frame containing buttons -//======================================================================= -QWidget* VisuGUI_CubeAxesDlg::createButtonFrame(QWidget* theParent) -{ - QFrame* aFrame = new QFrame(theParent); - aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken); - - myOkBtn = new QPushButton(tr("BUT_OK"), aFrame); - myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame); - myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame); - - QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); - - QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5); - - aLay->addWidget(myOkBtn); - aLay->addWidget(myApplyBtn); - aLay->addItem(aSpacer); - aLay->addWidget(myCloseBtn); - - connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk())); - connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply())); - connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose())); - - return aFrame; -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::~VisuGUI_CubeAxesDlg -// Purpose : Destructor -//======================================================================= -VisuGUI_CubeAxesDlg::~VisuGUI_CubeAxesDlg() -{ -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::Init -// Purpose : Init dialog fields, connect signals and slots, show dialog -//======================================================================= -bool VisuGUI_CubeAxesDlg::Init() -{ - SVTK_ViewWindow* aFrame = VISU::GetViewWindow(); - if (aFrame == 0) - return false; - - SVTK_CubeAxesActor2D* anActor = aFrame->GetCubeAxes(); - if (anActor == 0) - return false; - - myAxes[ 0 ]->ReadData(anActor->GetXAxisActor2D()); - myAxes[ 1 ]->ReadData(anActor->GetYAxisActor2D()); - myAxes[ 2 ]->ReadData(anActor->GetZAxisActor2D()); - - myIsVisible->setChecked(anActor->GetVisibility() ? true : false); - - return true; - -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::isValid -// Purpose : Verify validity of entry data -//======================================================================= -bool VisuGUI_CubeAxesDlg::isValid() const -{ - return true; -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::onApply -// Purpose : Verify validity of entry data -//======================================================================= -bool VisuGUI_CubeAxesDlg::onApply() -{ - bool isOk = true; - - try - { - SVTK_ViewWindow* aFrame = VISU::GetViewWindow(); - if (aFrame == 0) - return false; - - SVTK_CubeAxesActor2D* anActor = aFrame->GetCubeAxes(); - if (anActor == 0) - return false; - - isOk = isOk && myAxes[ 0 ]->Apply(anActor->GetXAxisActor2D()); - isOk = isOk && myAxes[ 1 ]->Apply(anActor->GetYAxisActor2D()); - isOk = isOk && myAxes[ 2 ]->Apply(anActor->GetZAxisActor2D()); - - - //anActor->SetXLabel(myAxes[ 0 ]->myAxisName->text()); - //anActor->SetYLabel(myAxes[ 1 ]->myAxisName->text()); - //anActor->SetZLabel(myAxes[ 2 ]->myAxisName->text()); - - //anActor->SetNumberOfLabels(anActor->GetXAxisActor2D()->GetNumberOfLabels()); - if (myIsVisible->isChecked()) - anActor->VisibilityOn(); - else - anActor->VisibilityOff(); - - if (isOk) - aFrame->Repaint(); - } - catch(...) - { - isOk = false; - } - - return isOk; -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::onOk -// Purpose : SLOT called when "Ok" button pressed. -//======================================================================= -void VisuGUI_CubeAxesDlg::onOk() -{ - if (onApply()) - onClose(); -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::onClose -// Purpose : SLOT called when "Close" button pressed. Close dialog -//======================================================================= -void VisuGUI_CubeAxesDlg::onClose() -{ - reject(); -} - -//======================================================================= -// name : VisuGUI_CubeAxesDlg::onClose -// Purpose : SLOT called when "Close" button pressed. Close dialog -//======================================================================= -void VisuGUI_CubeAxesDlg::onWindowActivated (QWidget*) -{ - SVTK_ViewWindow* aFrame = VISU::GetViewWindow(); - if (aFrame) - Init(); - else - onClose(); -} diff --git a/src/VISUGUI/VisuGUI_CubeAxesDlg.h b/src/VISUGUI/VisuGUI_CubeAxesDlg.h deleted file mode 100755 index 59bcbb0c..00000000 --- a/src/VISUGUI/VisuGUI_CubeAxesDlg.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : VisuGUI_CubeAxesDlg.h -// Author : Sergey LITONIN -// Module : VISU - - -#ifndef VisuGUI_CubeAxesDlg_H -#define VisuGUI_CubeAxesDlg_H - -#include -#include - -class QWidget; -class QFrame; -class QPushButton; -class QTabWidget; -class QCheckBox; -class QLineEdit; -class VisuGUI_FontWg; -class QGroupBox; -class VisuGUI_AxisWg; -class vtkAxisActor2D; - -/*! - * Class : VisuGUI_CubeAxesDlg - * Description : Dialog for specifynig cube axes properties - */ -class VisuGUI_CubeAxesDlg : public QDialog -{ - Q_OBJECT - -public: - VisuGUI_CubeAxesDlg( QWidget* ); - virtual ~VisuGUI_CubeAxesDlg(); - - bool Init(); - -private slots: - void onOk(); - bool onApply(); - void onClose(); - - void onWindowActivated( QWidget* ); - -private: - QWidget* createButtonFrame( QWidget* ); - QWidget* createMainFrame ( QWidget* ); - bool isValid() const; - -private: - QTabWidget* myTabWg; - QCheckBox* myIsVisible; - - QPushButton* myOkBtn; - QPushButton* myApplyBtn; - QPushButton* myCloseBtn; - VisuGUI_AxisWg* myAxes[ 3 ]; -}; - -/*! - * Class : VisuGUI_AxisWg - * Description : Tab of dialog - */ -class VisuGUI_AxisWg : public QFrame -{ - Q_OBJECT - -public: - VisuGUI_AxisWg( QWidget* ); - ~VisuGUI_AxisWg(); - - void UseName( const bool ); - void SetName( const QString& ); - void SetNameFont( const QColor&, const int, const bool, const bool, const bool ); - bool ReadData( vtkAxisActor2D* ); - bool Apply( vtkAxisActor2D* ); - -protected: - bool eventFilter(QObject*, QEvent*); - -private slots: - void onNameChecked(); - void onLabelsChecked(); - void onTicksChecked(); - -private: - void updateControlState(); - void setEnabled( QGroupBox*, const bool ); - -private: - // name - QGroupBox* myNameGrp; - QCheckBox* myIsNameVisible; - QLineEdit* myAxisName; - VisuGUI_FontWg* myNameFont; - - // labels - QGroupBox* myLabelsGrp; - QCheckBox* myIsLabelsVisible; - QLineEdit* myLabelNumber; - QLineEdit* myLabelOffset; - VisuGUI_FontWg* myLabelsFont; - - // tick marks - QGroupBox* myTicksGrp; - QCheckBox* myIsTicksVisible; - QLineEdit* myTickLength; - - friend class VisuGUI_CubeAxesDlg; -}; - -#endif diff --git a/src/VISUGUI/VisuGUI_Displayer.cxx b/src/VISUGUI/VisuGUI_Displayer.cxx index 68d8f28b..1fa6f098 100644 --- a/src/VISUGUI/VisuGUI_Displayer.cxx +++ b/src/VISUGUI/VisuGUI_Displayer.cxx @@ -27,6 +27,7 @@ // $Header: /home/server/cvs/VISU/VISU_SRC/src/VISUGUI/VisuGUI_Displayer.cxx #include "VisuGUI_Displayer.h" +#include "VVTK_ViewModel.h" #include "VisuGUI_Tools.h" #include "VISU_Actor.h" @@ -69,7 +70,8 @@ SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& entry, SALOME_V SVTK_Viewer* vtk_viewer = dynamic_cast( aViewFrame ); if( vtk_viewer ) { - SVTK_ViewWindow* wnd = dynamic_cast( vtk_viewer->getViewManager()->getActiveView() ); + SVTK_ViewWindow* wnd = + dynamic_cast( vtk_viewer->getViewManager()->getActiveView() ); if( wnd ) { VISU::Prs3d_i* thePrs = dynamic_cast( VISU::GetServant( anObj ).in() ); @@ -84,7 +86,8 @@ SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& entry, SALOME_V SPlot2d_Viewer* plot_viewer = dynamic_cast( aViewFrame ); if( plot_viewer ) { - Plot2d_ViewWindow* wnd = dynamic_cast( plot_viewer->getViewManager()->getActiveView() ); + Plot2d_ViewWindow* wnd = + dynamic_cast( plot_viewer->getViewManager()->getActiveView() ); if( !wnd ) return 0; @@ -116,11 +119,9 @@ void VisuGUI_Displayer::buildPrs3d( SVTK_ViewWindow* wnd, VISU::Prs3d_i* thePrs VISU_Actor* newAct = VISU::FindActor( wnd, thePrs ); if( !newAct ) { - VISU_Actor* a = thePrs->CreateActor(); - if( a ) - newAct = a->GetParent(); + newAct = thePrs->CreateActor(); } - if( newAct && newAct ) + if( newAct ) { wnd->AddActor( newAct ); wnd->Repaint(); @@ -227,7 +228,7 @@ bool VisuGUI_Displayer::canBeDisplayed( const QString& entry, const QString& vie if( study->isComponent( entry ) ) return true; - if( viewer_type==SVTK_Viewer::Type() ) + if( viewer_type==SVTK_Viewer::Type() || viewer_type==VVTK_Viewer::Type()) { VISU::Prs3d_i* thePrs = dynamic_cast( VISU::GetServant( anObj ).in() ); return thePrs; diff --git a/src/VISUGUI/VisuGUI_Factory.cxx b/src/VISUGUI/VisuGUI_Factory.cxx index 24ea841b..fea679cb 100644 --- a/src/VISUGUI/VisuGUI_Factory.cxx +++ b/src/VISUGUI/VisuGUI_Factory.cxx @@ -26,7 +26,7 @@ // Module : VISU // $Header$ -#include "VisuGUI.h" +#include "VisuGUI_Module.h" #include "CAM_Module.h" @@ -34,7 +34,7 @@ extern "C" { CAM_Module* createModule() { - return new VisuGUI(); + return new VisuGUI_Module(); } } diff --git a/src/VISUGUI/VisuGUI_FontWg.cxx b/src/VISUGUI/VisuGUI_FontWg.cxx deleted file mode 100755 index 78d62a1c..00000000 --- a/src/VISUGUI/VisuGUI_FontWg.cxx +++ /dev/null @@ -1,149 +0,0 @@ -// VISU VISUGUI : GUI for SMESH component -// -// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : VisuGUI_CubeAxesDlg.cxx -// Author : Sergey LITONIN -// Module : VISU - -#include "VisuGUI_FontWg.h" - -#include -#include -#include -#include - -#include - -/*! - * Class : VisuGUI_FontWg - * Description : Dialog for specifynig font - */ - -//======================================================================= -// name : VisuGUI_FontWg -// Purpose : Constructor -//======================================================================= -VisuGUI_FontWg::VisuGUI_FontWg( QWidget* theParent ) -: QHBox( theParent ) -{ - setSpacing( 5 ); - myColorBtn = new QToolButton( this ); - myColorBtn->setMinimumWidth( 20 ); - - myFamily = new QComboBox( this ); - myFamily->insertItem( tr( "ARIAL" ) ); - myFamily->insertItem( tr( "COURIER" ) ); - myFamily->insertItem( tr( "TIMES" ) ); - - myBold = new QCheckBox( tr( "BOLD" ), this ); - myItalic = new QCheckBox( tr( "ITALIC" ), this ); - myShadow = new QCheckBox( tr( "SHADOW" ), this ); - - connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) ); -} - -//======================================================================= -// name : ~VisuGUI_FontWg -// Purpose : Destructor -//======================================================================= -VisuGUI_FontWg::~VisuGUI_FontWg() -{ -} - -//======================================================================= -// name : SetColor -// Purpose : -//======================================================================= -void VisuGUI_FontWg::SetColor( const QColor& theColor ) -{ - myColorBtn->setPaletteBackgroundColor( theColor ); -} - -//======================================================================= -// name : GetColor -// Purpose : -//======================================================================= -QColor VisuGUI_FontWg::GetColor() const -{ - return myColorBtn->paletteBackgroundColor(); -} - -//======================================================================= -// name : onColor -// Purpose : -//======================================================================= -void VisuGUI_FontWg::onColor() -{ - QColor aColor = QColorDialog::getColor( GetColor(), this ); - if ( aColor.isValid() ) - SetColor( aColor ); -} - -//======================================================================= -// name : SetData -// Purpose : -//======================================================================= -void VisuGUI_FontWg::SetData( const QColor& theColor, - const int theFamily, - const bool theBold, - const bool theItalic, - const bool theShadow ) -{ - SetColor( theColor ); - - if ( theFamily == VTK_ARIAL ) - myFamily->setCurrentItem( 0 ); - else if ( theFamily == VTK_COURIER ) - myFamily->setCurrentItem( 1 ); - else - myFamily->setCurrentItem( 2 ); - - myBold->setChecked( theBold ); - myItalic->setChecked( theItalic ); - myShadow->setChecked( theShadow ); -} - -//======================================================================= -// name : GetData -// Purpose : -//======================================================================= -void VisuGUI_FontWg::GetData( QColor& theColor, - int& theFamily, - bool& theBold, - bool& theItalic, - bool& theShadow ) const -{ - theColor = GetColor(); - - int anItem =myFamily->currentItem(); - if ( anItem == 0 ) - theFamily = VTK_ARIAL; - else if ( anItem == 1 ) - theFamily = VTK_COURIER; - else - theFamily = VTK_TIMES; - - theBold = myBold->isChecked(); - theItalic = myItalic->isChecked(); - theShadow = myShadow->isChecked(); -} diff --git a/src/VISUGUI/VisuGUI_FontWg.h b/src/VISUGUI/VisuGUI_FontWg.h deleted file mode 100755 index e3a45ee4..00000000 --- a/src/VISUGUI/VisuGUI_FontWg.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : VisuGUI_FontWg.h -// Author : Sergey LITONIN -// Module : VISU - - -#ifndef VisuGUI_FontWg_H -#define VisuGUI_FontWg_H - -#include - -class QToolButton; -class QComboBox; -class QCheckBox; -class QColor; - - -/*! - * Class : VisuGUI_FontWg - * Description : Dialog for specifynig font - */ -class VisuGUI_FontWg : public QHBox -{ - Q_OBJECT - -public: - VisuGUI_FontWg( QWidget* ); - virtual ~VisuGUI_FontWg(); - - void SetColor( const QColor& ); - QColor GetColor() const; - - void SetData( const QColor&, const int, const bool, const bool, const bool ); - - void GetData( QColor&, int&, bool&, bool&, bool& ) const; - -private slots: - void onColor(); - -private: - QToolButton* myColorBtn; - QComboBox* myFamily; - QCheckBox* myBold; - QCheckBox* myItalic; - QCheckBox* myShadow; -}; - -#endif diff --git a/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx new file mode 100644 index 00000000..7492c7f5 --- /dev/null +++ b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx @@ -0,0 +1,733 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_GaussPointsDlg.cxx +// Author : Oleg UVAROV +// Module : VISU + +#include "VisuGUI_GaussPointsDlg.h" + +#include "VISUConfig.hh" + +#include "VisuGUI_Tools.h" + +#include "VISU_GaussPoints_i.hh" +#include "VISU_GaussPointsPL.hxx" +#include "VISU_OpenGLPointSpriteMapper.hxx" +#include "VISU_Convertor.hxx" + +#include "VVTK_PrimitiveBox.h" +#include "VVTK_SizeBox.h" + +#include "SalomeApp_Application.h" +#include "SalomeApp_Module.h" +#include "SUIT_Desktop.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" +#include "SUIT_MessageBox.h" +#include "SVTK_FontWidget.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace std; + +VisuGUI_GaussScalarBarPane::VisuGUI_GaussScalarBarPane (QWidget * parent, bool SetPref): + QVBox(parent) +{ + myVerX = 0.01; myVerY = 0.10; myVerW = 0.10; myVerH = 0.80; + myHorX = 0.20; myHorY = 0.01; myHorW = 0.60; myHorH = 0.12; + Imin = 0.0; Imax = 0.0; + myRangeMode = -1; + + setSpacing(6); + //setMargin(11); + + // Active bar ======================================================== + QGroupBox* ActiveBarGroup = new QGroupBox (tr("ACTIVE_BAR_GRP"), this, "ActiveBarGroup"); + ActiveBarGroup->setColumnLayout(0, Qt::Vertical ); + ActiveBarGroup->layout()->setSpacing( 0 ); + ActiveBarGroup->layout()->setMargin( 0 ); + QGridLayout* ActiveBarGroupLayout = new QGridLayout( ActiveBarGroup->layout() ); + ActiveBarGroupLayout->setAlignment( Qt::AlignTop ); + ActiveBarGroupLayout->setSpacing( 6 ); + ActiveBarGroupLayout->setMargin( 11 ); + + QButtonGroup* BarTypeGroup = new QButtonGroup( 2, Qt::Vertical, ActiveBarGroup, "BarTypeGroup" ); + BarTypeGroup->setRadioButtonExclusive( true ); + BarTypeGroup->setFrameStyle( QFrame::NoFrame ); + BarTypeGroup->layout()->setMargin( 0 ); + + myRBLocal = new QRadioButton( tr( "LOCAL" ), BarTypeGroup ); + myRBGlobal = new QRadioButton( tr( "GLOBAL" ), BarTypeGroup ); + + myCBDisplayed = new QCheckBox( tr( "DISPLAYED" ), ActiveBarGroup ); + + ActiveBarGroupLayout->addMultiCellWidget( BarTypeGroup, 0, 1, 0, 0 ); + ActiveBarGroupLayout->addWidget( myCBDisplayed, 1, 1 ); + + // Range ============================================================ + RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup"); + RangeGroup->setColumnLayout(0, Qt::Vertical ); + RangeGroup->layout()->setSpacing( 0 ); + RangeGroup->layout()->setMargin( 0 ); + QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() ); + RangeGroupLayout->setAlignment( Qt::AlignTop ); + RangeGroupLayout->setSpacing( 6 ); + RangeGroupLayout->setMargin( 11 ); + + myModeLbl = new QLabel("Scalar Mode", RangeGroup); + + myModeCombo = new QComboBox(RangeGroup); + + RangeGroupLayout->addWidget( myModeLbl, 0, 0 ); + RangeGroupLayout->addWidget( myModeCombo, 0, 1 ); + + //TopLayout->addWidget( RangeGroup ); + + // Colors and Labels ======================================================== + QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup"); + ColLabGroup->setColumnLayout(0, Qt::Vertical ); + ColLabGroup->layout()->setSpacing( 0 ); + ColLabGroup->layout()->setMargin( 0 ); + QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() ); + ColLabGroupLayout->setAlignment( Qt::AlignTop ); + ColLabGroupLayout->setSpacing( 6 ); + ColLabGroupLayout->setMargin( 11 ); + + QButtonGroup* TypeGroup = new QButtonGroup( 2, Qt::Vertical, ColLabGroup, "TypeGroup" ); + TypeGroup->setRadioButtonExclusive( true ); + TypeGroup->setFrameStyle( QFrame::NoFrame ); + TypeGroup->layout()->setMargin( 0 ); + + BicolorButton = new QRadioButton( tr( "BICOLOR" ), TypeGroup ); + RainbowButton = new QRadioButton( tr( "RAINBOW" ), TypeGroup ); + + ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel"); + ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup ); + ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + ColorSpin->setMinimumWidth( 70 ); + ColorSpin->setValue( 64 ); + + LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel"); + LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup ); + LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + LabelSpin->setMinimumWidth( 70 ); + LabelSpin->setValue( 5 ); + + ColLabGroupLayout->addMultiCellWidget( TypeGroup, 0, 1, 0, 0); + ColLabGroupLayout->addWidget( ColorLabel, 1, 1); + ColLabGroupLayout->addWidget( ColorSpin, 1, 2); + ColLabGroupLayout->addWidget( LabelLabel, 1, 3); + ColLabGroupLayout->addWidget( LabelSpin, 1, 4); + + //TopLayout->addWidget( ColLabGroup ); + + // Orientation ========================================================== + QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup"); + OrientGroup->setColumnLayout(0, Qt::Vertical ); + OrientGroup->layout()->setSpacing( 0 ); + OrientGroup->layout()->setMargin( 0 ); + QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() ); + OrientGroupLayout->setAlignment( Qt::AlignTop ); + OrientGroupLayout->setSpacing( 6 ); + OrientGroupLayout->setMargin( 11 ); + + RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert"); + RBvert->setChecked( true ); + RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori"); + OrientGroupLayout->addWidget( RBvert, 0, 0 ); + OrientGroupLayout->addWidget( RBhori, 0, 1 ); + + // TopLayout->addWidget( OrientGroup ); + + // Origin =============================================================== + QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup"); + OriginGroup->setColumnLayout(0, Qt::Vertical ); + OriginGroup->layout()->setSpacing( 0 ); + OriginGroup->layout()->setMargin( 0 ); + QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() ); + OriginGroupLayout->setAlignment( Qt::AlignTop ); + OriginGroupLayout->setSpacing( 6 ); + OriginGroupLayout->setMargin( 11 ); + + QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel"); + XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup ); + XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + XSpin->setMinimumWidth( 70 ); + XSpin->setValue( 0.01 ); + + QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel"); + YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup ); + YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + YSpin->setMinimumWidth( 70 ); + YSpin->setValue( 0.01 ); + + OriginGroupLayout->addWidget( XLabel, 0, 0); + OriginGroupLayout->addWidget( XSpin, 0, 1); + OriginGroupLayout->addWidget( YLabel, 0, 2); + OriginGroupLayout->addWidget( YSpin, 0, 3); + + //TopLayout->addWidget( OriginGroup ); + + // Dimensions ========================================================= + QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup"); + DimGroup->setColumnLayout(0, Qt::Vertical ); + DimGroup->layout()->setSpacing( 0 ); + DimGroup->layout()->setMargin( 0 ); + QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() ); + DimGroupLayout->setAlignment( Qt::AlignTop ); + DimGroupLayout->setSpacing( 6 ); + DimGroupLayout->setMargin( 11 ); + + QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel"); + WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup ); + WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + WidthSpin->setMinimumWidth( 70 ); + WidthSpin->setValue( 0.1 ); + + QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel"); + HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup ); + HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + HeightSpin->setMinimumWidth( 70 ); + HeightSpin->setValue( 0.8 ); + + QLabel* SpacingLabel = new QLabel (tr("LBL_SPACING"), DimGroup, "SpacingLabel"); + SpacingSpin = new QtxDblSpinBox( 0.0, 1.0, 0.01, DimGroup ); + SpacingSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + SpacingSpin->setMinimumWidth( 70 ); + SpacingSpin->setValue( 0.01 ); + + DimGroupLayout->addWidget( WidthLabel, 0, 0); + DimGroupLayout->addWidget( WidthSpin, 0, 1); + DimGroupLayout->addWidget( HeightLabel, 0, 2); + DimGroupLayout->addWidget( HeightSpin, 0, 3); + DimGroupLayout->addWidget( SpacingLabel, 0, 4); + DimGroupLayout->addWidget( SpacingSpin, 0, 5); + + //TopLayout->addWidget( DimGroup ); + + // Save check box =========================================================== + QHBox* aSaveBox = new QHBox(this); + if (!SetPref) { + CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave"); + //TopLayout->addWidget(CBSave); + } + else { + CBSave = 0; + } + myTextBtn = new QPushButton("Text properties...", aSaveBox); + myTextDlg = new VisuGUI_TextPrefDlg(this); + myTextDlg->setTitleVisible(!SetPref); + + // signals and slots connections =========================================== + connect( myRBLocal, SIGNAL( toggled( bool ) ), myCBDisplayed, SLOT( setEnabled( bool ) ) ); + connect( myRBGlobal, SIGNAL( clicked() ), this, SLOT( onSetDisplayGlobal() ) ); + connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorLabel, SLOT( setEnabled( bool ) ) ); + connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorSpin, SLOT( setEnabled( bool ) ) ); + connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelLabel, SLOT( setEnabled( bool ) ) ); + connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelSpin, SLOT( setEnabled( bool ) ) ); + connect( OrientGroup, SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) ); + connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) ); + connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) ); + connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) ); + + changeDefaults( 0 ); + myIsStoreTextProp = false; +} + +void VisuGUI_GaussScalarBarPane::onSetDisplayGlobal() +{ + myCBDisplayed->setChecked( true ); +} + + +/** + * Initialise dialog box from presentation object + */ +void VisuGUI_GaussScalarBarPane::initFromPrsObject(VISU::GaussPoints_i* thePrs) { + myModeCombo->setCurrentItem(thePrs->GetScalarMode()); + setPosAndSize( thePrs->GetPosX(), + thePrs->GetPosY(), + thePrs->GetWidth(), + thePrs->GetHeight(), + thePrs->GetBarOrientation()); + + SpacingSpin->setValue(thePrs->GetSpacing()); + + bool activeLocal = thePrs->GetIsActiveLocalScalarBar(); + myRBLocal->setChecked( activeLocal ); + + myRBGlobal->setChecked( !activeLocal ); + myRBGlobal->setEnabled( thePrs->IsGlobalRangeDefined() ); + if( !thePrs->IsGlobalRangeDefined() ) + myRBLocal->setChecked( true ); + + myCBDisplayed->setEnabled( activeLocal ); + myCBDisplayed->setChecked( thePrs->GetIsDispGlobalScalarBar() ); + + bool bicolor = thePrs->GetGaussPointsPL()->GetBicolor(); + BicolorButton->setChecked( bicolor ); + RainbowButton->setChecked( !bicolor ); + ColorLabel->setEnabled( !bicolor ); + ColorSpin->setEnabled( !bicolor ); + LabelLabel->setEnabled( !bicolor ); + LabelSpin->setEnabled( !bicolor ); + + setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() ); + + // Update myModeCombo + int aNbComp = thePrs->GetField()->myNbComp; + bool isScalarMode = (aNbComp > 1); + myModeCombo->clear(); + myModeCombo->insertItem(""); + const VISU::PField& aField = thePrs->GetField(); + const VISU::TNames& aCompNames = aField->myCompNames; + const VISU::TNames& aUnitNames = aField->myUnitNames; + for(int i = 0; i < aNbComp; i++){ + QString aComponent = QString(aCompNames[i]).simplifyWhiteSpace(); + if(aComponent.isNull() || aComponent == "") + aComponent = "Component " + QString::number(i+1); + else + aComponent = "[" + QString::number(i+1) + "] " + aComponent; + + QString anUnit = QString(aUnitNames[i]).simplifyWhiteSpace(); + if(anUnit.isNull() || anUnit == "") + anUnit = "-"; + + aComponent = aComponent + ", " + anUnit; + + myModeCombo->insertItem(aComponent); + } + // + myModeCombo->setCurrentItem(thePrs->GetScalarMode()); + if (aNbComp==1){ + myModeCombo->setCurrentItem(1); + } + // + myModeLbl->setEnabled(isScalarMode); + myModeCombo->setEnabled(isScalarMode); + + // "Title" + myTextDlg->setTitleText(QString(thePrs->GetTitle())); + + float R, G, B; + thePrs->GetTitleColor(&R, &G, &B); + + myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)), + thePrs->GetTitFontType(), + thePrs->IsBoldTitle(), + thePrs->IsItalicTitle(), + thePrs->IsShadowTitle()); + + // "Labels" + thePrs->GetLabelColor(&R, &G, &B); + + myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)), + thePrs->GetLblFontType(), + thePrs->IsBoldLabel(), + thePrs->IsItalicLabel(), + thePrs->IsShadowLabel()); +} + +/** + * Store values to presentation object + */ +int VisuGUI_GaussScalarBarPane::storeToPrsObject(VISU::GaussPoints_i* thePrs) { + thePrs->SetScalarMode(myModeCombo->currentItem()); + thePrs->SetPosition(XSpin->value(), YSpin->value()); + thePrs->SetSize(WidthSpin->value(), HeightSpin->value()); + thePrs->SetSpacing(SpacingSpin->value()); + thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL); + thePrs->SetIsActiveLocalScalarBar(myRBLocal->isChecked()); + thePrs->SetIsDispGlobalScalarBar(myCBDisplayed->isChecked()); + thePrs->SetNbColors(ColorSpin->value()); + thePrs->SetLabels(LabelSpin->value()); + + thePrs->GetGaussPointsPL()->SetBicolor(BicolorButton->isChecked()); + + //if (isToSave()) storeToResources(); + + if (myIsStoreTextProp) { + // "Title" + thePrs->SetTitle(myTextDlg->getTitleText().latin1()); + + QColor aTitColor (255, 255, 255); + int aTitleFontFamily = VTK_ARIAL; + bool isTitleBold = false; + bool isTitleItalic = false; + bool isTitleShadow = false; + + myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily, + isTitleBold, isTitleItalic, isTitleShadow); + + thePrs->SetBoldTitle(isTitleBold); + thePrs->SetItalicTitle(isTitleItalic); + thePrs->SetShadowTitle(isTitleShadow); + thePrs->SetTitFontType(aTitleFontFamily); + thePrs->SetTitleColor(aTitColor.red()/255., + aTitColor.green()/255., + aTitColor.blue()/255.); + + // "Label" + QColor aLblColor (255, 255, 255); + int aLabelFontFamily = VTK_ARIAL; + bool isLabelBold = false; + bool isLabelItalic = false; + bool isLabelShadow = false; + + myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily, + isLabelBold, isLabelItalic, isLabelShadow); + + thePrs->SetBoldLabel(isLabelBold); + thePrs->SetItalicLabel(isLabelItalic); + thePrs->SetShadowLabel(isLabelShadow); + thePrs->SetLblFontType(aLabelFontFamily); + thePrs->SetLabelColor(aLblColor.red()/255., + aLblColor.green()/255., + aLblColor.blue()/255.); + } + + return 1; +} + +/*! + Called when orientation is changed +*/ +void VisuGUI_GaussScalarBarPane::changeDefaults( int ) +{ + if ( RBvert->isChecked() ) { + XSpin->setValue( myVerX ); + YSpin->setValue( myVerY ); + WidthSpin->setValue( myVerW ); + HeightSpin->setValue( myVerH ); + } + else { + XSpin->setValue( myHorX ); + YSpin->setValue( myHorY ); + WidthSpin->setValue( myHorW ); + HeightSpin->setValue( myHorH ); + } +} + +/*! + Called when X,Y position is changed +*/ +void VisuGUI_GaussScalarBarPane::XYChanged( double ) +{ + QtxDblSpinBox* snd = (QtxDblSpinBox*)sender(); + if ( snd == XSpin ) { + WidthSpin->setMaxValue( 1.0 - XSpin->value() ); + } + if ( snd == YSpin ) { + HeightSpin->setMaxValue( 1.0 - YSpin->value() ); + } +} + +/*! + Sets size and position +*/ +void VisuGUI_GaussScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert ) +{ + if ( vert ) { + myVerX = x; + myVerY = y; + myVerW = w; + myVerH = h; + RBvert->setChecked( true ); + } + else { + myHorX = x; + myHorY = y; + myHorW = w; + myHorH = h; + RBhori->setChecked( true ); + } + changeDefaults( 0 ); +} + +/*! + Sets colors and labels number +*/ +void VisuGUI_GaussScalarBarPane::setScalarBarData( int colors, int labels ) +{ + ColorSpin->setValue( colors ); + LabelSpin->setValue( labels ); +} + +/*! + Gets orientation +*/ +int VisuGUI_GaussScalarBarPane::getOrientation() +{ + if (RBvert->isChecked() ) + return 1; + else + return 0; +} + + +void VisuGUI_GaussScalarBarPane::onTextPref() +{ + myIsStoreTextProp = myTextDlg->exec(); +} + + +/*! + * Constructor + */ +VisuGUI_GaussPointsDlg::VisuGUI_GaussPointsDlg(SalomeApp_Module* theModule, bool SetPref): + QDialog(VISU::GetDesktop(theModule), + "VisuGUI_GaussPointsDlg", true, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myPrs(NULL) +{ + setName("VisuGUI_ScalarBarDlg"); + setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE")); + setSizeGripEnabled(TRUE); + + QVBoxLayout* TopLayout = new QVBoxLayout(this); + TopLayout->setSpacing(6); + TopLayout->setMargin(11); + + + // Presentation + QButtonGroup* PrsGroup = new QButtonGroup( 3, Qt::Horizontal, tr( "PRS_TITLE" ), this, "PrimitiveTypeGroup" ); + PrsGroup->setRadioButtonExclusive( true ); + PrsGroup->layout()->setMargin( 11 ); + PrsGroup->layout()->setSpacing(6); + + myResultsButton = new QRadioButton( tr( "RESULTS" ), PrsGroup ); + myGeometryButton = new QRadioButton( tr( "GEOMETRY" ), PrsGroup ); + myDefShapeButton = new QRadioButton( tr( "DEFORMED_SHAPE" ), PrsGroup ); + + QTabWidget* aTabBox = new QTabWidget (this); + + // Gauss points pane + QVBox* aBox = new QVBox (this); + aBox->setMargin(11); + aBox->setSpacing(6); + + // Primitive + myPrimitiveBox = new VVTK_PrimitiveBox( aBox ); + + // Size + mySizeBox = new VVTK_SizeBox( aBox ); + + // Deformed Shape + myDefShapeBox = new QGroupBox( tr( "DEFORMED_SHAPE_TITLE" ), aBox ); + myDefShapeBox->setColumnLayout(0, Qt::Vertical ); + myDefShapeBox->layout()->setSpacing( 0 ); + myDefShapeBox->layout()->setMargin( 0 ); + + QGridLayout* aDefShapeLayout = new QGridLayout( myDefShapeBox->layout() ); + aDefShapeLayout->setAlignment(Qt::AlignTop); + aDefShapeLayout->setSpacing(6); + aDefShapeLayout->setMargin(11); + + QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox ); + myScaleSpinBox = new QtxDblSpinBox( 0.0, 10.0, 0.1, myDefShapeBox ); + + aDefShapeLayout->addWidget( aScaleLabel, 0, 0 ); + aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 ); + + // Scalar Bar pane + myScalarPane = new VisuGUI_GaussScalarBarPane(this, SetPref); + myScalarPane->setMargin(5); + + + connect( myResultsButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleResults() ) ); + connect( myResultsButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) ); + connect( myGeometryButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleGeometry() ) ); + connect( myDefShapeButton, SIGNAL( toggled( bool ) ), this, SLOT( onToggleDefShape( bool ) ) ); + connect( myDefShapeButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) ); + + aTabBox->addTab(aBox, tr("GAUSS_POINTS_TAB")); + aTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB")); + + // Common buttons =========================================================== + QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); + GroupButtons->setColumnLayout(0, Qt::Vertical ); + GroupButtons->layout()->setSpacing( 0 ); + GroupButtons->layout()->setMargin( 0 ); + QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setSpacing( 6 ); + GroupButtonsLayout->setMargin( 11 ); + + QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" ); + buttonOk->setAutoDefault( TRUE ); + buttonOk->setDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonOk, 0, 0 ); + GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" ); + buttonCancel->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonCancel, 0, 2 ); + + TopLayout->addWidget( PrsGroup ); + TopLayout->addWidget( aTabBox ); + TopLayout->addWidget( GroupButtons ); + + connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + +void VisuGUI_GaussPointsDlg::initFromPrsObject( VISU::GaussPoints_i* thePrs ) +{ + bool isDeformed = thePrs->GetIsDeformed(); + myScaleSpinBox->setValue( thePrs->GetScaleFactor() ); + myDefShapeButton->setChecked( isDeformed ); + myDefShapeButton->setEnabled( thePrs->GetField()->myNbComp > 1 ); + onToggleDefShape( isDeformed ); + + bool isResults = thePrs->GetIsColored(); + myResultsButton->setChecked( isResults && !isDeformed ); + myGeometryButton->setChecked( !isResults && !isDeformed ); + + myPrimitiveBox->setPrimitiveType( thePrs->GetPrimitiveType() ); + myPrimitiveBox->setClampMaximum( thePrs->GetMaximumSupportedSize() ); + myPrimitiveBox->setClamp( thePrs->GetClamp() ); + myPrimitiveBox->setMainTexture( thePrs->GetMainTexture() ); + myPrimitiveBox->setAlphaTexture( thePrs->GetAlphaTexture() ); + myPrimitiveBox->setAlphaThreshold( thePrs->GetAlphaThreshold() ); + myPrimitiveBox->setResolution( thePrs->GetResolution() ); + myPrimitiveBox->setFaceLimit( thePrs->GetFaceLimit() ); + + mySizeBox->setType( isResults || isDeformed ? VVTK_SizeBox::Results : VVTK_SizeBox::Geometry ); + mySizeBox->setGeomSize( thePrs->GetGeomSize() ); + mySizeBox->setMinSize( thePrs->GetMinSize() ); + mySizeBox->setMaxSize( thePrs->GetMaxSize() ); + mySizeBox->setMagnification( thePrs->GetMagnification() ); + mySizeBox->setIncrement( thePrs->GetMagnificationIncrement() ); + mySizeBox->setColor( thePrs->GetColor() ); + + myScalarPane->initFromPrsObject(thePrs); + + myPrs = thePrs; +} + +int VisuGUI_GaussPointsDlg::storeToPrsObject( VISU::GaussPoints_i* thePrs ) +{ + thePrs->SetIsDeformed( myDefShapeButton->isChecked() ); + thePrs->SetScaleFactor( myScaleSpinBox->value() ); + + thePrs->SetPrimitiveType( myPrimitiveBox->getPrimitiveType() ); + + thePrs->SetClamp( myPrimitiveBox->getClamp() ); + + QString aMainTexture = myPrimitiveBox->getMainTexture(); + QString anAlphaTexture = myPrimitiveBox->getAlphaTexture(); + + aMainTexture = aMainTexture.isNull() ? thePrs->GetMainTexture() : aMainTexture; + anAlphaTexture = anAlphaTexture.isNull() ? thePrs->GetAlphaTexture() : anAlphaTexture; + + thePrs->SetTextures( aMainTexture, anAlphaTexture ); + + thePrs->SetAlphaThreshold( myPrimitiveBox->getAlphaThreshold() ); + + thePrs->SetResolution( myPrimitiveBox->getResolution() ); + thePrs->SetFaceLimit( myPrimitiveBox->getFaceLimit() ); + + bool isColored = !myGeometryButton->isChecked(); + if( isColored ) + { + thePrs->SetIsColored( true ); + thePrs->SetMinSize( mySizeBox->getMinSize() ); + thePrs->SetMaxSize( mySizeBox->getMaxSize() ); + } + else + { + thePrs->SetIsColored( false ); + thePrs->SetColor( mySizeBox->getColor() ); + thePrs->SetGeomSize( mySizeBox->getGeomSize() ); + } + + thePrs->SetMagnification( mySizeBox->getMagnification() ); + thePrs->SetMagnificationIncrement( mySizeBox->getIncrement() ); + + return myScalarPane->storeToPrsObject(thePrs); +} + +void VisuGUI_GaussPointsDlg::onToggleDefShape( bool on ) +{ + if( on )//myDefShapeButton->isChecked() ) + { + myDefShapeBox->show(); + mySizeBox->setType( VVTK_SizeBox::Results ); + } + else + myDefShapeBox->hide(); +} + +void VisuGUI_GaussPointsDlg::accept() +{ + if( myPrs && myPrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere ) + { + int aNumberOfFaces = myPrimitiveBox->getFaceNumber(); + int aNumberOfPoints = ( (vtkPolyData*)myPrs->GetGaussPointsPL()->GetInput() )->GetNumberOfCells(); + + if( aNumberOfFaces * aNumberOfPoints > myPrimitiveBox->getFaceLimit() ) + { + QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n"; + aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" ); + aWarning.append( "Can you please confirm that you want to continue anyway?" ); + if( SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning, tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 1 ) + return; + } + + /* + float aMemory = 50.0 * 1024.0 * (float)aNumberOfFaces * (float)aNumberOfPoints; + + cout << aNumberOfFaces << endl; + cout << aNumberOfPoints << endl; + cout << aMemory << endl; + + vtkSphereSource* aSphere = vtkSphereSource::New(); + aSphere->SetThetaResolution( myPrimitiveBox->getResolution() ); + aSphere->SetPhiResolution( myPrimitiveBox->getResolution() ); + aSphere->GetOutput()->Update(); + aSphere->GetOutput()->GetActualMemorySize(); + + aMemory = aSphere->GetOutput()->GetActualMemorySize() * 1024.0 * (float)aNumberOfPoints; + + if( VISU_PipeLine::CheckAvailableMemory( aMemory ) == 0 ) + { + SUIT_MessageBox::error1( this, "caption", "text", "ok" ); + return 0; + } + */ + } + + //if( myScalarPane->check() ) + QDialog::accept(); +} diff --git a/src/VISUGUI/VisuGUI_GaussPointsDlg.h b/src/VISUGUI/VisuGUI_GaussPointsDlg.h new file mode 100644 index 00000000..c845d013 --- /dev/null +++ b/src/VISUGUI/VisuGUI_GaussPointsDlg.h @@ -0,0 +1,162 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_GaussPointsDlg.h +// Author : Oleg UVAROV +// Module : VISU + +#ifndef VISUGUI_GAUSSPOINTSDLS_H +#define VISUGUI_GAUSSPOINTSDLS_H + +#include "VisuGUI_ScalarBarDlg.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class SalomeApp_Module; +class VVTK_PrimitiveBox; +class VVTK_SizeBox; +class VisuGUI_TextPrefDlg; + +namespace VISU +{ + class GaussPoints_i; +} + +//! Specific Scalar Bar tab. +/*! Uses for set up Gauss Points Scalar Bars preferenses. */ +class VisuGUI_GaussScalarBarPane : public QVBox +{ + Q_OBJECT + + public: + VisuGUI_GaussScalarBarPane(QWidget* parent, bool SetPref); + ~VisuGUI_GaussScalarBarPane() {}; + + int getOrientation(); + void setPosAndSize( double x, double y, double w, double h, bool vert ); + double getX() {return XSpin->value();} + double getY() {return YSpin->value();} + double getWidth() {return WidthSpin->value();} + double getHeight() {return HeightSpin->value();} + void setScalarBarData( int colors, int labels ); + int getNbColors() {return ColorSpin->value();} + int getNbLabels() {return LabelSpin->value();} + bool isToSave() {return CBSave ? CBSave->isChecked() : false;} + + void initFromPrsObject(VISU::GaussPoints_i* thePrs); + int storeToPrsObject(VISU::GaussPoints_i* thePrs); + + protected: + QButtonGroup* RangeGroup; + + QRadioButton* RBhori; + QRadioButton* RBvert; + + QtxDblSpinBox* XSpin; + QtxDblSpinBox* YSpin; + + QtxDblSpinBox* WidthSpin; + QtxDblSpinBox* HeightSpin; + QtxDblSpinBox* SpacingSpin; + + QRadioButton* BicolorButton; + QRadioButton* RainbowButton; + QLabel* ColorLabel; + QSpinBox* ColorSpin; + QLabel* LabelLabel; + QSpinBox* LabelSpin; + + QCheckBox* CBSave; + QLabel* myModeLbl; + QComboBox* myModeCombo; + QPushButton* myTextBtn; + VisuGUI_TextPrefDlg* myTextDlg; + QRadioButton* myRBLocal; + QRadioButton* myRBGlobal; + QCheckBox* myCBDisplayed; + + double Imin, Imax; + double myHorX, myHorY, myHorW, myHorH; + double myVerX, myVerY, myVerW, myVerH; + int myRangeMode; + bool myIsStoreTextProp; + + private slots: + void changeDefaults( int ); + void changeRange( int ); + void XYChanged( double ); + void onTextPref(); + void onSetDisplayGlobal(); +}; + +//! Create Gauss Points Presentation Dialog. +/*! + * Uses for set up initial parameters of the Gauss Points + * presentation and edit them interactively. + */ +class VisuGUI_GaussPointsDlg : public QDialog +{ + Q_OBJECT + +public: + VisuGUI_GaussPointsDlg (SalomeApp_Module* theModule, bool SetPref = FALSE); + ~VisuGUI_GaussPointsDlg() {} + + //! Initializing dialog from the Gauss Points presentation. + void initFromPrsObject(VISU::GaussPoints_i* thePrs); + + //! Update Gauss Points presentation using parameters from the dialog. + int storeToPrsObject(VISU::GaussPoints_i* thePrs); + +protected slots: + void onToggleDefShape( bool ); + + void accept(); + +private: + VISU::GaussPoints_i* myPrs; + VisuGUI_GaussScalarBarPane* myScalarPane; + + QRadioButton* myResultsButton; + QRadioButton* myGeometryButton; + QRadioButton* myDefShapeButton; + + VVTK_PrimitiveBox* myPrimitiveBox; + VVTK_SizeBox* mySizeBox; + + QGroupBox* myDefShapeBox; + QtxDblSpinBox* myScaleSpinBox; +}; + +#endif // VISUGUI_GAUSSPOINTSDLS_H diff --git a/src/VISUGUI/VisuGUI_Module.cxx b/src/VISUGUI/VisuGUI_Module.cxx new file mode 100644 index 00000000..2ae2cea1 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Module.cxx @@ -0,0 +1,1660 @@ + +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_Module.cxx +// Author : Laurent CORNABE +// Module : VISU +// $Header$ + +#include "VisuGUI_Module.h" + +#include "QtxPopupMgr.h" + +#include "SUIT_Study.h" +#include "SUIT_Desktop.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_Accel.h" +#include "SUIT_Session.h" + +#include "CAM_Module.h" + +#include "SALOME_Event.hxx" +#include "SalomeApp_Application.h" +#include "LightApp_SelectionMgr.h" +#include "LightApp_VTKSelector.h" +#include "LightApp_Preferences.h" + +#include "VVTK_ViewManager.h" +#include "VVTK_ViewWindow.h" +#include "VVTK_ViewModel.h" + +#include "SVTK_ViewModel.h" +#include "SVTK_ViewManager.h" +#include "SVTK_MainWindow.h" +#include "SVTK_RenderWindowInteractor.h" +#include "VISU_Event.h" + +#include "VisuGUI_Prs3dTools.h" + +#include "VISU_GaussPoints_i.hh" +#include "VISU_GaussPtsAct.h" +#include "VisuGUI_GaussPointsDlg.h" + +#include "VISU_Gen_i.hh" +#include "VISU_Result_i.hh" +#include "VISU_CutLines_i.hh" + +#include "VISU_Actor.h" +#include "VisuGUI_Tools.h" +#include "VisuGUI_ActionsDef.h" + +#include "VISU_WidgetCtrl.hxx" +#include "VISU_PlanesWidget.hxx" +#include "VISU_SphereWidget.hxx" + +#include "SalomeApp_Study.h" +#include "VVTK_MainWindow.h" +#include "VISU_View_i.hh" + +#include + +#include +#include +#include + +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +#define GAUSS_NEW_VIEWER 5100 +#define GAUSS_CREATE_PRS 5200 +#define GAUSS_RENAME 5210 +#define GAUSS_EDIT_PRS 5300 +#define GAUSS_COPY_PRS 5310 +#define GAUSS_ERASE_PRS 5400 +#define GAUSS_DISPLAY_PRS 5500 +#define GAUSS_DISPLAY_ONLY_PRS 5600 + +#define GAUSS_SAVE_CONFIGURATION 5700 +#define GAUSS_OVERWRITE_CONFIGURATION 5701 +#define GAUSS_RESTORE_CONFIGURATION 5702 +#define GAUSS_RENAME_CONFIGURATION 5703 + +void +CreateCurves( SalomeApp_Module* theModule, + VISU::CutLines_i* thePrs, + QDialog* theDlg, + const bool theCreate = true ); + +using namespace VISU; + +namespace VISU +{ + //--------------------------------------------------------------- + class Viewer + { + VVTK_ViewManager* myViewManager; + LightApp_VTKSelector* mySelector; + public: + + Viewer(VisuGUI_Module* theModule, TViewerMap& theViewerMap) + { + SalomeApp_Application* anApp = theModule->getApp(); + myViewManager = new VVTK_ViewManager( anApp->activeStudy(), anApp->desktop() ); + VVTK_Viewer* aViewer = (VVTK_Viewer*)myViewManager->getViewModel(); + mySelector = new LightApp_VTKSelector( aViewer, anApp->selectionMgr() ); + anApp->addViewManager( myViewManager ); + + theViewerMap.insert(TViewerMap::value_type(myViewManager,PViewer(this))); + QObject::connect( myViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), + theModule, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); + + //aViewer->setBackgroundColor( Qt::darkGreen ); + myViewManager->createViewWindow(); + } + + VVTK_ViewManager* getViewManager() + { + return myViewManager; + } + + virtual + ~Viewer() + { + } + }; + + + //--------------------------------------------------------------- + typedef void (SUIT_ViewWindow::* TViewVisibility)(); + void + SetViewVisibility(const TViewerMap& theViewerMap, + TViewVisibility theViewVisibility) + { + TViewerMap::const_iterator anIter = theViewerMap.begin(); + for(; anIter != theViewerMap.end(); anIter++){ + if(SUIT_ViewManager* aViewManager = anIter->first){ + QPtrVector aViews = aViewManager->getViews(); + int aSize = aViews.size(); + for(int anId = 0; anId < aSize; anId++){ + if(SUIT_ViewWindow* aView = aViews[anId]){ + (aView->* theViewVisibility)(); + } + } + } + } + } + +} + +//--------------------------------------------------------------- +VisuGUI_Module +::VisuGUI_Module() : + VisuGUI() +{ +} + + +//--------------------------------------------------------------- +VisuGUI_Module +::~VisuGUI_Module() +{ +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::initialize( CAM_Application* theApp ) +{ + VisuGUI::initialize( theApp ); + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + QPixmap aPixmap; + aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_GAUSS_NEW_VIEWER")); + createAction( GAUSS_NEW_VIEWER, + tr("MEN_GAUSS_NEW_VIEWER"), + aPixmap, + tr("MEN_GAUSS_NEW_VIEWER"), + tr("MEN_GAUSS_NEW_VIEWER"), + ALT+Key_S, + this, + false, + this, + SLOT(onCreateViewManager())); + int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 ); + int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 ); + createMenu( action( GAUSS_NEW_VIEWER ), newWinMenu, -1 ); + + // Add actions to menus + createMenu( tr( "MEN_GAUSS" ), -1, -1, 30 ); + //createMenu( GAUSS_CREATE_PRS, aMenuId, 10 ); + + QString aViewerType = VVTK_Viewer::Type(); + SUIT_Accel* accel = getApp()->accel(); + accel->setActionKey( SUIT_Accel::PanLeft, Key_Left, aViewerType ); + accel->setActionKey( SUIT_Accel::PanRight, Key_Right, aViewerType ); + accel->setActionKey( SUIT_Accel::PanUp, Key_Up, aViewerType ); + accel->setActionKey( SUIT_Accel::PanDown, Key_Down, aViewerType ); + accel->setActionKey( SUIT_Accel::ZoomIn, Key_PageUp, aViewerType ); + accel->setActionKey( SUIT_Accel::ZoomOut, Key_PageDown, aViewerType ); + accel->setActionKey( SUIT_Accel::RotateLeft, CTRL+Key_Left, aViewerType ); + accel->setActionKey( SUIT_Accel::RotateRight, CTRL+Key_Right, aViewerType ); + accel->setActionKey( SUIT_Accel::RotateUp, CTRL+Key_Up, aViewerType ); + accel->setActionKey( SUIT_Accel::RotateDown, CTRL+Key_Down, aViewerType ); + accel->setActionKey( SVTK::PlusSpeedIncrementEvent, Key_Plus, aViewerType ); + accel->setActionKey( SVTK::MinusSpeedIncrementEvent, Key_Minus, aViewerType ); + + connect( getApp(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ), this, SLOT( OnViewManagerAdded (SUIT_ViewManager*) ) ); + + // Prepare popup menus + QtxPopupMgr* mgr = popupMgr(); + QString aRule; + + aPixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_GAUSS_POINTS" ) ); + createAction( GAUSS_CREATE_PRS, tr("MEN_GAUSS_CREATE_PRS"), aPixmap, + tr("MEN_GAUSS_CREATE_PRS"), "", 0, this, false, + this, SLOT(OnCreateGaussPoints())); + mgr->insert( action( GAUSS_CREATE_PRS ), -1, 0, -1 ); + mgr->setRule( action( GAUSS_CREATE_PRS ), + "client='ObjectBrowser' and selcount=1 " + "and type='VISU::TTIMESTAMP' " + "and $medEntity in {'EDGE_ENTITY' 'FACE_ENTITY' 'CELL_ENTITY'} " + "and $medSource in {'eImportFile' 'eCopyAndImportFile'} ", + true ); + + createMenu( action( GAUSS_CREATE_PRS ), createMenu( tr( "MEN_VISUALISATION" ), -1 ), -1 ); + createTool( GAUSS_CREATE_PRS, createTool( tr( "TOOL_VISUALISATION" ) ), -1 ); + + createAction( GAUSS_RENAME, VisuGUI::tr("MEN_RENAME"), QIconSet(), + VisuGUI::tr("MEN_RENAME"), "", 0, this, false, + this, SLOT(OnRename())); + mgr->insert( action( GAUSS_RENAME ), -1, 0, -1 ); + mgr->setRule( action( GAUSS_RENAME ), + "selcount=1 and type='VISU::TGAUSSPOINTS'", + true ); + + createAction( GAUSS_EDIT_PRS, VisuGUI::tr("MEN_EDIT_PRS"), QIconSet(), + VisuGUI::tr("MEN_EDIT_PRS"), "", 0, this, false, + this, SLOT(OnEditGaussPoints())); + mgr->insert( action( GAUSS_EDIT_PRS ), -1, 0, -1 ); + mgr->setRule( action( GAUSS_EDIT_PRS ), + "selcount=1 and type='VISU::TGAUSSPOINTS'", + true ); + + createAction( GAUSS_COPY_PRS, VisuGUI::tr("MEN_COPY_PRS"), QIconSet(), + VisuGUI::tr("MEN_COPY_PRS"), "", 0, this, false, + this, SLOT(OnCopyPresentation())); + mgr->insert( action( GAUSS_COPY_PRS ), -1, 0, -1 ); + mgr->setRule( action( GAUSS_COPY_PRS ), + "selcount=1 and type='VISU::TGAUSSPOINTS'", + true ); + action( GAUSS_COPY_PRS )->setEnabled(false); + + aRule = "(selcount>0 and type='VISU::TGAUSSPOINTS')"; + + createAction( GAUSS_ERASE_PRS, VisuGUI::tr("MEN_ERASE"), QIconSet(), + VisuGUI::tr("MEN_ERASE"), "", 0, this, false, + this, SLOT(OnErasePrs())); + mgr->insert( action( GAUSS_ERASE_PRS ), -1, -1, -1 ); // erase + mgr->setRule( action( GAUSS_ERASE_PRS ), + aRule + " and (isVisible=true)", true ); + + createAction( GAUSS_DISPLAY_PRS, VisuGUI::tr("MEN_DISPLAY"), QIconSet(), + VisuGUI::tr("MEN_DISPLAY"), "", 0, this, false, + this, SLOT(OnDisplayPrs())); + mgr->insert( action( GAUSS_DISPLAY_PRS ), -1, -1, -1 ); // display + mgr->setRule( action( GAUSS_DISPLAY_PRS ), + aRule + " and (isVisible=false)", true ); + + createAction( GAUSS_DISPLAY_ONLY_PRS, VisuGUI::tr("MEN_DISPLAY_ONLY"), QIconSet(), + VisuGUI::tr("MEN_DISPLAY_ONLY"), "", 0, this, false, + this, SLOT(OnDisplayOnlyPrs())); + mgr->insert( action( GAUSS_DISPLAY_ONLY_PRS ), -1, -1, -1 ); // display only + mgr->setRule( action( GAUSS_DISPLAY_ONLY_PRS ), + aRule, true ); + + createAction( GAUSS_RENAME_CONFIGURATION, VisuGUI::tr("MEN_RENAME"), QIconSet(), + VisuGUI::tr("MEN_RENAME"), "", 0, this, false, + this, SLOT(OnRename())); + mgr->insert( action( GAUSS_RENAME_CONFIGURATION ), -1, -1, -1 ); + mgr->setRule( action( GAUSS_RENAME_CONFIGURATION ), "selcount=1 and type='VISU::TGAUSSVIEW'", true ); + + createAction( GAUSS_SAVE_CONFIGURATION, tr("MEN_SAVE_CONFIGURATION"), QIconSet(), + tr("MEN_SAVE_CONFIGURATION"), "", 0, this, false, + this, SLOT(OnSaveConfiguration())); + mgr->insert( action( GAUSS_SAVE_CONFIGURATION ), -1, -1, -1 ); + mgr->setRule( action( GAUSS_SAVE_CONFIGURATION ), "selcount>=0 and client='VVTK' and activeView='VVTK'", true ); + + createAction( GAUSS_OVERWRITE_CONFIGURATION, tr("MEN_OVERWRITE_CONFIGURATION"), QIconSet(), + tr("MEN_OVERWRITE_CONFIGURATION"), "", 0, this, false, + this, SLOT(OnOverwriteConfiguration())); + mgr->insert( action( GAUSS_OVERWRITE_CONFIGURATION ), -1, -1, -1 ); + mgr->setRule( action( GAUSS_OVERWRITE_CONFIGURATION ), + "selcount>0 and type='VISU::TGAUSSVIEW' and activeView='VVTK'", true ); + + createAction( GAUSS_RESTORE_CONFIGURATION, tr("MEN_RESTORE_CONFIGURATION"), QIconSet(), + tr("MEN_RESTORE_CONFIGURATION"), "", 0, this, false, + this, SLOT(OnRestoreConfiguration())); + mgr->insert( action( GAUSS_RESTORE_CONFIGURATION ), -1, -1, -1 ); + mgr->setRule( action( GAUSS_RESTORE_CONFIGURATION ), + "selcount=1 and type='VISU::TGAUSSVIEW'", true ); +} + +//--------------------------------------------------------------- +bool +VisuGUI_Module +::activateModule( SUIT_Study* theStudy ) +{ + VisuGUI::activateModule( theStudy ); + + SetViewVisibility(myViewerMap,&SUIT_ViewWindow::show); + + return true; +} + + +//--------------------------------------------------------------- +bool +VisuGUI_Module +::deactivateModule( SUIT_Study* theStudy ) +{ + VisuGUI::deactivateModule( theStudy ); + + SetViewVisibility(myViewerMap,&SUIT_ViewWindow::hide); + + return true; +} + + +//--------------------------------------------------------------- +SUIT_ViewManager* +VisuGUI_Module +::onCreateViewManager() +{ + Viewer* aViewer = new Viewer( this, myViewerMap ); + return aViewer->getViewManager(); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::onLastViewClosed(SUIT_ViewManager* theViewManager) +{ + myViewerMap.erase(theViewManager); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::createPreferences() +{ + VisuGUI::createPreferences(); + + createGaussPointsPreferences(); + createInsideCursorPreferences(); + createOutsideCursorPreferences(); + createPickingPreferences(); + createSpaceMousePreferences(); + createRecorderPreferences(); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::createGaussPointsPreferences() +{ + int gaussTab = addPreference( tr( "VISU_GAUSS_PREF_TAB_TTL" ) ); + int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), gaussTab ); + setPreferenceProperty( primitiveGr, "columns", 1 ); + + int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr, + LightApp_Preferences::Selector, "VISU", "point_sprite_primitive_type" ); + + QStringList values; + values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) ); + values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) ); + values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) ); + QValueList indices; + indices.append( 0 ); + indices.append( 1 ); + indices.append( 2 ); + setPreferenceProperty( primitiveTypePref, "strings", values ); + setPreferenceProperty( primitiveTypePref, "indexes", indices ); + + int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "point_sprite_clamp" ); + setPreferenceProperty( clampPref, "min", 1 ); + setPreferenceProperty( clampPref, "max", 512 ); + + addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr, + LightApp_Preferences::File, "VISU", "point_sprite_main_texture" ); + + addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr, + LightApp_Preferences::File, "VISU", "point_sprite_alpha_texture" ); + + int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr, + LightApp_Preferences::DblSpin, "VISU", "point_sprite_alpha_threshold" ); + setPreferenceProperty( alphaThresholdPref, "min", 0.0 ); + setPreferenceProperty( alphaThresholdPref, "max", 1.0 ); + setPreferenceProperty( alphaThresholdPref, "step", 0.1 ); + + int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "geom_sphere_resolution" ); + setPreferenceProperty( resolutionPref, "min", 3 ); + setPreferenceProperty( resolutionPref, "max", 100 ); + + int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "geom_sphere_face_limit" ); + setPreferenceProperty( faceLimitPref, "min", 10 ); + setPreferenceProperty( faceLimitPref, "max", 1000000 ); + + int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), gaussTab ); + setPreferenceProperty( sizeGr, "columns", 2 ); + + int minSizePref = addPreference( tr( "VISU_GAUSS_PREF_MIN_SIZE" ), sizeGr, + LightApp_Preferences::IntSpin, "VISU", "point_sprite_min_size" ); + setPreferenceProperty( minSizePref, "min", 1 ); + setPreferenceProperty( minSizePref, "max", 100 ); + + int maxSizePref = addPreference( tr( "VISU_GAUSS_PREF_MAX_SIZE" ), sizeGr, + LightApp_Preferences::IntSpin, "VISU", "point_sprite_max_size" ); + setPreferenceProperty( maxSizePref, "min", 1 ); + setPreferenceProperty( maxSizePref, "max", 100 ); + + int magnificationPref = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION" ), sizeGr, + LightApp_Preferences::IntSpin, "VISU", "point_sprite_magnification" ); + setPreferenceProperty( magnificationPref, "min", 10 ); + setPreferenceProperty( magnificationPref, "max", 1000 ); + + int incrementPref = addPreference( tr( "VISU_GAUSS_PREF_INCREMENT" ), sizeGr, + LightApp_Preferences::DblSpin, "VISU", "point_sprite_increment" ); + setPreferenceProperty( incrementPref, "min", 0.01 ); + setPreferenceProperty( incrementPref, "max", 10 ); + setPreferenceProperty( incrementPref, "step", 0.1 ); + + int geomGr = addPreference( tr( "VISU_GAUSS_PREF_GEOM_GROUP_TTL" ), gaussTab ); + setPreferenceProperty( geomGr, "columns", 1 ); + + int sizePref = addPreference( tr( "VISU_GAUSS_PREF_SIZE" ), geomGr, + LightApp_Preferences::IntSpin, "VISU", "point_sprite_size" ); + setPreferenceProperty( sizePref, "min", 1 ); + setPreferenceProperty( sizePref, "max", 100 ); + + addPreference( tr( "VISU_GAUSS_PREF_COLOR" ), geomGr, + LightApp_Preferences::Color, "VISU", "point_sprite_color" ); + + // ScalarBar Preferences + int scalarBarGr = addPreference( tr( "VISU_GAUSS_SCALAR_BAR_PREF_GROUP_TTL" ), gaussTab ); + setPreferenceProperty( scalarBarGr, "columns", 1 ); + + int activeBarPref = addPreference( tr( "VISU_GAUSS_PREF_ACTIVE_BAR" ), scalarBarGr, + LightApp_Preferences::Selector, "VISU", "scalar_bar_active_local" ); + + values.clear(); + values.append( tr( "VISU_GAUSS_PREF_LOCAL" ) ); + values.append( tr( "VISU_GAUSS_PREF_GLOBAL" ) ); + indices.clear(); + indices.append( 0 ); + indices.append( 1 ); + setPreferenceProperty( activeBarPref, "strings", values ); + setPreferenceProperty( activeBarPref, "indexes", indices ); + + addPreference( tr( "VISU_GAUSS_PREF_DISPLAY_GLOBAL" ), scalarBarGr, + LightApp_Preferences::Bool, "VISU", "scalar_bar_display_global" ); + + int colorPref = addPreference( tr( "VISU_GAUSS_PREF_SCALAR_BAR_MODE" ), scalarBarGr, + LightApp_Preferences::Selector, "VISU", "scalar_bar_bicolor" ); + + values.clear(); + values.append( tr( "VISU_GAUSS_PREF_BICOLOR" ) ); + values.append( tr( "VISU_GAUSS_PREF_RAINBOW" ) ); + indices.clear(); + indices.append( 0 ); + indices.append( 1 ); + setPreferenceProperty( colorPref, "strings", values ); + setPreferenceProperty( colorPref, "indexes", indices ); + + int spacingPref = addPreference( tr( "VISU_GAUSS_PREF_SPACING" ), scalarBarGr, + LightApp_Preferences::DblSpin, "VISU", "scalar_bar_spacing" ); + setPreferenceProperty( spacingPref, "min", 0.01 ); + setPreferenceProperty( spacingPref, "max", 1.0 ); + setPreferenceProperty( spacingPref, "step", 0.01 ); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::createInsideCursorPreferences() +{ + int insideCursorTab = addPreference( tr( "VISU_GAUSS_INSIDE_CURSOR_PREF_TAB_TTL" ) ); + + int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), insideCursorTab ); + setPreferenceProperty( primitiveGr, "columns", 1 ); + + int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr, + LightApp_Preferences::Selector, "VISU", "inside_point_sprite_primitive_type" ); + + QStringList values; + values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) ); + values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) ); + values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) ); + QValueList indices; + indices.append( 0 ); + indices.append( 1 ); + indices.append( 2 ); + setPreferenceProperty( primitiveTypePref, "strings", values ); + setPreferenceProperty( primitiveTypePref, "indexes", indices ); + + int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "inside_point_sprite_clamp" ); + setPreferenceProperty( clampPref, "min", 1 ); + setPreferenceProperty( clampPref, "max", 512 ); + + addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr, + LightApp_Preferences::File, "VISU", "inside_point_sprite_main_texture" ); + + addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr, + LightApp_Preferences::File, "VISU", "inside_point_sprite_alpha_texture" ); + + int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr, + LightApp_Preferences::DblSpin, "VISU", "inside_point_sprite_alpha_threshold" ); + setPreferenceProperty( alphaThresholdPref, "min", 0.0 ); + setPreferenceProperty( alphaThresholdPref, "max", 1.0 ); + setPreferenceProperty( alphaThresholdPref, "step", 0.1 ); + + int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "inside_geom_sphere_resolution" ); + setPreferenceProperty( resolutionPref, "min", 3 ); + setPreferenceProperty( resolutionPref, "max", 100 ); + + int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "inside_geom_sphere_face_limit" ); + setPreferenceProperty( faceLimitPref, "min", 10 ); + setPreferenceProperty( faceLimitPref, "max", 1000000 ); + + int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), insideCursorTab ); + setPreferenceProperty( sizeGr, "columns", 2 ); + + int minSizePref = addPreference( tr( "VISU_GAUSS_PREF_MIN_SIZE" ), sizeGr, + LightApp_Preferences::IntSpin, "VISU", "inside_point_sprite_min_size" ); + setPreferenceProperty( minSizePref, "min", 1 ); + setPreferenceProperty( minSizePref, "max", 100 ); + + int maxSizePref = addPreference( tr( "VISU_GAUSS_PREF_MAX_SIZE" ), sizeGr, + LightApp_Preferences::IntSpin, "VISU", "inside_point_sprite_max_size" ); + setPreferenceProperty( maxSizePref, "min", 1 ); + setPreferenceProperty( maxSizePref, "max", 100 ); + + int magnificationGr = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION_GROUP_TTL" ), insideCursorTab ); + setPreferenceProperty( magnificationGr, "columns", 2 ); + + int magnificationPref = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION" ), magnificationGr, + LightApp_Preferences::IntSpin, "VISU", "inside_point_sprite_magnification" ); + setPreferenceProperty( magnificationPref, "min", 10 ); + setPreferenceProperty( magnificationPref, "max", 1000 ); + + int incrementPref = addPreference( tr( "VISU_GAUSS_PREF_INCREMENT" ), magnificationGr, + LightApp_Preferences::DblSpin, "VISU", "inside_point_sprite_increment" ); + setPreferenceProperty( incrementPref, "min", 0.01 ); + setPreferenceProperty( incrementPref, "max", 10 ); + setPreferenceProperty( incrementPref, "step", 0.1 ); + +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::createOutsideCursorPreferences() +{ + int outsideCursorTab = addPreference( tr( "VISU_GAUSS_OUTSIDE_CURSOR_PREF_TAB_TTL" ) ); + + int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), outsideCursorTab ); + setPreferenceProperty( primitiveGr, "columns", 1 ); + + int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr, + LightApp_Preferences::Selector, "VISU", "outside_point_sprite_primitive_type" ); + + QStringList values; + values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) ); + values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) ); + values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) ); + QValueList indices; + indices.append( 0 ); + indices.append( 1 ); + indices.append( 2 ); + setPreferenceProperty( primitiveTypePref, "strings", values ); + setPreferenceProperty( primitiveTypePref, "indexes", indices ); + + int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "outside_point_sprite_clamp" ); + setPreferenceProperty( clampPref, "min", 1 ); + setPreferenceProperty( clampPref, "max", 512 ); + + addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr, + LightApp_Preferences::File, "VISU", "outside_point_sprite_main_texture" ); + + addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr, + LightApp_Preferences::File, "VISU", "outside_point_sprite_alpha_texture" ); + + int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr, + LightApp_Preferences::DblSpin, "VISU", "outside_point_sprite_alpha_threshold" ); + setPreferenceProperty( alphaThresholdPref, "min", 0.0 ); + setPreferenceProperty( alphaThresholdPref, "max", 1.0 ); + setPreferenceProperty( alphaThresholdPref, "step", 0.1 ); + + int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "outside_geom_sphere_resolution" ); + setPreferenceProperty( resolutionPref, "min", 3 ); + setPreferenceProperty( resolutionPref, "max", 100 ); + + int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr, + LightApp_Preferences::IntSpin, "VISU", "outside_geom_sphere_face_limit" ); + setPreferenceProperty( faceLimitPref, "min", 10 ); + setPreferenceProperty( faceLimitPref, "max", 1000000 ); + + int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), outsideCursorTab ); + + int sizePref = addPreference( tr( "VISU_GAUSS_PREF_SIZE" ), sizeGr, + LightApp_Preferences::IntSpin, "VISU", "outside_point_sprite_size" ); + setPreferenceProperty( sizePref, "min", 1 ); + setPreferenceProperty( sizePref, "max", 100 ); + + int colorGr = addPreference( tr( "VISU_GAUSS_PREF_COLOR_GROUP_TTL" ), outsideCursorTab ); + setPreferenceProperty( colorGr, "columns", 1 ); + + addPreference( tr( "VISU_GAUSS_PREF_UNIFORM_COLOR" ), colorGr, + LightApp_Preferences::Bool, "VISU", "outside_point_sprite_uniform" ); + + addPreference( tr( "VISU_GAUSS_PREF_COLOR" ), colorGr, + LightApp_Preferences::Color, "VISU", "outside_point_sprite_color" ); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::createPickingPreferences() +{ + int pickingTab = addPreference( tr( "VISU_PICKING_PREF_TAB_TTL" ) ); + + // Cursor + int cursorGr = addPreference( tr( "VISU_PICKING_PREF_CURSOR_GROUP_TTL" ), pickingTab ); + setPreferenceProperty( cursorGr, "columns", 1 ); + + int cursorSizePref = addPreference( tr( "VISU_PICKING_PREF_CURSOR_SIZE" ), cursorGr, + LightApp_Preferences::DblSpin, "VISU", "picking_cursor_size" ); + setPreferenceProperty( cursorSizePref, "min", 0 ); + setPreferenceProperty( cursorSizePref, "max", 1.0 ); + setPreferenceProperty( cursorSizePref, "step", 0.1 ); + + int pyramidHeightPref = addPreference( tr( "VISU_PICKING_PREF_PYRAMID_HEIGHT" ), cursorGr, + LightApp_Preferences::DblSpin, "VISU", "picking_pyramid_height" ); + setPreferenceProperty( pyramidHeightPref, "min", 1 ); + setPreferenceProperty( pyramidHeightPref, "max", 100 ); + + int selectionColorPref = addPreference( tr( "VISU_PICKING_PREF_SELECTION_COLOR" ), cursorGr, + LightApp_Preferences::Color, "VISU", "picking_selection_color" ); + + // Tolerance + int toleranceGr = addPreference( tr( "VISU_PICKING_PREF_TOLERANCE_GROUP_TTL" ), pickingTab ); + + int pointTolerancePref = addPreference( tr( "VISU_PICKING_PREF_POINT_SELECTION_TOLERANCE" ), toleranceGr, + LightApp_Preferences::DblSpin, "VISU", "picking_point_tolerance" ); + setPreferenceProperty( pointTolerancePref, "min", 0.001 ); + setPreferenceProperty( pointTolerancePref, "max", 10 ); + setPreferenceProperty( pointTolerancePref, "step", 0.01 ); + + // Info window + int infoWindowGr = addPreference( tr( "VISU_PICKING_PREF_INFO_WINDOW_GROUP_TTL" ), pickingTab ); + setPreferenceProperty( infoWindowGr, "columns", 1 ); + + int transparencyPref = addPreference( tr( "VISU_PICKING_PREF_TRANSPARENCY" ), infoWindowGr, + LightApp_Preferences::IntSpin, "VISU", "picking_transparency" ); + setPreferenceProperty( transparencyPref, "min", 0 ); + setPreferenceProperty( transparencyPref, "max", 100 ); + setPreferenceProperty( transparencyPref, "step", 10 ); + + int positionPref = addPreference( tr( "VISU_PICKING_PREF_POSITION" ), infoWindowGr, + LightApp_Preferences::Selector, "VISU", "picking_position" ); + QStringList values; + values.append( tr( "VISU_PICKING_PREF_BELOW_POINT" ) ); + values.append( tr( "VISU_PICKING_PREF_TOP_LEFT_CORNER" ) ); + QValueList indices; + indices.append( 0 ); + indices.append( 1 ); + setPreferenceProperty( positionPref, "strings", values ); + setPreferenceProperty( positionPref, "indexes", indices ); + + // Camera + int cameraGr = addPreference( tr( "VISU_PICKING_PREF_CAMERA_GROUP_TTL" ), pickingTab ); + setPreferenceProperty( cameraGr, "columns", 1 ); + + int zoomFactorPref = addPreference( tr( "VISU_PICKING_PREF_ZOOM_FACTOR" ), cameraGr, + LightApp_Preferences::DblSpin, "VISU", "picking_zoom_factor" ); + setPreferenceProperty( zoomFactorPref, "min", 0.1 ); + setPreferenceProperty( zoomFactorPref, "max", 10.0 ); + setPreferenceProperty( zoomFactorPref, "step", 0.1 ); + + int stepNumberPref = addPreference( tr( "VISU_PICKING_PREF_STEP_NUMBER" ), cameraGr, + LightApp_Preferences::IntSpin, "VISU", "picking_step_number" ); + setPreferenceProperty( stepNumberPref, "min", 1 ); + setPreferenceProperty( stepNumberPref, "max", 100 ); + + // Display parent mesh + int parentMeshGr = addPreference( tr( "VISU_PICKING_PREF_PARENT_MESH_TTL" ), pickingTab ); + setPreferenceProperty( parentMeshGr, "columns", 1 ); + + addPreference( tr( "VISU_PICKING_PREF_DISPLAY_PARENT_MESH" ), parentMeshGr, + LightApp_Preferences::Bool, "VISU", "picking_display_parent_mesh" ); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::createSpaceMousePreferences() +{ + int mouseTab = addPreference( tr( "VISU_MOUSE_PREF_TAB_TLT" ) ); + + int mouseGr = addPreference( tr( "VISU_MOUSE_PREF_GROUP_TLT" ), mouseTab ); + int mousePref = addPreference( tr( "VISU_MOUSE_PREF" ), mouseGr, LightApp_Preferences::Selector, "VISU", "mouse_behaviour" ); + QStringList values; + values.append( tr( "VISU_MOUSE_PREF_STANDARD" ) ); + values.append( tr( "VISU_MOUSE_PREF_KEYBOARD_FREE" ) ); + QValueList indices; + indices.append( 0 ); + indices.append( 1 ); + setPreferenceProperty( mousePref, "strings", values ); + setPreferenceProperty( mousePref, "indexes", indices ); + + int keybrdGr = addPreference( tr( "VISU_KEYBOARD_PREF_GROUP_TTL" ), mouseTab ); + int keybrdPref = addPreference( tr( "VISU_KEYBOARD_PREF" ), keybrdGr, LightApp_Preferences::IntSpin, "VISU", "speed_increment" ); + setPreferenceProperty( keybrdPref, "max", 1000 ); + + int spacemouseGr = addPreference( tr( "VISU_SPACEMOUSE_PREF" ), mouseTab ); + setPreferenceProperty( spacemouseGr, "columns", 1 ); + int spacemousePref1 = addPreference( tr( "VISU_SPACEMOUSE_PREF_1" ), spacemouseGr, LightApp_Preferences::Selector, "VISU", "spacemouse_func1_btn" ); //decrease_speed_increment + int spacemousePref2 = addPreference( tr( "VISU_SPACEMOUSE_PREF_2" ), spacemouseGr, LightApp_Preferences::Selector, "VISU", "spacemouse_func2_btn" ); //increase_speed_increment + int spacemousePref3 = addPreference( tr( "VISU_SPACEMOUSE_PREF_3" ), spacemouseGr, LightApp_Preferences::Selector, "VISU", "spacemouse_func3_btn" ); //decrease_gauss_point_magnification + int spacemousePref4 = addPreference( tr( "VISU_SPACEMOUSE_PREF_4" ), spacemouseGr, LightApp_Preferences::Selector, "VISU", "spacemouse_func4_btn" ); //increase_gauss_point_magnification + int spacemousePref5 = addPreference( tr( "VISU_SPACEMOUSE_PREF_5" ), spacemouseGr, LightApp_Preferences::Selector, "VISU", "spacemouse_func5_btn" ); //dominant_combined_switch + values.clear(); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_1" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_2" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_3" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_4" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_5" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_6" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_7" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_8" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_*" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_10" ) ); + values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_11" ) ); + indices.clear(); + indices.append( 1 ); + indices.append( 2 ); + indices.append( 3 ); + indices.append( 4 ); + indices.append( 5 ); + indices.append( 6 ); + indices.append( 7 ); + indices.append( 8 ); + indices.append( 9 ); // == button_* + indices.append( 10 ); + indices.append( 11 ); + setPreferenceProperty( spacemousePref1, "strings", values ); + setPreferenceProperty( spacemousePref1, "indexes", indices ); + setPreferenceProperty( spacemousePref2, "strings", values ); + setPreferenceProperty( spacemousePref2, "indexes", indices ); + setPreferenceProperty( spacemousePref3, "strings", values ); + setPreferenceProperty( spacemousePref3, "indexes", indices ); + setPreferenceProperty( spacemousePref4, "strings", values ); + setPreferenceProperty( spacemousePref4, "indexes", indices ); + setPreferenceProperty( spacemousePref5, "strings", values ); + setPreferenceProperty( spacemousePref5, "indexes", indices ); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::createRecorderPreferences() +{ + int recorderTab = addPreference( tr( "VISU_RECORDER_PREF_TAB_TTL" ) ); + + int recorderGr = addPreference( tr( "VISU_RECORDER_PREF_GROUP_TTL" ), recorderTab ); + setPreferenceProperty( recorderGr, "columns", 1 ); + + int modePref = addPreference( tr( "VISU_RECORDER_PREF_RECORDING_MODE" ), recorderGr, + LightApp_Preferences::Selector, "VISU", "recorder_mode" ); + QStringList values; + values.append( tr( "VISU_RECORDER_PREF_SKIPPED_FRAMES" ) ); + values.append( tr( "VISU_RECORDER_PREF_ALL_DISLPAYED_FRAMES" ) ); + QValueList indices; + indices.append( 0 ); + indices.append( 1 ); + setPreferenceProperty( modePref, "strings", values ); + setPreferenceProperty( modePref, "indexes", indices ); + + int fpsPref = addPreference( tr( "VISU_RECORDER_PREF_FPS" ), recorderGr, + LightApp_Preferences::DblSpin, "VISU", "recorder_fps" ); + setPreferenceProperty( fpsPref, "min", 0.1 ); + setPreferenceProperty( fpsPref, "max", 100 ); + + int qualityPref = addPreference( tr( "VISU_RECORDER_PREF_QUALITY" ), recorderGr, + LightApp_Preferences::IntSpin, "VISU", "recorder_quality" ); + setPreferenceProperty( qualityPref, "min", 1 ); + setPreferenceProperty( qualityPref, "max", 100 ); + + addPreference( tr( "VISU_RECORDER_PREF_PROGRESSIVE" ), recorderGr, + LightApp_Preferences::Bool, "VISU", "recorder_progressive" ); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::OnCreateGaussPoints() +{ + double initialTime = vtkTimerLog::GetCPUTime(); + CreatePrs3d(this,true); + INFOS( "VisuGUI_Module::OnCreateGaussPoints() : Gauss Points created in " << + vtkTimerLog::GetCPUTime() - initialTime << " seconds" ); +} + +void +VisuGUI_Module +::OnViewManagerAdded(SUIT_ViewManager* viewMgr) +{ + QString type = viewMgr->getViewModel()->getType(); + if ( type == VVTK_Viewer::Type() ) + connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), this, SLOT( OnViewCreated( SUIT_ViewWindow* ) ) ); +} + +void +VisuGUI_Module +::OnViewCreated(SUIT_ViewWindow* view) +{ + SVTK_ViewWindow* viewWindow = dynamic_cast( view ); + if ( viewWindow ) { + setProperty( viewWindow, "speed_increment" ); + setProperty( viewWindow, "spacemouse_func1_btn" ); + setProperty( viewWindow, "spacemouse_func2_btn" ); + setProperty( viewWindow, "spacemouse_func3_btn" ); + setProperty( viewWindow, "spacemouse_func4_btn" ); + setProperty( viewWindow, "spacemouse_func5_btn" ); + } +} + +void +VisuGUI_Module +::setProperty( SVTK_ViewWindow* viewWindow, const QString& pref ) +{ + if ( !viewWindow ) + return; + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + SVTK_MainWindow* aMainWindow = viewWindow->getMainWindow(); + int val; + if ( pref == "speed_increment" ) { + val = resMgr->integerValue( "VISU", pref, 10 ); + aMainWindow->InvokeEvent( SVTK::SetSpeedIncrementEvent, &val ); + } + else if ( pref == "spacemouse_func1_btn" ) { + val = resMgr->integerValue( "VISU", pref, 1 ); + aMainWindow->InvokeEvent( SVTK::SetSMDecreaseSpeedEvent, &val ); + } + else if ( pref == "spacemouse_func2_btn" ) { + val = resMgr->integerValue( "VISU", pref, 2 ); + aMainWindow->InvokeEvent( SVTK::SetSMIncreaseSpeedEvent, &val ); + } + else if ( pref == "spacemouse_func3_btn" ) { + val = resMgr->integerValue( "VISU", pref, 10 ); + aMainWindow->InvokeEvent( VISU::SetSMDecreaseMagnificationEvent, &val ); + } + else if ( pref == "spacemouse_func4_btn" ) { + val = resMgr->integerValue( "VISU", pref, 11 ); + aMainWindow->InvokeEvent( VISU::SetSMIncreaseMagnificationEvent, &val ); + } + else if ( pref == "spacemouse_func5_btn" ) { + val = resMgr->integerValue( "VISU", pref, 9 ); + aMainWindow->InvokeEvent( SVTK::SetSMDominantCombinedSwitchEvent, &val ); + } +} + +void +VisuGUI_Module +::setProperty( SVTK_ViewManager* vm, const QString& prop ) +{ + if ( !vm ) + return; + + QPtrVector windows = vm->getViews(); + for ( int n = windows.count(), i = 0; i < n; i++ ) + setProperty( dynamic_cast( windows[i] ), prop ); +} + +void +VisuGUI_Module +::preferencesChanged( const QString& group, const QString& pref ) +{ + VisuGUI::preferencesChanged(group,pref); + + if ( group == "VISU" && ( pref == "speed_increment" || pref == "spacemouse_func1_btn" || + pref == "spacemouse_func2_btn" || pref == "spacemouse_func3_btn" || + pref == "spacemouse_func4_btn" || pref == "spacemouse_func5_btn" ) ) { + + // update properties of VVTK view windows + SUIT_ViewManager* vm = getApp()->getViewManager( VVTK_Viewer::Type(), false ); + if ( vm ) + setProperty( dynamic_cast( vm ), pref ); + } +} + + +//--------------------------------------------------------------- +SUIT_ViewManager* +VisuGUI_Module +::getViewManager(const QString& theType, + const bool theIsCreate) +{ + if(SUIT_ViewManager* aViewManager = VisuGUI::getViewManager(theType,theIsCreate)) + return aViewManager; + + if(theIsCreate && VVTK_Viewer::Type() == theType) + return onCreateViewManager(); + + return NULL; +} + +//--------------------------------------------------------------- +void +VisuGUI_Module +::OnEditGaussPoints() +{ + Handle(SALOME_InteractiveObject) anIO; + if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){ + EditPrs3d(this, aPrs3d); + if(SVTK_ViewWindow* aViewWindow = GetViewWindow(this,true)){ + aViewWindow->highlight(anIO,1); + } + } +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::OnDisplayPrs() +{ + if(MYDEBUG) MESSAGE("VisuGUI_Module::OnDisplayPrs"); + + QApplication::setOverrideCursor(Qt::waitCursor); + + if(LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this)){ + SALOME_ListIO aList; + aSelectionMgr->selectedObjects(aList); + for(SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next()){ + Handle(SALOME_InteractiveObject) anIO = it.Value(); + CORBA::Object_var anObject = GetSelectedObj( GetAppStudy(this), anIO->getEntry() ); + + // is it a Prs3d object ? + if(!CORBA::is_nil(anObject)){ + if(VISU::Prs3d_i* aPrs3d = dynamic_cast(VISU::GetServant(anObject).in())){ + if(MYDEBUG) MESSAGE("VisuGUI_Module::OnDisplayPrs : Prs3d object"); + if(aPrs3d->GetType() == VISU::TGAUSSPOINTS) + VISU::UpdateViewer(this,aPrs3d,false,true,true); + else if(SUIT_ViewManager* aViewManager = getApp()->activeViewManager()){ + QString aType = aViewManager->getType(); + if(aType == SVTK_Viewer::Type()) + VISU::UpdateViewer(this,aPrs3d,false,true,true); + else if(aType == VVTK_Viewer::Type()) + VISU::UpdateViewer(this,aPrs3d,false,true,true); + } + continue; + } + } + + // is it Curve ? + if(VISU::Curve_i* aCurve = dynamic_cast(VISU::GetServant(anObject).in())){ + if(MYDEBUG) MESSAGE("VisuGUI_Module::OnDisplayPrs : Curve object"); + PlotCurve( this, aCurve, VISU::eDisplay ); + continue; + } + + // is it Container ? + if(VISU::Container_i* aContainer = dynamic_cast(VISU::GetServant(anObject).in())){ + if(MYDEBUG) MESSAGE("VisuGUI_Module::DisplayPrs : Container object"); + PlotContainer( this, aContainer, VISU::eDisplay ); + continue; + } + + // is it Table ? + if(VISU::Table_i* aTable = dynamic_cast(VISU::GetServant(anObject).in())){ + if(MYDEBUG) MESSAGE("VisuGUI_Module::DisplayPrs : Table object"); + PlotTable( this, aTable, VISU::eDisplay ); + continue; + } + } + } + + QApplication::restoreOverrideCursor(); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::OnEraseAll() +{ + if(SUIT_ViewManager* aViewManager = getApp()->activeViewManager()){ + QString aType = aViewManager->getType(); + if(aType == SVTK_Viewer::Type()) + VISU::OnEraseAll(this); + else if(aType == VVTK_Viewer::Type()) + VISU::OnEraseAll(this); + else if(aType == SPlot2d_Viewer::Type()) + VISU::OnEraseAll(this); + } +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::OnDisplayOnlyPrs() +{ + OnEraseAll(); + OnDisplayPrs(); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module +::OnErasePrs() +{ + QApplication::setOverrideCursor(Qt::waitCursor); + + SALOME_ListIO aList; + LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this); + aSelectionMgr->selectedObjects(aList); + + for(SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next()){ + Handle(SALOME_InteractiveObject) anIO = it.Value(); + CORBA::Object_var anObject = GetSelectedObj(GetAppStudy(this),anIO->getEntry()); + if(!CORBA::is_nil(anObject)){ + VISU::Base_var aBase = VISU::Base::_narrow(anObject); + if(!CORBA::is_nil(aBase)) + VISU::ErasePrs(this,aBase,true); + } + } + + QApplication::restoreOverrideCursor(); +} + + +//--------------------------------------------------------------- +namespace +{ + void + GetViewParams(VVTK_MainWindow* theViewWindow, + const char* theSuffix, + std::ostringstream& theStr) + { + float aColor[3]; + vtkRenderer* aRenderer = theViewWindow->getRenderer(); + aRenderer->GetBackground(aColor); + Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".R",aColor[0]); + Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".G",aColor[1]); + Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".B",aColor[2]); + + double aPosition[3]; + vtkCamera* aCamera = aRenderer->GetActiveCamera(); + aCamera->GetPosition(aPosition); + Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[0]",aPosition[0]); + Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[1]",aPosition[1]); + Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[2]",aPosition[2]); + + double aFocalPnt[3]; + aCamera->GetFocalPoint(aFocalPnt); + Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[0]",aFocalPnt[0]); + Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[1]",aFocalPnt[1]); + Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[2]",aFocalPnt[2]); + + double aViewUp[3]; + aCamera->GetViewUp(aViewUp); + Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[0]",aViewUp[0]); + Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[1]",aViewUp[1]); + Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[2]",aViewUp[2]); + + float aParallelScale = aCamera->GetParallelScale(); + Storable::DataToStream(theStr,std::string("myParallelScale") + theSuffix,aParallelScale); + + double aScaleFactor[3]; + theViewWindow->GetScale(aScaleFactor); + Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[0]",aScaleFactor[0]); + Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[1]",aScaleFactor[1]); + Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[2]",aScaleFactor[2]); + } + + //--------------------------------------------------------------- + void + SetViewParams(VVTK_MainWindow* theViewWindow, + const char* theSuffix, + const Storable::TRestoringMap& theMap) + { + float aColor[3]; + aColor[0] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".R").toDouble(); + aColor[1] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".G").toDouble(); + aColor[2] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".B").toDouble(); + vtkRenderer* aRenderer = theViewWindow->getRenderer(); + aRenderer->SetBackground(aColor); + + double aPosition[3]; + aPosition[0] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[0]").toDouble(); + aPosition[1] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[1]").toDouble(); + aPosition[2] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[2]").toDouble(); + vtkCamera* aCamera = aRenderer->GetActiveCamera(); + aCamera->SetPosition(aPosition); + + double aFocalPnt[3]; + aFocalPnt[0] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[0]").toDouble(); + aFocalPnt[1] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[1]").toDouble(); + aFocalPnt[2] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[2]").toDouble(); + aCamera->SetFocalPoint(aFocalPnt); + + double aViewUp[3]; + aViewUp[0] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[0]").toDouble(); + aViewUp[1] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[1]").toDouble(); + aViewUp[2] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[2]").toDouble(); + aCamera->SetViewUp(aViewUp); + + float aParallelScale = Storable::FindValue(theMap,std::string("myParallelScale") + theSuffix).toDouble(); + aCamera->SetParallelScale(aParallelScale); + + double aScaleFactor[3]; + aScaleFactor[0] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[0]").toDouble(); + aScaleFactor[1] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[1]").toDouble(); + aScaleFactor[2] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[2]").toDouble(); + theViewWindow->SetScale(aScaleFactor); + } + + //--------------------------------------------------------------- + void + GetViewParams(VVTK_MainWindow1* theViewWindow, + std::ostringstream& theStr) + { + GetViewParams(theViewWindow,"1",theStr); + + VISU_WidgetCtrl* aWidgetCtrl = theViewWindow->GetWidgetCtrl(); + if(aWidgetCtrl->GetEnabled()){ + std::string aSegmentationMode; + if(aWidgetCtrl->IsPlanesActive()){ + VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget(); + float anOrigin[3]; + aPlanesWidget->GetOrigin(anOrigin); + Storable::DataToStream(theStr,"myCursorOrigin[0]",anOrigin[0]); + Storable::DataToStream(theStr,"myCursorOrigin[1]",anOrigin[1]); + Storable::DataToStream(theStr,"myCursorOrigin[2]",anOrigin[2]); + + float aNormal[3]; + aPlanesWidget->GetNormal(aNormal); + Storable::DataToStream(theStr,"myCursorNormal[0]",aNormal[0]); + Storable::DataToStream(theStr,"myCursorNormal[1]",aNormal[1]); + Storable::DataToStream(theStr,"myCursorNormal[2]",aNormal[2]); + + float aDepth = aPlanesWidget->Distance(); + Storable::DataToStream(theStr,"myCursorDepth",aDepth); + + aSegmentationMode = "Planes"; + }else if(aWidgetCtrl->IsSphereActive()){ + VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget(); + float aCenter[3]; + aSphereWidget->GetCenter(aCenter); + Storable::DataToStream(theStr,"mySphereCursorCenter[0]",aCenter[0]); + Storable::DataToStream(theStr,"mySphereCursorCenter[1]",aCenter[1]); + Storable::DataToStream(theStr,"mySphereCursorCenter[2]",aCenter[2]); + + float aRadius = aSphereWidget->GetRadius(); + Storable::DataToStream(theStr,"mySphereCursorRaduis",aRadius); + + aSegmentationMode = "Sphere"; + } + + Storable::DataToStream(theStr,"mySegmentationMode",aSegmentationMode); + } + } + + //--------------------------------------------------------------- + void + SetViewParams(VVTK_MainWindow1* theViewWindow, + const Storable::TRestoringMap& theMap) + { + SetViewParams(theViewWindow,"1",theMap); + } + + + //--------------------------------------------------------------- + void + GetViewParams(VVTK_MainWindow2* theViewWindow, + std::ostringstream& theStr) + { + GetViewParams(theViewWindow,"2",theStr); + } + + void + SetViewParams(VVTK_MainWindow2* theViewWindow, + const Storable::TRestoringMap& theMap) + { + SetViewParams(theViewWindow,"2",theMap); + } + + + //--------------------------------------------------------------- + std::string + GetViewParams(VVTK_ViewWindow* theViewWindow) + { + std::ostringstream aStream; + + Storable::DataToStream(aStream,"myComment","GAUSSVIEW"); + + SVTK_Selector* aSelector = theViewWindow->GetSelector(); + Selection_Mode aSelectionMode = aSelector->SelectionMode(); + Storable::DataToStream(aStream,"mySelectionMode",aSelectionMode); + + GetViewParams(theViewWindow->getMainWindow1(),aStream); + GetViewParams(theViewWindow->getMainWindow2(),aStream); + + return aStream.str(); + } + + //--------------------------------------------------------------- + struct TSelection + { + bool myIsSelected; + bool myHasSubId; + int mySubId; + + TSelection(): + myIsSelected(false), + myHasSubId(false), + mySubId(-1) + {} + }; + + typedef std::map TVisibleEntries; + + struct TGetVisibleEntries + { + TVisibleEntries& myVisibleEntries; + + TGetVisibleEntries(TVisibleEntries& theVisibleEntries): + myVisibleEntries(theVisibleEntries) + {} + + void + operator()(VISU_GaussPtsAct* theActor) + { + if(theActor->GetVisibility()){ + const Handle(SALOME_InteractiveObject)& anIO = theActor->getIO(); + myVisibleEntries.insert(TVisibleEntries::value_type(anIO->getEntry(),TSelection())); + } + } + }; + + void + GetGaussPointsSelection(VVTK_ViewWindow* theViewWindow, + TVisibleEntries& theVisibleEntries) + { + // First find all visible Gauss Points presentations + vtkRenderer* aRenderer = theViewWindow->getRenderer(); + vtkActorCollection* anActors = aRenderer->GetActors(); + TGetVisibleEntries aGetVisibleEntries(theVisibleEntries); + SVTK::ForEach(anActors, + aGetVisibleEntries); + + // Next, find the sub-ids for the visible Gauss Points presentations + SVTK_Selector* aSelector = theViewWindow->GetSelector(); + const SALOME_ListIO& aListIO = aSelector->StoredIObjects(); + SALOME_ListIteratorOfListIO anIter(aListIO); + for(; anIter.More(); anIter.Next()){ + Handle(SALOME_InteractiveObject) anIO = anIter.Value(); + std::string anEntry = anIO->getEntry(); + TVisibleEntries::iterator anEntriesIter = theVisibleEntries.find(anEntry); + if(anEntriesIter != theVisibleEntries.end()){ + TSelection& aSelection = anEntriesIter->second; + aSelection.myIsSelected = true; + TColStd_IndexedMapOfInteger anIndexes; + aSelector->GetIndex(anIO,anIndexes); + if(anIndexes.Extent() > 0){ + aSelection.myHasSubId = true; + aSelection.mySubId = anIndexes(1); + } + } + } + } + + + //--------------------------------------------------------------- + inline + void + CreateReference(_PTR(Study) theStudyDocument, + _PTR(StudyBuilder) theStudyBuilder, + _PTR(SObject) theFatherSObject, + const string& theRefEntry, + const TSelection& theSelection) + { + _PTR(SObject) aNewObj = theStudyBuilder->NewObject(theFatherSObject); + _PTR(SObject) aRefSObj = theStudyDocument->FindObjectID(theRefEntry); + theStudyBuilder->Addreference(aNewObj,aRefSObj); + + std::ostringstream aStream; + Storable::DataToStream(aStream,"myIsSelected",theSelection.myIsSelected); + Storable::DataToStream(aStream,"myHasSubId",theSelection.myHasSubId); + Storable::DataToStream(aStream,"mySubId",theSelection.mySubId); + + _PTR(GenericAttribute) anAttr; + anAttr = theStudyBuilder->FindOrCreateAttribute(aNewObj,"AttributeComment"); + _PTR(AttributeComment) aComment(anAttr); + aComment->SetValue(aStream.str()); + } + + + //--------------------------------------------------------------- + void + SetGaussPointsSelection(VisuGUI* theModule, + VVTK_ViewWindow* theViewWindow, + _PTR(Study) theCStudy, + _PTR(SObject) theSObject) + { + SVTK_Selector* aSelector = theViewWindow->GetSelector(); + aSelector->ClearIObjects(); + + bool anIsFirst = true; + _PTR(ChildIterator) aChildIter = theCStudy->NewChildIterator(theSObject); + for (; aChildIter->More(); aChildIter->Next()) { + _PTR(SObject) aChildSObject = aChildIter->Value(); + _PTR(SObject) aSObject; + if(aChildSObject->ReferencedObject(aSObject)){ + CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject); + PortableServer::ServantBase_var aServant = VISU::GetServant(anObject); + if(VISU::Prs3d_i* aPrs3d = dynamic_cast(aServant.in())){ + // To set visiblity + VISU::UpdateViewer(theModule,aPrs3d,anIsFirst,false,false); + anIsFirst = false; + + // To update selection + _PTR(GenericAttribute) anAttr; + if(aChildSObject->FindAttribute(anAttr,"AttributeComment")){ + _PTR(AttributeComment) aComment(anAttr); + + QString aStream(aComment->Value().c_str()); + Storable::TRestoringMap aMap; + Storable::StrToMap(aStream,aMap); + + bool anIsSelected = Storable::FindValue(aMap,"myIsSelected").toInt(); + bool aHasSubId = Storable::FindValue(aMap,"myHasSubId").toInt(); + int aSubId = Storable::FindValue(aMap,"mySubId").toInt(); + + if(anIsSelected){ + std::string anEntry = aSObject->GetID(); + Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(anEntry.c_str(),""); + aSelector->AddIObject(anIO); + if(aHasSubId) + aSelector->AddOrRemoveIndex(anIO,aSubId,false); + } + } + } + } + } + + aSelector->EndPickCallback(); // To invoke selection changed signal + } + + + //--------------------------------------------------------------- + void + OnStoreConfiguration(SalomeApp_Module* theModule, + bool theIsNew) + { + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule)); + if (CheckLock(aCStudy,GetDesktop(theModule))) + return; + + LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule); + + SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager(); + if(aViewManager->getType() == VVTK_Viewer::Type()){ + SUIT_ViewWindow* aWindow = aViewManager->getActiveView(); + VVTK_ViewWindow* aViewWindow = dynamic_cast(aWindow); + + SUIT_Study* aSStudy = aViewManager->study(); + SalomeApp_Study* aStudy = dynamic_cast(aSStudy); + _PTR(Study) aCStudy = aStudy->studyDS(); + _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder(); + + std::string anEntry; + std::string aValue = GetViewParams(aViewWindow); + + if(theIsNew){ + _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy); + + static int myNbConfigs = 0; + std::string aName = VISU::GenerateName("Config.", ++myNbConfigs).latin1(); + + std::string aSComponentEntry = aSComponent->GetID(); + anEntry = CreateAttributes(aCStudy, + aSComponentEntry.c_str(), + "", + "", + aName.c_str(), + "", + aValue.c_str()); + }else{ + SALOME_ListIO aListIO; + aSelectionMgr->selectedObjects(aListIO); + SALOME_ListIteratorOfListIO aListIter( aListIO ); + for(; aListIter.More(); aListIter.Next()){ + Handle(SALOME_InteractiveObject) anIO = aListIter.Value(); + _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry()); + _PTR(GenericAttribute) anAttr; + if(aSObject->FindAttribute(anAttr,"AttributeComment")){ + _PTR(AttributeComment) aComment(anAttr); + std::string aCommentValue(aComment->Value()); + if(aCommentValue.compare("myComment=GAUSSVIEW") >= 0){ + aComment->SetValue(aValue.c_str()); + anEntry = aSObject->GetID(); + + _PTR(ChildIterator) aChildIter = aCStudy->NewChildIterator(aSObject); + for (; aChildIter->More(); aChildIter->Next()) { + _PTR(SObject) aChildSObject = aChildIter->Value(); + aStudyBuilder->RemoveObject(aChildSObject); + } + break; + } + } + } + } + + if(anEntry != ""){ + TVisibleEntries aVisibleEntries; + GetGaussPointsSelection(aViewWindow, + aVisibleEntries); + + _PTR(SObject) aSObject = aCStudy->FindObjectID(anEntry); + _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder(); + TVisibleEntries::const_iterator anIter = aVisibleEntries.begin(); + for(; anIter != aVisibleEntries.end(); anIter++){ + const std::string& anEntry = anIter->first; + const TSelection& aSelection = anIter->second; + + CreateReference(aCStudy, + aStudyBuilder, + aSObject, + anEntry, + aSelection); + } + + //UpdateObjBrowser(theModule,true,aSObject); + UpdateObjBrowser(theModule,true); + } + } + } + + + //--------------------------------------------------------------- + template + void + SetMainWindowParams(VisuGUI* theModule, + _PTR(SObject) theSObject, + VVTK_ViewWindow* theViewWindow, + TMainWindow* theMainWindow) + { + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule)); + + _PTR(GenericAttribute) anAttr; + if(theSObject->FindAttribute(anAttr,"AttributeComment")){ + _PTR(AttributeComment) aComment(anAttr); + QString aStream(aComment->Value().c_str()); + Storable::TRestoringMap aMap; + Storable::StrToMap(aStream,aMap); + SetViewParams(theMainWindow,aMap); + } + } +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module:: +OnSaveConfiguration() +{ + ::OnStoreConfiguration(this,true); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module:: +OnOverwriteConfiguration() +{ + ::OnStoreConfiguration(this,false); +} + + +//--------------------------------------------------------------- +void +VisuGUI_Module:: +OnRestoreConfiguration() +{ + LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this); + + SALOME_ListIO aListIO; + aSelectionMgr->selectedObjects(aListIO); + if(aListIO.Extent() > 1) + return; + + if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),true)){ + const Handle(SALOME_InteractiveObject)& anIO = aListIO.First(); + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); + _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry()); + myConfigSObject = aSObject; + _PTR(GenericAttribute) anAttr; + if(aSObject->FindAttribute(anAttr,"AttributeComment")){ + _PTR(AttributeComment) aComment(anAttr); + QString aStream(aComment->Value().c_str()); + Storable::TRestoringMap aMap; + Storable::StrToMap(aStream,aMap); + SUIT_ViewWindow* aWindow = aViewManager->getActiveView(); + VVTK_ViewWindow* aViewWindow = dynamic_cast(aWindow); + + Selection_Mode aSelectionMode = Storable::FindValue(aMap,"mySelectionMode").toInt(); + SVTK_Selector* aSelector = aViewWindow->GetSelector(); + aSelector->SetSelectionMode(aSelectionMode); + + SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObject); + + std::string aSegmentationMode; + if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){ + aMainWindow->SetPlanesSegementation(false); + aMainWindow->SetSphereSegementation(false); + VISU_WidgetCtrl* aWidgetCtrl = aMainWindow->GetWidgetCtrl(); + aSegmentationMode = Storable::FindValue(aMap,"mySegmentationMode").latin1(); + + if(aSegmentationMode == "Planes"){ + VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget(); + float anOrigin[3]; + anOrigin[0] = Storable::FindValue(aMap,"myCursorOrigin[0]").toDouble(); + anOrigin[1] = Storable::FindValue(aMap,"myCursorOrigin[1]").toDouble(); + anOrigin[2] = Storable::FindValue(aMap,"myCursorOrigin[2]").toDouble(); + aPlanesWidget->SetOrigin(anOrigin); + + float aNormal[3]; + aNormal[0] = Storable::FindValue(aMap,"myCursorNormal[0]").toDouble(); + aNormal[1] = Storable::FindValue(aMap,"myCursorNormal[1]").toDouble(); + aNormal[2] = Storable::FindValue(aMap,"myCursorNormal[2]").toDouble(); + aPlanesWidget->SetNormal(aNormal); + + float aDepth = Storable::FindValue(aMap,"myCursorDepth").toDouble(); + aPlanesWidget->SetDistance(aDepth); + + aMainWindow->SetPlanesSegementation(true); + }else if(aSegmentationMode == "Sphere"){ + VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget(); + float aCenter[3]; + aCenter[0] = Storable::FindValue(aMap,"mySphereCursorCenter[0]").toDouble(); + aCenter[1] = Storable::FindValue(aMap,"mySphereCursorCenter[1]").toDouble(); + aCenter[2] = Storable::FindValue(aMap,"mySphereCursorCenter[2]").toDouble(); + aSphereWidget->SetCenter(aCenter); + + float aRadius = Storable::FindValue(aMap,"mySphereCursorRaduis").toDouble(); + aSphereWidget->SetRadius(aRadius); + + aMainWindow->SetSphereSegementation(true); + } + } + + if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){ + SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor(); + if(anInteractor->isVisible()){ + SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow); + }else + anInteractor->installEventFilter(this); + } + + if(aSegmentationMode != ""){ + if(VVTK_MainWindow2* aMainWindow = aViewWindow->getMainWindow2()){ + SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor(); + if(anInteractor->isVisible()) + SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow); + else + anInteractor->installEventFilter(this); + } + } + + SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObject); + } + } +} + + +//--------------------------------------------------------------- +bool +VisuGUI_Module:: +eventFilter( QObject * theWatched, QEvent * theEvent ) +{ + bool aRet = VisuGUI::eventFilter(theWatched,theEvent); + if(theEvent->type() == QEvent::Show){ + if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),false)){ + SUIT_ViewWindow* aWindow = aViewManager->getActiveView(); + VVTK_ViewWindow* aViewWindow = dynamic_cast(aWindow); + if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){ + SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor(); + if(theWatched == anInteractor){ + SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow); + anInteractor->removeEventFilter(this); + } + } + if(VVTK_MainWindow2* aMainWindow = aViewWindow->getMainWindow2()){ + SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor(); + if(theWatched == aMainWindow->GetInteractor()){ + SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow); + anInteractor->removeEventFilter(this); + } + } + } + } + return aRet; +} diff --git a/src/VISUGUI/VisuGUI_Module.h b/src/VISUGUI/VisuGUI_Module.h new file mode 100644 index 00000000..c13c8235 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Module.h @@ -0,0 +1,192 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_Module.h +// Author : +// Module : VISU +// $Header$ + +#ifndef VisuGUI_Module_HeaderFile +#define VisuGUI_Module_HeaderFile + +#include "VisuGUI.h" +#include "STD_Application.h" +#include "SALOMEDSClient_SObject.hxx" + +class SUIT_ViewManager; +class SVTK_ViewManager; +class SVTK_ViewWindow; + +#include "MED_SharedPtr.hxx" + +namespace VISU +{ + class Viewer; + typedef MED::SharedPtr PViewer; + + typedef std::map TViewerMap; +} + +//! This class inherits base VisuGUI. +/*! Used to display, erase end edit presentations in the VVTK viewer. */ +class VisuGUI_Module: public VisuGUI +{ + Q_OBJECT; + + friend class VISU::Viewer; + +public: + VisuGUI_Module(); + + virtual + ~VisuGUI_Module(); + + virtual + bool + eventFilter( QObject * theWatched, QEvent * theEvent ); + + //! Redifined method of the module initializing. + virtual + void + initialize( CAM_Application* ); + + //! Redefined method of creating prefernces. + virtual + void + createPreferences(); + + virtual + void + preferencesChanged( const QString&, const QString& ); + + virtual + SUIT_ViewManager* + getViewManager(const QString& theType, + const bool theIsCreate); + +public slots: + //! Reimplemented method of the module deactivation. + virtual + bool + deactivateModule( SUIT_Study* ); + + //! Reimplemented method of the module activation. + virtual + bool + activateModule( SUIT_Study* ); + +protected: + //! Create preferences for Gauss Points presentation. + virtual + void + createGaussPointsPreferences(); + + //! Create preferences for Outside Cursor Gauss Points presentations. + virtual + void + createInsideCursorPreferences(); + + virtual + void + createOutsideCursorPreferences(); + + //! Create preferences for Picking. + virtual + void + createPickingPreferences(); + + //! Create preferences for Space Mouse. + virtual + void + createSpaceMousePreferences(); + + //! Create preferences for Recorder. + virtual + void + createRecorderPreferences(); + +protected slots: + SUIT_ViewManager* + onCreateViewManager(); + + void + onLastViewClosed(SUIT_ViewManager*); + + void + OnCreateGaussPoints(); + + void + OnViewCreated(SUIT_ViewWindow*); + + void + OnViewManagerAdded(SUIT_ViewManager*); + + //! Reimplemented method of the Gauss Points edition. + virtual + void + OnEditGaussPoints(); + + //! Reimplemented method of the Gauss Points displaying. + virtual + void + OnDisplayPrs(); + + //! Reimplemented method of the Gauss Points displaying only. + virtual + void + OnDisplayOnlyPrs(); + + //! Reimplemented method of the Gauss Points full erasing. + virtual + void + OnEraseAll(); + + //! Reimplemented method of the Gauss Points erasing. + virtual + void + OnErasePrs(); + + //! Virtual method of saving configuration. + virtual + void + OnSaveConfiguration(); + + //! Virtual method of overwriting configuration. + virtual + void + OnOverwriteConfiguration(); + + //! Virtual method of restoring configuration. + virtual + void + OnRestoreConfiguration(); + +protected: + VISU::TViewerMap myViewerMap; + _PTR(SObject) myConfigSObject; + + void setProperty( SVTK_ViewWindow*, const QString& ); // set a property (speed_increment, etc ) for SVTK ViewWindow + void setProperty( SVTK_ViewManager*, const QString& ); // set a property for SVTK ViewWindow // set only 1 property for all ViewWindows of given view manager +}; + +#endif diff --git a/src/VISUGUI/VisuGUI_NonIsometricDlg.h b/src/VISUGUI/VisuGUI_NonIsometricDlg.h deleted file mode 100644 index 739f87ec..00000000 --- a/src/VISUGUI/VisuGUI_NonIsometricDlg.h +++ /dev/null @@ -1,40 +0,0 @@ -// VISU VISUGUI : GUI of VISU component -// -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : VisuGUI_NonIsometricDlg.h -// Author : Vasily Rusyaev -// Module : VISU -// $Header$ - -#ifndef VisuGUI_NONISOMETRICDLG_H -#define VisuGUI_NONISOMETRICDLG_H - -#include -class QtxDblSpinBox; -class QPushButton; - -class VisuGUI_NonIsometricDlg : public QDialog -{ - Q_OBJECT - -public: - VisuGUI_NonIsometricDlg (QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0); - ~VisuGUI_NonIsometricDlg(); - -private: - QtxDblSpinBox* m_sbXcoeff; - QtxDblSpinBox* m_sbYcoeff; - QtxDblSpinBox* m_sbZcoeff; - QPushButton* m_bReset ; - -private slots: - void onClickApply(); - void onClickReset(); - void onClickOk(); - void onFunctionChanged(); -}; - -#endif // VisuGUI_NONISOMETRICDLG_H diff --git a/src/VISUGUI/VisuGUI_OffsetDlg.cxx b/src/VISUGUI/VisuGUI_OffsetDlg.cxx index a0bd394a..3fca41a1 100644 --- a/src/VISUGUI/VisuGUI_OffsetDlg.cxx +++ b/src/VISUGUI/VisuGUI_OffsetDlg.cxx @@ -175,7 +175,7 @@ void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, float* theOffset) ViewManagerList aViewManagerList; SalomeApp_Application* anApp = myModule->getApp(); - anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList); + anApp->viewManagers(aViewManagerList); QPtrListIterator anVMIter (aViewManagerList); for (; anVMIter.current(); ++anVMIter) { SUIT_ViewManager* aViewManager = anVMIter.current(); diff --git a/src/VISUGUI/VisuGUI_Plot3DDlg.cxx b/src/VISUGUI/VisuGUI_Plot3DDlg.cxx index 62ca7306..a7935632 100644 --- a/src/VISUGUI/VisuGUI_Plot3DDlg.cxx +++ b/src/VISUGUI/VisuGUI_Plot3DDlg.cxx @@ -254,6 +254,7 @@ void VisuGUI_Plot3DPane::storePrsParams() if (!myPipeCopy) myPipeCopy = VISU_Plot3DPL::New(); if (myPrs) { + myPipeCopy->SetIDMapper(myPrs->GetPL()->GetIDMapper()); myPipeCopy->ShallowCopy(myPrs->GetPL()); storeToPrsObject(myPrs); } diff --git a/src/VISUGUI/VisuGUI_PopupTools.cxx b/src/VISUGUI/VisuGUI_PopupTools.cxx index 39f904b0..b4ca7c20 100644 --- a/src/VISUGUI/VisuGUI_PopupTools.cxx +++ b/src/VISUGUI/VisuGUI_PopupTools.cxx @@ -26,12 +26,15 @@ // Module : VISU #include "VisuGUI_PopupTools.h" +#include "VisuGUI_ViewTools.h" #include "VisuGUI_Tools.h" #include "SalomeApp_Study.h" #include "LightApp_Study.h" #include "VISU_Actor.h" #include "VISU_ScalarMapAct.h" +#include "VISU_Result_i.hh" +#include "SalomeApp_Study.h" using namespace VISU; @@ -45,6 +48,8 @@ QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const if ( !val.isValid() ) { if ( p == "type" ) val = QtxValue( type( ind ) ); else if ( p == "nbComponents" ) val = QtxValue( nbComponents( ind ) ); + else if ( p == "medEntity" ) val = QtxValue( medEntity( ind ) ); + else if ( p == "medSource" ) val = QtxValue( medSource( ind ) ); else if ( p == "representation" ) val = QtxValue( representation( ind ) ); else if ( p == "nbTimeStamps" ) val = QtxValue( nbTimeStamps( ind ) ); else if ( p == "nbChildren" ) val = QtxValue( nbChildren( ind ) ); @@ -69,7 +74,7 @@ QString VisuGUI_Selection::type( const int ind ) const { QString aResStr; VISU::Storable::TRestoringMap aMap; - SalomeApp_Study* aStudy = dynamic_cast( ( LightApp_Study* )study() ); + SalomeApp_Study* aStudy = GetStudy(); if ( !aStudy ) return aResStr; CORBA::Object_var anObject = GetSelectedObj( aStudy, entry( ind ), &aMap ); @@ -87,6 +92,7 @@ QString VisuGUI_Selection::type( const int ind ) const ENUM2STRING( aResStr, VISU::TSCALARMAP ); ENUM2STRING( aResStr, VISU::TISOSURFACE ); ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE ); + ENUM2STRING( aResStr, VISU::TSCALARMAPONDEFORMEDSHAPE ); ENUM2STRING( aResStr, VISU::TCUTPLANES ); ENUM2STRING( aResStr, VISU::TCUTLINES ); ENUM2STRING( aResStr, VISU::TVECTORS ); @@ -125,7 +131,7 @@ QString VisuGUI_Selection::nbComponents( const int ind ) const { QString aResStr; VISU::Storable::TRestoringMap aMap; - SalomeApp_Study* aStudy = dynamic_cast( ( LightApp_Study* )study() ); + SalomeApp_Study* aStudy = GetStudy(); if ( !aStudy ) return aResStr; GetSelectedObj( aStudy, entry( ind ), &aMap ); @@ -136,11 +142,61 @@ QString VisuGUI_Selection::nbComponents( const int ind ) const return aResStr; } +QString VisuGUI_Selection::medEntity( const int ind ) const +{ + bool isExist; + VISU::Storable::TRestoringMap aMap; + GetSelectedObj( GetStudy(), entry( ind ), &aMap ); + const QString& aVal = VISU::Storable::FindValue(aMap,"myEntityId",&isExist); + if ( isExist ) { + using namespace VISU; + TEntity anEntityId = TEntity(aVal.toInt()); + switch(anEntityId){ + case NODE_ENTITY : + return "NODE_ENTITY"; + case EDGE_ENTITY : + return "EDGE_ENTITY"; + case FACE_ENTITY : + return "FACE_ENTITY"; + case CELL_ENTITY : + return "CELL_ENTITY"; + default: + return QString(); + } + } + return QString(); +} + +QString VisuGUI_Selection::medSource( const int ind ) const +{ + _PTR(Study) aStudyDS = GetStudy()->studyDS(); + if(_PTR(SObject) aSObject = aStudyDS->FindObjectID(entry(ind))){ + VISU::Result_var aRes; + if(VISU::Result_i* aResult = CheckResult(myModule,aSObject,aRes)){ + using namespace VISU; + Result_i::ECreationId aCreationId = aResult->GetCreationId(); + switch(aCreationId){ + case Result_i::eImportFile : + return "eImportFile"; + case Result_i::eCopyAndImportFile : + return "eCopyAndImportFile"; + case Result_i::eImportMed : + return "eImportMed"; + case Result_i::eImportMedField : + return "eImportMedField"; + default: + return QString(); + } + } + } + return QString(); +} + QString VisuGUI_Selection::nbTimeStamps( const int ind ) const { QString aResStr; VISU::Storable::TRestoringMap aMap; - SalomeApp_Study* aStudy = dynamic_cast( ( LightApp_Study* )study() ); + SalomeApp_Study* aStudy = GetStudy(); if ( !aStudy ) return aResStr; GetSelectedObj( aStudy, entry( ind ), &aMap ); @@ -171,10 +227,17 @@ QString VisuGUI_Selection::representation( const int ind ) const return aResStr; } +SalomeApp_Study* VisuGUI_Selection::GetStudy() const + +{ + LightApp_Study* aLightStudy = const_cast( study() ); + return dynamic_cast( aLightStudy ); +} + int VisuGUI_Selection::nbChild( const int ind, const bool named ) const { int cnt = 0; - SalomeApp_Study* aSStudy = dynamic_cast( ( LightApp_Study* )study() ); + SalomeApp_Study* aSStudy = GetStudy(); if ( !aSStudy ) return cnt; _PTR(Study) aStudy = GetCStudy( aSStudy ); @@ -205,15 +268,47 @@ QString VisuGUI_Selection::nbNamedChildren( const int ind ) const return aResStr; } -QString VisuGUI_Selection::isVisible( const int ind ) const +namespace { - QString aResStr; + struct TIsVisibleFunctor + { + template + QString + Get(VisuGUI* theModule, + const QString& theEntry) + { + typedef typename TViewer::TViewWindow TViewWindow; + if(TViewWindow* aViewWindow = GetViewWindow(theModule)) + if(VISU_Actor* anActor = FindActor(aViewWindow,theEntry.latin1())) + return anActor->GetVisibility() ? "true" : "false"; - if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) ) - if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) ) - aResStr = anVISUActor->GetVisibility() ? "1" : "0"; + return QString(); + } + }; - return aResStr; + template + struct TPopupDispatcher + { + QString + operator()(VisuGUI* theModule, + const QString& theEntry) + { + if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){ + QString aType = aViewManager->getType(); + TPopupFunctor aFunctor; + if(aType == SVTK_Viewer::Type()) + return aFunctor.template Get(theModule,theEntry); + else if(aType == VVTK_Viewer::Type()) + return aFunctor.template Get(theModule,theEntry); + } + return QString(); + } + }; +} + +QString VisuGUI_Selection::isVisible( const int ind ) const +{ + return TPopupDispatcher()((VisuGUI*)myModule,entry(ind)); } QString VisuGUI_Selection::isShrunk( const int ind ) const diff --git a/src/VISUGUI/VisuGUI_PopupTools.h b/src/VISUGUI/VisuGUI_PopupTools.h index 19005c88..1a7ae957 100644 --- a/src/VISUGUI/VisuGUI_PopupTools.h +++ b/src/VISUGUI/VisuGUI_PopupTools.h @@ -35,6 +35,7 @@ ////////////////////////////////////////////////// class SalomeApp_Module; +class SalomeApp_Study; class VisuGUI_Selection : public LightApp_Selection { @@ -47,6 +48,8 @@ public: private: QString type( const int ) const; QString nbComponents( const int ) const; + QString medEntity( const int ) const; + QString medSource( const int ) const; QString nbTimeStamps( const int ) const; QString representation( const int ) const; QString nbChildren( const int ) const; @@ -59,6 +62,7 @@ private: private: int nbChild( const int, const bool ) const; + SalomeApp_Study* GetStudy() const; private: SalomeApp_Module* myModule; diff --git a/src/VISUGUI/VisuGUI_Prs3dTools.h b/src/VISUGUI/VisuGUI_Prs3dTools.h index d6a6959b..ab12f335 100644 --- a/src/VISUGUI/VisuGUI_Prs3dTools.h +++ b/src/VISUGUI/VisuGUI_Prs3dTools.h @@ -29,42 +29,59 @@ #ifndef VisuGUI_Prs3dTools_HeaderFile #define VisuGUI_Prs3dTools_HeaderFile -#include "VisuGUI_Tools.h" +#include "VISU_Gen_i.hh" +#include "VisuGUI_ViewTools.h" #include "VisuGUI_DialogRunner.h" -int runAndWait( QDialog* dlg, const bool modal ) -{ - VisuGUI_DialogRunner r( dlg ); - return r.run( modal ); -} +#include namespace VISU { class CutLines_i; //--------------------------------------------------------------- - template + inline + int + runAndWait( QDialog* dlg, const bool modal ) + { + VisuGUI_DialogRunner r( dlg ); + return r.run( modal ); + } + + //--------------------------------------------------------------- + template void - EditPrs3d (SalomeApp_Module* theModule, VISU::Prs3d_i* thePrs3d) + EditPrs3d(VisuGUI* theModule, + VISU::Prs3d_i* thePrs3d) { - TPrs3d_i* aPrsObject = dynamic_cast(thePrs3d); - if (aPrsObject) { + if(TPrs3d_i* aPrs3d = dynamic_cast(thePrs3d)){ TDlg* aDlg = new TDlg (theModule); - aDlg->initFromPrsObject(aPrsObject); - if (runAndWait(aDlg,IsDlgModal)) { - if (!(aDlg->storeToPrsObject(aPrsObject))) { + aDlg->initFromPrsObject(aPrs3d); + if (runAndWait(aDlg,TIsDlgModal)) { + if (!(aDlg->storeToPrsObject(aPrs3d))) { delete aDlg; return; } - RecreateActor(theModule, aPrsObject); - if (SVTK_ViewWindow* vw = GetViewWindow(theModule)) { - vw->getRenderer()->ResetCameraClippingRange(); - vw->Repaint(); + try { + aPrs3d->UpdateActors(); + } catch (std::runtime_error& exc) { + INFOS(exc.what()); + SUIT_MessageBox::warn1 + (GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": pammy1 " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); + + aPrs3d->RemoveActors(); + } + typedef typename TViewer::TViewWindow TViewWindow; + if(TViewWindow* aViewWindow = GetViewWindow(theModule)){ + aViewWindow->getRenderer()->ResetCameraClippingRange(); + aViewWindow->Repaint(); } // Optionally, create table and curves for cut lines QApplication::setOverrideCursor(Qt::waitCursor); CreateCurves( theModule, - dynamic_cast( aPrsObject ), + dynamic_cast( aPrs3d ), aDlg, false ); // in edition mode QApplication::restoreOverrideCursor(); @@ -73,11 +90,20 @@ namespace VISU } } + template + inline + void + EditPrs3d(VisuGUI* theModule, + VISU::Prs3d_i* thePrs3d) + { + EditPrs3d(theModule,thePrs3d); + } //--------------------------------------------------------------- template + inline TPrs3d_i* - CreatePrs3d(SalomeApp_Module* theModule, + CreatePrs3d(VisuGUI* theModule, _PTR(SObject) theTimeStamp, const char* theMeshName, VISU::Entity theEntity, @@ -87,13 +113,12 @@ namespace VISU VISU::Result_var aResult; if (CheckResult(theModule,theTimeStamp,aResult)){ QApplication::setOverrideCursor(Qt::waitCursor); - typedef typename TPrs3d_i::TInterface TPrs3d; - typename TPrs3d::_var_type aPrs3d = - GetVisuGen(theModule)->template Prs3dOnField + TPrs3d_i* aPrs3d = + GetVisuGen(theModule)->template CreatePrs3d (aResult,theMeshName,theEntity,theFieldName,theTimeId); QApplication::restoreOverrideCursor(); - if (!CORBA::is_nil(aPrs3d.in())) - return dynamic_cast(VISU::GetServant(aPrs3d.in()).in()); + if(aPrs3d) + return aPrs3d; } SUIT_MessageBox::warn1(GetDesktop(theModule), QObject::tr("WRN_VISU"), @@ -104,28 +129,28 @@ namespace VISU //--------------------------------------------------------------- - template + template + inline bool - CreatePrs3d(SalomeApp_Module* theModule, + CreatePrs3d(VisuGUI* theModule, _PTR(SObject) theTimeStamp, - const Handle(SALOME_InteractiveObject)& theIO) + const Handle(SALOME_InteractiveObject)& theIO, + const bool theIsCreateView = false) { - using namespace VISU; Storable::TRestoringMap aMap = getMapOfValue(theTimeStamp); + bool isExist; QString aType = Storable::FindValue(aMap,"myType",&isExist); if(!isExist || aType.toInt() != TTIMESTAMP ) return false; + QString aMeshName = Storable::FindValue(aMap,"myMeshName",&isExist).latin1(); QString anEntity = Storable::FindValue(aMap,"myEntityId",&isExist).latin1(); QString aFieldName = Storable::FindValue(aMap,"myFieldName",&isExist).latin1(); QString aTimeStampId = Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1(); // - SUIT_ResourceMgr* aResourceMgr = GetResourceMgr(); - VisuGUI* aMod = dynamic_cast(theModule); - int aPos = 1; - if (aMod) aPos = GetFreePositionOfDefaultScalarBar(aMod); - aResourceMgr->setValue("VISU","scalar_bar_position_num",aPos); + int aPos = GetFreePositionOfDefaultScalarBar(theModule); + GetResourceMgr()->setValue("VISU","scalar_bar_position_num",aPos); // QApplication::setOverrideCursor(Qt::waitCursor); @@ -152,6 +177,7 @@ namespace VISU dynamic_cast( aPrs3d ), aDlg, true ); // in creation mode + UpdateObjBrowser(theModule,true,theTimeStamp); QApplication::restoreOverrideCursor(); delete aDlg; } else { @@ -161,40 +187,57 @@ namespace VISU } } } - PublishInView(theModule,aPrs3d); - Prs3d_i* aPrs_i = dynamic_cast(aPrs3d); - if (aPrs_i != NULL && aMod != NULL) - AddScalarBarPosition(aMod,aPrs_i,aPos); + PublishInView(theModule,aPrs3d,true,theIsCreateView); + + AddScalarBarPosition(theModule,aPrs3d,aPos); + return true; } + return false; } - + //--------------------------------------------------------------- - template + template + inline void - CreatePrs3d(SalomeApp_Module* theModule) + CreatePrs3d(VisuGUI* theModule, + const bool theIsCreateView = true) { - if (CheckLock(GetCStudy(GetAppStudy(theModule)))) + if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule))) return; _PTR(SObject) aTimeStampSObj; Handle(SALOME_InteractiveObject) anIO; - if (!CheckTimeStamp(theModule,aTimeStampSObj,&anIO)) + if(!CheckTimeStamp(theModule,aTimeStampSObj,&anIO)) return; - if (!CreatePrs3d(theModule,aTimeStampSObj,anIO)) + if(!CreatePrs3d(theModule,aTimeStampSObj,anIO,theIsCreateView)) return; theModule->application()->putInfo(QObject::tr("INF_DONE")); - theModule->updateObjBrowser(); - UpdateObjBrowser(theModule); - if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) + typedef typename TViewer::TViewWindow TView; + if(TView* aView = GetViewWindow(theModule,theIsCreateView)) aView->onFitAll(); } + template + inline + void + CreatePrs3d(VisuGUI* theModule, + const bool theIsCreateView = true) + { + if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){ + QString aType = aViewManager->getType(); + if(aType == SVTK_Viewer::Type()) + CreatePrs3d(theModule,theIsCreateView); + else if(aType == VVTK_Viewer::Type()) + CreatePrs3d(theModule,theIsCreateView); + } + } + } #endif diff --git a/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx b/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx index 5d89779d..ddc63e88 100644 --- a/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx +++ b/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx @@ -30,7 +30,10 @@ #include "VisuGUI.h" #include "VisuGUI_Tools.h" -#include "VisuGUI_FontWg.h" + +#include "SVTK_FontWidget.h" + +#include "SVTK_ViewWindow.h" #include "SVTK_ViewWindow.h" @@ -80,10 +83,6 @@ VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref): myModeLbl = new QLabel("Scalar Mode", RangeGroup); myModeCombo = new QComboBox(RangeGroup); - myModeCombo->insertItem("Modulus"); - myModeCombo->insertItem("Component 1"); - myModeCombo->insertItem("Component 2"); - myModeCombo->insertItem("Component 3"); CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), RangeGroup); CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); @@ -250,6 +249,7 @@ VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref): // signals and slots connections =========================================== connect( RangeGroup, SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) ); + connect( myModeCombo, SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( int ) ) ); connect( OrientGroup, SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) ); connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) ); connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) ); @@ -538,7 +538,6 @@ void VisuGUI_ScalarBarPane::storeToResources() { void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) { initFromResources(); myScalarMap = thePrs; - myModeCombo->setCurrentItem(thePrs->GetScalarMode()); setPosAndSize( thePrs->GetPosX(), thePrs->GetPosY(), thePrs->GetWidth(), @@ -557,7 +556,36 @@ void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) { setRange( thePrs->GetMin(), thePrs->GetMax(), /*0.0, 0.0,*/ thePrs->IsRangeFixed() ); setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() ); - bool isScalarMode = (thePrs->GetField()->myNbComp > 1); + + // Update myModeCombo + int aNbComp = thePrs->GetField()->myNbComp; + bool isScalarMode = (aNbComp > 1); + myModeCombo->clear(); + myModeCombo->insertItem(""); + const VISU::PField& aField = thePrs->GetField(); + const VISU::TNames& aCompNames = aField->myCompNames; + const VISU::TNames& aUnitNames = aField->myUnitNames; + for(int i = 0; i < aNbComp; i++){ + QString aComponent = QString(aCompNames[i]).simplifyWhiteSpace(); + if(aComponent.isNull() || aComponent == "") + aComponent = "Component " + QString::number(i+1); + else + aComponent = "[" + QString::number(i+1) + "] " + aComponent; + + QString anUnit = QString(aUnitNames[i]).simplifyWhiteSpace(); + if(anUnit.isNull() || anUnit == "") + anUnit = "-"; + + aComponent = aComponent + ", " + anUnit; + + myModeCombo->insertItem(aComponent); + } + // + myModeCombo->setCurrentItem(thePrs->GetScalarMode()); + if (aNbComp==1){ + myModeCombo->setCurrentItem(1); + } + // myModeLbl->setEnabled(isScalarMode); myModeCombo->setEnabled(isScalarMode); @@ -610,7 +638,7 @@ void VisuGUI_ScalarBarPane::createScalarBar() if (myPreviewActor != 0) return; if (myScalarMap == NULL) return; - if (!check()) return; + if(!check()) return; if ( myBusy ) return; @@ -706,9 +734,9 @@ void VisuGUI_ScalarBarPane::createScalarBar() void VisuGUI_ScalarBarPane::deleteScalarBar() { if ( myBusy ) return; - + if (myPreviewActor == 0) return; - if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) { + if (SVTK_ViewWindow* vf = VISU::GetViewWindow()){ vf->RemoveActor(myPreviewActor); myPreviewActor->GetScalarBar()->VisibilityOff(); } @@ -724,8 +752,7 @@ void VisuGUI_ScalarBarPane::deletePreview() /** * Store values to presentation object */ -int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) -{ +int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) { thePrs->SetScalarMode(myModeCombo->currentItem()); thePrs->SetPosition(XSpin->value(), YSpin->value()); thePrs->SetSize(WidthSpin->value(), HeightSpin->value()); @@ -861,6 +888,22 @@ void VisuGUI_ScalarBarPane::XYChanged( double ) updatePreview(); } +/*! + Called when scalar mode is changed +*/ +void VisuGUI_ScalarBarPane::changeScalarMode( int theMode ) +{ + if ( myScalarMap ) { + if ( RBFrange->isChecked() ) { + float aRange[2]; + myScalarMap->SetScalarMode(theMode); + myScalarMap->GetScalarMapPL()->GetSourceRange(aRange); + MinEdit->setText( QString::number( aRange[0] ) ); + MaxEdit->setText( QString::number( aRange[1] ) ); + } + } +} + /*! Sets default values and range mode */ @@ -883,6 +926,14 @@ void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, d changeRange( 0 ); } +/*! + Sets default values and range mode +*/ +void VisuGUI_ScalarBarPane::setDefaultRange(double imin, double imax){ + Rmin = imin; + Rmax = imax; +} + /*! Sets size and position */ @@ -1081,7 +1132,7 @@ VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent) // font QHBox* aHBox = new QHBox (aTitleGrp); aHBox->setSpacing(5); - myTitleFont = new VisuGUI_FontWg (aHBox); + myTitleFont = new SVTK_FontWidget (aHBox); TopLayout->addWidget(aTitleGrp); @@ -1091,7 +1142,7 @@ VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent) // font aHBox = new QHBox (aLabelsGrp); aHBox->setSpacing(5); - myLabelFont = new VisuGUI_FontWg (aHBox); + myLabelFont = new SVTK_FontWidget (aHBox); TopLayout->addWidget(aLabelsGrp); diff --git a/src/VISUGUI/VisuGUI_ScalarBarDlg.h b/src/VISUGUI/VisuGUI_ScalarBarDlg.h index ccb704ad..4f53a39b 100644 --- a/src/VISUGUI/VisuGUI_ScalarBarDlg.h +++ b/src/VISUGUI/VisuGUI_ScalarBarDlg.h @@ -24,6 +24,7 @@ // File : VisuGUI_ScalarBarDlg.h // Author : Laurent CORNABE & Hubert ROLLAND // Module : VISU +// $Header$ #ifndef VISUGUI_SCALARBARDLG_H #define VISUGUI_SCALARBARDLG_H @@ -59,7 +60,7 @@ class QToolButton; class QtxDblSpinBox; class SalomeApp_Module; -class VisuGUI_FontWg; +class SVTK_FontWidget; class VISU_ScalarMapAct; class VisuGUI_TextPrefDlg: public QDialog @@ -77,8 +78,8 @@ class VisuGUI_TextPrefDlg: public QDialog { (isVisible)? myTitleEdt->show() : myTitleEdt->hide(); } public: - VisuGUI_FontWg* myTitleFont; - VisuGUI_FontWg* myLabelFont; + SVTK_FontWidget* myTitleFont; + SVTK_FontWidget* myLabelFont; private: QLineEdit* myTitleEdt; @@ -94,6 +95,7 @@ class VisuGUI_ScalarBarPane : public QVBox ~VisuGUI_ScalarBarPane() {}; void setRange( double imin, double imax, /*double fmin, double fmax,*/ bool sbRange ); + void setDefaultRange(double imin, double imax); bool isIRange() {return RBIrange->isChecked();} double getMin() {return MinEdit->text().toDouble();} double getMax() {return MaxEdit->text().toDouble();} @@ -155,6 +157,7 @@ class VisuGUI_ScalarBarPane : public QVBox void changeDefaults( int ); void changeRange( int ); void XYChanged( double ); + void changeScalarMode( int ); void onTextPref(); void onPreviewCheck(bool thePreview); void updatePreview(); diff --git a/src/VISUGUI/VisuGUI_ScalarMapOnDeformedShapeDlg.cxx b/src/VISUGUI/VisuGUI_ScalarMapOnDeformedShapeDlg.cxx new file mode 100644 index 00000000..95e13191 --- /dev/null +++ b/src/VISUGUI/VisuGUI_ScalarMapOnDeformedShapeDlg.cxx @@ -0,0 +1,380 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_ScalarMapOnDeformedShapeDlg.cxx +// Author : Eugeny Nikolaev +// Module : VISU + +#include "VisuGUI_ScalarMapOnDeformedShapeDlg.h" +#include "VisuGUI_Tools.h" +#include "VISU_ScalarMapOnDeformedShape_i.hh" +#include "VISU_ScalarMapOnDeformedShapePL.hxx" +#include "SalomeApp_Module.h" +#include "LightApp_SelectionMgr.h" +#include "SUIT_Desktop.h" +#include "VISU_ScalarMapPL.hxx" + +#include "SALOME_ListIO.hxx" + +#include "VISU_Convertor.hxx" + +#include "SALOMEDSClient_AttributeComment.hxx" +#include "SALOMEDSClient_AttributeName.hxx" + +#include +#include + +using namespace std; + +#define MYDEBUG 0 + +/*! + * Constructor + */ +VisuGUI_ScalarMapOnDeformedShapeDlg::VisuGUI_ScalarMapOnDeformedShapeDlg (SalomeApp_Module* theModule) + : QDialog(VISU::GetDesktop(theModule), "VisuGUI_ScalarMapOnDeformedShapeDlg", false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myVisuGUI(theModule) +{ + myPrs = NULL; + setCaption(tr("DLG_TITLE")); + setSizeGripEnabled(TRUE); + + QVBoxLayout* TopLayout = new QVBoxLayout (this); + TopLayout->setSpacing(6); + TopLayout->setMargin(11); + + QTabWidget* aTabBox = new QTabWidget (this); + + // Scalar Map on Deformed shape pane + QVBox* aBox = new QVBox (this); + aBox->setMargin(11); + QFrame* TopGroup = new QFrame (aBox, "TopGroup"); + TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken); + TopGroup->setLineWidth(1); + QGridLayout* TopGroupLayout = new QGridLayout (TopGroup); + TopGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + TopGroupLayout->setSpacing(6); + TopGroupLayout->setMargin(11); + + // Scale factor + QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup, "ScaleLabel"); + TopGroupLayout->addWidget(ScaleLabel, 0, 0); + + ScalFact = new QtxDblSpinBox (0.0, 1.0E+38, 0.1, TopGroup); + ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + ScalFact->setPrecision(5); + ScalFact->setValue(0.1); + TopGroupLayout->addWidget(ScalFact, 0, 1); + + // Fields combo box + QLabel* FieldLabel = new QLabel (tr("FIELD_ITEM"), TopGroup, "FieldLabel"); + myFieldsCombo = new QComboBox (TopGroup,"Fields"); + + TopGroupLayout->addWidget(FieldLabel, 1, 0); + TopGroupLayout->addWidget(myFieldsCombo,1,1); + + // TimeStamps combo box + QLabel* TimeStampLabel = new QLabel (tr("TIMESTAMP_ITEM"), TopGroup, "TimeStampLabel"); + myTimeStampsCombo = new QComboBox (TopGroup,"TimeStamp"); + + TopGroupLayout->addWidget(TimeStampLabel, 2, 0); + TopGroupLayout->addWidget(myTimeStampsCombo,2,1); + + // + aTabBox->addTab(aBox, tr("SCALAR_MAP_ON_DEFORMED_SHAPE_TAB")); + + // Scalar bar pane + myScalarPane = new VisuGUI_ScalarBarPane (this, false); + myScalarPane->setMargin(5); + + aTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB")); + + // Buttons + QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons"); + GroupButtons->setGeometry(QRect(10, 10, 281, 48)); + GroupButtons->setColumnLayout(0, Qt::Vertical); + GroupButtons->layout()->setSpacing(0); + GroupButtons->layout()->setMargin(0); + QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout()); + GroupButtonsLayout->setAlignment(Qt::AlignTop); + GroupButtonsLayout->setSpacing(6); + GroupButtonsLayout->setMargin(11); + + QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk"); + buttonOk->setAutoDefault(TRUE); + buttonOk->setDefault(TRUE); + GroupButtonsLayout->addWidget(buttonOk, 0, 0); + + GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding, + QSizePolicy::Minimum), 0, 1); + + QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel"); + buttonCancel->setAutoDefault(TRUE); + GroupButtonsLayout->addWidget(buttonCancel, 0, 2); + + // Add Tab box and Buttons to the top layout + TopLayout->addWidget(aTabBox); + TopLayout->addWidget(GroupButtons); + + // signals and slots connections + connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept())); + connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); + connect(myFieldsCombo, SIGNAL(activated(int)), this, SLOT(onFieldChanged(int))); + connect(myTimeStampsCombo, SIGNAL(activated(int)), this, SLOT(onTimeStampChanged(int))); + +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject (VISU::ScalarMapOnDeformedShape_i* thePrs,bool isAnim) +{ + myPrs = thePrs; + + setFactor(thePrs->GetScale()); + myTimeStampsCombo->setDisabled(isAnim); + + QString aFieldName(thePrs->GetScalarFieldName()); + float aIterFloat = GetFloatValueOfTimeStamp(thePrs->GetScalarIteration()); + QString aIteration(QString("%1").arg(aIterFloat)); + + if (myMeshFieldsTimes.size() == 0) + { + // find all fields and time stamps on it + _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI)); + LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI); + SALOME_ListIO selected; + aSel->selectedObjects(selected); + if (selected.Extent() > 0) { + Handle(SALOME_InteractiveObject) aIO = selected.First(); + if (aIO->hasEntry()) { + _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry()); + aSObject = aSObject->GetFather(); + aSObject = aSObject->GetFather(); + aSObject = aSObject->GetFather(); + aSObject = aSObject->GetFather(); + mySelectionObj = aSObject; + CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj); + VISU::Result_var aResult; + if (CORBA::is_nil(anObject)) { + mySelectionObj = mySelectionObj->GetFather(); + } + _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj); + + for (aIter->InitEx(true); aIter->More(); aIter->Next()) { + _PTR(SObject) aChildSObj = aIter->Value(); + CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj); + + _PTR(GenericAttribute) anAttr; + if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) { + _PTR(AttributeComment) aComment (anAttr); + string aComm = aComment->Value(); + QString strIn (aComm.c_str()); + VISU::Storable::TRestoringMap aMap; + VISU::Storable::StrToMap(strIn,aMap); + bool isExist; + VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt(); + if (isExist) { + if ((aType == VISU::TTIMESTAMP)) { + _PTR(GenericAttribute) aNameAttr; + if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) { + _PTR(AttributeName) aName (aNameAttr); + VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject); + QString aMeshName = VISU::getValue(aChildSObj,"myMeshName"); + if(QString(thePrs->GetMeshName().c_str()) != aMeshName) continue; + myCurrMeshName = aMeshName; + QString aFieldName = VISU::getValue(aChildSObj,"myFieldName"); + QString aTimeIter = VISU::getValue(aChildSObj,"myTimeStampId"); + QString aEntity = VISU::getValue(aChildSObj,"myEntityId"); + VISU::TEntity anEntity; + switch(aEntity.toInt()){ + case 0: anEntity = VISU::NODE_ENTITY; break; + case 1: anEntity = VISU::EDGE_ENTITY; break; + case 2: anEntity = VISU::FACE_ENTITY; break; + case 3: anEntity = VISU::CELL_ENTITY; break; + } + TFT &aFieldsMap = myMeshFieldsTimes[aMeshName.latin1()]; + TFE aKey(aFieldName.latin1(),anEntity); + aFieldsMap[aKey][aTimeIter.toInt()] = GetFloatValueOfTimeStamp(aTimeIter.toInt()); + } + } + } + } + } + } + } + + AddAllFieldNames(); + + } + myFieldsCombo->setCurrentText(aFieldName); + AddAllTimes(myFieldsCombo->currentText()); + myTimeStampsCombo->setCurrentText(aIteration); + SetScalarField(); + + myScalarPane->initFromPrsObject(myPrs); +} + +int VisuGUI_ScalarMapOnDeformedShapeDlg::storeToPrsObject(VISU::ScalarMapOnDeformedShape_i* thePrs, bool theUpdateScalar) { + + thePrs->SetScale(getFactor()); + + thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(), + myPrs->GetScalarFieldName().c_str(), + myPrs->GetScalarIteration(), + myPrs->GetScalarEntity()); + + if (theUpdateScalar) SetScalarField(); + + thePrs->ShowColored(true); + + myScalarPane->storeToPrsObject(thePrs); + + myPrs = thePrs; + + return 1; +} + +int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldNamePos(){ + return myFieldsCombo->currentItem(); +} + +QString VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldName(){ + return myFieldsCombo->currentText(); +} + +int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarNbIterations(){ + return myTimeStampsCombo->count(); +} + +VISU::TEntity VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarEntity(){ + VISU::TEntity anEntity; + TFT::const_iterator aIterField = myMeshFieldsTimes[myCurrMeshName].begin(); + for(;aIterField != myMeshFieldsTimes[myCurrMeshName].end();aIterField++){ + if (aIterField->first.first == myFieldsCombo->currentText()){ + anEntity = aIterField->first.second; + break; + } + } + return anEntity; +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(){ + SetScalarField(myTimeStampsCombo->currentItem()+1); +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(int theIter,QString theFieldName){ + + QString aFieldName; + + if(theFieldName.isEmpty()) + aFieldName = myFieldsCombo->currentText(); + else + aFieldName = theFieldName; + + VISU::TEntity anEntity = getCurrentScalarEntity(); + + myPrs->SetScalarField(myCurrMeshName.latin1(), + aFieldName.latin1(), + theIter, + anEntity); + + myScalarPane->storeToPrsObject(myPrs); + + UpdateScalarField(); +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::accept() +{ + if (myScalarPane->check()){ + myScalarPane->deletePreview(); + QDialog::accept(); + } +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::reject() +{ + myScalarPane->deletePreview(); + QDialog::reject(); +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllFieldNames(){ + TMF::const_iterator aIterMesh = myMeshFieldsTimes.begin(); + for(;aIterMesh != myMeshFieldsTimes.end();aIterMesh++){ + QString aMeshName = aIterMesh->first; + TFT::const_iterator aIterField = (aIterMesh->second).begin(); + for(;aIterField != (aIterMesh->second).end(); aIterField++){ + QString aFieldName = aIterField->first.first; + myFieldsCombo->insertItem(aFieldName); + } + } +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllTimes(const QString& theFieldName){ + TMF::const_iterator aIterMesh = myMeshFieldsTimes.begin(); + for(;aIterMesh != myMeshFieldsTimes.end();aIterMesh++){ + QString aMeshName = aIterMesh->first; + TFT::const_iterator aIterField = (aIterMesh->second).begin(); + for(;aIterField != (aIterMesh->second).end(); aIterField++){ + QString aFieldName = aIterField->first.first; + if(theFieldName != aFieldName) continue; + myTimeStampsCombo->clear(); + TTL::const_iterator aTimeIter = (aIterField->second).begin(); + for(;aTimeIter != (aIterField->second).end(); aTimeIter++) + myTimeStampsCombo->insertItem(QString("%1").arg(aTimeIter->second)); + return; + } + } +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::onFieldChanged(int){ + AddAllTimes(myFieldsCombo->currentText()); + SetScalarField(); + UpdateScalarField(); +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::onTimeStampChanged(int){ + SetScalarField(); + UpdateScalarField(); +} + +void VisuGUI_ScalarMapOnDeformedShapeDlg::UpdateScalarField(){ + myPrs->SetScale(getFactor()); + float aRange[2]; + myPrs->GetScalarMapOnDeformedShapePL()->Build(); + myPrs->GetScalarMapOnDeformedShapePL()->Update(); + myPrs->GetScalarMapOnDeformedShapePL()->GetSourceRange(aRange); + double aDoubleRange[2]; + aDoubleRange[0] = double(aRange[0]); + aDoubleRange[1] = double(aRange[1]); + myScalarPane->initFromPrsObject(myPrs); + myScalarPane->setRange(aDoubleRange[0],aDoubleRange[1],myScalarPane->isIRange()); +} + +float VisuGUI_ScalarMapOnDeformedShapeDlg::GetFloatValueOfTimeStamp(int theIter){ + float ret=1; + VISU::PField aField = myPrs->GetField(); + VISU::TValField& aValField = aField->myValField; + VISU::PValForTime aValForTime = aValField.find(theIter)->second; + if(aValForTime) + ret = float(aValForTime->myTime.first); + return ret; +} diff --git a/src/VISUGUI/VisuGUI_ScalarMapOnDeformedShapeDlg.h b/src/VISUGUI/VisuGUI_ScalarMapOnDeformedShapeDlg.h new file mode 100644 index 00000000..c49a3de1 --- /dev/null +++ b/src/VISUGUI/VisuGUI_ScalarMapOnDeformedShapeDlg.h @@ -0,0 +1,108 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_ScalarMapOnDeformedShapeDlg.h +// Author : Eugeny Nikolaev +// Module : VISU + +#ifndef VISUGUI_SCALARMAPONDEFORMEDSHAPEDLS_H +#define VISUGUI_SCALARMAPONDEFORMEDSHAPEDLS_H + +#include "VisuGUI_ScalarBarDlg.h" + +#include "QtxDblSpinBox.h" + +#include +#include +#include +#include +#include + +#include + +class SalomeApp_Module; +class QComboBox; +class QString; + +namespace VISU{ + class ScalarMapOnDeformedShape_i; +} + +class VisuGUI_ScalarMapOnDeformedShapeDlg : public QDialog +{ + Q_OBJECT + +public: + VisuGUI_ScalarMapOnDeformedShapeDlg (SalomeApp_Module* theModule); + ~VisuGUI_ScalarMapOnDeformedShapeDlg() {}; + + double getFactor() + { return ScalFact->value(); } + void setFactor(double theFactor) + { ScalFact->setValue(theFactor); } + + + void initFromPrsObject(VISU::ScalarMapOnDeformedShape_i* thePrs,bool isAnim=false); + int storeToPrsObject(VISU::ScalarMapOnDeformedShape_i* thePrs,bool theUpdateScalar=true); + + int getCurrentScalarFieldNamePos(); + QString getCurrentScalarFieldName(); + int getCurrentScalarNbIterations(); + VISU::TEntity getCurrentScalarEntity(); + void SetScalarField(int theIter,QString theFieldName=QString("")); + +protected slots: + void accept(); + void reject(); + +private slots: + void onFieldChanged(int i=0); + void onTimeStampChanged(int i=0); + +private: + QtxDblSpinBox* ScalFact; + VisuGUI_ScalarBarPane* myScalarPane; + QComboBox *myFieldsCombo; + QComboBox *myTimeStampsCombo; + + typedef std::map TTL; // Times map definition (iteration time, real value of time) + typedef std::pair TFE; // pair field name and entity + typedef std::map TFT; // Field name and enity to Times + typedef std::map TMF; // Mesh to fields map + + TMF myMeshFieldsTimes; + QString myCurrMeshName; + + _PTR(SObject) mySelectionObj; + VISU::ScalarMapOnDeformedShape_i* myPrs; + SalomeApp_Module* myVisuGUI; + +protected: + void UpdateScalarField(); + void SetScalarField(); + void AddAllFieldNames(); + void AddAllTimes(const QString& theFieldName); + float GetFloatValueOfTimeStamp(int iteration); +}; + +#endif // VISUGUI_DEFORMEDSHAPEDLS_H diff --git a/src/VISUGUI/VisuGUI_Selection.cxx b/src/VISUGUI/VisuGUI_Selection.cxx index 7b0bf293..5bcf465f 100644 --- a/src/VISUGUI/VisuGUI_Selection.cxx +++ b/src/VISUGUI/VisuGUI_Selection.cxx @@ -89,10 +89,13 @@ using namespace std; static VisuGUI_SelectionDlg* mySelectionDlg = NULL; -VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent) - : QDialog(parent, 0, false, WStyle_Customize | WStyle_NormalBorder | - WStyle_Title | WStyle_SysMenu | WDestructiveClose), - mySelectionMgr(NULL) +VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (const SalomeApp_Module* theModule): + QDialog(VISU::GetDesktop(theModule), + 0, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), + mySelectionMgr(NULL), + myModule(theModule) { if (mySelectionDlg) mySelectionDlg->close(true); @@ -259,10 +262,9 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent) myFl = false; // Activate Points pane - SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); myWidgetStack->raiseWidget(myPointsPane); - if (aSVTKVW) - aSVTKVW->SetSelectionMode(NodeSelection); + if(SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myModule)) + aViewWindow->SetSelectionMode(NodeSelection); onSelectionEvent(); mySelectionDlg = this; @@ -274,23 +276,23 @@ VisuGUI_SelectionDlg::~VisuGUI_SelectionDlg() void VisuGUI_SelectionDlg::onSelectionChange (int theId) { - SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); - if (!aSVTKVW) return; + SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myModule); + if (!aViewWindow) return; switch (theId) { case 0: // Points myWidgetStack->raiseWidget(myPointsPane); - aSVTKVW->SetSelectionMode(NodeSelection); + aViewWindow->SetSelectionMode(NodeSelection); onPointIdEdit(myIDValLbl->text()); break; case 1: // Cells myWidgetStack->raiseWidget(myCellsPane); - aSVTKVW->SetSelectionMode(CellSelection); + aViewWindow->SetSelectionMode(CellSelection); onCellIdEdit(myCellIDValLbl->text()); break; case 2: // Actor myWidgetStack->raiseWidget(myActorsPane); - aSVTKVW->SetSelectionMode(ActorSelection); + aViewWindow->SetSelectionMode(ActorSelection); onSelectionEvent(); } } @@ -298,12 +300,19 @@ void VisuGUI_SelectionDlg::onSelectionChange (int theId) void VisuGUI_SelectionDlg::closeEvent (QCloseEvent* theEvent) { - SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); - - mySelectionDlg = NULL; - if (aSVTKVW) - aSVTKVW->SetSelectionMode(ActorSelection); - disconnect(mySelectionMgr,0,0,0); + if( mySelectionDlg ) + { + mySelectionDlg = NULL; + disconnect(mySelectionMgr,0,0,0); + if(SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myModule)){ + switch(aViewWindow->SelectionMode()){ + case NodeSelection: + case CellSelection: + aViewWindow->SetSelectionMode(ActorSelection); + break; + } + } + } QDialog::closeEvent(theEvent); } @@ -328,8 +337,18 @@ template QString getVector(TData* theData, int theId){ #define ABS(a) (a>=0)?a:-a void VisuGUI_SelectionDlg::onSelectionEvent() { - SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); - if (!aSVTKVW) return; + SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myModule); + if (!aViewWindow) return; + + switch(aViewWindow->SelectionMode()){ + case NodeSelection: + case CellSelection: + case ActorSelection: + break; + default: + close( TRUE ); + return; + } if (myFl) return; myFl = true; @@ -339,14 +358,14 @@ void VisuGUI_SelectionDlg::onSelectionEvent() { SalomeApp_Application* anApp = dynamic_cast (SUIT_Session::session()->activeApplication()); - SVTK_Selector* aSelector = aSVTKVW->GetSelector(); + SVTK_Selector* aSelector = aViewWindow->GetSelector(); VISU::Prs3d_i* aPrs3d = NULL; _PTR(SObject) aSObject; Handle(SALOME_InteractiveObject) anIO; SALOME_ListIO aListIO; - mySelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type()); + mySelectionMgr->selectedObjects(aListIO); if (aListIO.Extent() == 1) { anIO = aListIO.First(); @@ -392,7 +411,7 @@ void VisuGUI_SelectionDlg::onSelectionEvent() { myFieldName->setText((aFieldName == "NULL") ? QString("No name") : aFieldName); VISU_Actor* anVISUActor = - VISU::FindActor(aSVTKVW, aSObject->GetID().c_str()); + VISU::FindActor(aViewWindow, aSObject->GetID().c_str()); if (anVISUActor) { float aCoord[6]; anVISUActor->GetBounds(aCoord); @@ -414,33 +433,34 @@ void VisuGUI_SelectionDlg::onSelectionEvent() { vtkPointData* aPntData = aDataSet->GetPointData(); for (int ind = 1; ind <= aMapIndex.Extent(); ind++) { - int aID = aMapIndex(ind); + int anID = aMapIndex(ind); switch (aType) { case 0: { - float aCoord[3]; - aDataSet->GetPoint(aID, aCoord); + float* aCoord = anVISUActor->GetNodeCoord(anID); + int aVTKID = anVISUActor->GetNodeVTKID(anID); myXValLbl->setText( QString::number( aCoord[0] ) ); myYValLbl->setText( QString::number( aCoord[1] ) ); myZValLbl->setText( QString::number( aCoord[2] ) ); - myIDValLbl->setText( QString::number(aID) ); - myScalarValLbl->setText(getValue(aPntData, aID)); - myVectorValLbl->setText(getVector(aPntData, aID)); + myIDValLbl->setText( QString::number(anID) ); + myScalarValLbl->setText(getValue(aPntData, aVTKID)); + myVectorValLbl->setText(getVector(aPntData, aVTKID)); } break; case 1: { - vtkCellData* aData = aDataSet->GetCellData(); - vtkCell* aCell = aDataSet->GetCell(aID); + vtkCellData* aCellData = aDataSet->GetCellData(); + vtkCell* aCell = anVISUActor->GetElemCell(anID); + int aVTKID = anVISUActor->GetElemVTKID(anID); if (aCell != NULL) { int aNbOfPoints = aCell->GetNumberOfPoints(); - if (aNbOfPoints <=1 ) { // Cell is point + if ( aNbOfPoints <= 1 ) { // Cell is point clearFields(); } else { - myCellIDValLbl->setText( QString::number(aID) ); - myCellScalarValLbl->setText(getValue(aData, aID)); - myCellVectorValLbl->setText(getVector(aData, aID)); + myCellIDValLbl->setText( QString::number(anID) ); + myCellScalarValLbl->setText(getValue(aCellData, aVTKID)); + myCellVectorValLbl->setText(getVector(aCellData, aVTKID)); float* aCoord; vtkIdList *aPointList = aCell->GetPointIds(); @@ -511,16 +531,16 @@ typedef vtkIdType (vtkDataSet::* TDataSetMethod)(); bool onIdEdit (const QString& theText, TDataSetMethod theMethod, bool theIsCell, + const SalomeApp_Module* theModule, LightApp_SelectionMgr* theSelectionMgr, QLabel* theMeshName, QString theValue, QLabel* theFieldName) { - SalomeApp_Application* anApp = dynamic_cast - (SUIT_Session::session()->activeApplication()); - SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); - if (!aSVTKVW) return false; - SVTK_Selector* aSelector = aSVTKVW->GetSelector(); + SalomeApp_Application* anApp = theModule->getApp(); + SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(theModule); + if (!aViewWindow) return false; + SVTK_Selector* aSelector = aViewWindow->GetSelector(); VISU::Prs3d_i* aPrs3d = NULL; Handle(SALOME_InteractiveObject) anIO; @@ -560,7 +580,7 @@ bool onIdEdit (const QString& theText, TColStd_MapOfInteger newIndices; newIndices.Add(anId); aSelector->AddOrRemoveIndex(anIO, newIndices, false); - aSVTKVW->highlight(anIO, true, true); + aViewWindow->highlight(anIO, true, true); return true; @@ -575,7 +595,7 @@ void VisuGUI_SelectionDlg::onPointIdEdit (const QString& theText) { if (myFl) return; TDataSetMethod aMethod = &vtkDataSet::GetNumberOfPoints; - bool anIsSelected = onIdEdit(theText,aMethod,false,mySelectionMgr, + bool anIsSelected = onIdEdit(theText,aMethod,false,myModule,mySelectionMgr, myMeshName,tr("WRN_NO_AVAILABLE_DATA"), myFieldName); if (anIsSelected) @@ -589,7 +609,7 @@ void VisuGUI_SelectionDlg::onCellIdEdit (const QString& theText) { if (myFl) return; TDataSetMethod aMethod = &vtkDataSet::GetNumberOfCells; - bool anIsSelected = onIdEdit(theText,aMethod,true,mySelectionMgr, + bool anIsSelected = onIdEdit(theText,aMethod,true,myModule,mySelectionMgr, myMeshName,tr("WRN_NO_AVAILABLE_DATA"), myFieldName); if (anIsSelected) diff --git a/src/VISUGUI/VisuGUI_Selection.h b/src/VISUGUI/VisuGUI_Selection.h index 4fc4f265..467e9c18 100644 --- a/src/VISUGUI/VisuGUI_Selection.h +++ b/src/VISUGUI/VisuGUI_Selection.h @@ -38,12 +38,13 @@ class QLineEdit; class QTable; class LightApp_SelectionMgr; class SalomeApp_Application; +class SalomeApp_Module; class VisuGUI_SelectionDlg: public QDialog { Q_OBJECT public: - VisuGUI_SelectionDlg (QWidget*); + VisuGUI_SelectionDlg (const SalomeApp_Module* theModule); virtual ~VisuGUI_SelectionDlg (); protected: @@ -85,6 +86,7 @@ private slots: QLabel* myDYLbl; QLabel* myDZLbl; + const SalomeApp_Module* myModule; LightApp_SelectionMgr* mySelectionMgr; bool myFl; }; diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.cxx b/src/VISUGUI/VisuGUI_TimeAnimation.cxx index 0918a05e..dd40bb95 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.cxx +++ b/src/VISUGUI/VisuGUI_TimeAnimation.cxx @@ -18,6 +18,8 @@ #include "VisuGUI_VectorsDlg.h" #include "VisuGUI_IsoSurfacesDlg.h" #include "VisuGUI_StreamLinesDlg.h" +#include "VisuGUI_ScalarMapOnDeformedShapeDlg.h" +#include "VisuGUI_GaussPointsDlg.h" #include "VISU_TimeAnimation.h" @@ -29,6 +31,8 @@ #include "VISU_CutLines_i.hh" #include "VISU_Vectors_i.hh" #include "VISU_StreamLines_i.hh" +#include "VISU_ScalarMapOnDeformedShape_i.hh" +#include "VISU_GaussPoints_i.hh" #include "VISU_ViewManager_i.hh" @@ -46,6 +50,7 @@ #include "SUIT_FileDlg.h" #include +#include #include #include @@ -95,7 +100,7 @@ ArrangeDlg::ArrangeDlg(QWidget* theParent, SVTK_ViewWindow* theViewWindow) VISU_Actor* anVISUActor = dynamic_cast(anActor); if (anVISUActor) if (anVISUActor->GetVisibility() != 0) { - VISU::Prs3d_i* aPrs = anVISUActor->GetParent()->GetPrs3d(); + VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d(); if (aPrs) { if (!myPrsMap.contains(aPrs)) { SALOMEDS::SObject_var aSObject = aPrs->GetSObject(); @@ -431,22 +436,25 @@ void ArrangeDlg::acceptViewWindow() } -//***************************************************************************************************** -//***************************************************************************************************** -//***************************************************************************************************** -SetupDlg::SetupDlg (VisuGUI* theModule, VISU_TimeAnimation* theAnimator) - : QDialog(VISU::GetDesktop(theModule), "SetupDlg", true, WStyle_Customize | - WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), - myModule(theModule) +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +SetupDlg::SetupDlg (QWidget* theParent, + VisuGUI* theModule, + VISU_TimeAnimation* theAnimator) : + QDialog(theParent, + "SetupDlg", + true, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myAnimator(theAnimator), + myModule(theModule) { setCaption("Setup Animation"); setSizeGripEnabled( TRUE ); - myAnimator = theAnimator; QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6); aMainLayout->setSpacing(5); - QFrame* aRangeGrp = new QFrame(this); QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp ); aRangeLayout->setSpacing( 6 ); @@ -548,7 +556,7 @@ SetupDlg::SetupDlg (VisuGUI* theModule, VISU_TimeAnimation* theAnimator) aMainLayout->addWidget(aBtnBox); } -//************************************************************************ +//------------------------------------------------------------------------ enum PrsComboItem { TSCALARMAP_ITEM = 0, // VISU::TSCALARMAP TISOSURFACE_ITEM = 1, // VISU::TISOSURFACE @@ -556,59 +564,102 @@ enum PrsComboItem { TPLOT3D_ITEM = 3, // VISU::TPLOT3D TDEFORMEDSHAPE_ITEM = 4, // VISU::TDEFORMEDSHAPE TVECTORS_ITEM = 5, // VISU::TVECTORS - TSTREAMLINES_ITEM = 6 // VISU::TSTREAMLINES + TSTREAMLINES_ITEM = 6, // VISU::TSTREAMLINES + TGAUSSPOINTS_ITEM = 7, // VISU::TGAUSSPOINTS + TSCALARMAPONDEFORMEDSHAPE_ITEM = 8 // VISU::TSCALARMAPONDEFORMEDSHAPE }; -//************************************************************************ +//------------------------------------------------------------------------ void SetupDlg::onFieldChange (int theIndex) { FieldData& aData = myAnimator->getFieldData(theIndex); myTypeCombo->clear(); + myTypeId2ComboId.clear(); + myComboId2TypeId.clear(); + // ATTENTION: append items in the same order like it is done in the PrsComboItem enumeration myTypeCombo->insertItem("Scalar Map"); // item 0 + myTypeId2ComboId[TSCALARMAP_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TSCALARMAP_ITEM);; + myTypeCombo->insertItem("Iso Surfaces"); // item 1 + myTypeId2ComboId[TISOSURFACE_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TISOSURFACE_ITEM);; + myTypeCombo->insertItem("Cut Planes"); // item 2 + myTypeId2ComboId[TCUTPLANES_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TCUTPLANES_ITEM);; + myTypeCombo->insertItem("Plot 3D"); // item 3 + myTypeId2ComboId[TPLOT3D_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TPLOT3D_ITEM);; _PTR(SObject) aSObject = aData.myField; long aNumComp = VISU::getValue(aSObject, "myNumComponent").toLong(); if (aNumComp > 1) { myTypeCombo->insertItem("Deformed Shape"); // item 4 + myTypeId2ComboId[TDEFORMEDSHAPE_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TDEFORMEDSHAPE_ITEM);; + myTypeCombo->insertItem("Vectors"); // item 5 + myTypeId2ComboId[TVECTORS_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TVECTORS_ITEM);; + myTypeCombo->insertItem("Stream Lines"); // item 6 + myTypeId2ComboId[TSTREAMLINES_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TSTREAMLINES_ITEM);; + + myTypeCombo->insertItem("Scalar map on Deformed shape"); // item 8 + myTypeId2ComboId[TSCALARMAPONDEFORMEDSHAPE_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TSCALARMAPONDEFORMEDSHAPE_ITEM);; + } + + long anEntityId = VISU::getValue(aSObject, "myEntityId").toLong(); + if(anEntityId == VISU::CELL){ + myTypeCombo->insertItem("Gauss Points"); // item 7 + myTypeId2ComboId[TGAUSSPOINTS_ITEM] = myComboId2TypeId.size(); + myComboId2TypeId.push_back(TGAUSSPOINTS_ITEM);; + } + switch (aData.myPrsType) { case VISU::TSCALARMAP: //Scalar Map - myTypeCombo->setCurrentItem(TSCALARMAP_ITEM); + myTypeCombo->setCurrentItem(myTypeId2ComboId[TSCALARMAP_ITEM]); break; case VISU::TISOSURFACE: //Iso Surfaces - myTypeCombo->setCurrentItem(TISOSURFACE_ITEM); + myTypeCombo->setCurrentItem(myTypeId2ComboId[TISOSURFACE_ITEM]); break; case VISU::TCUTPLANES: //Cut Planes - myTypeCombo->setCurrentItem(TCUTPLANES_ITEM); + myTypeCombo->setCurrentItem(myTypeId2ComboId[TCUTPLANES_ITEM]); break; case VISU::TPLOT3D: //Plot 3D - myTypeCombo->setCurrentItem(TPLOT3D_ITEM); + myTypeCombo->setCurrentItem(myTypeId2ComboId[TPLOT3D_ITEM]); break; case VISU::TDEFORMEDSHAPE: //Deformed Shape - myTypeCombo->setCurrentItem(TDEFORMEDSHAPE_ITEM); + myTypeCombo->setCurrentItem(myTypeId2ComboId[TDEFORMEDSHAPE_ITEM]); + break; + case VISU::TSCALARMAPONDEFORMEDSHAPE: //Scalar Map on Deformed Shape + myTypeCombo->setCurrentItem(TSCALARMAPONDEFORMEDSHAPE_ITEM); break; case VISU::TVECTORS: //Vectors - myTypeCombo->setCurrentItem(TVECTORS_ITEM); + myTypeCombo->setCurrentItem(myTypeId2ComboId[TVECTORS_ITEM]); break; case VISU::TSTREAMLINES: //Stream Lines - myTypeCombo->setCurrentItem(TSTREAMLINES_ITEM); - aData.myPrsType = VISU::TSTREAMLINES; + myTypeCombo->setCurrentItem(myTypeId2ComboId[TSTREAMLINES_ITEM]); + break; + case VISU::TGAUSSPOINTS: //Gauss Points + myTypeCombo->setCurrentItem(myTypeId2ComboId[TGAUSSPOINTS_ITEM]); break; } //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP); } -//************************************************************************ +//------------------------------------------------------------------------ void SetupDlg::onTypeChanged (int theIndex) { FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem()); - switch (theIndex) { + int aType = myComboId2TypeId[theIndex]; + switch (aType) { case TSCALARMAP_ITEM: //Scalar Map aData.myPrsType = VISU::TSCALARMAP; break; @@ -624,36 +675,43 @@ void SetupDlg::onTypeChanged (int theIndex) case TDEFORMEDSHAPE_ITEM: //Deformed Shape aData.myPrsType = VISU::TDEFORMEDSHAPE; break; + case TSCALARMAPONDEFORMEDSHAPE_ITEM: //Scalar Map on Deformed Shape + aData.myPrsType = VISU::TSCALARMAPONDEFORMEDSHAPE; + break; case TVECTORS_ITEM: //Vectors aData.myPrsType = VISU::TVECTORS; break; case TSTREAMLINES_ITEM: //Stream Lines aData.myPrsType = VISU::TSTREAMLINES; break; + case TGAUSSPOINTS_ITEM: //Gauss Points + aData.myPrsType = VISU::TGAUSSPOINTS; + break; } myAnimator->clearData(aData); //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP); //myAnimator->generatePresentations(myFieldLst->currentItem()); } -//************************************************************************ -/*void SetupDlg::onScalarBarDlg() { - QApplication::setOverrideCursor( Qt::waitCursor ); - FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem()); - if (aData.myPrs == 0) - myAnimator->generatePresentations(myFieldLst->currentItem()); - QApplication::restoreOverrideCursor(); - VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg(); - aScalarBarDlg->initFromPrsObject(aData.myPrs[0]); - if (aScalarBarDlg->exec()) { - for (int i = 0; i < aData.myNbFrames; i++) - aScalarBarDlg->storeToPrsObject(aData.myPrs[i]); +//------------------------------------------------------------------------ +namespace +{ + template + void + EditPrs(VisuGUI* theModule, + FieldData& theData) + { + TDialog* aDlg = new TDialog(theModule); + aDlg->initFromPrsObject(dynamic_cast(theData.myPrs[0])); + if (aDlg->exec()) + for (int i = 0; i < theData.myNbFrames; i++) + aDlg->storeToPrsObject(dynamic_cast(theData.myPrs[i])); + delete aDlg; } } -*/ -//************************************************************************ + void SetupDlg::onPreferencesDlg() { SUIT_OverrideCursor c; @@ -661,83 +719,74 @@ void SetupDlg::onPreferencesDlg() if (aData.myPrs.empty()) myAnimator->generatePresentations(myFieldLst->currentItem()); -// BUG VISU5725 : Compatibility gcc 2.95 -// #define EDITPRS(TYPE, DLG) \ -// { \ -// DLG* aDlg = new DLG(); \ -// aDlg->initFromPrsObject(dynamic_cast(aData.myPrs.at(0))); \ -// if (aDlg->exec()) { \ -// for (int i = 0; i < aData.myNbFrames; i++) \ -// aDlg->storeToPrsObject(dynamic_cast(aData.myPrs.at(i))); \ -// } \ -// delete aDlg; \ -// } - - -#define EDITPRS(TYPE, DLG) {\ - DLG* aDlg = new DLG (myModule);\ - aDlg->initFromPrsObject(dynamic_cast(aData.myPrs[0]));\ - if (aDlg->exec())\ - { \ - for (int i = 0; i < aData.myNbFrames; i++)\ - aDlg->storeToPrsObject(dynamic_cast(aData.myPrs[i]));\ - } \ - delete aDlg;} - - switch (myTypeCombo->currentItem()) { + int aType = myComboId2TypeId[myTypeCombo->currentItem()]; + switch (aType) { case TSCALARMAP_ITEM: //Scalar Map c.suspend(); - EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg); + EditPrs(myModule,aData); break; case TISOSURFACE_ITEM: //Iso Surfaces c.suspend(); - EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg); + EditPrs(myModule,aData); break; case TCUTPLANES_ITEM: //Cut Planes c.suspend(); - EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg); - /*{ - VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg (myModule); - //_CS_PhB :operator [] .at aDlg->initFromPrsObject(dynamic_cast(aData.myPrs.at(0))); - aDlg->initFromPrsObject(dynamic_cast(aData.myPrs[0])); - - if (aDlg->exec()) { - for (int i = 0; i < aData.myNbFrames; i++) - //_CS_PhB:operator [] .at aDlg->storeToPrsObject(dynamic_cast(aData.myPrs.at(i))); - aDlg->storeToPrsObject(dynamic_cast(aData.myPrs[i])); - } - delete aDlg; - }*/ + EditPrs(myModule,aData); break; case TPLOT3D_ITEM: //Plot 3D c.suspend(); - EDITPRS(VISU::Plot3D_i, VisuGUI_Plot3DDlg); + EditPrs(myModule,aData); break; case TDEFORMEDSHAPE_ITEM: //Deformed Shape c.suspend(); - EDITPRS(VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg); + EditPrs(myModule,aData); + break; + case TSCALARMAPONDEFORMEDSHAPE_ITEM: //Scalar Map on Deformed Shape + c.suspend(); + { + typedef VisuGUI_ScalarMapOnDeformedShapeDlg DLG; + typedef VISU::ScalarMapOnDeformedShape_i TYPE; + DLG* aDlg = new DLG (myModule); + aDlg->initFromPrsObject(dynamic_cast(aData.myPrs[0]),true); + if (aDlg->exec()) + { + int anbFrames=aDlg->getCurrentScalarNbIterations(); + for (int i = 0; i < aData.myNbFrames; i++){ + TYPE* aCurrPrs_i = dynamic_cast(aData.myPrs[i]); + if(i+1 > anbFrames) + aDlg->SetScalarField(anbFrames); + else + aDlg->SetScalarField(i+1); + aDlg->storeToPrsObject(aCurrPrs_i,false); + } + } + delete aDlg; + } break; case TVECTORS_ITEM: //Vectors c.suspend(); - EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg); + EditPrs(myModule,aData); break; case TSTREAMLINES_ITEM: //Stream Lines c.suspend(); - EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg); + EditPrs(myModule,aData); + break; + case TGAUSSPOINTS_ITEM: //Gauss Points + c.suspend(); + EditPrs(myModule,aData); break; } -#undef EDITPRS } -//************************************************************************ +//------------------------------------------------------------------------ void SetupDlg::onArrangeDlg() { ArrangeDlg aDlg(this, myAnimator); aDlg.exec(); } -//************************************************************************ +//------------------------------------------------------------------------ void SetupDlg::onRangeCheck (bool theCheck) { for (int i = 0; i < myAnimator->getNbFields(); i++) @@ -758,7 +807,7 @@ void SetupDlg::onRangeCheck (bool theCheck) } } -//************************************************************************ +//------------------------------------------------------------------------ void SetupDlg::onMinValue (double theVal) { if (theVal > myAnimator->getMaxRange()) { @@ -771,7 +820,7 @@ void SetupDlg::onMinValue (double theVal) myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange()); } -//************************************************************************ +//------------------------------------------------------------------------ void SetupDlg::onMaxValue (double theVal) { if (theVal < myAnimator->getMinRange()) { @@ -891,11 +940,14 @@ static const char * pauseIco[] = { static QPixmap MYpausePixmap(pauseIco); -VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy) - : QDialog(VISU::GetDesktop(theModule), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize | - WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), - myModule(theModule), - myStudy(theStudy) +VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy) : + QDialog(VISU::GetDesktop(theModule), + "VisuGUI_TimeAnimationDlg", + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), + myModule(theModule), + myStudy(theStudy), + mySetupDlg(NULL) { setCaption("Animation"); setSizeGripEnabled( TRUE ); @@ -903,7 +955,7 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu myAnimator = new VISU_TimeAnimation (theStudy); myAnimator->setSpeed(1); - myAnimator->setViewer(VISU::GetViewWindow()); + myAnimator->setViewer(VISU::GetViewWindow(theModule)); connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double))); connect(myAnimator, SIGNAL(stopped()), this, SLOT(onStop())); @@ -1086,13 +1138,13 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu myPlayFrame->setEnabled(false); } -//************************************************************************ +//------------------------------------------------------------------------ VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg() { delete myAnimator; } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onTypeChange (int index) { stopAnimation(); @@ -1102,14 +1154,14 @@ void VisuGUI_TimeAnimationDlg::onTypeChange (int index) myPlayFrame->setEnabled(false); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject) { myPlayFrame->setEnabled(false); myAnimator->addField(theSObject); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::createFrames() { stopAnimation(); @@ -1142,7 +1194,7 @@ void VisuGUI_TimeAnimationDlg::createFrames() //myPlayFrame->setEnabled(true); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onPlayPressed() { if (myPlayBtn->isOn() && (!myAnimator->running())) { @@ -1165,38 +1217,44 @@ void VisuGUI_TimeAnimationDlg::onPlayPressed() } } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onBackPressed() { //stopAnimation(); myAnimator->prevFrame(); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onForvardPressed() { myAnimator->nextFrame(); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onLastPressed() { myAnimator->lastFrame(); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onFirstPressed() { myAnimator->firstFrame(); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::clearView() { myAnimator->clearView(); } -//************************************************************************ +//------------------------------------------------------------------------ +void VisuGUI_TimeAnimationDlg::showEvent(QShowEvent* theEvent) +{ + mySetupDlg = new SetupDlg(this,myModule, myAnimator); +} + +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent) { myAnimator->stopAnimation(); @@ -1209,20 +1267,20 @@ void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent) } } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onWindowChanged (int index) { if (myAnimator->isRunning()) return; myAnimator->gotoFrame(index); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed) { myAnimator->setSpeed((int)theSpeed); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::stopAnimation() { myAnimator->stopAnimation(); @@ -1232,24 +1290,23 @@ void VisuGUI_TimeAnimationDlg::stopAnimation() myGenBtn->setEnabled(true); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime) { myTimeLbl->setText(QString("%1").arg(theTime)); mySlider->setValue(theNewFrame); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onSetupDlg() { - if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame(); - SetupDlg* aDlg = new SetupDlg (myModule, myAnimator); - aDlg->exec(); + if (myAnimator->getNbFrames() > 0) + myAnimator->firstFrame(); + mySetupDlg->exec(); myPlayFrame->setEnabled(false); - delete aDlg; } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onBrowse() { QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/", "Select path"); @@ -1257,7 +1314,7 @@ void VisuGUI_TimeAnimationDlg::onBrowse() myPathEdit->setText(Qtx::addSlash(aPath)); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onStop() { if (isClosing) { @@ -1270,14 +1327,14 @@ void VisuGUI_TimeAnimationDlg::onStop() } } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::saveToStudy() { myAnimator->saveAnimation(); VISU::UpdateObjBrowser(myModule, true); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::publishToStudy() { myAnimator->publishInStudy(); @@ -1285,7 +1342,7 @@ void VisuGUI_TimeAnimationDlg::publishToStudy() mySaveBtn->setEnabled(myAnimator->isSavedInStudy()); } -//************************************************************************ +//------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation) { myAnimator->restoreFromStudy(theAnimation); diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.h b/src/VISUGUI/VisuGUI_TimeAnimation.h index daeb134e..53191604 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.h +++ b/src/VISUGUI/VisuGUI_TimeAnimation.h @@ -90,7 +90,9 @@ class SetupDlg: public QDialog { Q_OBJECT public: - SetupDlg(VisuGUI* theModule, VISU_TimeAnimation* theAnimator); + SetupDlg(QWidget* theParent, + VisuGUI* theModule, + VISU_TimeAnimation* theAnimator); ~SetupDlg() {}; private slots: @@ -106,8 +108,12 @@ class SetupDlg: public QDialog { private: VisuGUI* myModule; VISU_TimeAnimation* myAnimator; + QListBox* myFieldLst; QComboBox* myTypeCombo; + std::vector myComboId2TypeId; + std::map myTypeId2ComboId; + QPushButton* myPropBtn; QPushButton* myArrangeBtn; QCheckBox* myUseRangeChk; @@ -130,6 +136,7 @@ class VisuGUI_TimeAnimationDlg: public QDialog protected: virtual void closeEvent(QCloseEvent* theEvent); + virtual void showEvent(QShowEvent* theEvent); void stopAnimation(); private slots: @@ -159,6 +166,7 @@ class VisuGUI_TimeAnimationDlg: public QDialog QPushButton* myGenBtn; QFrame* myPlayFrame; + SetupDlg* mySetupDlg; _PTR(Study) myStudy; VisuGUI* myModule; diff --git a/src/VISUGUI/VisuGUI_Timer.cxx b/src/VISUGUI/VisuGUI_Timer.cxx new file mode 100644 index 00000000..ca1eea96 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Timer.cxx @@ -0,0 +1,104 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_Timer.cxx +// Module : SALOME + +#include "VisuGUI_Timer.h" + +#include "SUIT_Desktop.h" + +#include "utilities.h" + +#ifndef WNT +static struct timezone *tz=(struct timezone*) malloc(sizeof(struct timezone)); +#else +//timezone *tz=_timezone; +#endif + +#ifndef CLK_TCK +# define CLK_TCK CLOCKS_PER_SEC +#endif + +VisuGUI_Timer::VisuGUI_Timer() : + Utils_Timer() +{ +} + +VisuGUI_Timer::~VisuGUI_Timer() +{ +} + +void VisuGUI_Timer::Start() +{ + if (Stopped) { + Stopped = 0; +#ifndef WNT + times(RefToInitialTMS); + gettimeofday(RefToInitialTimeB,tz); +#else + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st, RefToInitialTMS); + time(RefToCurrentTimeB); +#endif + } +} + +void VisuGUI_Timer::Stop() +{ + if (!Stopped) { +#ifndef WNT + times(RefToCurrentTMS); + int diffr_user = RefToCurrentTMS->tms_utime - RefToInitialTMS->tms_utime; + int diffr_sys = RefToCurrentTMS->tms_stime - RefToInitialTMS->tms_stime; + gettimeofday(RefToCurrentTimeB,tz); + + static long aCLK_TCK=sysconf(_SC_CLK_TCK); + Cumul_user += (double) diffr_user / aCLK_TCK ; + Cumul_sys += (double) diffr_sys / aCLK_TCK ; +#else + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st, RefToCurrentTMS); + Cumul_user += (int)(((ULARGE_INTEGER*)(RefToCurrentTMS))->QuadPart - ((ULARGE_INTEGER*)(RefToInitialTMS))->QuadPart) / 10000000; + Cumul_sys = Cumul_user; + time(RefToCurrentTimeB); +#endif + Stopped = 1; + } +} + +void VisuGUI_Timer::Reset() { + Stopped = 1; + Cumul_user = Cumul_sys = 0. ; +} + +QString VisuGUI_Timer::GetTime() { + bool StopSav = Stopped; + if (!StopSav) Stop(); + + return QString::number( Cumul_user ); + + if (!StopSav) Start(); +} diff --git a/src/VISUGUI/VisuGUI_Timer.h b/src/VISUGUI/VisuGUI_Timer.h new file mode 100644 index 00000000..bbfb7e57 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Timer.h @@ -0,0 +1,43 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_Timer.h +// Module : SALOME + +#include + +#include + +class VisuGUI_Timer : public Utils_Timer +{ + public: + VisuGUI_Timer(); + virtual ~VisuGUI_Timer(); + + public: + void Start(); + void Stop(); + void Reset(); + + QString GetTime(); +}; diff --git a/src/VISUGUI/VisuGUI_Tools.cxx b/src/VISUGUI/VisuGUI_Tools.cxx index 300112d5..970ef604 100644 --- a/src/VISUGUI/VisuGUI_Tools.cxx +++ b/src/VISUGUI/VisuGUI_Tools.cxx @@ -41,6 +41,9 @@ #include "SalomeApp_Module.h" #include "SalomeApp_Study.h" #include "SalomeApp_Application.h" + +#include "OB_Browser.h" +#include "LightApp_DataObject.h" #include "LightApp_SelectionMgr.h" #include "SALOME_ListIO.hxx" @@ -101,21 +104,83 @@ namespace VISU } bool - CheckLock( _PTR(Study) theStudy ) + CheckLock( _PTR(Study) theStudy, + QWidget* theWidget ) { - if(IsStudyLocked(theStudy)) - { - SalomeApp_Application* anApp = dynamic_cast - (SUIT_Session::session()->activeApplication()); - if (anApp) - { - SUIT_MessageBox::warn1(anApp->desktop(), - QObject::tr("WRN_VISU_WARNING"), - QObject::tr("WRN_STUDY_LOCKED"), - QObject::tr("BUT_OK")); - return true; + if(IsStudyLocked(theStudy)){ + SUIT_MessageBox::warn1(theWidget, + QObject::tr("WRN_VISU_WARNING"), + QObject::tr("WRN_STUDY_LOCKED"), + QObject::tr("BUT_OK")); + return true; + } + return false; + } + + LightApp_DataObject* + FindDataObject(SUIT_DataObject* theDataObject, + const QString& theEntry, + int theLevel) + { + int aLevel = theDataObject->level() + 2; + QString aSourceEntry = theEntry.section(':',0,aLevel); + DataObjectList aList; + theDataObject->children(aList); + DataObjectListIterator aDataObjectIter(aList); + while(SUIT_DataObject* aDataObject = aDataObjectIter.current()){ + if(LightApp_DataObject* aChildDataObject = dynamic_cast(aDataObject)){ + QString anEntry = aChildDataObject->entry(); + QString aCurrentEntry = anEntry.section(':',0,aLevel); + if(aSourceEntry == aCurrentEntry){ + if(theLevel == aLevel){ + return aChildDataObject; + }else{ + return FindDataObject(aChildDataObject,theEntry,theLevel); } + } } + ++aDataObjectIter; + } + return NULL; + } + + LightApp_DataObject* + FindDataObject(CAM_Module* theModule, + _PTR(SObject) theSObject) + { + CAM_DataModel* aDataModel = theModule->dataModel(); + CAM_DataObject* aRootDataObject = aDataModel->root(); + if(_PTR(SComponent) aComponent = theSObject) + return dynamic_cast(aRootDataObject); + + int aLevel = theSObject->Depth(); + std::string anEntry = theSObject->GetID(); + return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel); + } + + void + UpdateObjBrowser(SalomeApp_Module* theModule, + bool theIsUpdateDataModel, + _PTR(SObject) theSObject) + { + LightApp_DataObject* aDataObject = NULL; + if(theSObject) + aDataObject = FindDataObject(theModule,theSObject); + + theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject); + theModule->getApp()->updateActions(); + } + + bool + IsSObjectTable( _PTR(SObject) theSObject ) + { + if ( theSObject ) { + _PTR(GenericAttribute) anAttr; + if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" )) + return true; + if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" )) + return true; + } return false; } @@ -225,7 +290,7 @@ namespace VISU Handle(SALOME_InteractiveObject)* theIO, VISU::Storable::TRestoringMap* theMap) { - if (CheckLock(GetCStudy(GetAppStudy(theModule)))) + if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule))) return NULL; CORBA::Object_var anObject = GetSelectedObj(theModule, theIO); @@ -400,27 +465,24 @@ namespace VISU } void - DeleteSObject (SalomeApp_Module* theModule, - _PTR(Study) theStudy, - _PTR(SObject) theSObject) + DeleteSObject(VisuGUI* theModule, + _PTR(Study) theStudy, + _PTR(SObject) theSObject) { - //SalomeApp_Study* study = GetAppStudy( theModule ); - _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject); for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { _PTR(SObject) aChildSObject = aChildIter->Value(); CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject); - VisuGUI* aMod = dynamic_cast(theModule); - if(aMod) RemoveScalarBarPosition(aMod,aChildObj); + RemoveScalarBarPosition(theModule,aChildObj); ErasePrs(theModule, aChildObj); } CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject); if (!CORBA::is_nil(anObj)) { - VisuGUI* aMod = dynamic_cast(theModule); - if(aMod) RemoveScalarBarPosition(aMod,anObj); + RemoveScalarBarPosition(theModule,anObj); ErasePrs(theModule, anObj); + VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj); if (!CORBA::is_nil(aRemovableObject)) { aRemovableObject->RemoveFromStudy(); @@ -435,32 +497,17 @@ namespace VISU } void - DeletePrs3d(SalomeApp_Module* theModule, + DeletePrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs, const Handle(SALOME_InteractiveObject)& theIO) { if (!thePrs) return; - if (CheckLock(GetCStudy(GetAppStudy(theModule)))) + if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule))) return; - SALOMEDS::SObject_var aSObject = thePrs->GetSObject(); - CORBA::String_var anEntry = aSObject->GetID(); - LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule); - Remove(aSelectionMgr,theIO); - TViewWindows aViewWindows = GetViews(theModule); - for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){ - SVTK_ViewWindow* aView = aViewWindows[i]; - if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){ - aView->RemoveActor(anActor); - anActor->Delete(); - } - } - thePrs->RemoveFromStudy(); - VisuGUI* aMod = dynamic_cast(theModule); - Prs3d_i* aPrs_i = dynamic_cast(thePrs); - if (aMod && aPrs_i) - RemoveScalarBarPosition(aMod,aPrs_i); + RemoveScalarBarPosition(theModule,thePrs); + thePrs->RemoveFromStudy(); } void @@ -468,9 +515,7 @@ namespace VISU VISU::Prs3d_i* thePrs) { if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){ - VISU_Actor* anVISUActor = FindActor( vw, thePrs ); - - if (anVISUActor) { + if (VISU_Actor* anVISUActor = FindActor( vw, thePrs )) { anVISUActor->VisibilityOff(); } } @@ -482,9 +527,7 @@ namespace VISU ChangeRepresentation (const SalomeApp_Module* theModule, VISU::PresentationType theType) { - SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type()); - if (!aView) return; - SVTK_ViewWindow* vw = dynamic_cast( aView ); + SVTK_ViewWindow* vw = GetViewWindow( theModule, false ); if( !vw ) return; @@ -581,6 +624,9 @@ namespace VISU _PTR(SObject) theSource, VISU::Result_var& theResult) { + if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object + return NULL; + _PTR(SObject) aSObj = theSource->GetFather(); if (!aSObj) return NULL; @@ -605,13 +651,7 @@ namespace VISU return NULL; theResult = VISU::Result::_narrow(anObject); - VISU::Result_i* pResult = dynamic_cast(VISU::GetServant(anObject).in()); - if (pResult == NULL) - SUIT_MessageBox::warn1(GetDesktop(theModule), - QObject::tr("WRN_VISU"), - QObject::tr("WRN_NO_AVAILABLE_DATA"), - QObject::tr("BUT_OK")); - return pResult; + return dynamic_cast(VISU::GetServant(anObject).in()); } // Views @@ -673,11 +713,15 @@ namespace VISU /*SVTK_ViewWindow* GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate ) { - if(SalomeApp_Application* anApp = theModule->getApp()){ - if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){ - if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){ - return dynamic_cast(aViewWindow); - } + if (SalomeApp_Application* anApp = theModule->getApp()) + { + SVTK_ViewWindow* wnd = dynamic_cast(anApp->desktop()->activeWindow()); + if( wnd ) + return wnd; + else + { + if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )) + return dynamic_cast( aViewManager->getActiveView() ); } } return NULL; @@ -714,10 +758,10 @@ namespace VISU if(aActor = thePrs->CreateActor()) aView->AddActor(aActor); }catch(std::exception& exc){ - SUIT_MessageBox::warn1(GetDesktop(theModule), - QObject::tr("WRN_VISU"), - QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()), - QObject::tr("BUT_OK")); + SUIT_MessageBox::warn1 + (GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_CREATE_ACTOR") + ": pammy2 " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); } QApplication::restoreOverrideCursor(); } @@ -734,31 +778,31 @@ namespace VISU vtkRenderer *aRen = vw->getRenderer(); vtkActorCollection *anActColl = aRen->GetActors(); + anActColl->InitTraversal(); vtkActor *anActor; VISU_Actor* anVISUActor = NULL; VISU_Actor* aResActor = NULL; - for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){ - if(!SALOME_Actor::SafeDownCast(anActor)) - continue; - if(anActor->IsA("VISU_Actor")){ - anVISUActor = VISU_Actor::SafeDownCast(anActor); + while(vtkActor *anActor = anActColl->GetNextActor()){ + anVISUActor = VISU_Actor::SafeDownCast(anActor); + if(anVISUActor){ VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d(); if(aPrs == NULL) continue; if (thePrs == aPrs) { - aResActor = anVISUActor->GetParent(); try { + aResActor = anVISUActor; thePrs->UpdateActor(aResActor); aResActor->VisibilityOn(); - } catch (std::runtime_error& ex) { + } catch (std::runtime_error& exc) { aResActor->VisibilityOff(); - INFOS(ex.what()); - SUIT_MessageBox::warn1(GetDesktop(theModule), QObject::tr("WRN_VISU"), - QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(ex.what()), - QObject::tr("BUT_OK")); + INFOS(exc.what()); + SUIT_MessageBox::warn1 + (GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_CREATE_ACTOR") + ": pammy3 " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); } } else if (theDispOnly) { - anVISUActor->GetParent()->VisibilityOff(); + anVISUActor->VisibilityOff(); } else { } } else if (theDispOnly && anActor->GetVisibility()) { @@ -804,11 +848,11 @@ namespace VISU FindActor(SVTK_ViewWindow* theViewWindow, const char* theEntry) { - using namespace VTK; + using namespace SVTK; if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){ if(vtkActorCollection* aCollection = aRenderer->GetActors()){ if(VISU_Actor* anActor = Find(aCollection,TIsSameEntry(theEntry))){ - return anActor->GetParent(); + return anActor; } } } @@ -829,43 +873,24 @@ namespace VISU VISU::Prs3d_i* thePrs) { QApplication::setOverrideCursor(Qt::waitCursor); - bool isPublished = false; SALOMEDS::SObject_var aSObject = thePrs->GetSObject(); CORBA::String_var anEntry = aSObject->GetID(); try { - thePrs->Update(); - - TViewWindows aViewWindows = GetViews(theModule); - for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) { - SVTK_ViewWindow* aView = aViewWindows[i]; - if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) { - isPublished = true; - thePrs->UpdateActor(anActor); - } - } - } catch (std::runtime_error& ex) { - INFOS(ex.what()); + thePrs->UpdateActors(); + } catch (std::runtime_error& exc) { + INFOS(exc.what()); QApplication::restoreOverrideCursor(); - SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"), - QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(ex.what()), - QObject::tr("BUT_OK")); + SUIT_MessageBox::warn1 + (GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": pammy4 " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); - TViewWindows aViewWindows = GetViews(theModule); - for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) { - SVTK_ViewWindow* aView = aViewWindows[i]; - if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) { - aView->RemoveActor(anActor); - anActor->Delete(); - } - } + thePrs->RemoveActors(); return; } QApplication::restoreOverrideCursor(); - - if (!isPublished) - PublishInView(theModule, thePrs); } static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow, @@ -1156,6 +1181,12 @@ namespace VISU } } PlotContainer( theModule, pContainer, VISU::eDisplay ); + + QString anEntry = pContainer->GetEntry(); + _PTR(Study) aStudy = theTableSO->GetStudy(); + _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.latin1()); + _PTR(SObject) aParentSO = aContainerSO->GetFather(); + UpdateObjBrowser(theModule,true,aParentSO); } } } @@ -1243,10 +1274,10 @@ namespace VISU theModule->getApp()->updateActions(); } catch (std::runtime_error& exc) { INFOS(exc.what()); - SUIT_MessageBox::warn1 (GetDesktop(theModule), - QObject::tr("WRN_VISU"), - QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()), - QObject::tr("BUT_OK")); + SUIT_MessageBox::warn1 + (GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_CREATE_ACTOR") + ": pammy5 " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); } } } @@ -1289,6 +1320,7 @@ namespace VISU case VISU::TVECTORS: case VISU::TSTREAMLINES: case VISU::TPLOT3D: + case VISU::TSCALARMAPONDEFORMEDSHAPE: { PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject); if (aServant.in()) { diff --git a/src/VISUGUI/VisuGUI_Tools.h b/src/VISUGUI/VisuGUI_Tools.h index 3fcfa37e..d514b4b3 100644 --- a/src/VISUGUI/VisuGUI_Tools.h +++ b/src/VISUGUI/VisuGUI_Tools.h @@ -32,14 +32,13 @@ #include "VISUConfig.hh" -#include "SalomeApp_Module.h" -#include "SalomeApp_Application.h" - #include "SALOMEDSClient_Study.hxx" #include "SALOMEconfig.h" #include CORBA_SERVER_HEADER(MED_Gen) +class QWidget; + class SUIT_Desktop; class SUIT_ViewWindow; class VISU_Actor; @@ -49,6 +48,7 @@ class SPlot2d_Curve; class Plot2d_ViewFrame; class CAM_Module; class LightApp_SelectionMgr; +class SalomeApp_Module; class SalomeApp_Study; class VisuGUI; @@ -66,10 +66,12 @@ namespace VISU { _PTR(Study) GetCStudy(const SalomeApp_Study* theStudy); bool IsStudyLocked( _PTR(Study) theStudy ); - bool CheckLock( _PTR(Study) theStudy ); + bool CheckLock( _PTR(Study) theStudy, + QWidget* theWidget ); - inline void UpdateObjBrowser(SalomeApp_Module* theModule, - bool updateDataModel = true); + void UpdateObjBrowser(SalomeApp_Module* theModule, + bool theIsUpdateDataModel = true, + _PTR(SObject) theSObject = _PTR(SObject)()); VISU_Gen_i* GetVisuGen(const CAM_Module* theModule); SALOME_MED::MED_Gen_var GetMEDEngine(); @@ -100,10 +102,10 @@ namespace VISU { void ErasePrs(const SalomeApp_Module* theModule, CORBA::Object_ptr theObject, bool theUpdate = true); - void DeleteSObject(SalomeApp_Module* theModule, + void DeleteSObject(VisuGUI* theModule, _PTR(Study) theStudy, _PTR(SObject) theSObject); - void DeletePrs3d(SalomeApp_Module* theModule, + void DeletePrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs, const Handle(SALOME_InteractiveObject)& theIO); void ErasePrs3d(const SalomeApp_Module* theModule, @@ -122,7 +124,7 @@ namespace VISU { VISU::Result_i* CheckResult(const SalomeApp_Module* theModule, _PTR(SObject) theSource, VISU::Result_var& theResult); - inline bool IsSObjectTable(_PTR(SObject) theSObject); + bool IsSObjectTable(_PTR(SObject) theSObject); // Views SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, @@ -203,23 +205,4 @@ namespace VISU { void RemoveScalarBarPosition(VisuGUI* theModule,CORBA::Object_ptr theObject); } -bool VISU::IsSObjectTable( _PTR(SObject) theSObject ) -{ - if ( theSObject ) { - _PTR(GenericAttribute) anAttr; - if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" )) - return true; - if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" )) - return true; - } - return false; -} - -void VISU::UpdateObjBrowser(SalomeApp_Module* theModule, - bool updateDataModel) -{ - theModule->updateObjBrowser(updateDataModel); - theModule->getApp()->updateActions(); -} - #endif diff --git a/src/VISUGUI/VisuGUI_TransparencyDlg.cxx b/src/VISUGUI/VisuGUI_TransparencyDlg.cxx new file mode 100644 index 00000000..bf893f50 --- /dev/null +++ b/src/VISUGUI/VisuGUI_TransparencyDlg.cxx @@ -0,0 +1,245 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_TransparencyDlg.cxx +// Author : Nicolas REJNERI +// Module : VISU +// $Header$ + +#include "VisuGUI_TransparencyDlg.h" + +#include "VisuGUI.h" +#include "VisuGUI_ViewTools.h" +#include "VisuGUI_Tools.h" +#include "VISU_Actor.h" + +#include "SUIT_Desktop.h" +#include "SUIT_OverrideCursor.h" + +#include "SALOME_ListIO.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" +#include "SALOME_InteractiveObject.hxx" + +#include "LightApp_Study.h" +#include "LightApp_SelectionMgr.h" + +#include "SVTK_ViewWindow.h" + +// QT Includes +#include +#include +#include +#include +#include + +using namespace std; + +//================================================================================= +// class : VisuGUI_TransparencyDlg() +// purpose : +// +//================================================================================= +VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule, + const char* name, + bool modal, + WFlags fl) + : QDialog( VISU::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | + WStyle_Title | WStyle_SysMenu | WDestructiveClose ), + mySelectionMgr( VISU::GetSelectionMgr( theModule ) ), + myViewWindow( VISU::GetViewWindow( theModule ) ) +{ + if (!name) + setName("VisuGUI_TransparencyDlg"); + setCaption(tr("TRANSPARENCY_TITLE" )); + setSizeGripEnabled(TRUE); + QGridLayout* VisuGUI_TransparencyDlgLayout = new QGridLayout(this); + VisuGUI_TransparencyDlgLayout->setSpacing(6); + VisuGUI_TransparencyDlgLayout->setMargin(11); + + /*************************************************************************/ + QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1"); + GroupC1->setColumnLayout(0, Qt::Vertical); + GroupC1->layout()->setSpacing(0); + GroupC1->layout()->setMargin(0); + QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout()); + GroupC1Layout->setAlignment(Qt::AlignTop); + GroupC1Layout->setSpacing(6); + GroupC1Layout->setMargin(11); + + TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent"); + TextLabelTransparent->setText(tr("TRANSPARENCY_TRANSPARENT" )); + TextLabelTransparent->setAlignment(AlignLeft); + GroupC1Layout->addWidget(TextLabelTransparent, 0, 0); + + ValueLab = new QLabel(GroupC1, "ValueLab"); + ValueLab->setAlignment(AlignCenter); + ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt); + GroupC1Layout->addWidget(ValueLab, 0, 1); + + TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque"); + TextLabelOpaque->setText(tr("TRANSPARENCY_OPAQUE" )); + TextLabelOpaque->setAlignment(AlignRight); + GroupC1Layout->addWidget(TextLabelOpaque, 0, 2); + + Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1"); + Slider1->setFocusPolicy(QWidget::NoFocus); + Slider1->setMinimumSize(300, 0); + Slider1->setTickmarks(QSlider::Above); + Slider1->setTickInterval(10); + Slider1->setTracking(true); + Slider1->setMinValue(0); + Slider1->setMaxValue(100); + Slider1->setLineStep(1); + Slider1->setPageStep(10); + GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2); + + /*************************************************************************/ + QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons"); + GroupButtons->setColumnLayout(0, Qt::Vertical); + GroupButtons->layout()->setSpacing(0); + GroupButtons->layout()->setMargin(0); + QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout()); + GroupButtonsLayout->setAlignment(Qt::AlignTop); + GroupButtonsLayout->setSpacing(6); + GroupButtonsLayout->setMargin(11); + + buttonOk = new QPushButton(GroupButtons, "buttonOk"); + buttonOk->setText(tr("BUT_CLOSE")); + buttonOk->setAutoDefault(TRUE); + buttonOk->setDefault(TRUE); + GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0); + GroupButtonsLayout->addWidget(buttonOk, 0, 1); + GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2); + + VisuGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0); + VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0); + + // Initial state + this->onSelectionChanged(); + + // signals and slots connections : after ValueHasChanged() + connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency())); + connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged())); + connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged())); +} + +//================================================================================= +// function : ~VisuGUI_TransparencyDlg() +// purpose : +//================================================================================= +VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +//======================================================================= +// function : ClickOnOk() +// purpose : +//======================================================================= +void VisuGUI_TransparencyDlg::ClickOnOk() +{ + close(); +} + +//================================================================================= +// function : SetTransparency() +// purpose : Called when value of slider change +// : or the first time as initilisation +//================================================================================= +void VisuGUI_TransparencyDlg::SetTransparency() +{ + if( myViewWindow ) { + SUIT_OverrideCursor wc; + float opacity = this->Slider1->value() / 100.; + + SALOME_ListIO aList; + mySelectionMgr->selectedObjects(aList); + + SALOME_ListIteratorOfListIO It (aList); + for (;It.More(); It.Next()) { + Handle(SALOME_InteractiveObject) IOS = It.Value(); + VISU_Actor* anActor = VISU::FindActor(myViewWindow, IOS->getEntry()); + if (anActor) + anActor->SetOpacity(opacity); + } + myViewWindow->Repaint(); + } + ValueHasChanged(); +} + +//================================================================================= +// function : ValueHasChanged() +// purpose : Called when user moves a slider +//================================================================================= +void VisuGUI_TransparencyDlg::ValueHasChanged() +{ + ValueLab->setText(QString::number(this->Slider1->value()) + "%"); +} + +//================================================================================= +// function : onSelectionChanged() +// purpose : Called when selection is changed +//================================================================================= +void VisuGUI_TransparencyDlg::onSelectionChanged() +{ + if( myViewWindow ) { + int opacity = 100; + + SALOME_ListIO aList; + mySelectionMgr->selectedObjects(aList); + + if (aList.Extent() == 1) { + Handle(SALOME_InteractiveObject) FirstIOS = aList.First(); + if (!FirstIOS.IsNull()) { + VISU_Actor* anActor = VISU::FindActor(myViewWindow, FirstIOS->getEntry()); + if (anActor) + opacity = int(anActor->GetOpacity() * 100. + 0.5); + } + } else if (aList.Extent() > 1) { + SALOME_ListIteratorOfListIO It (aList); + int setOp = -1; + for (; It.More(); It.Next()) { + Handle(SALOME_InteractiveObject) IO = It.Value(); + if (!IO.IsNull()) { + VISU_Actor* anActor = VISU::FindActor(myViewWindow, IO->getEntry()); + if (anActor) { + int op = int(anActor->GetOpacity() * 100. + 0.5); + if (setOp < 0) + setOp = op; + else if (setOp != op) { + setOp = 100; + break; + } + } + } + } + if (setOp >= 0) + opacity = setOp; + } else { + } + Slider1->setValue(opacity); + } + ValueHasChanged(); +} diff --git a/src/VISUGUI/VisuGUI_TransparencyDlg.h b/src/VISUGUI/VisuGUI_TransparencyDlg.h new file mode 100644 index 00000000..6dbc9437 --- /dev/null +++ b/src/VISUGUI/VisuGUI_TransparencyDlg.h @@ -0,0 +1,76 @@ +// VISU VisuGUI : GUI for VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_TransparencyDlg.h +// Author : Nicolas REJNERI +// Module : VISU +// $Header$ + +#ifndef VISUGUI_TRANSPARENCYDLG_H +#define VISUGUI_TRANSPARENCYDLG_H + +// QT Includes +#include + +class QLabel; +class QPushButton; +class QSlider; +class LightApp_SelectionMgr; +class SVTK_Selector; +class SVTK_ViewWindow; +class VisuGUI; + +//================================================================================= +// class : VisuGUI_TransparencyDlg +// purpose : +//================================================================================= +class VisuGUI_TransparencyDlg : public QDialog +{ + Q_OBJECT + +public: + VisuGUI_TransparencyDlg( VisuGUI* = 0, + const char* name = 0, + bool modal = false, + WFlags fl = 0 ); + + ~VisuGUI_TransparencyDlg(); + +private : + LightApp_SelectionMgr* mySelectionMgr; + SVTK_ViewWindow* myViewWindow; + + QPushButton* buttonOk; + QLabel* TextLabelOpaque; + QLabel* ValueLab; + QLabel* TextLabelTransparent; + QSlider* Slider1; + +public slots: + void ClickOnOk(); + void ValueHasChanged(); + void SetTransparency(); + void onSelectionChanged(); +}; + +#endif diff --git a/src/VISUGUI/VisuGUI_ViewTools.cxx b/src/VISUGUI/VisuGUI_ViewTools.cxx new file mode 100644 index 00000000..868ab606 --- /dev/null +++ b/src/VISUGUI/VisuGUI_ViewTools.cxx @@ -0,0 +1,74 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2005 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_Tools.cxx +// Author : Sergey Anikin +// Module : VISU + + +#include "VisuGUI_ViewTools.h" + +#include "VISU_Actor.h" + +#include "SVTK_ViewModel.h" +#include "SVTK_ViewWindow.h" + +namespace VISU +{ + void + ErasePrs(VisuGUI* theModule, + VISU::Base_ptr theBase, + bool thIsUpdate) + { + VISU::VISUType aType = theBase->GetType(); + switch (aType) { + case VISU::TCURVE: { + if (VISU::Curve_i* aCurve = dynamic_cast(VISU::GetServant(theBase).in())) + PlotCurve(theModule, aCurve, VISU::eErase ); + break; + } + case VISU::TCONTAINER: { + if (VISU::Container_i* aContainer = dynamic_cast(VISU::GetServant(theBase).in())) + PlotContainer(theModule, aContainer, VISU::eErase ); + break; + } + case VISU::TTABLE: { + if (VISU::Table_i* aTable = dynamic_cast(VISU::GetServant(theBase).in())) + PlotTable(theModule, aTable, VISU::eErase ); + break; + } + default: { + if(VISU::Prs3d_i* aPrsObject = dynamic_cast(VISU::GetServant(theBase).in())){ + if(aType == VISU::TGAUSSPOINTS) + ErasePrs3d(theModule,aPrsObject,thIsUpdate); + else if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){ + QString aType = aViewManager->getType(); + if(aType == SVTK_Viewer::Type()) + ErasePrs3d(theModule,aPrsObject,thIsUpdate); + else if(aType == VVTK_Viewer::Type()) + ErasePrs3d(theModule,aPrsObject,thIsUpdate); + } + } + }} // switch (aType) + } +} diff --git a/src/VISUGUI/VisuGUI_ViewTools.h b/src/VISUGUI/VisuGUI_ViewTools.h new file mode 100644 index 00000000..d70ee509 --- /dev/null +++ b/src/VISUGUI/VisuGUI_ViewTools.h @@ -0,0 +1,255 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2005 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_Tools.h +// Author : Sergey Anikin +// Module : VISU + +#ifndef VisuGUI_ViewTools_HeaderFile +#define VisuGUI_ViewTools_HeaderFile + +#include "VisuGUI.h" + +#include "SUIT_MessageBox.h" +#include "SUIT_ViewManager.h" +#include "SUIT_ViewWindow.h" + +#include "SalomeApp_Module.h" +#include "SalomeApp_Application.h" + +#include "VISU_Prs3d_i.hh" + +#include "VVTK_ViewModel.h" +#include "VVTK_ViewWindow.h" + +#include "SVTK_ViewModel.h" +#include "SVTK_ViewWindow.h" + +#include "VisuGUI_Tools.h" +#include "VTKViewer_Algorithm.h" +#include "SVTK_Functor.h" + +#include "VISU_Table_i.hh" +#include "VISU_ViewManager_i.hh" +#include "SALOME_ListIO.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" + +#include "SPlot2d_ViewModel.h" + +#include "VISU_Actor.h" + +#include +#include + +class VVTK_Viewer; + +namespace VISU +{ + //--------------------------------------------------------------- + template + inline + typename TViewer::TViewWindow* + GetViewWindow(VisuGUI* theModule, + const bool theIsViewCreate = false) + { + typedef typename TViewer::TViewWindow TView; + if(SUIT_ViewManager* aViewManager = theModule->getViewManager(TViewer::Type(),theIsViewCreate)){ + if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){ + if(TView* aView = dynamic_cast(aViewWindow)){ + aViewWindow->raise(); + aViewWindow->setFocus(); + return aView; + } + } + } + return NULL; + } + + + //--------------------------------------------------------------- + template + inline + VISU_Actor* + PublishInView(VisuGUI* theModule, + Prs3d_i* thePrs, + const bool theIsHighlight = false, + const bool theIsCreateView = false) + { + typedef typename TViewer::TViewWindow TView; + if(TView* aView = GetViewWindow(theModule,theIsCreateView)){ + QApplication::setOverrideCursor( Qt::waitCursor ); + try { + if(VISU_Actor* anActor = thePrs->CreateActor()){ + aView->AddActor(anActor); + if(theIsHighlight) + aView->highlight(anActor->getIO(),true); + aView->getRenderer()->ResetCameraClippingRange(); + aView->Repaint(); + QApplication::restoreOverrideCursor(); + return anActor; + } + } catch(std::exception& exc) { + QApplication::restoreOverrideCursor(); + INFOS(exc.what()); + SUIT_MessageBox::warn1 + (GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_CREATE_ACTOR") + ": pammy6 " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); + } + } + return NULL; + } + + + //--------------------------------------------------------------- + template + inline + VISU_Actor* + UpdateViewer(VisuGUI* theModule, + VISU::Prs3d_i* thePrs, + bool theDispOnly = false, + const bool theIsHighlight = false, + const bool theIsViewCreate = false) + { + typedef typename TViewer::TViewWindow TView; + if(TView* aView = GetViewWindow(theModule,theIsViewCreate)){ + vtkRenderer *aRen = aView->getRenderer(); + vtkActorCollection *anActColl = aRen->GetActors(); + anActColl->InitTraversal(); + VISU_Actor* aResActor = NULL; + while(vtkActor *anAct = anActColl->GetNextActor()){ + if(VISU_Actor* anActor = dynamic_cast(anAct)){ + if(VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d()){ + if(thePrs == aPrs3d){ + try { + thePrs->UpdateActors(); + } catch (std::runtime_error& exc) { + INFOS(exc.what()); + QApplication::restoreOverrideCursor(); + SUIT_MessageBox::warn1 + (GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": pammy7 " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); + + thePrs->RemoveActors(); + return NULL; + } + aResActor = anActor; + aResActor->VisibilityOn(); + }else if(theDispOnly){ + anActor->VisibilityOff(); + } + }else if(theDispOnly && anActor->GetVisibility()){ + anActor->VisibilityOff(); + } + } + } + if(aResActor){ + if(theIsHighlight) + aView->highlight(aResActor->getIO(),true); + aView->getRenderer()->ResetCameraClippingRange(); + aView->Repaint(); + return aResActor; + } + return PublishInView(theModule,thePrs,theIsHighlight,theIsViewCreate); + } + return NULL; + } + + + //--------------------------------------------------------------- + template + inline + void + OnEraseAll(VisuGUI* theModule) + { + typedef typename TViewer::TViewWindow TViewWindow; + if(TViewWindow* aViewWindow = GetViewWindow(theModule)){ + aViewWindow->unHighlightAll(); + if(vtkRenderer *aRen = aViewWindow->getRenderer()){ + vtkActorCollection *aCollection = aRen->GetActors(); + aCollection->InitTraversal(); + while(vtkActor *anAct = aCollection->GetNextActor()){ + if(anAct->GetVisibility() > 0) + if(SALOME_Actor* anActor = dynamic_cast(anAct)){ + anActor->VisibilityOff(); + } + } + aViewWindow->Repaint(); + } + } + } + + template<> + inline + void + OnEraseAll(VisuGUI* theModule) + { + if(SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule,false)) + aPlot2d->EraseAll(); + } + + + //--------------------------------------------------------------- + template + inline + VISU_Actor* + FindActor(TVieweWindow* theViewWindow, + const char* theEntry) + { + using namespace SVTK; + if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){ + if(vtkActorCollection* aCollection = aRenderer->GetActors()){ + if(VISU_Actor* anActor = Find(aCollection,TIsSameEntry(theEntry))){ + return anActor; + } + } + } + return NULL; + } + + template + inline + void + ErasePrs3d(VisuGUI* theModule, + VISU::Prs3d_i* thePrs, + const bool thIsUpdate = true) + { + typedef typename TViewer::TViewWindow TViewWindow; + if(TViewWindow* aViewWindow = GetViewWindow(theModule)){ + if(VISU_Actor* anActor = FindActor(aViewWindow,thePrs)){ + anActor->VisibilityOff(); + if(thIsUpdate) + aViewWindow->Repaint(); + } + } + } + + + void + ErasePrs(VisuGUI* theModule, + VISU::Base_ptr theBase, + bool thIsUpdate); +} + +#endif diff --git a/src/VISU_I/Makefile.in b/src/VISU_I/Makefile.in index 330d5468..20168853 100644 --- a/src/VISU_I/Makefile.in +++ b/src/VISU_I/Makefile.in @@ -18,50 +18,154 @@ VPATH=.:@srcdir@:@top_srcdir@/idl # Libraries targets LIB = libVISUEngineImpl.la -LIB_SRC = VISUConfig.cc VISU_Gen_i.cc \ - VISU_Result_i.cc VISU_PrsObject_i.cc VISU_Table_i.cc \ - VISU_Prs3d_i.cc VISU_Mesh_i.cc VISU_ScalarMap_i.cc \ - VISU_IsoSurfaces_i.cc VISU_DeformedShape_i.cc \ - VISU_Plot3D_i.cc VISU_CutPlanes_i.cc VISU_CutLines_i.cc \ - VISU_Vectors_i.cc VISU_StreamLines_i.cc \ - VISU_ViewManager_i.cc VISU_View_i.cc \ - VISU_TimeAnimation.cxx VISU_CorbaMedConvertor.cxx \ - VISU_DumpPython.cc - -LIB_MOC = VISU_TimeAnimation.h +LIB_SRC = \ + VISU_Result_i.cc \ + VISUConfig.cc \ + VISU_PrsObject_i.cc \ + VISU_Prs3d_i.cc \ + VISU_ColoredPrs3d_i.cc \ + VISU_ScalarMap_i.cc \ + VISU_GaussPoints_i.cc \ + VISU_IsoSurfaces_i.cc \ + VISU_DeformedShape_i.cc \ + VISU_Plot3D_i.cc \ + VISU_CutPlanes_i.cc \ + VISU_CutLines_i.cc \ + VISU_Vectors_i.cc \ + VISU_StreamLines_i.cc \ + VISU_Mesh_i.cc \ + VISU_Table_i.cc \ + VISU_Gen_i.cc \ + VISU_ViewManager_i.cc \ + VISU_View_i.cc \ + VISU_TimeAnimation.cxx \ + VISU_CorbaMedConvertor.cxx \ + VISU_DumpPython.cc \ + VISU_ScalarMapOnDeformedShape_i.cc + +LIB_MOC = \ + VISU_TimeAnimation.h -LIB_SERVER_IDL = VISU_Gen.idl SALOME_Component.idl \ - SALOME_Exception.idl SALOME_GenericObj.idl MED.idl +LIB_SERVER_IDL = \ + MED.idl \ + VISU_Gen.idl \ + SALOME_Component.idl \ + SALOME_Exception.idl \ + SALOME_GenericObj.idl -LIB_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Comm.idl +LIB_CLIENT_IDL = \ + SALOMEDS.idl \ + SALOMEDS_Attributes.idl \ + SALOME_Comm.idl # Executables targets -BIN = +BIN = VISU_I BIN_SRC = BIN_CLIENT_IDL = BIN_SERVER_IDL = -EXPORT_HEADERS = VISUConfig.hh VISU_Gen_i.hh \ - VISU_Result_i.hh VISU_PrsObject_i.hh VISU_Table_i.hh \ - VISU_Prs3d_i.hh VISU_Mesh_i.hh VISU_ScalarMap_i.hh \ - VISU_IsoSurfaces_i.hh VISU_DeformedShape_i.hh \ - VISU_Plot3D_i.hh VISU_CutPlanes_i.hh VISU_CutLines_i.hh \ - VISU_Vectors_i.hh VISU_StreamLines_i.hh \ - VISU_ViewManager_i.hh VISU_View_i.hh \ - VISU_TimeAnimation.h +EXPORT_HEADERS = \ + VISUConfig.hh \ + VISU_Gen_i.hh \ + VISU_Result_i.hh \ + VISU_PrsObject_i.hh \ + VISU_Table_i.hh \ + VISU_Prs3d_i.hh \ + VISU_Mesh_i.hh \ + VISU_ColoredPrs3d_i.hh \ + VISU_ScalarMap_i.hh \ + VISU_IsoSurfaces_i.hh \ + VISU_DeformedShape_i.hh \ + VISU_Plot3D_i.hh \ + VISU_CutPlanes_i.hh \ + VISU_CutLines_i.hh \ + VISU_Vectors_i.hh \ + VISU_StreamLines_i.hh \ + VISU_GaussPoints_i.hh \ + VISU_ViewManager_i.hh \ + VISU_View_i.hh \ + VISU_TimeAnimation.h \ + VISU_ScalarMapOnDeformedShape_i.hh # additionnal information to compil and link file -CPPFLAGS += -ftemplate-depth-32 $(QT_INCLUDES) $(PYTHON_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) \ - $(HDF5_INCLUDES) $(QWT_INCLUDES) $(BOOST_CPPFLAGS)\ - -I${KERNEL_ROOT_DIR}/include/salome -I${GUI_ROOT_DIR}/include/salome - -LDFLAGS += $(PYTHON_LIBS) $(QT_MT_LIBS) $(VTK_LIBS) $(QWT_LIBS) -lSalomeNS -lTOOLSDS \ - -lSalomeContainer -lOpUtil -lSalomeApp -lVTKViewer -lSVTK -lSPlot2d -lSalomeHDFPersist \ - -lSalomeGenericObj -lVisuConvertor -lVisuPipeLine -lVisuObject -lVISUGUITOOLS \ - -L${KERNEL_ROOT_DIR}/lib/salome -L${GUI_ROOT_DIR}/lib/salome -lEvent - -LIBS+= -lPlot2d -L${KERNEL_ROOT_DIR}/lib/salome +CPPFLAGS += \ + -ftemplate-depth-32 \ + $(QT_INCLUDES) \ + $(PYTHON_INCLUDES) \ + $(OCC_INCLUDES) \ + $(VTK_INCLUDES) \ + $(HDF5_INCLUDES) \ + $(QWT_INCLUDES) \ + $(BOOST_CPPFLAGS)\ + -I${KERNEL_ROOT_DIR}/include/salome \ + -I${MED_ROOT_DIR}/include/salome \ + -I${GUI_ROOT_DIR}/include/salome + +LDFLAGS += \ + $(PYTHON_LIBS) \ + $(QT_MT_LIBS) \ + $(VTK_LIBS) \ + $(QWT_LIBS) \ + $(BOOST_LIBS) \ + -L${KERNEL_ROOT_DIR}/lib/salome \ + -L${GUI_ROOT_DIR}/lib/salome \ + -L${MED_ROOT_DIR}/lib/salome + +LIBS+= -lboost_signals-mt \ + -lSalomeHDFPersist \ + -lSalomeGenericObj \ + -lSalomeContainer \ + -lSalomeNS \ + -lTOOLSDS \ + -lOpUtil \ + -lEvent \ + -lCASCatch \ + -lSalomeApp \ + -lSalomeSession \ + -lVTKViewer \ + -lSVTK \ + -lSPlot2d \ + -lVisuConvertor \ + -lVisuPipeLine \ + -lVisuObject \ + -lVISUGUITOOLS + +LDFLAGSFORBIN=$(LDFLAGS) $(LIBS) \ + -L${KERNEL_ROOT_DIR}/lib/salome \ + -lSALOMEBasics \ + -lSalomeCatalog \ + -lwith_loggerTraceCollector \ + -lSalomeLifeCycleCORBA \ + -lRegistry \ + -lSalomeNotification \ + -lSALOMELocalTrace \ + -lSalomeResourcesManager \ + -lSalomeDS \ + -lSalomeDSImpl \ + -lSalomeObject \ + -lqtx \ + -lsuit \ + -lstd \ + -lCAM \ + -lLightApp \ + -lObjBrowser \ + -lSalomePrs \ + -lPyInterp \ + -lPythonConsole \ + -lLogWindow \ + -lToolsGUI \ + -lGLViewer \ + -lOCCViewer \ + -lSUPERVGraph \ + -lSOCC \ + -lVVTK \ + -lPlot2d \ + -lMEDWrapper \ + -lMEDWrapperBase \ + -lMEDWrapper_V2_2 \ + -lMEDWrapper_V2_1 \ + -lmed_V2_1 # additional file to be cleaned MOSTLYCLEAN = diff --git a/src/VISU_I/VISUConfig.cc b/src/VISU_I/VISUConfig.cc index 56ef09c5..ee879b6a 100644 --- a/src/VISU_I/VISUConfig.cc +++ b/src/VISU_I/VISUConfig.cc @@ -432,13 +432,6 @@ namespace VISU{ if (CORBA::is_nil(aRemovableObject)) continue; aRemovableObject->RemoveFromStudy(); - - // Destroy - if (theDestroySubObjects) { - VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aRemovableObject); - if (CORBA::is_nil(aPrs3d)) continue; - aPrs3d->Destroy(); - } } // asl, fix for PAL10455: Remove references to SObject @@ -475,19 +468,14 @@ namespace VISU{ for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { _PTR(SObject) aChildSObject = aChildIter->Value(); CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject); - if (CORBA::is_nil(aChildObj)) continue; + if (CORBA::is_nil(aChildObj)) + continue; VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj); - if (CORBA::is_nil(aRemovableObject)) continue; + if (CORBA::is_nil(aRemovableObject)) + continue; aRemovableObject->RemoveFromStudy(); - - // Destroy - if (theDestroySubObjects) { - VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aRemovableObject); - if (CORBA::is_nil(aPrs3d)) continue; - aPrs3d->Destroy(); - } } // Remove the SObject itself diff --git a/src/VISU_I/VISUConfig.hh b/src/VISU_I/VISUConfig.hh index 3224f05a..6ec9a2d0 100644 --- a/src/VISU_I/VISUConfig.hh +++ b/src/VISU_I/VISUConfig.hh @@ -39,8 +39,8 @@ #include "Utils_CorbaException.hxx" #include "utilities.h" -#include -#include +#include "SALOMEDSClient_SObject.hxx" +#include "SALOMEDSClient_Study.hxx" // QT headers #include @@ -61,8 +61,8 @@ class SUIT_Session; class SUIT_ResourceMgr; - -namespace VISU{ +namespace VISU +{ SUIT_Session *GetSession(); SUIT_ResourceMgr *GetResourceMgr(); diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.cc b/src/VISU_I/VISU_ColoredPrs3d_i.cc new file mode 100644 index 00000000..8a691fd4 --- /dev/null +++ b/src/VISU_I/VISU_ColoredPrs3d_i.cc @@ -0,0 +1,747 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_PrsObject_i.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_ColoredPrs3d_i.hh" + +#include "VISU_ScalarMapPL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_Convertor.hxx" + +#include "SUIT_ResourceMgr.h" +#include "SALOME_Event.hxx" + +#include + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +//#define _DEXCEPT_ +#else +static int MYDEBUG = 0; +#endif + + +//============================================================================ +VISU::ColoredPrs3d_i:: +ColoredPrs3d_i(Result_i* theResult, + bool theAddToStudy) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult,theAddToStudy), + myScalarMapPL(NULL), + myIsFixedRange(false) +{} + +VISU::ColoredPrs3d_i:: +ColoredPrs3d_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult,theSObject), + myScalarMapPL(NULL), + myIsFixedRange(false) +{} + +VISU::ColoredPrs3d_i +::~ColoredPrs3d_i() +{} + +//--------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::RemoveFromStudy() +{ + struct TRemoveFromStudy: public SALOME_Event + { + VISU::ColoredPrs3d_i* myRemovable; + TRemoveFromStudy(VISU::ColoredPrs3d_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + SALOMEDS::SObject_var aSObject = myRemovable->GetSObject(); + if(!CORBA::is_nil(aSObject.in())) + VISU::RemoveFromStudy(aSObject,false); + myRemovable->TSuperClass::RemoveFromStudy(); + } + }; + + ProcessVoidEvent(new TRemoveFromStudy(this)); +} + +//--------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::SameAs(const Prs3d_i* theOrigin) +{ + if(const ColoredPrs3d_i* aPrs3d = dynamic_cast(theOrigin)){ + DoHook(); + + ColoredPrs3d_i* anOrigin = const_cast(aPrs3d); + + myField = anOrigin->GetField(); + myMeshName = myField->myMeshName; + myEntity = myField->myEntity; + myIteration = anOrigin->GetIteration(); + myFieldName = anOrigin->GetFieldName(); + + Build(-1); + + TSuperClass::SameAs(theOrigin); + + SetScalarMode(anOrigin->GetScalarMode()); + SetNbColors(anOrigin->GetNbColors()); + SetBarOrientation(anOrigin->GetBarOrientation()); + + SetPosition(anOrigin->GetPosX(), anOrigin->GetPosY()); + SetSize(anOrigin->GetWidth(), anOrigin->GetHeight()); + SetLabels(anOrigin->GetLabels()); + SetTitle(anOrigin->GetTitle()); + + SetBoldTitle(anOrigin->IsBoldTitle()); + SetItalicTitle(anOrigin->IsItalicTitle()); + SetShadowTitle(anOrigin->IsShadowTitle()); + SetTitFontType(anOrigin->GetTitFontType()); + float r,g,b; + anOrigin->GetTitleColor(&r,&g,&b); + SetTitleColor(r,g,b); + + SetBoldLabel(anOrigin->IsBoldLabel()); + SetItalicLabel(anOrigin->IsItalicLabel()); + SetShadowLabel(anOrigin->IsShadowLabel()); + SetLblFontType(anOrigin->GetLblFontType()); + anOrigin->GetLabelColor(&r,&g,&b); + SetLabelColor(r,g,b); + } +} + +void +VISU::ColoredPrs3d_i +::SameAsParams(const ColoredPrs3d_i* theOrigin) +{ + int anIteration = GetIteration(); + SameAs(theOrigin); + myIteration = anIteration; + + Build(-1); + Update(); +} + + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetScalarMode() +{ + return myScalarMapPL->GetScalarMode(); +} + +void +VISU::ColoredPrs3d_i +::SetScalarMode(CORBA::Long theScalarMode) +{ + myScalarMapPL->SetScalarMode(theScalarMode); +} + +CORBA::Double +VISU::ColoredPrs3d_i +::GetMin() +{ + return myScalarMapPL->GetScalarRange()[0]; +} + +CORBA::Double +VISU::ColoredPrs3d_i +::GetMax() +{ + return myScalarMapPL->GetScalarRange()[1]; +} + +void +VISU::ColoredPrs3d_i +::SetNbColors(CORBA::Long theNbColors) +{ + myScalarMapPL->SetNbColors(theNbColors); +} + +CORBA::Long +VISU::ColoredPrs3d_i +::GetNbColors() +{ + return myScalarMapPL->GetNbColors(); +} + +void +VISU::ColoredPrs3d_i +::SetBarOrientation(VISU::ScalarMap::Orientation theOrientation) +{ + myOrientation = theOrientation; +} + +VISU::ScalarMap::Orientation +VISU::ColoredPrs3d_i +::GetBarOrientation() +{ + return myOrientation; +} + +void +VISU::ColoredPrs3d_i +::SetPosition(CORBA::Double X, CORBA::Double Y) +{ + myPosition[0] = X; + myPosition[1] = Y; +} + +CORBA::Double +VISU::ColoredPrs3d_i +::GetPosX() +{ + return myPosition[0]; +} + +CORBA::Double +VISU::ColoredPrs3d_i +::GetPosY() +{ + return myPosition[1]; +} + +void +VISU::ColoredPrs3d_i +::SetSize(CORBA::Double theWidth, CORBA::Double theHeight) +{ + myWidth = theWidth; + myHeight = theHeight; +} + +CORBA::Double +VISU::ColoredPrs3d_i +::GetWidth() +{ + return myWidth; +} + +CORBA::Double +VISU::ColoredPrs3d_i +::GetHeight() +{ + return myHeight; +} + +void +VISU::ColoredPrs3d_i +::SetLabels(CORBA::Long theNbLabels) +{ + myNumberOfLabels = theNbLabels; +} + +CORBA::Long +VISU::ColoredPrs3d_i +::GetLabels() +{ + return myNumberOfLabels; +} + +void +VISU::ColoredPrs3d_i +::SetTitle(const char* theName) +{ + myTitle = theName; +} + +char* +VISU::ColoredPrs3d_i +::GetTitle() +{ + return CORBA::string_dup(myTitle.c_str()); +} + +bool +VISU::ColoredPrs3d_i +::IsBoldTitle() +{ + return myIsBoldTitle; +} + +void +VISU::ColoredPrs3d_i +::SetBoldTitle(bool isBold) +{ + myIsBoldTitle = isBold; +} + +bool +VISU::ColoredPrs3d_i +::IsItalicTitle() +{ + return myIsItalicTitle; +} + +void +VISU::ColoredPrs3d_i +::SetItalicTitle(bool isItalic) +{ + myIsItalicTitle = isItalic; +} + +bool +VISU::ColoredPrs3d_i +::IsShadowTitle() +{ + return myIsShadowTitle; +} + +void +VISU::ColoredPrs3d_i +::SetShadowTitle(bool isShadow) +{ + myIsShadowTitle = isShadow; +} + +int +VISU::ColoredPrs3d_i +::GetTitFontType() +{ + return myTitFontType; +} + +void +VISU::ColoredPrs3d_i +::SetTitFontType(int theType) +{ + myTitFontType = theType; +} + +void +VISU::ColoredPrs3d_i +::GetTitleColor(float* theR, float* theG, float* theB) +{ + *theR = myTitleColor[0]; + *theG = myTitleColor[1]; + *theB = myTitleColor[2]; +} + +void +VISU::ColoredPrs3d_i +::SetTitleColor(float theR, float theG, float theB) +{ + myTitleColor[0] = theR; + myTitleColor[1] = theG; + myTitleColor[2] = theB; +} + +bool +VISU::ColoredPrs3d_i +::IsBoldLabel() +{ + return myIsBoldLabel; +} + +void +VISU::ColoredPrs3d_i +::SetBoldLabel(bool isBold) +{ + myIsBoldLabel = isBold; +} + +bool +VISU::ColoredPrs3d_i +::IsItalicLabel() +{ + return myIsItalicLabel; +} + +void +VISU::ColoredPrs3d_i +::SetItalicLabel(bool isItalic) +{ + myIsItalicLabel = isItalic; +} + +bool +VISU::ColoredPrs3d_i +::IsShadowLabel() +{ + return myIsShadowLabel; +} + +void +VISU::ColoredPrs3d_i +::SetShadowLabel(bool isShadow) +{ + myIsShadowLabel = isShadow; +} + +int +VISU::ColoredPrs3d_i +::GetLblFontType() +{ + return myLblFontType; +} + +void +VISU::ColoredPrs3d_i +::SetLblFontType(int theType) +{ + myLblFontType = theType; +} + +void +VISU::ColoredPrs3d_i +::GetLabelColor(float* theR, float* theG, float* theB) +{ + *theR = myLabelColor[0]; + *theG = myLabelColor[1]; + *theB = myLabelColor[2]; +} + +void +VISU::ColoredPrs3d_i +::SetLabelColor(float theR, float theG, float theB) +{ + myLabelColor[0] = theR; + myLabelColor[1] = theG; + myLabelColor[2] = theB; +} + + +//---------------------------------------------------------------------------- +/** + * Creates ColoredPrs3d and initialises it from resources + */ +VISU::Storable* +VISU::ColoredPrs3d_i +::Create(const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + int theIteration) +{ + DoHook(); // to create proper pipeline + + myMeshName = theMeshName; + myEntity = (VISU::TEntity)theEntity; + myFieldName =theFieldName; + myIteration = theIteration; + + Build(false); // to get corresponding input from result and initilize the pipeline + + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + + int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0); + SetScalarMode(aScalarMode); + + int aNumberOfColors = aResourceMgr->integerValue( "VISU", "scalar_bar_num_colors", 64 ); + SetNbColors(aNumberOfColors); + + // Orientation + int anOrientation = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0); + if(anOrientation == 1) + myOrientation = VISU::ScalarMap::HORIZONTAL; + else + myOrientation = VISU::ScalarMap::VERTICAL; + + // Scalar Bar origin + QString propertyName = QString( "scalar_bar_%1_" ).arg( anOrientation == 0 ? "vertical" : "horizontal" ); + + float aXorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.01 : 0.2; + aXorigin = aResourceMgr->doubleValue("VISU", propertyName + "x", aXorigin); + myPosition[0] = aXorigin; + + float aYorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.1 : 0.012; + aYorigin = aResourceMgr->doubleValue("VISU", propertyName + "y", aYorigin); + myPosition[1] = aYorigin; + + // Scalar Bar size + myWidth = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.1 : 0.6; + myWidth = aResourceMgr->doubleValue("VISU", propertyName + "width", myWidth); + + myHeight = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12; + myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight); + + // scalar bar default position + bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0); + int aPlace = 1; + if (anIsArrangeBar){ + aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0); + } + if(myOrientation == VISU::ScalarMap::HORIZONTAL){ + myPosition[1] += myHeight*(aPlace-1); + } else { + myPosition[0] += myWidth*(aPlace-1); + } + + // Nb of Labels + myNumberOfLabels = aResourceMgr->integerValue( "VISU", "scalar_bar_num_labels", 5 ); + + // Fonts properties definition + myIsBoldTitle = myIsItalicTitle = myIsShadowTitle = true; + myTitFontType = VTK_ARIAL; + + if(aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" )){ + QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" ); + if ( f.family() == "Arial" ) + myTitFontType = VTK_ARIAL; + else if ( f.family() == "Courier" ) + myTitFontType = VTK_COURIER; + else if ( f.family() == "Times" ) + myTitFontType = VTK_TIMES; + + myIsBoldTitle = f.bold(); + myIsItalicTitle = f.italic(); + myIsShadowTitle = f.underline(); + } + + QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) ); + + myTitleColor[0] = aTextColor.red() / 255; + myTitleColor[1] = aTextColor.green() / 255; + myTitleColor[2] = aTextColor.blue() / 255; + + myIsBoldLabel = myIsItalicLabel = myIsShadowLabel = true; + myLblFontType = VTK_ARIAL; + + if( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" )){ + QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" ); + if ( f.family() == "Arial" ) + myLblFontType = VTK_ARIAL; + else if ( f.family() == "Courier" ) + myLblFontType = VTK_COURIER; + else if ( f.family() == "Times" ) + myLblFontType = VTK_TIMES; + + myIsBoldLabel = f.bold(); + myIsItalicLabel = f.italic(); + myIsShadowLabel = f.underline(); + } + + QColor aLabelColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) ); + + myLabelColor[0] = aLabelColor.red() / 255; + myLabelColor[1] = aLabelColor.green() / 255; + myLabelColor[2] = aLabelColor.blue() / 255; + + return this; +} + +VISU::Storable* +VISU::ColoredPrs3d_i +::Restore(const Storable::TRestoringMap& theMap) +{ + DoHook(); + + myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1(); + myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt(); + myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1(); + myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt(); + + myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study. + + Build(true); + + TSuperClass::Restore(theMap); + + SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt()); + SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt()); + SetBarOrientation((VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt()); + + myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1(); + myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt(); + myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble(); + myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble(); + myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble(); + myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble(); + + myTitFontType = VISU::Storable::FindValue(theMap,"myTitFontType").toInt(); + myIsBoldTitle = VISU::Storable::FindValue(theMap,"myIsBoldTitle").toInt(); + myIsItalicTitle = VISU::Storable::FindValue(theMap,"myIsItalicTitle").toInt(); + myIsShadowTitle = VISU::Storable::FindValue(theMap,"myIsShadowTitle").toInt(); + myTitleColor[0] = VISU::Storable::FindValue(theMap,"myTitleColor[0]").toFloat(); + myTitleColor[1] = VISU::Storable::FindValue(theMap,"myTitleColor[1]").toFloat(); + myTitleColor[2] = VISU::Storable::FindValue(theMap,"myTitleColor[2]").toFloat(); + + myLblFontType = VISU::Storable::FindValue(theMap,"myLblFontType").toInt(); + myIsBoldLabel = VISU::Storable::FindValue(theMap,"myIsBoldLabel").toInt(); + myIsItalicLabel = VISU::Storable::FindValue(theMap,"myIsItalicLabel").toInt(); + myIsShadowLabel = VISU::Storable::FindValue(theMap,"myIsShadowLabel").toInt(); + myLabelColor[0] = VISU::Storable::FindValue(theMap,"myLabelColor[0]").toFloat(); + myLabelColor[1] = VISU::Storable::FindValue(theMap,"myLabelColor[1]").toFloat(); + myLabelColor[2] = VISU::Storable::FindValue(theMap,"myLabelColor[2]").toFloat(); + + return this; +} + +void +VISU::ColoredPrs3d_i +::ToStream(std::ostringstream& theStr) +{ + TSuperClass::ToStream(theStr); + + Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) ); + Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) ); + Storable::DataToStream( theStr, "myOrientation", myOrientation ); + + Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() ); + Storable::DataToStream( theStr, "myEntity", myEntity ); + Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() ); + Storable::DataToStream( theStr, "myIteration", myIteration ); + + Storable::DataToStream( theStr, "myTitle", myTitle.c_str() ); + Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels ); + Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] ); + Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] ); + Storable::DataToStream( theStr, "myWidth", myWidth ); + Storable::DataToStream( theStr, "myHeight", myHeight ); + + Storable::DataToStream( theStr, "myTitFontType", myTitFontType ); + Storable::DataToStream( theStr, "myIsBoldTitle", myIsBoldTitle ); + Storable::DataToStream( theStr, "myIsItalicTitle", myIsItalicTitle ); + Storable::DataToStream( theStr, "myIsShadowTitle", myIsShadowTitle ); + Storable::DataToStream( theStr, "myTitleColor[0]", myTitleColor[0] ); + Storable::DataToStream( theStr, "myTitleColor[1]", myTitleColor[1] ); + Storable::DataToStream( theStr, "myTitleColor[2]", myTitleColor[2] ); + + Storable::DataToStream( theStr, "myLblFontType", myLblFontType ); + Storable::DataToStream( theStr, "myIsBoldLabel", myIsBoldLabel ); + Storable::DataToStream( theStr, "myIsItalicLabel", myIsItalicLabel ); + Storable::DataToStream( theStr, "myIsShadowLabel", myIsShadowLabel ); + Storable::DataToStream( theStr, "myLabelColor[0]", myLabelColor[0] ); + Storable::DataToStream( theStr, "myLabelColor[1]", myLabelColor[1] ); + Storable::DataToStream( theStr, "myLabelColor[2]", myLabelColor[2] ); +} + + +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::DoHook() +{ + if(MYDEBUG) MESSAGE("ColoredPrs3d_i::DoHook() - "<GetMapper()->SetScalarVisibility(1); + } + myScalarMapPL = dynamic_cast(myPipeLine); +} + +//---------------------------------------------------------------------------- +VISU::Storable* +VISU::ColoredPrs3d_i +::Build(int theRestoring) +{ + if(MYDEBUG) + MESSAGE("ColoredPrs3d_i::Build - "<Init(); + if(!myIsFixedRange) myScalarMapPL->SetSourceRange(); + const VISU::TValField& aValField = myField->myValField; + const VISU::PValForTime aValForTime = aValField.find(myIteration)->second; + aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime->myTime).c_str()); + if (theRestoring == 0) myTitle = aComment.simplifyWhiteSpace().latin1(); + } + if(myAddToStudy){ + myName = GenerateName().latin1(); + aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); + string aResultEntry = myResult->GetEntry(); + string aRefFatherEntry = myResult->GetRefFatherEntry(); + string anEntry = myResult->GetEntry(aComment.latin1()); + if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!"); + aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); + CORBA::String_var anIOR = GetID(); + CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true); + mySObject = myStudy->FindObjectIOR(anIOR); + } +#ifndef _DEXCEPT_ + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<CommitCommand(); + return this; +} + + +//---------------------------------------------------------------------------- +const VISU::PField& +VISU::ColoredPrs3d_i +::GetField() const +{ + return myField; +} + +const std::string& +VISU::ColoredPrs3d_i +::GetMeshName() const +{ + return myMeshName; +} + +VISU::Entity +VISU::ColoredPrs3d_i +::GetEntity() const +{ + return VISU::Entity(myEntity); +} + +const std::string& +VISU::ColoredPrs3d_i +::GetFieldName() const +{ + return myFieldName; +} + +int +VISU::ColoredPrs3d_i +::GetIteration() const +{ + return myIteration; +} + +VISU_ScalarMapPL* +VISU::ColoredPrs3d_i +::GetScalarMapPL() +{ + return myScalarMapPL; +} diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.hh b/src/VISU_I/VISU_ColoredPrs3d_i.hh new file mode 100644 index 00000000..e03d772e --- /dev/null +++ b/src/VISU_I/VISU_ColoredPrs3d_i.hh @@ -0,0 +1,304 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_ColoredPrs3d_i_HeaderFile +#define VISU_ColoredPrs3d_i_HeaderFile + +#include "VISU_Prs3d_i.hh" + +class VISU_ScalarMapPL; + +namespace VISU +{ + //============================================================================ + class ColoredPrs3d_i : public virtual POA_VISU::ColoredPrs3d, + public virtual Prs3d_i + { + ColoredPrs3d_i(); + ColoredPrs3d_i(const ColoredPrs3d_i&); + public: + //---------------------------------------------------------------------------- + typedef Prs3d_i TSuperClass; + + explicit + ColoredPrs3d_i(Result_i* theResult, + bool theAddToStudy); + explicit + ColoredPrs3d_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject); + + virtual + ~ColoredPrs3d_i(); + + virtual + void + RemoveFromStudy(); + + //---------------------------------------------------------------------------- + virtual + CORBA::Long + GetScalarMode(); + + virtual + void + SetScalarMode(CORBA::Long theScalarMode); + + virtual + CORBA::Double + GetMin(); + + virtual + CORBA::Double + GetMax(); + + virtual + void + SetNbColors(CORBA::Long theNbColors); + + virtual + CORBA::Long + GetNbColors(); + + virtual + void + SetBarOrientation(VISU::ScalarMap::Orientation theOrientation); + + virtual + VISU::ScalarMap::Orientation + GetBarOrientation(); + + virtual + void + SetPosition(CORBA::Double X, CORBA::Double Y); + + virtual + CORBA::Double + GetPosX(); + + virtual + CORBA::Double + GetPosY(); + + virtual + void + SetSize(CORBA::Double theWidth, CORBA::Double theHeight); + + virtual + CORBA::Double + GetWidth(); + + virtual + CORBA::Double + GetHeight(); + + virtual + void + SetLabels(CORBA::Long theNbLabels); + + virtual + CORBA::Long + GetLabels(); + + virtual + void + SetTitle(const char* theName); + + virtual + char* + GetTitle(); + + //---------------------------------------------------------------------------- + protected: + VISU::ScalarMap::Orientation myOrientation; + std::string myTitle; + int myNumberOfLabels; + float myPosition[2], myWidth, myHeight; + + public: + //---------------------------------------------------------------------------- + virtual + Storable* + Create(const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + int theIteration); + + virtual + Storable* + Restore(const Storable::TRestoringMap& theMap); + + virtual + void + ToStream(std::ostringstream& theStr); + + virtual + void + SameAs(const Prs3d_i* theOrigin); + + /*! + * \brief Works like SameAs() method, but keep myIteration value unchanged. + * + * Is used in VISU_TimeAnimation class implementation. + */ + void + SameAsParams(const ColoredPrs3d_i* theOrigin); + + const VISU::PField& + GetField() const; + + const std::string& + GetMeshName() const; + + VISU::Entity + GetEntity() const; + + const std::string& + GetFieldName() const; + + int + GetIteration() const; + + VISU_ScalarMapPL* + GetScalarMapPL(); + + virtual + bool + IsBoldTitle(); + + virtual + void + SetBoldTitle(bool isBold); + + virtual + bool + IsItalicTitle(); + + virtual + void + SetItalicTitle(bool isItalic); + + virtual + bool + IsShadowTitle(); + + virtual + void + SetShadowTitle(bool isShadow); + + virtual + int + GetTitFontType(); + + virtual + void + SetTitFontType(int theType); + + virtual + void + GetTitleColor(float* theR, float* theG, float* theB); + + virtual + void + SetTitleColor(float theR, float theG, float theB); + + virtual + bool + IsBoldLabel(); + + virtual + void + SetBoldLabel(bool isBold); + + virtual + bool + IsItalicLabel(); + + virtual + void + SetItalicLabel(bool isItalic); + + virtual + bool + IsShadowLabel(); + + virtual + void + SetShadowLabel(bool isShadow); + + virtual + int + GetLblFontType(); + + virtual + void + SetLblFontType(int theType); + + virtual + void + GetLabelColor(float* theR, float* theG, float* theB); + + virtual + void + SetLabelColor(float theR, float theG, float theB); + + //---------------------------------------------------------------------------- + protected: + PField myField; + TEntity myEntity; + std::string myFieldName; + int myIteration; + + //Font management + bool myIsBoldTitle; + bool myIsItalicTitle; + bool myIsShadowTitle; + int myTitFontType; + float myTitleColor[3]; + + bool myIsBoldLabel; + bool myIsItalicLabel; + bool myIsShadowLabel; + int myLblFontType; + float myLabelColor[3]; + + VISU_ScalarMapPL* myScalarMapPL; + bool myIsFixedRange; + + virtual + void + DoSetInput(Result_i* theResult) = 0; + + Storable* + Build(int theRestoring); + + virtual + void + DoHook(); + }; + +} + +#endif diff --git a/src/VISU_I/VISU_CorbaMedConvertor.cxx b/src/VISU_I/VISU_CorbaMedConvertor.cxx index 56c39876..b1dc814b 100644 --- a/src/VISU_I/VISU_CorbaMedConvertor.cxx +++ b/src/VISU_I/VISU_CorbaMedConvertor.cxx @@ -58,7 +58,8 @@ extern "C" { } } -namespace{ +namespace +{ using namespace SALOME_MED; const int MED_NBR_GEOMETRIE_MAILLE = 15; @@ -107,7 +108,10 @@ namespace{ MED_POINT1, }; - int GetEntity2Geom(const VISU::TEntity& theEntity, medGeometryElement*& theVector) + + //--------------------------------------------------------------- + int + GetEntity2Geom(const VISU::TEntity& theEntity, medGeometryElement*& theVector) { switch(theEntity){ case CELL_ENTITY: theVector = CELLGEOM; return MED_NBR_GEOMETRIE_MAILLE; break; @@ -118,7 +122,10 @@ namespace{ return -1; } - int MEDGeom2NbNodes(int theMEDGeomType) + + //--------------------------------------------------------------- + int + MEDGeom2NbNodes(int theMEDGeomType) { switch(theMEDGeomType){ case MED_NONE: return 0; @@ -141,45 +148,35 @@ namespace{ return -1; } - int MEDGeomToVTK(medGeometryElement theMEDGeomType) + + //--------------------------------------------------------------- + VISU::EGeometry + MEDGeom2VISU(medGeometryElement theGeom) { - switch(theMEDGeomType){ - case MED_NONE: return VTK_EMPTY_CELL; - case MED_POINT1: return VTK_VERTEX; - case MED_SEG2: return VTK_LINE; - case MED_SEG3: return VTK_LINE; - case MED_TRIA3: return VTK_TRIANGLE; - case MED_TRIA6: return VTK_TRIANGLE; - case MED_QUAD4: return VTK_QUAD; - case MED_QUAD8: return VTK_QUAD; - case MED_TETRA4: return VTK_TETRA; - case MED_TETRA10: return VTK_TETRA; - case MED_HEXA8: return VTK_HEXAHEDRON; - case MED_HEXA20: return VTK_HEXAHEDRON; - case MED_PENTA6: return VTK_WEDGE; - case MED_PENTA15: return VTK_WEDGE; - case MED_PYRA5: return VTK_PYRAMID; - case MED_PYRA13: return VTK_PYRAMID; + switch(theGeom){ + case MED_POINT1: return VISU::ePOINT1; + case MED_SEG2: return VISU::eSEG2; + case MED_SEG3: return VISU::eSEG3; + case MED_TRIA3: return VISU::eTRIA3; + case MED_TRIA6: return VISU::eTRIA6; + case MED_QUAD4: return VISU::eQUAD4; + case MED_QUAD8: return VISU::eQUAD8; + case MED_TETRA4: return VISU::eTETRA4; + case MED_TETRA10: return VISU::eTETRA10; + case MED_HEXA8: return VISU::eHEXA8; + case MED_HEXA20: return VISU::eHEXA20; + case MED_PENTA6: return VISU::ePENTA6; + case MED_PENTA15: return VISU::ePENTA15; + case MED_PYRA5: return VISU::ePYRA5; + case MED_PYRA13: return VISU::ePYRA13; } - return -1; + return VISU::eNONE; } - int VTKGeom2NbNodes(int theVTKGeomType) - { - switch(theVTKGeomType){ - case VTK_VERTEX: return 1; - case VTK_LINE: return 2; - case VTK_TRIANGLE: return 3; - case VTK_QUAD: return 4; - case VTK_TETRA: return 4; - case VTK_HEXAHEDRON: return 8; - case VTK_WEDGE: return 6; - case VTK_PYRAMID: return 5; - } - return -1; - } - - medGeometryElement VTKGeomToMED(int theVTKGeomType) + + //--------------------------------------------------------------- + medGeometryElement + VTKGeomToMED(int theVTKGeomType) { switch(theVTKGeomType){ case VTK_VERTEX: return MED_POINT1; @@ -194,7 +191,9 @@ namespace{ return medGeometryElement(-1); } - VISU::TEntity MEDEntityToVTK(medEntityMesh theMEDEntity) + //--------------------------------------------------------------- + VISU::TEntity + MEDEntityToVTK(medEntityMesh theMEDEntity) { switch(theMEDEntity){ case MED_NODE: return NODE_ENTITY; @@ -205,7 +204,9 @@ namespace{ return VISU::TEntity(-1); } - medEntityMesh VTKEntityToMED(VISU::TEntity theVTKEntity) + //--------------------------------------------------------------- + medEntityMesh + VTKEntityToMED(VISU::TEntity theVTKEntity) { switch(theVTKEntity){ case NODE_ENTITY: return MED_NODE; @@ -215,8 +216,12 @@ namespace{ } return medEntityMesh(-1); } + - string GetSObjectName(SALOMEDS::SObject_ptr aSObject){ + //--------------------------------------------------------------- + std::string + GetSObjectName(SALOMEDS::SObject_ptr aSObject) + { SALOMEDS::GenericAttribute_var anAttr; if (aSObject->FindAttribute(anAttr,"AttributeName")) { SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); @@ -226,8 +231,11 @@ namespace{ return ""; } + + //--------------------------------------------------------------- void - GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize, + GetCellsSize(vtkIdType& theNbCells, + vtkIdType& theCellsSize, SALOME_MED::MESH_ptr theMEDMesh, const VISU::TEntity& theVEntity) { @@ -236,20 +244,22 @@ namespace{ int iGeomEnd = GetEntity2Geom(theVEntity,aGeomElems); const medEntityMesh& aMEntity = VTKEntityToMED(theVEntity); if(MYDEBUG) MESSAGE("GetCellsSize - theVEntity = "<getNumberOfElements(aMEntity,aMEDGeom); - if(iNumElemEnd > 0){ - if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<getNumberOfElements(aMEntity,aMEDGeom); + if(iNumElemEnd > 0){ + if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<getTypes(); @@ -269,6 +279,7 @@ namespace{ } + //--------------------------------------------------------------- void GetCellsSize(VISU::PCMesh theMesh, SALOME_MED::MESH_ptr theMEDMesh, @@ -277,31 +288,40 @@ namespace{ TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap; VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[theEntity]; if(theEntity == NODE_ENTITY){ - theMesh->myNbPoints = theMEDMesh->getNumberOfNodes(); aMeshOnEntity->myNbCells = theMesh->myNbPoints; aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints; - vtkIdType aNbCells, aCellsSize; - GetCellsSize(aNbCells,aCellsSize,theMEDMesh,CELL_ENTITY); - if(aNbCells > 0){ - - TMeshOnEntityMap::iterator aIter = aMeshOnEntityMap.find(CELL_ENTITY); - if (aIter != aMeshOnEntityMap.end()){ - VISU::PCMeshOnEntity aMeshOnCells = aIter->second; - - aMeshOnCells->myEntity = VISU::CELL_ENTITY; - aMeshOnCells->myMeshName = theMesh->myName; - aMeshOnCells->myNbCells = aNbCells; - aMeshOnCells->myCellsSize = aCellsSize; - } - } }else{ GetCellsSize(aMeshOnEntity->myNbCells,aMeshOnEntity->myCellsSize,theMEDMesh,theEntity); } } - + + + //--------------------------------------------------------------- + PCMeshOnEntity + InitMeshOnEntity(const VISU::PCMesh& theMesh, + const VISU::TEntity& theEntity, + const VISU::PCMeshOnEntity& theMeshOnEntity) + { + PCMeshOnEntity aMeshOnEntity; + TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap; + TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(theEntity); + if(anIter == aMeshOnEntityMap.end()){ + aMeshOnEntity.reset(new TCMeshOnEntity()); + *aMeshOnEntity = *theMeshOnEntity; + aMeshOnEntity->myEntity = theEntity; + aMeshOnEntityMap[theEntity] = aMeshOnEntity; + }else + aMeshOnEntity = anIter->second; + + GetCellsSize(theMesh,theMesh->myMesh,theEntity); + + return aMeshOnEntity; + } + } +//--------------------------------------------------------------- VISU_Convertor* VISU_MEDFieldConvertor::Build() { @@ -322,11 +342,15 @@ VISU_MEDFieldConvertor::Build() CORBA::String_var aFieldName = myField->getName(); PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh()); + aMesh->myNamedPointCoords(new TNamedPointCoords()); + aMesh->myNbPoints = aMEDMesh->getNumberOfNodes(); aMesh->myDim = aMEDMesh->getSpaceDimension(); - aMesh->myPointsDim.resize(aMesh->myDim); aMesh->myName = aMeshName.in(); aMesh->myMesh = aMEDMesh; + TNamedPointCoords& aCoords = aMesh->myNamedPointCoords; + aCoords.Init(aMesh->myNbPoints,aMesh->myDim); + if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<myEntity); - aFamilyAndEntitySet.insert(aFamilyAndEntity); - - aGroup->myNbCells += aFamily->myNbCells; - aGroup->myCellsSize += aFamily->myCellsSize; - - VISU::TBindGroups& aBindGroups = aFamily->myGroups; - aBindGroups.insert(aSupportName.in()); + aFamilySet.insert(aFamily); } } - if(!aGroup->myFamilyAndEntitySet.empty()){ + if(!aFamilySet.empty()){ TGroupMap& aGroupMap = aMesh->myGroupMap; aGroupMap[aSupportName.in()] = aGroup; } @@ -731,12 +765,10 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED) aField->myName = aFieldName.in(); aField->myEntity = anEntity; aField->myMeshName = aMeshName.in(); - aField->myNbComp = aMEDField->getNumberOfComponents(); + aField->InitArrays(aMEDField->getNumberOfComponents()); aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp; if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<myNbCells); - aField->myCompNames.resize(aField->myNbComp); - aField->myUnitNames.resize(aField->myNbComp); }else aField = aFieldMapIter->second; @@ -757,6 +789,7 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED) } +//--------------------------------------------------------------- VISU_Convertor* VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator) { @@ -784,48 +817,66 @@ VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator) CORBA::String_var aMeshName = aMEDMesh->getName(); CORBA::String_var aFieldName = aMEDField->getName(); - PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh()); - aMesh->myDim = aMEDMesh->getSpaceDimension(); - aMesh->myPointsDim.resize(aMesh->myDim); - aMesh->myName = aMeshName.in(); - aMesh->myNbPoints = aMEDMesh->getNumberOfNodes(); - aMesh->myMesh = aMEDMesh; - if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<myNbCells = "<myNbCells); - aField->myCompNames.resize(aField->myNbComp); - aField->myUnitNames.resize(aField->myNbComp); - } + }else + aField = aFieldMapIter->second; + TValField& aValField = aField->myValField; int anId = aMEDField->getIterationNumber(); PCValForTime aValForTime = aValField[anId](new TCValForTime()); @@ -834,274 +885,381 @@ VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator) aValForTime->myTime = TTime(aDT,""); aValForTime->myField = aMEDField; if(MYDEBUG) - MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<myIsDone) + return 0; + SALOME_MED::MESH_var& aMedMesh = theMesh->myMesh; - int iNumElemEnd = aMedMesh->getNumberOfNodes(); - TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord; + int aDim = theMesh->myDim; + TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; + int aNbElem = aCoords.GetNbPoints(); - if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<> There is no points in the mesh !!!"); - aPointsCoord.resize(theMesh->myDim*iNumElemEnd,0.0); - SALOME_MED::double_array_var coord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE); - if(!isPointsLoaded){ - for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) - for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iNumElem2Dim++) - aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim]; + SALOME_MED::double_array_var aCCoord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE); + for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++){ + VISU::TCoordSlice aCoordSlice = aCoords.GetCoordSlice(iElem); + for(int iDim = 0; iDim < aDim; iDim++) + aCoordSlice[iDim] = aCCoord[anId++]; + } + + if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY"); + + TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh; + PSubMeshImpl aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new TCSubMesh()); - if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY"); + aSubMesh->myNbCells = theMesh->myNbPoints; + aSubMesh->myCellsSize = 2*theMesh->myNbPoints; - TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX]; - aConnForCellType.resize(iNumElemEnd); - for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) - aConnForCellType[iNumElem] = TMeshOnEntityImpl::TConnect(1,iNumElem); - } - if(aFamily){ - if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh"); - - SALOME_MED::FAMILY_var aMedFamily = aFamily->myFamily; - CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements(); - TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX]; - - if(!anIsOnAllElements){ - SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes(); - SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]); - int iNumElemEndTmp = iNumElemEnd; - iNumElemEnd = aCellNumForType->length(); - for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) { - int tmp = aCellNumForType[iNumElem]-1; - if(0 > tmp || tmp >= iNumElemEndTmp) { - static QString aString; - aString.sprintf("LoadPoints >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEnd,iNumElem,tmp); - throw std::runtime_error(aString.latin1()); - } - aSubMeshOnCellType.insert(tmp); - } - }else{ - for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++){ - aSubMeshOnCellType.insert(iNumElem); + TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect; + aCell2Connect.resize(aNbElem); + for(int iElem = 0; iElem < aNbElem; iElem++) + aCell2Connect[iElem] = TConnect(1,iElem); + + theMesh->myIsDone = true; + + return 1; +} + + +//--------------------------------------------------------------- +int +VISU_MEDConvertor +::LoadPointsOnFamily(VISU::PCMesh theMesh, + VISU::PCFamily theFamily) +{ + PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY]; + + if(theFamily->myIsDone) + return 0; + + TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; + int aNbElem = aCoords.GetNbPoints(); + + SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily; + CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements(); + TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1]; + + if(!anIsOnAllElements){ + SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes(); + SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]); + int aSize = aNbElem; + aNbElem = aCellNumForType->length(); + for(int iElem = 0; iElem < aNbElem; iElem++){ + int anID = aCellNumForType[iElem] - 1; + if(0 > anID || anID >= aSize){ + static QString aString; + aString.sprintf("LoadPointsOnFamily - aSize(%d) <= aCellNumForType[%d] = %d < 0",aSize,iElem,anID); + throw std::runtime_error(aString.latin1()); } + aSubMeshID.push_back(anID); + } + }else{ + for(int iElem = 0; iElem < aNbElem; iElem++){ + aSubMeshID.push_back(iElem); } } + + theFamily->myIsDone = true; + return 1; } +//--------------------------------------------------------------- int -VISU_MEDConvertor::LoadCellsOnEntity(VISU::PCMesh theMesh, - VISU::PCMeshOnEntity theMeshOnEntity, - const string& theFamilyName) +VISU_MEDConvertor +::LoadCellsOnEntity(VISU::PCMesh theMesh, + VISU::PCMeshOnEntity theMeshOnEntity) { - //Check on existing family - PCFamily aFamily = GetFamily(theMeshOnEntity,theFamilyName); - //Check on loading already done - bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty(); - if(isCellsLoaded) - if(!aFamily) - return 0; - else if(!aFamily->mySubMesh.empty()) - return 0; + if(theMeshOnEntity->myIsDone) + return 0; SALOME_MED::SUPPORT_var& aMedSupport = theMeshOnEntity->mySupport; SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh(); - if(MYDEBUG) { - MESSAGE("LoadCellsOnEntity - theFamilyName = '"<> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iNumElem,k,anArray[k]); - throw std::runtime_error(aString.latin1()); - } - aConnForCellType.push_back(anArray); + anArray[k] = aConnect[k]; } - //Workaround for MED Component data structure - int aSize = aConnForCellType.size(); - theMeshOnEntity->myCellsFirstIndex[aGeom] = TCMeshOnEntity::TIndexAndSize(aCounter,aSize); - aCounter += aSize; - } - } - } - //Filling aFamily SubMesh - if(aFamily){ - SALOME_MED::FAMILY_var aMedFamily = aFamily->myFamily; - CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements(); - if(!anIsOnAllElements){ - SALOME_MED::medGeometryElement_array_var aGeoms = aMedFamily->getTypes(); - iGeomEnd = aGeoms->length(); - if(MYDEBUG) MESSAGE("LoadCellsOnEntity - iGeomEnd = "<getNumber(aGeom); - int aVGeom = MEDGeomToVTK(aGeom); - TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVGeom]; - int iNumElemEndTmp = theMeshOnEntity->myCellsConn[aVGeom].size(); - int iNumElemEnd = aCellNumForType->length(); - int aCounter = theMeshOnEntity->myCellsFirstIndex[aGeom].first; - if(MYDEBUG) - MESSAGE("LoadCellsOnEntity - aGeom = "<> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEndTmp,iNumElem,tmp); + aString.sprintf("LoadCellsOnEntity >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iElem,k,anArray[k]); throw std::runtime_error(aString.latin1()); } - aSubMeshOnCellType.insert(tmp); - } + aCell2Connect.push_back(anArray); } - }else{ - const TMeshOnEntityImpl::TCellsConn& aCellsConn = theMeshOnEntity->myCellsConn; - TMeshOnEntityImpl::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin(); - for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){ - int aVGeom = aCellsConnIter->first; - const TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aCellsConnIter->second; - TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVGeom]; - int iNumElemEnd = aConnForCellType.size(); - for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) - aSubMeshOnCellType.insert(iNumElem); + //Workaround for MED Component data structure + int aSize = aCell2Connect.size(); + if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aCounter = "<myGeom2SubMesh; + VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin(); + for(; anIter != aGeom2SubMesh.end(); anIter++){ + VISU::EGeometry aEGeom = anIter->first; + const VISU::TSubMeshImpl& aSubMesh = anIter->second; + const VISU::TCell2Connect& aCell2Connect = aSubMesh.myCell2Connect; + TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom]; + int iNumElemEnd = aCell2Connect.size(); + for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) + aSubMeshID.push_back(iNumElem); + } } + + theFamily->myIsDone = true; + return 1; } + template int ImportField(TArray& theArray, @@ -1110,35 +1268,55 @@ ImportField(TArray& theArray, VISU::PCValForTime theValForTime, VISU::PCMeshOnEntity theMeshOnEntity) { + int aNbComp = theField->myNbComp; if(theField->myEntity == NODE_ENTITY){ - TValForTimeImpl::TValForCellsWithType& aValForCellsWithType = - theValForTime->myValForCells[VTK_VERTEX]; - int iNumElemEnd = theMesh->myPointsCoord.size()/theMesh->myDim*theField->myNbComp; - if(MYDEBUG) MESSAGE("ImportField - iNumElemEnd = "<GetNbGauss(aEGeom); + const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; + int aNbElem = aCoords.GetNbPoints(); + + if(MYDEBUG) MESSAGE("ImportField - aNbElem = "<GetMeshValue(VISU::ePOINT1); + aMeshValue.Init(aNbElem,aNbGauss,aNbComp); + for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++){ + TValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem); + for(int iGauss = 0; iGauss < aNbGauss; iGauss++){ + TValueSlice& aValueSlice = aValueSliceArr[iGauss]; + for(int iComp = 0; iComp < aNbComp; iComp++){ + aValueSlice[iComp] = theArray[anId++]; + } + } + } }else{ SALOME_MED::medGeometryElement* aGeomElems; const TEntity& aVEntity = theField->myEntity; int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems); for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){ - SALOME_MED::medGeometryElement aGeom = aGeomElems[iGeom]; - int aVGeom = MEDGeomToVTK(aGeom); + SALOME_MED::medGeometryElement aMGeom = aGeomElems[iGeom]; + VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom); + int aNbGauss = theValForTime->GetNbGauss(aEGeom); const TCMeshOnEntity::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity->myCellsFirstIndex; - TCMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aGeom); + TCMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMGeom); if(aCellsFirstIndexIter != aCellsFirstIndex.end()){ const TCMeshOnEntity::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second; - int iNumElemEnd = aIndexAndSize.second; if(MYDEBUG) - MESSAGE("ImportField - aGeom = "<myValForCells[aVGeom]; - aValForCellsWithType.resize(iNumElemEnd*theField->myNbComp); - for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) - for(int k = 0, kj = iNumElem*theField->myNbComp; k < theField->myNbComp; k++) - aValForCellsWithType[kj+k] = theArray[aIndexAndSize.first*theField->myNbComp+kj+k]; + + int aNbElem = aIndexAndSize.second; + int aStart = aIndexAndSize.first*aNbComp; + TMeshValue& aMeshValue = theValForTime->GetMeshValue(aEGeom); + aMeshValue.Init(aNbElem,aNbGauss,aNbComp); + for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++, anId += aNbComp){ + TValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem); + for(int iGauss = 0; iGauss < aNbGauss; iGauss++){ + TValueSlice& aValueSlice = aValueSliceArr[iGauss]; + for(int iComp = 0; iComp < aNbComp; iComp++) + aValueSlice[iComp] = theArray[aStart+anId+iComp]; + } + } } } } @@ -1146,15 +1324,21 @@ ImportField(TArray& theArray, } int -VISU_MEDConvertor::LoadField(VISU::PCMesh theMesh, - VISU::PCMeshOnEntity theMeshOnEntity, - VISU::PField theField, - VISU::PCValForTime theValForTime) +VISU_MEDConvertor +::LoadField(VISU::PCMesh theMesh, + VISU::PCMeshOnEntity theMeshOnEntity, + VISU::PField theField, + VISU::PCValForTime theValForTime) { //Check on loading already done - if(!theValForTime->myValForCells.empty()) + PIDMapperFilter anIDMapperFilter = theValForTime->myIDMapperFilter; + if(anIDMapperFilter->myIsVTKDone) return 0; - + + PCProfile aProfile(new TCProfile()); + aProfile->myIsAll = true; + theValForTime->myProfile = aProfile; + SALOME_MED::FIELD_var aMEDField = theValForTime->myField; SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField); if(!aFieldDouble->_is_nil()){ @@ -1168,5 +1352,8 @@ VISU_MEDConvertor::LoadField(VISU::PCMesh theMesh, if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<length()); ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity); } + + anIDMapperFilter->myIsVTKDone = true; + return 1; } diff --git a/src/VISU_I/VISU_CorbaMedConvertor.hxx b/src/VISU_I/VISU_CorbaMedConvertor.hxx index 6b7c9410..f4a975aa 100644 --- a/src/VISU_I/VISU_CorbaMedConvertor.hxx +++ b/src/VISU_I/VISU_CorbaMedConvertor.hxx @@ -35,39 +35,67 @@ #include -namespace VISU{ - - struct TCMesh: TMeshImpl{ +namespace VISU +{ + //--------------------------------------------------------------- + struct TCMesh: virtual TMeshImpl + { SALOME_MED::MESH_var myMesh; }; - typedef shared_ptr PCMesh; + typedef SharedPtr PCMesh; + + + //--------------------------------------------------------------- + struct TCProfile: virtual TProfileImpl + {}; + typedef SharedPtr PCProfile; + + + //--------------------------------------------------------------- + struct TCSubMesh: virtual TSubMeshImpl + {}; + typedef SharedPtr PCSubMesh; + - struct TCMeshOnEntity: TMeshOnEntityImpl{ + //--------------------------------------------------------------- + struct TCMeshOnEntity: virtual TMeshOnEntityImpl + { SALOME_MED::SUPPORT_var mySupport; typedef std::pair TIndexAndSize; typedef std::map TCellsFirstIndex; TCellsFirstIndex myCellsFirstIndex; }; - typedef shared_ptr PCMeshOnEntity; + typedef SharedPtr PCMeshOnEntity; - struct TCFamily: TFamilyImpl{ + + //--------------------------------------------------------------- + struct TCFamily: virtual TFamilyImpl + { SALOME_MED::FAMILY_var myFamily; }; - typedef shared_ptr PCFamily; + typedef SharedPtr PCFamily; - struct TCGroup: TGroupImpl{ + + //--------------------------------------------------------------- + struct TCGroup: virtual TGroupImpl + { SALOME_MED::GROUP_var myGroup; }; - typedef shared_ptr PCGroup; + typedef SharedPtr PCGroup; - struct TCField: TFieldImpl{ - }; - typedef shared_ptr PCField; - struct TCValForTime: TValForTimeImpl{ + //--------------------------------------------------------------- + struct TCField: virtual TFieldImpl + {}; + typedef SharedPtr PCField; + + + //--------------------------------------------------------------- + struct TCValForTime: virtual TValForTimeImpl + { SALOME_MED::FIELD_var myField; }; - typedef shared_ptr PCValForTime; + typedef SharedPtr PCValForTime; } @@ -78,47 +106,93 @@ class VISU_MEDConvertor: public VISU_Convertor_impl{ VISU_MEDConvertor() {}; public: - VISU_MEDConvertor(SALOMEDS::SObject_ptr theMedSObject) : mySObject(SALOMEDS::SObject::_duplicate(theMedSObject)) {} - virtual VISU_Convertor* Build(); - - protected: - - VISU_Convertor* Build(SALOME_MED::MED_ptr theMED); - VISU_Convertor* Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator); - - virtual int LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity, - const std::string& theFamilyName = ""); + VISU_MEDConvertor(SALOMEDS::SObject_ptr theMedSObject): + mySObject(SALOMEDS::SObject::_duplicate(theMedSObject)) + {} - virtual int LoadMeshOnGroup(VISU::PMeshImpl theMesh, - const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet); + virtual + VISU_Convertor* + Build(); - virtual int LoadFieldOnMesh(VISU::PMeshImpl theMesh, - VISU::PMeshOnEntityImpl theMeshOnEntity, - VISU::PFieldImpl theField, - VISU::PValForTimeImpl theValForTime); + protected: - int LoadPoints(VISU::PCMesh theMesh, - const std::string& theFamilyName = "") ; + VISU_Convertor* + Build(SALOME_MED::MED_ptr theMED); + + VISU_Convertor* + Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator); - int LoadCellsOnEntity(VISU::PCMesh theMesh, - VISU::PCMeshOnEntity theMeshOnEntity, - const std::string& theFamilyName = ""); + virtual + int + LoadMeshOnEntity(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity); - int LoadField(VISU::PCMesh theMesh, - VISU::PCMeshOnEntity theMeshOnEntity, - VISU::PField theField, - VISU::PCValForTime theValForTime); + virtual + int + LoadFamilyOnEntity(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFamilyImpl theFamily); + + virtual + int + LoadMeshOnGroup(VISU::PMeshImpl theMesh, + const VISU::TFamilySet& theFamilySet); + + virtual + int + LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFieldImpl theField, + VISU::PValForTimeImpl theValForTime); + + virtual + int + LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, + VISU::PMeshOnEntityImpl theMeshOnEntity, + VISU::PFieldImpl theField, + VISU::PValForTimeImpl theValForTime) + { + return 0; + } + + int + LoadPoints(VISU::PCMesh theMesh) ; + + int + LoadPointsOnFamily(VISU::PCMesh theMesh, + VISU::PCFamily theFamily) ; + + int + LoadCellsOnEntity(VISU::PCMesh theMesh, + VISU::PCMeshOnEntity theMeshOnEntity); + + int + LoadCellsOnFamily(VISU::PCMesh theMesh, + VISU::PCMeshOnEntity theMeshOnEntity, + VISU::PCFamily theFamily); + + int + LoadField(VISU::PCMesh theMesh, + VISU::PCMeshOnEntity theMeshOnEntity, + VISU::PField theField, + VISU::PCValForTime theValForTime); }; -class VISU_MEDFieldConvertor: public VISU_MEDConvertor{ +class VISU_MEDFieldConvertor: public VISU_MEDConvertor +{ protected: SALOME_MED::FIELD_var myField; + public: + VISU_MEDFieldConvertor(SALOME_MED::FIELD_ptr theField) : myField(SALOME_MED::FIELD::_duplicate(theField)) {} - virtual VISU_Convertor* Build() ; + + virtual + VISU_Convertor* + Build(); }; extern "C" { diff --git a/src/VISU_I/VISU_CutLines_i.cc b/src/VISU_I/VISU_CutLines_i.cc index e08e3ff7..879b0531 100644 --- a/src/VISU_I/VISU_CutLines_i.cc +++ b/src/VISU_I/VISU_CutLines_i.cc @@ -24,11 +24,12 @@ // Author : Alexey PETROV // Module : VISU -#include "VISU_CutLinesPL.hxx" -#include "VISU_Result_i.hh" #include "VISU_CutLines_i.hh" -#include "VISU_Actor.h" +#include "VISU_Result_i.hh" +#include "VISU_Actor.h" +#include "VISU_CutLinesPL.hxx" +#include "VISU_Convertor.hxx" #include "VISU_PipeLineUtils.hxx" #include @@ -62,10 +63,10 @@ CutLines_i(Result_i* theResult, bool theAddToStudy) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), ScalarMap_i(theResult,theAddToStudy), myCutLinesPL(NULL) -{ -} +{} VISU::CutLines_i:: @@ -73,6 +74,7 @@ CutLines_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), ScalarMap_i(theResult,theSObject), myCutLinesPL(NULL) { @@ -95,7 +97,8 @@ VISU::Storable* VISU::CutLines_i::Create(const char* theMeshName, VISU::Entity t VISU::Storable* VISU::CutLines_i::Restore(const Storable::TRestoringMap& theMap) { - DoHook(); + TSuperClass::Restore(theMap); + SetNbLines(VISU::Storable::FindValue(theMap,"myNbLines").toInt()); SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble()); SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble()); @@ -130,7 +133,7 @@ VISU::Storable* VISU::CutLines_i::Restore(const Storable::TRestoringMap& theMap) SetCurveInverted(i,false); } - return ScalarMap_i::Restore(theMap); + return this; } @@ -302,6 +305,17 @@ void VISU::CutLines_i::DoHook(){ ScalarMap_i::DoHook(); } +VISU_Actor* +VISU::CutLines_i +::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +{ + if(VISU_Actor* anActor = ScalarMap_i::CreateActor(theIO)){ + anActor->SetVTKMapping(true); + return anActor; + } + return NULL; +} + void VISU::CutLines_i::BuildTableOfReal(SALOMEDS::SObject_ptr theSObject){ try{ if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal"); diff --git a/src/VISU_I/VISU_CutLines_i.hh b/src/VISU_I/VISU_CutLines_i.hh index 84540a18..7acb62a7 100644 --- a/src/VISU_I/VISU_CutLines_i.hh +++ b/src/VISU_I/VISU_CutLines_i.hh @@ -38,7 +38,10 @@ namespace VISU{ static int myNbPresent; CutLines_i(); CutLines_i(const CutLines_i&); + public: + typedef ScalarMap_i TSuperClass; + explicit CutLines_i(Result_i* theResult, bool theAddToStudy); @@ -111,6 +114,10 @@ namespace VISU{ virtual Storable* Restore(const Storable::TRestoringMap& theMap); + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + void BuildTableOfReal(SALOMEDS::SObject_ptr theSObject); static const std::string myComment; diff --git a/src/VISU_I/VISU_CutPlanes_i.cc b/src/VISU_I/VISU_CutPlanes_i.cc index 9cd09af5..d5c0ea04 100644 --- a/src/VISU_I/VISU_CutPlanes_i.cc +++ b/src/VISU_I/VISU_CutPlanes_i.cc @@ -58,10 +58,10 @@ CutPlanes_i(Result_i* theResult, bool theAddToStudy) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), ScalarMap_i(theResult,theAddToStudy), myCutPlanesPL(NULL) -{ -} +{} VISU::CutPlanes_i:: @@ -69,6 +69,7 @@ CutPlanes_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), ScalarMap_i(theResult,theSObject), myCutPlanesPL(NULL) { @@ -84,7 +85,8 @@ VISU::Storable* VISU::CutPlanes_i::Create(const char* theMeshName, VISU::Entity VISU::Storable* VISU::CutPlanes_i::Restore(const Storable::TRestoringMap& theMap) { - DoHook(); + TSuperClass::Restore(theMap); + SetNbPlanes(VISU::Storable::FindValue(theMap,"myNbPlanes").toInt()); SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement").toDouble()); SetOrientation(VISU::CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane").toInt()), @@ -96,7 +98,7 @@ VISU::Storable* VISU::CutPlanes_i::Restore(const Storable::TRestoringMap& theMap if(aCondList[i].toInt() == 0) SetPlanePosition(i,aPosList[i].toDouble()); - return ScalarMap_i::Restore(theMap); + return this; } @@ -180,3 +182,15 @@ void VISU::CutPlanes_i::DoHook(){ ScalarMap_i::DoHook(); } + +VISU_Actor* +VISU::CutPlanes_i +::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +{ + if(VISU_Actor* anActor = ScalarMap_i::CreateActor(theIO)){ + anActor->SetVTKMapping(true); + return anActor; + } + return NULL; +} + diff --git a/src/VISU_I/VISU_CutPlanes_i.hh b/src/VISU_I/VISU_CutPlanes_i.hh index 7c76d8c8..1ade4906 100644 --- a/src/VISU_I/VISU_CutPlanes_i.hh +++ b/src/VISU_I/VISU_CutPlanes_i.hh @@ -38,7 +38,10 @@ namespace VISU{ static int myNbPresent; CutPlanes_i(); CutPlanes_i(const CutPlanes_i&); + public: + typedef ScalarMap_i TSuperClass; + explicit CutPlanes_i(Result_i* theResult, bool theAddToStudy); @@ -86,6 +89,10 @@ namespace VISU{ virtual Storable* Restore(const Storable::TRestoringMap& theMap); + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + static const std::string myComment; virtual const char* GetComment() const; virtual QString GenerateName(); diff --git a/src/VISU_I/VISU_DeformedShape_i.cc b/src/VISU_I/VISU_DeformedShape_i.cc index f99b0794..83f679ce 100644 --- a/src/VISU_I/VISU_DeformedShape_i.cc +++ b/src/VISU_I/VISU_DeformedShape_i.cc @@ -24,12 +24,15 @@ // Author : Alexey PETROV // Module : VISU -#include "VISU_DeformedShapePL.hxx" -#include "VISU_Result_i.hh" #include "VISU_DeformedShape_i.hh" +#include "VISU_Result_i.hh" + #include "VISU_ScalarMapAct.h" +#include "VISU_DeformedShapePL.hxx" +#include "VISU_Convertor.hxx" #include +#include using namespace VISU; using namespace std; @@ -67,6 +70,7 @@ DeformedShape_i(Result_i* theResult, bool theAddToStudy) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), ScalarMap_i(theResult,theAddToStudy), myDeformedShapePL(NULL) { @@ -79,6 +83,7 @@ DeformedShape_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), ScalarMap_i(theResult,theSObject), myDeformedShapePL(NULL) { @@ -88,12 +93,12 @@ DeformedShape_i(Result_i* theResult, void VISU::DeformedShape_i::SameAs(const Prs3d_i* theOrigin) { - VISU::ScalarMap_i::SameAs(theOrigin); + TSuperClass::SameAs(theOrigin); - if (const DeformedShape_i* aConstDefShape = dynamic_cast(theOrigin)) { - DeformedShape_i* aDefShape = const_cast(aConstDefShape); - SetColor(aDefShape->GetColor()); - ShowColored(aDefShape->IsColored()); + if(const DeformedShape_i* aPrs3d = dynamic_cast(theOrigin)){ + DeformedShape_i* anOrigin = const_cast(aPrs3d); + SetColor(anOrigin->GetColor()); + ShowColored(anOrigin->IsColored()); } } @@ -109,14 +114,15 @@ VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Ent VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap) { - DoHook(); + TSuperClass::Restore(theMap); + SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble()); myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt(); myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble(); myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble(); myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble(); - return ScalarMap_i::Restore(theMap); + return this; } @@ -159,11 +165,14 @@ void VISU::DeformedShape_i::SetMapScale(double theMapScale){ } -VISU_Actor* VISU::DeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +VISU_Actor* +VISU::DeformedShape_i +::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) { VISU_Actor* anActor = VISU::ScalarMap_i::CreateActor(theIO); anActor->SetRepresentation(1); anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B); + anActor->SetVTKMapping(false); return anActor; } diff --git a/src/VISU_I/VISU_DeformedShape_i.hh b/src/VISU_I/VISU_DeformedShape_i.hh index de9167b4..814438d6 100644 --- a/src/VISU_I/VISU_DeformedShape_i.hh +++ b/src/VISU_I/VISU_DeformedShape_i.hh @@ -38,7 +38,10 @@ namespace VISU{ static int myNbPresent; DeformedShape_i(); DeformedShape_i(const DeformedShape_i&); + public: + typedef ScalarMap_i TSuperClass; + explicit DeformedShape_i(Result_i* theResult, bool theAddToStudy); @@ -85,7 +88,9 @@ namespace VISU{ virtual void SetMapScale(double theMapScale = 1.0); - virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); virtual void UpdateActor(VISU_Actor* theActor) ; }; diff --git a/src/VISU_I/VISU_GaussPoints_i.cc b/src/VISU_I/VISU_GaussPoints_i.cc new file mode 100644 index 00000000..93da92ac --- /dev/null +++ b/src/VISU_I/VISU_GaussPoints_i.cc @@ -0,0 +1,835 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : +// Author : +// Module : + +#include "VISU_GaussPoints_i.hh" +#include "VISU_ScalarMap_i.hh" + +#include "VISU_Result_i.hh" +#include "VISU_GaussPtsAct.h" +#include "VISU_GaussPointsPL.hxx" +#include "VVTK_SegmentationCursorDlg.h" + +#include "VISU_OpenGLPointSpriteMapper.hxx" +#include "VISU_ScalarBarCtrl.hxx" + +#include "SUIT_ResourceMgr.h" + +#include +#include +#include +#include +#include + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +//---------------------------------------------------------------------------- +int +VISU::GaussPoints_i +::IsPossible(Result_i* theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + int theIteration, + int isMemoryCheck) +{ + try{ + if(theEntity != VISU::NODE) + return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,isMemoryCheck); + else + return false; + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<GetStudyDocument()), + Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), + myGaussPointsPL(NULL), + myIsColored(true), + myColor(Qt::blue), + myIsActiveLocalScalarBar(true), + myIsDispGlobalScalarBar(true), + mySpacing(0.01), + myFaceLimit(50000) +{ + if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<GetStudyDocument()), + Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), + myGaussPointsPL(NULL), + myIsColored(true), + myColor(Qt::blue), + myIsActiveLocalScalarBar(true), + myIsDispGlobalScalarBar(true), + myFaceLimit(50000) +{ + if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<integerValue( "VISU", "scalar_bar_active_local", GetIsActiveLocalScalarBar() ); + SetIsActiveLocalScalarBar( anActiveLocal == 0 ); + + bool aDisplayGlobal = aResourceMgr->booleanValue( "VISU", "scalar_bar_diplay_global", GetIsDispGlobalScalarBar() ); + SetIsDispGlobalScalarBar( aDisplayGlobal ); + + int aBicolor = aResourceMgr->integerValue( "VISU", "scalar_bar_bicolor", GetBiColor() ); + SetBiColor( aBicolor == 0 ); + + float aSpacing = aResourceMgr->doubleValue( "VISU", "scalar_bar_spacing", GetSpacing() ); + SetSpacing( aSpacing ); + + float aScaleFactor = aResourceMgr->doubleValue( "VISU", "deformed_shape_scale_factor", GetScaleFactor() ); + SetScaleFactor( aScaleFactor ); + + int aPrimitiveType = aResourceMgr->integerValue( "VISU", "point_sprite_primitive_type", GetPrimitiveType() ); + SetPrimitiveType( aPrimitiveType ); + + float aClamp = aResourceMgr->doubleValue( "VISU", "point_sprite_clamp", GetClamp() ); + SetClamp( aClamp ); + + int aMinSize = aResourceMgr->integerValue( "VISU", "point_sprite_min_size", ( int )( GetMinSize() * 100.0 ) ); + SetMinSize( aMinSize / 100.0 ); + + int aMaxSize = aResourceMgr->integerValue( "VISU", "point_sprite_max_size", ( int )( GetMaxSize() * 100.0 ) ); + SetMaxSize( aMaxSize / 100.0 ); + + int aGeomSize = aResourceMgr->integerValue( "VISU", "point_sprite_size", ( int )( GetGeomSize() * 100.0 ) ); + SetGeomSize( aGeomSize / 100.0 ); + + int aMagnification = aResourceMgr->integerValue( "VISU", "point_sprite_magnification", ( int )( GetMagnification() * 100.0 ) ); + SetMagnification( aMagnification / 100.0 ); + + float anIncrement = aResourceMgr->doubleValue( "VISU", "point_sprite_increment", GetMagnificationIncrement() ); + SetMagnificationIncrement( anIncrement ); + + bool isColored = aResourceMgr->booleanValue( "VISU", "point_sprite_results", GetIsColored() ); + SetIsColored( isColored ); + + QColor aColor = aResourceMgr->colorValue( "VISU", "point_sprite_color", GetColor() ); + SetColor( aColor ); + + float anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "point_sprite_alpha_threshold", GetAlphaThreshold() ); + SetAlphaThreshold( anAlphaThreshold ); + + int aResolution = aResourceMgr->integerValue( "VISU", "geom_sphere_resolution", GetResolution() ); + SetResolution( aResolution ); + + int aFaceLimit = aResourceMgr->integerValue( "VISU", "geom_sphere_face_limit", GetFaceLimit() ); + SetFaceLimit( aFaceLimit ); + + QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp"; + aMainTexture = aResourceMgr->stringValue( "VISU", "point_sprite_main_texture", aMainTexture ); + + QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp"; + anAlphaTexture = aResourceMgr->stringValue( "VISU", "point_sprite_alpha_texture", anAlphaTexture ); + + SetTextures( aMainTexture, anAlphaTexture ); + + return this; +} + + +//---------------------------------------------------------------------------- +VISU::Storable* +VISU::GaussPoints_i +::Restore(const Storable::TRestoringMap& theMap) +{ + TSuperClass::Restore(theMap); + + SetIsActiveLocalScalarBar(Storable::FindValue(theMap,"myIsActiveLocalScalarBar").toInt()); + SetIsDispGlobalScalarBar(Storable::FindValue(theMap,"myIsDispGlobalScalarBar").toInt()); + SetBiColor(Storable::FindValue(theMap,"myIsBiColor").toInt()); + SetSpacing(Storable::FindValue(theMap,"mySpacing").toDouble()); + + SetPrimitiveType(Storable::FindValue(theMap,"myPrimitiveType").toInt()); + SetClamp(Storable::FindValue(theMap,"myClamp").toDouble()); + SetMinSize(Storable::FindValue(theMap,"myMinSize").toDouble()); + SetMaxSize(Storable::FindValue(theMap,"myMaxSize").toDouble()); + SetGeomSize(Storable::FindValue(theMap,"myGeomSize").toDouble()); + + SetMagnification(Storable::FindValue(theMap,"myMagnification").toDouble()); + SetMagnificationIncrement(Storable::FindValue(theMap,"myMagnificationIncrement").toDouble()); + + SetIsDeformed(Storable::FindValue(theMap,"myIsDeformed").toInt()); + SetScaleFactor(Storable::FindValue(theMap,"myScaleFactor").toDouble()); + + SetFaceLimit(Storable::FindValue(theMap,"myFaceLimit").toInt()); + + SetIsColored(Storable::FindValue(theMap,"myIsColored").toInt()); + int aRed = Storable::FindValue(theMap,"myColor.R").toInt(); + int aGreen = Storable::FindValue(theMap,"myColor.G").toInt(); + int aBlue = Storable::FindValue(theMap,"myColor.B").toInt(); + SetColor( QColor(aRed,aGreen,aBlue) ); + + SetAlphaThreshold(Storable::FindValue(theMap,"myAlphaThreshold").toDouble()); + + SetTextures( Storable::FindValue(theMap,"myMainTexture"), + Storable::FindValue(theMap,"myAlphaTexture") ); + + SetResolution(Storable::FindValue(theMap,"myResolution").toInt()); + + return this; +} + + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::ToStream(std::ostringstream& theStr) +{ + TSuperClass::ToStream(theStr); + + Storable::DataToStream( theStr, "myIsActiveLocalScalarBar", myIsActiveLocalScalarBar ); + Storable::DataToStream( theStr, "myIsDispGlobalScalarBar", myIsDispGlobalScalarBar ); + Storable::DataToStream( theStr, "myIsBiColor", GetBiColor() ); + Storable::DataToStream( theStr, "mySpacing", GetSpacing() ); + + Storable::DataToStream( theStr, "myPrimitiveType", GetPrimitiveType() ); + Storable::DataToStream( theStr, "myClamp", GetClamp() ); + Storable::DataToStream( theStr, "myMinSize", GetMinSize() ); + Storable::DataToStream( theStr, "myMaxSize", GetMaxSize() ); + Storable::DataToStream( theStr, "myGeomSize", GetGeomSize() ); + + Storable::DataToStream( theStr, "myMagnification", GetMagnification() ); + Storable::DataToStream( theStr, "myMagnificationIncrement", GetMagnificationIncrement() ); + + Storable::DataToStream( theStr, "myIsDeformed", GetIsDeformed() ); + Storable::DataToStream( theStr, "myScaleFactor", GetScaleFactor() ); + + Storable::DataToStream( theStr, "myFaceLimit", GetFaceLimit() ); + + Storable::DataToStream( theStr, "myIsColored", GetIsColored() ); + QColor aColor = GetColor(); + Storable::DataToStream( theStr, "myColor.R", aColor.red() ); + Storable::DataToStream( theStr, "myColor.G", aColor.green() ); + Storable::DataToStream( theStr, "myColor.B", aColor.blue() ); + + Storable::DataToStream( theStr, "myAlphaThreshold", GetAlphaThreshold() ); + Storable::DataToStream( theStr, "myMainTexture", GetMainTexture() ); + Storable::DataToStream( theStr, "myAlphaTexture", GetAlphaTexture() ); + + Storable::DataToStream( theStr, "myResolution", GetResolution() ); +} + + +VISU::GaussPoints_i +::~GaussPoints_i() +{ + if(MYDEBUG) MESSAGE("GaussPoints_i::~GaussPoints_i() - this = "<SetIsDeformed( theIsDeformed ); +} + +bool +VISU::GaussPoints_i +::GetIsDeformed() +{ + return myGaussPointsPL->GetIsDeformed(); +} + +void +VISU::GaussPoints_i +::SetScaleFactor( float theScaleFactor ) +{ + myGaussPointsPL->SetScale( theScaleFactor ); +} + +float +VISU::GaussPoints_i +::GetScaleFactor() +{ + return myGaussPointsPL->GetScale(); +} + +void +VISU::GaussPoints_i +::SetIsColored( bool theIsColored ) +{ + myIsColored = theIsColored; + myGaussPointsPL->SetIsColored( theIsColored ); +} + +bool +VISU::GaussPoints_i +::SetMainTexture( const QString& theMainTexture ) +{ + bool update = myMainTexture != theMainTexture; + myMainTexture = theMainTexture; + return update; +} + +const QString& +VISU::GaussPoints_i +::GetMainTexture() +{ + return myMainTexture; +} + +bool +VISU::GaussPoints_i +::SetAlphaTexture( const QString& theAlphaTexture ) +{ + bool update = myAlphaTexture != theAlphaTexture; + myAlphaTexture = theAlphaTexture; + return update; +} + +const QString& +VISU::GaussPoints_i +::GetAlphaTexture() +{ + return myAlphaTexture; +} + +void +VISU::GaussPoints_i +::SetAlphaThreshold( float theAlphaThreshold ) +{ + myGaussPointsPL->SetAlphaThreshold( theAlphaThreshold ); +} + +float +VISU::GaussPoints_i +::GetAlphaThreshold() +{ + return myGaussPointsPL->GetAlphaThreshold(); +} + +void +VISU::GaussPoints_i +::SetResolution( int theResolution ) +{ + myGaussPointsPL->SetResolution( theResolution ); +} + +int +VISU::GaussPoints_i +::GetResolution() +{ + return myGaussPointsPL->GetResolution(); +} + +void +VISU::GaussPoints_i +::SetPrimitiveType(int thePrimitiveType) +{ + myGaussPointsPL->SetPrimitiveType( thePrimitiveType ); +} + +int +VISU::GaussPoints_i +::GetPrimitiveType() +{ + return myGaussPointsPL->GetPrimitiveType(); +} + +float +VISU::GaussPoints_i +::GetMaximumSupportedSize() +{ + return myGaussPointsPL->GetMaximumSupportedSize(); +} + +void +VISU::GaussPoints_i +::SetClamp(float theClamp) +{ + myGaussPointsPL->SetClamp( theClamp ); +} + +float +VISU::GaussPoints_i +::GetClamp() +{ + return myGaussPointsPL->GetClamp(); +} + +void +VISU::GaussPoints_i +::SetGeomSize( float theGeomSize ) +{ + myGaussPointsPL->SetSize( theGeomSize ); +} + +float +VISU::GaussPoints_i +::GetGeomSize() +{ + return myGaussPointsPL->GetSize(); +} + +void +VISU::GaussPoints_i +::SetMinSize( float theMinSize ) +{ + myGaussPointsPL->SetMinSize( theMinSize ); +} + +float +VISU::GaussPoints_i +::GetMinSize() +{ + return myGaussPointsPL->GetMinSize(); +} + +void +VISU::GaussPoints_i +::SetMaxSize( float theMaxSize ) +{ + myGaussPointsPL->SetMaxSize( theMaxSize ); +} + +float +VISU::GaussPoints_i +::GetMaxSize() +{ + return myGaussPointsPL->GetMaxSize(); +} + +void +VISU::GaussPoints_i +::SetMagnification( float theMagnification ) +{ + myGaussPointsPL->SetMagnification( theMagnification ); +} + +float +VISU::GaussPoints_i +::GetMagnification() +{ + return myGaussPointsPL->GetMagnification(); +} + +void +VISU::GaussPoints_i +::SetMagnificationIncrement( float theIncrement ) +{ + myGaussPointsPL->SetMagnificationIncrement( theIncrement ); +} + +float +VISU::GaussPoints_i +::GetMagnificationIncrement() +{ + return myGaussPointsPL->GetMagnificationIncrement(); +} + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::DoSetInput(Result_i* theResult) +{ + VISU::Result_i::TInput* anInput = theResult->GetInput(); + if(!anInput) + throw std::runtime_error("Mesh_i::Build - theResult->GetInput() == NULL !!!"); + + myField = anInput->GetField(myMeshName,myEntity,myFieldName); + if(!myField) + throw std::runtime_error("There is no Field with the parameters !!!"); + + VISU::PGaussPtsIDMapper aGaussPtsIDMapper = + anInput->GetTimeStampOnGaussPts(myMeshName,myEntity,myFieldName,myIteration); + + if(!aGaussPtsIDMapper) + throw std::runtime_error("There is no TimeStamp with the parameters !!!"); + + myGaussPointsPL->SetGaussPtsIDMapper(aGaussPtsIDMapper); + myGaussPointsPL->Init(); + myGaussPointsPL->Build(); + + theResult->MinMaxConnect(this); +} + + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::DoHook() +{ + if(!myPipeLine) + myPipeLine = VISU_GaussPointsPL::New(); + + myGaussPointsPL = dynamic_cast(myPipeLine); + + TSuperClass::DoHook(); +} + + +//---------------------------------------------------------------------------- +VISU_PipeLine* +VISU::GaussPoints_i +::GetPipeLine() +{ + // We create a new PipeLine instance in order to provide + // different representations for different actors (basic and segmented) + VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New(); + aPipeLine->SetGaussPtsIDMapper(myGaussPointsPL->GetGaussPtsIDMapper()); + aPipeLine->ShallowCopy(myPipeLine); + aPipeLine->Update(); + return aPipeLine; +} + + +//---------------------------------------------------------------------------- +bool +VISU::GaussPoints_i +::OnCreateActor(VISU_GaussPtsAct* theActor, + const Handle(SALOME_InteractiveObject)& theIO) +{ + try{ + TSuperClass::CreateActor(theActor,theIO); + theActor->GetPipeLine()->Delete(); + UpdateActor(theActor); + return true; + }catch(...){ + theActor->Delete(); + throw ; + } + return false; +} + +VISU_GaussPtsAct1* +VISU::GaussPoints_i +::OnCreateActor1(const Handle(SALOME_InteractiveObject)& theIO) +{ + VISU_GaussPtsAct1* anActor = VISU_GaussPtsAct1::New(); + if(OnCreateActor(anActor,theIO)) + return anActor; + return NULL; +} + +VISU_GaussPtsAct2* +VISU::GaussPoints_i +::OnCreateActor2(const Handle(SALOME_InteractiveObject)& theIO) +{ + VISU_GaussPtsAct2* anActor = VISU_GaussPtsAct2::New(); + if(OnCreateActor(anActor,theIO)) + return anActor; + return NULL; +} + +VISU_Actor* +VISU::GaussPoints_i +::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +{ + return OnCreateActor1(theIO); +} + +//---------------------------------------------------------------------------- +VISU_GaussPtsAct2* +VISU::GaussPoints_i +::CloneActor(VISU_GaussPtsAct1* theActor) +{ + if(MYDEBUG) MESSAGE("GaussPoints_i::CloneActor - this = "<Connect(anActor); + return anActor; + } + return NULL; +} + + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::UpdateScalarBar(vtkScalarBarActor *theScalarBar, + vtkLookupTable* theLookupTable) +{ + theScalarBar->SetTitle(myTitle.c_str()); + theScalarBar->SetOrientation(myOrientation); + theScalarBar->SetNumberOfLabels(myNumberOfLabels); + + vtkLookupTable* aLookupTable = myScalarMapPL->GetBarTable(); + + theLookupTable->SetNumberOfColors(aLookupTable->GetNumberOfColors()); + theScalarBar->SetMaximumNumberOfColors(aLookupTable->GetNumberOfColors()); + + vtkTextProperty* aTitleProp = theScalarBar->GetTitleTextProperty(); + aTitleProp->SetFontFamily(myTitFontType); + aTitleProp->SetColor(myTitleColor); + (myIsBoldTitle)? aTitleProp->BoldOn() : aTitleProp->BoldOff(); + (myIsItalicTitle)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff(); + (myIsShadowTitle)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff(); + + vtkTextProperty* aLabelProp = theScalarBar->GetLabelTextProperty(); + aLabelProp->SetFontFamily(myLblFontType); + aLabelProp->SetColor(myLabelColor); + (myIsBoldLabel)? aLabelProp->BoldOn() : aLabelProp->BoldOff(); + (myIsItalicLabel)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff(); + (myIsShadowLabel)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff(); + + theScalarBar->Modified(); +} + + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::UpdateActor(VISU_Actor* theActor) +{ + if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ + VISU_ScalarBarCtrl *aScalarBarCtrl = anActor->GetScalarBarCtrl(); + if(GetIsColored()){ + anActor->SetBarVisibility(true); + myPipeLine->GetMapper()->SetScalarVisibility(1); + + float aRange[2]; + myScalarMapPL->GetSourceRange(aRange); + aScalarBarCtrl->SetRangeLocal(aRange); + + TMinMax aTMinMax(-VTK_LARGE_FLOAT,VTK_LARGE_FLOAT); + bool anIsMinMaxDone = IsGlobalRangeDefined(); + if(anIsMinMaxDone) + aTMinMax = myField->GetMinMax(GetScalarMode()); + aScalarBarCtrl->SetGlobalRangeIsDefined(anIsMinMaxDone); + aScalarBarCtrl->SetRangeGlobal(aTMinMax.first, aTMinMax.second); + + VISU_ScalarBarCtrl::EMode aScalarBarMode = VISU_ScalarBarCtrl::eGlobal; + if(myIsActiveLocalScalarBar){ + if(myIsDispGlobalScalarBar){ + aScalarBarMode = VISU_ScalarBarCtrl::eLocal; + }else{ + aScalarBarMode = VISU_ScalarBarCtrl::eSimple; + } + } + + if(aScalarBarMode == VISU_ScalarBarCtrl::eGlobal){ + float aRangeGlobal[2]; + // + aRangeGlobal[0] = aTMinMax.first; + aRangeGlobal[1] = aTMinMax.second; + + GetGaussPointsPL()->GetMapper()->SetScalarRange(aRangeGlobal); + } + + aScalarBarCtrl->SetMode(aScalarBarMode); + + // Position + aScalarBarCtrl->SetWidth(myWidth); + aScalarBarCtrl->SetHeight(myHeight); + aScalarBarCtrl->SetPosition(myPosition); + + aScalarBarCtrl->SetSpacing(mySpacing); + + // Bicolor + bool anIsBicolor = GetGaussPointsPL()->GetBicolor(); + aScalarBarCtrl->SetBicolor(anIsBicolor); + + UpdateScalarBar(aScalarBarCtrl->GetLocalBar(), + aScalarBarCtrl->GetLocalTable()); + + UpdateScalarBar(aScalarBarCtrl->GetGlobalBar(), + aScalarBarCtrl->GetGlobalTable()); + + aScalarBarCtrl->Update(); + }else{ + anActor->SetBarVisibility(false); + + myPipeLine->GetMapper()->SetScalarVisibility(0); + + anActor->GetProperty()->SetColor(myColor.red() / 255.0, + myColor.green() / 255.0, + myColor.blue() / 255.0); + } + + if( GetGaussPointsPL()->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere ) + theActor->SetRepresentation( VTK_POINTS ); + else + theActor->SetRepresentation( VTK_SURFACE ); + } + TSuperClass::UpdateActor(theActor); +} + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::UpdateFromActor(VISU_GaussPtsAct* theActor) +{ + if(MYDEBUG) MESSAGE("GaussPoints_i::UpdateFromActor - this = "<ChangeMagnification(theActor->GetChangeMagnification()); + UpdateActors(); +} + + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::SetTextures( const QString& theMainTexture, + const QString& theAlphaTexture ) +{ + bool updateMainTexture = SetMainTexture( theMainTexture ); + bool updateAlphaTexture = SetAlphaTexture( theAlphaTexture ); + if( !updateMainTexture && !updateAlphaTexture ) + return; + + using namespace VISU; + TTextureValue aTextureValue = GetTexture(theMainTexture,theAlphaTexture); + myGaussPointsPL->SetImageData( aTextureValue.GetPointer() ); +} + + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::SetIsActiveLocalScalarBar(const bool theFlag) +{ + myIsActiveLocalScalarBar = theFlag; +} + +bool +VISU::GaussPoints_i +::GetIsActiveLocalScalarBar() const +{ + return myIsActiveLocalScalarBar; +} + +void +VISU::GaussPoints_i +::SetIsDispGlobalScalarBar(const bool theFlag) +{ + myIsDispGlobalScalarBar=theFlag; +} + +bool +VISU::GaussPoints_i +::IsGlobalRangeDefined() const +{ + return myResult->IsMinMaxDone(); +} + +bool +VISU::GaussPoints_i +::GetIsDispGlobalScalarBar() const +{ + return myIsDispGlobalScalarBar; +} + +void +VISU::GaussPoints_i +::SetBiColor(bool theIsBiColor) +{ + GetGaussPointsPL()->SetBicolor(theIsBiColor); +} + +bool +VISU::GaussPoints_i +::GetBiColor() +{ + return GetGaussPointsPL()->GetBicolor(); +} + +void +VISU::GaussPoints_i +::SetSpacing(const float theSpacing) +{ + mySpacing = theSpacing; +} + +float +VISU::GaussPoints_i +::GetSpacing() const +{ + return mySpacing; +} + +//---------------------------------------------------------------------------- +void +VISU::GaussPoints_i +::UpdateMinMax() +{ + MinMaxCunsomer::UpdateMinMax(); + UpdateActors(); +} diff --git a/src/VISU_I/VISU_GaussPoints_i.hh b/src/VISU_I/VISU_GaussPoints_i.hh new file mode 100644 index 00000000..5a0fe102 --- /dev/null +++ b/src/VISU_I/VISU_GaussPoints_i.hh @@ -0,0 +1,343 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_GaussPoints_i_HeaderFile +#define VISU_GaussPoints_i_HeaderFile + +#include "VISU_Result_i.hh" +#include "VISU_ColoredPrs3d_i.hh" +#include "VISU_GaussPtsActorFactory.h" + +class vtkLookupTable; +class vtkScalarBarActor; + +class VISU_GaussPointsPL; + +namespace VISU +{ + //! Class of the Gauss Points presentation. + class GaussPoints_i : public virtual POA_VISU::GaussPoints, + public virtual VISU::TGaussPtsActorFactory, + public virtual MinMaxCunsomer, + public virtual ColoredPrs3d_i + { + static int myNbPresent; + GaussPoints_i(); + GaussPoints_i(const GaussPoints_i&); + + public: + //---------------------------------------------------------------------------- + typedef ColoredPrs3d_i TSuperClass; + + explicit + GaussPoints_i(Result_i* theResult, + bool theAddToStudy); + explicit + GaussPoints_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject); + + virtual + ~GaussPoints_i(); + + virtual + VISU::VISUType + GetType() + { + return VISU::TGAUSSPOINTS; + } + + typedef VISU::GaussPoints TInterface; + + //! Get the Gauss Points Pipeline. + VISU_GaussPointsPL* + GetGaussPointsPL(); + + int + GetFaceLimit() { return myFaceLimit; } + + void + SetFaceLimit( int theFaceLimit ) { myFaceLimit = theFaceLimit; } + + bool + GetIsDeformed(); + + void + SetIsDeformed( bool theIsDeformed ); + + float + GetScaleFactor(); + + void + SetScaleFactor( float theScaleFactor ); + + //! Get color for Geometry mode of the presentation. + QColor + GetColor() { return myColor; } + + //! Set color for Geometry mode of the presentation. + void + SetColor( const QColor& theColor ) { myColor = theColor; } + + //! Get flag indicating which mode of the presentation is active. + /*! When Results mode is active, returns true. Geometry - false. */ + bool + GetIsColored() { return myIsColored; } + + //! Get flag indicating which mode of the presentation is active. + void + SetIsColored( bool theIsColored ); + + //! Set path to the image using for Main Point Sprite texture. + bool + SetMainTexture( const QString& theMainTexture ); + + //! Get path to the image using for Main Point Sprite texture. + const QString& + GetMainTexture(); + + //! Set path to the image using for Alpha Point Sprite texture. + bool + SetAlphaTexture( const QString& theAlphaTexture ); + + //! Get path to the image using for Alpha Point Sprite texture. + const QString& + GetAlphaTexture(); + + //! Convert Main and AlphaMask images to VTI format and set them to pipeline. + void + SetTextures( const QString& theMainTexture, + const QString& theAlphaTexture ); + + //! Redirect the request to VISU_GaussPointsPL::SetAlphaThreshold. + void + SetAlphaThreshold(float theAlphaThreshold); + + //! Redirect the request to VISU_GaussPointsPL::GetAlphaThreshold. + float + GetAlphaThreshold(); + + //! Redirect the request to VISU_GaussPointsPL::SetResolution. + void + SetResolution(int theResolution); + + //! Redirect the request to VISU_GaussPointsPL::GetResolution. + int + GetResolution(); + + void + SetPrimitiveType(int thePrimitiveType); + + int + GetPrimitiveType(); + + //! Redirect the request to VISU_GaussPointsPL::GetMaximumSupportedSize. + float + GetMaximumSupportedSize(); + + //! Redirect the request to VISU_GaussPointsPL::SetClamp. + void + SetClamp(float theClamp); + + //! Redirect the request to VISU_GaussPointsPL::GetClamp. + float + GetClamp(); + + //! Redirect the request to VISU_GaussPointsPL::SetSize. + void + SetGeomSize(float theGeomSize); + + //! Redirect the request to VISU_GaussPointsPL::GetSize. + float + GetGeomSize(); + + //! Redirect the request to VISU_GaussPointsPL::SetMinSize. + void + SetMinSize(float theMinSize); + + //! Redirect the request to VISU_GaussPointsPL::GetMinSize. + float + GetMinSize(); + + //! Redirect the request to VISU_GaussPointsPL::SetMaxSize. + void + SetMaxSize(float theMaxSize); + + //! Redirect the request to VISU_GaussPointsPL::GetMaxSize. + float + GetMaxSize(); + + //! Redirect the request to VISU_GaussPointsPL::SetMagnification. + void + SetMagnification(float theMagnification); + + //! Redirect the request to VISU_GaussPointsPL::GetMagnification. + float + GetMagnification(); + + //! Redirect the request to VISU_GaussPointsPL::SetMagnificationIncrement. + void + SetMagnificationIncrement(float theIncrement); + + //! Redirect the request to VISU_GaussPointsPL::GetMagnificationIncrement. + float + GetMagnificationIncrement(); + + //! Set flag indicating which scalar bar is active. + void + SetIsActiveLocalScalarBar(const bool theFlag); + + //! Get flag indicating which scalar bar is active. + bool + GetIsActiveLocalScalarBar() const; + + //! Set flag indicating visibility of global scalar bar. + void + SetIsDispGlobalScalarBar(const bool theFlag); + + //! Get flag indicating visibility of global scalar bar. + bool + GetIsDispGlobalScalarBar() const; + + //! Redirect the request to VISU_GaussPointsPL::SetBicolor. + void + SetBiColor(bool theIsBiColor); + + //! Redirect the request to VISU_GaussPointsPL::GetBicolor. + bool + GetBiColor(); + + //! Set value of the distance between global and local scalar bars. + void + SetSpacing(const float theSpacing); + + //! Get value of the distance between global and local scalar bars. + float + GetSpacing() const; + + //! Let know is the global range is already calculated + bool + IsGlobalRangeDefined() const; + + //! To update the min / max automatically + virtual + void + UpdateMinMax(); + + protected: + virtual + void + DoSetInput(Result_i* theResult); + + virtual + void + DoHook(); + + virtual + VISU_PipeLine* + GetPipeLine(); + + bool + OnCreateActor(VISU_GaussPtsAct* theActor, + const Handle(SALOME_InteractiveObject)& theIO = NULL); + + VISU_GaussPtsAct1* + OnCreateActor1(const Handle(SALOME_InteractiveObject)& theIO = NULL); + + VISU_GaussPtsAct2* + OnCreateActor2(const Handle(SALOME_InteractiveObject)& theIO = NULL); + + void + UpdateScalarBar(vtkScalarBarActor *theScalarBar, + vtkLookupTable* theLookupTable); + + + VISU_GaussPointsPL *myGaussPointsPL; + + bool myIsColored; + bool myIsDispGlobalScalarBar; + bool myIsActiveLocalScalarBar; + QColor myColor; + float mySpacing; + int myFaceLimit; + + QString myMainTexture; + QString myAlphaTexture; + + public: + static + int + IsPossible(Result_i* theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + int theIteration, + int isMemoryCheck = true); + virtual + Storable* + Create(const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + int theIteration); + + static const std::string myComment; + + virtual + const char* + GetComment() const; + + virtual + QString + GenerateName(); + + virtual + void + ToStream(std::ostringstream& theStr); + + virtual + Storable* + Restore(const Storable::TRestoringMap& theMap); + + //---------------------------------------------------------------------------- + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + + virtual + VISU_GaussPtsAct2* + CloneActor(VISU_GaussPtsAct1* theActor); + + virtual + void + UpdateActor(VISU_Actor* theActor); + + virtual + void + UpdateFromActor(VISU_GaussPtsAct* theActor); + }; +} + +#endif + diff --git a/src/VISU_I/VISU_Gen_i.cc b/src/VISU_I/VISU_Gen_i.cc index 2a86c3a8..bf51d9b3 100644 --- a/src/VISU_I/VISU_Gen_i.cc +++ b/src/VISU_I/VISU_Gen_i.cc @@ -38,6 +38,7 @@ #include "VISU_CutLines_i.hh" #include "VISU_Vectors_i.hh" #include "VISU_StreamLines_i.hh" +#include "VISU_GaussPoints_i.hh" #include "VISU_Plot3D_i.hh" #include "VISU_Table_i.hh" #include "VISU_TimeAnimation.h" @@ -89,7 +90,8 @@ using namespace std; static QFileInfo aFileInfo; #ifdef _DEBUG_ -static int MYDEBUG = 1; +static int MYDEBUG = 0; +//#define _DEXCEPT_ #else static int MYDEBUG = 0; #endif @@ -107,7 +109,8 @@ extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB, return aVISU_Gen->_this(); } -namespace VISU{ +namespace VISU +{ static string VisuTmpDir; static CORBA::Boolean myIsMultiFile; @@ -186,6 +189,7 @@ namespace VISU{ Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore)); Storable::Registry(Mesh_i::myComment.c_str(),&(Restore)); Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore)); + Storable::Registry(GaussPoints_i::myComment.c_str(),&(Restore)); Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore)); Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore)); Storable::Registry(CutLines_i::myComment.c_str(),&(Restore)); @@ -225,6 +229,28 @@ namespace VISU{ if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!"); } + bool + CreatColoredPrs3d(ColoredPrs3d_i* theColoredPrs3d, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { +#ifndef _DEXCEPT_ + try{ +#endif + if(theColoredPrs3d->Create(theMeshName,theEntity,theFieldName,int(theIteration))) + return true; +#ifndef _DEXCEPT_ + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<activeStudy()) { if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { if (_PTR(Study) aCStudy = aStudy->studyDS()) { - MESSAGE("There is an application with active study : StudyId = " - << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'"); + if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = " + << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'"); if (myStudyName == aCStudy->Name()) { isActive = true; break; @@ -448,12 +474,12 @@ namespace VISU{ { CORBA::String_var aName = theStudy->Name(); std::string aStudyName (aName.in()); - MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'"); + if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'"); myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); ProcessVoidEvent(new TEvent(aStudyName)); } else { - MESSAGE("CORBA::is_nil(theStudy)"); + INFOS("CORBA::is_nil(theStudy)"); } } @@ -497,6 +523,23 @@ namespace VISU{ } } + Result_ptr VISU_Gen_i::CreateResult(const char* theFileName){ + if(myStudyDocument->GetProperties()->IsLocked()) + return Result::_nil(); + Mutex mt(myMutex); + aFileInfo.setFile(theFileName); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eFile, + Result_i::eImportFile, + false); + if(pResult->Create(theFileName) != NULL) + return pResult->_this(); + else{ + pResult->_remove_ref(); + return VISU::Result::_nil(); + } + } + Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){ if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil(); @@ -607,6 +650,15 @@ namespace VISU{ return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn(); } + GaussPoints_ptr VISU_Gen_i::GaussPointsOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn(); + } + DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, @@ -726,62 +778,12 @@ namespace VISU{ void VISU_Gen_i::DeleteResult (Result_ptr theResult) { - class TEvent: public SALOME_Event { - Result_ptr myResult; - public: - TEvent(Result_ptr theResult): myResult(theResult) {} - virtual void Execute() - { - if (Result_i* aResult = dynamic_cast(GetServant(myResult).in())) { - SALOMEDS::SObject_var aSObject = aResult->GetSObject(); - VISU::RemoveFromStudy(aSObject, - false, // not only attribute - true); // destroy sub-objects - - //jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop()) - //jfa tmp: if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)) - //jfa tmp: aStudy->updateObjBrowser(); //update Object browser - } - - myResult->Destroy(); - } - }; - - if (myStudyDocument->GetProperties()->IsLocked()) - return; - Mutex mt(myMutex); // jfa ??? - - ProcessVoidEvent(new TEvent(theResult)); + theResult->RemoveFromStudy(); } void VISU_Gen_i::DeletePrs3d (Prs3d_ptr thePrs3d) { - class TEvent: public SALOME_Event { - Prs3d_ptr myPrs3d; - public: - TEvent(Prs3d_ptr thePrs3d): myPrs3d(thePrs3d) {} - virtual void Execute() { - myPrs3d->RemoveFromStudy(); - - //update Object browser - /*jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop()) { - if (Prs3d_i* aPrs3d = dynamic_cast(GetServant(myPrs3d).in())) { - SALOMEDS::SObject_var aSObject = aPrs3d->GetSObject(); - SALOMEDS::Study_var aStudyDocument = aSObject->GetStudy(); - if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)) - aStudy->updateObjBrowser(); - } - }*/ - - myPrs3d->Destroy(); - } - }; - - if (myStudyDocument->GetProperties()->IsLocked()) - return; - Mutex mt(myMutex); // jfa ??? - - ProcessVoidEvent(new TEvent(thePrs3d)); + thePrs3d->RemoveFromStudy(); } void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){ diff --git a/src/VISU_I/VISU_Gen_i.hh b/src/VISU_I/VISU_Gen_i.hh index 240b6bea..d1ab5424 100644 --- a/src/VISU_I/VISU_Gen_i.hh +++ b/src/VISU_I/VISU_Gen_i.hh @@ -15,8 +15,18 @@ #include "SALOME_Component_i.hxx" #include "SALOME_NamingService.hxx" -namespace VISU{ +namespace VISU +{ class Result_i; + class ColoredPrs3d_i; + + bool + CreatColoredPrs3d(ColoredPrs3d_i* theColoredPrs3d, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + class VISU_Gen_i : public virtual POA_VISU::VISU_Gen, public virtual ::Engines_Component_i, public virtual Base_i @@ -31,56 +41,110 @@ namespace VISU{ QMutex* theMutex); virtual ~VISU_Gen_i(); - virtual char* GetID(); - virtual VISU::VISUType GetType() { return VISU::TVISUGEN;}; + virtual + char* + GetID(); + + virtual + VISU::VISUType + GetType() { return VISU::TVISUGEN;}; + + virtual + void + SetCurrentStudy(SALOMEDS::Study_ptr theStudy); - virtual void SetCurrentStudy(SALOMEDS::Study_ptr theStudy); - virtual SALOMEDS::Study_ptr GetCurrentStudy(); + virtual + SALOMEDS::Study_ptr + GetCurrentStudy(); - virtual ViewManager_ptr GetViewManager(); + virtual + ViewManager_ptr + GetViewManager(); - virtual SALOMEDS::SObject_ptr ImportTables(const char* theFileName); - virtual CORBA::Boolean ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName ); + virtual + SALOMEDS::SObject_ptr + ImportTables(const char* theFileName); + + virtual + CORBA::Boolean + ExportTableToFile(SALOMEDS::SObject_ptr theTable, + const char* theFileName ); //Create Result - virtual Result_ptr ImportFile(const char* theFileName); - virtual Result_ptr CopyAndImportFile(const char* theFileName); - virtual Result_ptr ImportMed(SALOMEDS::SObject_ptr theMedSObject); - virtual Result_ptr ImportMedField(SALOME_MED::FIELD_ptr theField); + virtual + Result_ptr + ImportFile(const char* theFileName); + + virtual + Result_ptr + CreateResult(const char* theFileName); + + virtual + Result_ptr + CopyAndImportFile(const char* theFileName); + + virtual + Result_ptr + ImportMed(SALOMEDS::SObject_ptr theMedSObject); + + virtual + Result_ptr + ImportMedField(SALOME_MED::FIELD_ptr theField); + //Create Presentation Of Submeshes - virtual Mesh_ptr MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity); - virtual Mesh_ptr FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName, - VISU::Entity theEntity, const char* theFamilyName); - virtual Mesh_ptr GroupMesh(Result_ptr theResult, const char* theMeshName, const char* theGroupName); + virtual + Mesh_ptr + MeshOnEntity(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity); + + virtual + Mesh_ptr + FamilyMeshOnEntity(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFamilyName); + + virtual + Mesh_ptr + GroupMesh(Result_ptr theResult, + const char* theMeshName, + const char* theGroupName); //Create 3D collored Presentation Of Different Types template TPrs3d_i* - CreatePrs3d(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration, bool theAddToStudy = true) + CreatePrs3d(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration, + bool theAddToStudy = true) { - TPrs3d_i* aPresent = NULL; if(myStudyDocument->GetProperties()->IsLocked()) - return aPresent; + return NULL; typedef typename TPrs3d_i::TInterface TPrs3d; typename TPrs3d::_var_type aPrs3d; Mutex mt(myMutex); - if(Result_i* pResult = dynamic_cast(GetServant(theResult).in())){ - if(TPrs3d_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,int(theIteration))){ - aPresent = new TPrs3d_i(pResult,theAddToStudy); - if(aPresent->Create(theMeshName,theEntity,theFieldName,int(theIteration)) == NULL){ - aPresent->_remove_ref(); - aPresent = NULL; - } + if(Result_i* aResult = dynamic_cast(GetServant(theResult).in())){ + if(TPrs3d_i::IsPossible(aResult,theMeshName,theEntity,theFieldName,int(theIteration))){ + TPrs3d_i* aPresent = new TPrs3d_i(aResult,theAddToStudy); + if(CreatColoredPrs3d(aPresent,theMeshName,theEntity,theFieldName,theIteration)) + return aPresent; + aPresent->_remove_ref(); } } - return aPresent; + return NULL; } template typename TPrs3d_i::TInterface::_var_type - Prs3dOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration, bool theAddToStudy = true) + Prs3dOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration, + bool theAddToStudy = true) { typedef typename TPrs3d_i::TInterface TPrs3d; typename TPrs3d::_var_type aPrs3d; @@ -89,38 +153,104 @@ namespace VISU{ return TPrs3d::_nil(); } - virtual ScalarMap_ptr ScalarMapOnField(Result_ptr theResult, - const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration); - virtual DeformedShape_ptr DeformedShapeOnField(Result_ptr theResult, - const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration); - virtual Vectors_ptr VectorsOnField(Result_ptr theResult, - const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration); - virtual IsoSurfaces_ptr IsoSurfacesOnField(Result_ptr theResult, - const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration); - virtual CutPlanes_ptr CutPlanesOnField(Result_ptr theResult, - const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration); - virtual CutLines_ptr CutLinesOnField(Result_ptr theResult, - const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration); - virtual StreamLines_ptr StreamLinesOnField(Result_ptr theResult, - const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration); - virtual Plot3D_ptr Plot3DOnField(Result_ptr theResult, - const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration); + virtual + ScalarMap_ptr + ScalarMapOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + + virtual + GaussPoints_ptr + GaussPointsOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + + virtual + DeformedShape_ptr + DeformedShapeOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + + virtual + Vectors_ptr + VectorsOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + + virtual + IsoSurfaces_ptr + IsoSurfacesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + + virtual + CutPlanes_ptr + CutPlanesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + + virtual + CutLines_ptr + CutLinesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + + virtual + StreamLines_ptr + StreamLinesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + + virtual + Plot3D_ptr + Plot3DOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration); + //Create Digital Presentation - virtual Table_ptr CreateTable(const char* theTableEntry); - virtual Curve_ptr CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow); - virtual Container_ptr CreateContainer(); - virtual Animation_ptr CreateAnimation(View3D_ptr theView3d); + virtual + Table_ptr + CreateTable(const char* theTableEntry); - virtual void DeleteResult(Result_ptr theResult); - virtual void DeletePrs3d(Prs3d_ptr thePrs3d); + virtual + Curve_ptr + CreateCurve(Table_ptr theTable, + CORBA::Long theHRow, + CORBA::Long theVRow); + + virtual + Container_ptr + CreateContainer(); + + virtual + Animation_ptr + CreateAnimation(View3D_ptr theView3d); + + virtual + void + DeleteResult(Result_ptr theResult); + + virtual + void + DeletePrs3d(Prs3d_ptr thePrs3d); // inherited methods from Engines::Component virtual @@ -128,47 +258,83 @@ namespace VISU{ DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean theIsPublished, CORBA::Boolean& theIsValidScript); + // inherited methods from SALOMEDS::Driver - virtual SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile); - virtual SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile); - virtual bool Load(SALOMEDS::SComponent_ptr, - const SALOMEDS::TMPFile &, - const char* theURL, - bool isMultiFile); - virtual bool LoadASCII(SALOMEDS::SComponent_ptr, - const SALOMEDS::TMPFile &, - const char* theURL, - bool isMultiFile); - - virtual void Close(SALOMEDS::SComponent_ptr IORSComponent); - - virtual char* ComponentDataType(); - - virtual char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, - const char* IORString, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII); - virtual char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, - const char* aLocalPersistentID, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII); - - virtual bool CanPublishInStudy(CORBA::Object_ptr theIOR); - virtual SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theSObject, - CORBA::Object_ptr theObject, - const char* theName) throw (SALOME::SALOME_Exception); - - CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject); - SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID); - CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID); - SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream, - CORBA::Long theObjectID, - SALOMEDS::SObject_ptr theObject); + virtual + SALOMEDS::TMPFile* + Save(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); + + virtual + SALOMEDS::TMPFile* + SaveASCII(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); + + virtual + bool + Load(SALOMEDS::SComponent_ptr, + const SALOMEDS::TMPFile &, + const char* theURL, + bool isMultiFile); + + virtual + bool + LoadASCII(SALOMEDS::SComponent_ptr, + const SALOMEDS::TMPFile &, + const char* theURL, + bool isMultiFile); + + virtual + void + Close(SALOMEDS::SComponent_ptr IORSComponent); + + virtual + char* + ComponentDataType(); + + virtual + char* + IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, + const char* IORString, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII); + + virtual + char* + LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, + const char* aLocalPersistentID, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII); + + virtual + bool + CanPublishInStudy(CORBA::Object_ptr theIOR); + + virtual + SALOMEDS::SObject_ptr + PublishInStudy(SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject, + const char* theName) throw (SALOME::SALOME_Exception); + + CORBA::Boolean + CanCopy(SALOMEDS::SObject_ptr theObject); + + SALOMEDS::TMPFile* + CopyFrom(SALOMEDS::SObject_ptr theObject, + CORBA::Long& theObjectID); + + CORBA::Boolean + CanPaste(const char* theComponentName, + CORBA::Long theObjectID); + + SALOMEDS::SObject_ptr + PasteInto(const SALOMEDS::TMPFile& theStream, + CORBA::Long theObjectID, + SALOMEDS::SObject_ptr theObject); }; } + #endif diff --git a/src/VISU_I/VISU_I.cxx b/src/VISU_I/VISU_I.cxx new file mode 100644 index 00000000..a3a39f28 --- /dev/null +++ b/src/VISU_I/VISU_I.cxx @@ -0,0 +1,54 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "VISUConfig.hh" +#include "VISU_Gen_i.hh" +#include "VISU_Result_i.hh" +#include "VISU_PrsObject_i.hh" +#include "VISU_Table_i.hh" +#include "VISU_Prs3d_i.hh" +#include "VISU_Mesh_i.hh" +#include "VISU_ScalarMap_i.hh" +#include "VISU_IsoSurfaces_i.hh" +#include "VISU_DeformedShape_i.hh" +#include "VISU_DeformedShape_i.hh" +#include "VISU_Plot3D_i.hh" +#include "VISU_CutPlanes_i.hh" +#include "VISU_CutLines_i.hh" +#include "VISU_Vectors_i.hh" +#include "VISU_StreamLines_i.hh" +#include "VISU_GaussPoints_i.hh" +#include "VISU_ViewManager_i.hh" +#include "VISU_View_i.hh" +#include "VISU_TimeAnimation.h" + +int +main(int argc, char** argv) +{ + return 0; +} diff --git a/src/VISU_I/VISU_IsoSurfaces_i.cc b/src/VISU_I/VISU_IsoSurfaces_i.cc index 853a5499..4198c8a6 100644 --- a/src/VISU_I/VISU_IsoSurfaces_i.cc +++ b/src/VISU_I/VISU_IsoSurfaces_i.cc @@ -56,10 +56,10 @@ IsoSurfaces_i(Result_i* theResult, bool theAddToStudy) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), ScalarMap_i(theResult,theAddToStudy), myIsoSurfacesPL(NULL) -{ -} +{} VISU::IsoSurfaces_i:: @@ -67,6 +67,7 @@ IsoSurfaces_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), ScalarMap_i(theResult,theSObject), myIsoSurfacesPL(NULL) { @@ -82,13 +83,14 @@ VISU::Storable* VISU::IsoSurfaces_i::Create(const char* theMeshName, VISU::Entit VISU::Storable* VISU::IsoSurfaces_i::Restore(const Storable::TRestoringMap& theMap) { - DoHook(); + TSuperClass::Restore(theMap); + SetNbSurfaces(VISU::Storable::FindValue(theMap,"myNbSurface").toInt()); float aMin = VISU::Storable::FindValue(theMap,"myRange[0]").toDouble(); float aMax = VISU::Storable::FindValue(theMap,"myRange[1]").toDouble(); SetSubRange(aMin,aMax); - return ScalarMap_i::Restore(theMap); + return this; } void VISU::IsoSurfaces_i::ToStream(std::ostringstream& theStr){ @@ -134,6 +136,17 @@ void VISU::IsoSurfaces_i::DoHook(){ } +VISU_Actor* +VISU::IsoSurfaces_i +::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +{ + if(VISU_Actor* anActor = ScalarMap_i::CreateActor(theIO)){ + anActor->SetVTKMapping(true); + return anActor; + } + return NULL; +} + void VISU::IsoSurfaces_i::SetMapScale(double theMapScale){ myIsoSurfacesPL->SetMapScale(theMapScale); } diff --git a/src/VISU_I/VISU_IsoSurfaces_i.hh b/src/VISU_I/VISU_IsoSurfaces_i.hh index d51f36aa..b10ef520 100644 --- a/src/VISU_I/VISU_IsoSurfaces_i.hh +++ b/src/VISU_I/VISU_IsoSurfaces_i.hh @@ -38,7 +38,10 @@ namespace VISU{ static int myNbPresent; IsoSurfaces_i(); IsoSurfaces_i(const IsoSurfaces_i&); + public: + typedef ScalarMap_i TSuperClass; + explicit IsoSurfaces_i(Result_i* theResult, bool theAddToStudy); @@ -77,6 +80,10 @@ namespace VISU{ virtual Storable* Restore(const Storable::TRestoringMap& theMap); + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + virtual void SetMapScale(double theMapScale = 1.0); }; } diff --git a/src/VISU_I/VISU_Mesh_i.cc b/src/VISU_I/VISU_Mesh_i.cc index 5c3cb317..2a65400b 100644 --- a/src/VISU_I/VISU_Mesh_i.cc +++ b/src/VISU_I/VISU_Mesh_i.cc @@ -29,8 +29,11 @@ #include "VISU_Result_i.hh" #include "VISU_ViewManager_i.hh" -#include "VISU_MeshPL.hxx" #include "VISU_MeshAct.h" +#include "VISU_MeshPL.hxx" +#include "VISU_Convertor.hxx" + +#include "SALOME_Event.hxx" using namespace VISU; using namespace std; @@ -72,10 +75,26 @@ Mesh_i(Result_i* theResult, } +//--------------------------------------------------------------- void VISU::Mesh_i::RemoveFromStudy() { - VISU::DeleteActors(this); - VISU::RemoveFromStudy(mySObject); + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Mesh_i* myRemovable; + TRemoveFromStudy(VISU::Mesh_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + VISU::RemoveFromStudy(myRemovable->GetSObject()); + myRemovable->TSuperClass::RemoveFromStudy(); + } + }; + + ProcessVoidEvent(new TRemoveFromStudy(this)); } @@ -92,7 +111,7 @@ int VISU::Mesh_i::IsPossible (Result_i* theResult, const char* theMeshName, try{ MESSAGE("Mesh_i::IsPossible - theMeshName = '"<GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity,theFamilyName); + theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity); bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize); MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<= 0) + if(mySubMeshName == "") myType = VISU::TENTITY; else myType = VISU::TFAMILY; else myType = VISU::TGROUP; + if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<GetInput()->GetMeshOnEntity(myMeshName,myEntity); - anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity);//jfa IPAL9284 + anIDMapper = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity);//jfa IPAL9284 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d", VISU::TENTITY,myMeshName.c_str(),myEntity); break; case VISU::TFAMILY : - //jfa IPAL9284:anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,myEntity,mySubMeshName); - anOutput = myResult->GetInput()->GetMeshOnEntity - (myMeshName,(VISU::TEntity)myEntity,mySubMeshName);//jfa IPAL9284 + anIDMapper = myResult->GetInput()->GetFamilyOnEntity(myMeshName,(VISU::TEntity)myEntity,mySubMeshName); aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", VISU::TFAMILY,myMeshName.c_str(),myEntity,mySubMeshName.c_str()); break; case VISU::TGROUP : - anOutput = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName); + anIDMapper = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName); aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s", VISU::TGROUP,myMeshName.c_str(),mySubMeshName.c_str()); break; } - if(anOutput == NULL) throw std::runtime_error("Mesh_i::Build - anOutput == NULL !!!"); - myMeshPL->SetInput(anOutput); + if(!anIDMapper) + throw std::runtime_error("Mesh_i::Build - !anIDMapper !!!"); + + myMeshPL->SetIDMapper(anIDMapper); myMeshPL->Build(); + if(!theRestoring) { //Setting IOR on the label myMeshPL->Init(); string aResultEntry = myResult->GetEntry(); diff --git a/src/VISU_I/VISU_Mesh_i.hh b/src/VISU_I/VISU_Mesh_i.hh index a9eb6f7e..4bb0809e 100644 --- a/src/VISU_I/VISU_Mesh_i.hh +++ b/src/VISU_I/VISU_Mesh_i.hh @@ -31,19 +31,25 @@ class VISU_MeshPL; -namespace VISU{ +namespace VISU +{ class Mesh_i : public virtual POA_VISU::Mesh, public virtual Prs3d_i { static int myNbPresent; Mesh_i(); Mesh_i(const Mesh_i&); + public: + typedef Prs3d_i TSuperClass; + explicit Mesh_i(Result_i* theResult); + explicit Mesh_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject); + virtual void SameAs(const Prs3d_i* theOrigin); virtual ~Mesh_i(); virtual void RemoveFromStudy(); diff --git a/src/VISU_I/VISU_Plot3D_i.cc b/src/VISU_I/VISU_Plot3D_i.cc index 8f69fd9f..0cc631b2 100644 --- a/src/VISU_I/VISU_Plot3D_i.cc +++ b/src/VISU_I/VISU_Plot3D_i.cc @@ -48,21 +48,25 @@ QString VISU::Plot3D_i::GenerateName() { return VISU::GenerateName("Plot3D",myNb const string VISU::Plot3D_i::myComment = "PLOT3D"; const char* VISU::Plot3D_i::GetComment() const { return myComment.c_str(); } -VISU::Plot3D_i::Plot3D_i (Result_i* theResult, bool theAddToStudy) - : PrsObject_i(theResult->GetStudyDocument()), - Prs3d_i(theResult,theAddToStudy), - ScalarMap_i(theResult,theAddToStudy), - myPlot3DPL(NULL) -{ -} - -VISU::Plot3D_i::Plot3D_i (Result_i* theResult, SALOMEDS::SObject_ptr theSObject) - : PrsObject_i(theResult->GetStudyDocument()), - Prs3d_i(theResult,theSObject), - ScalarMap_i(theResult,theSObject), - myPlot3DPL(NULL) -{ -} +VISU::Plot3D_i +::Plot3D_i(Result_i* theResult, + bool theAddToStudy) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), + ScalarMap_i(theResult,theAddToStudy), + myPlot3DPL(NULL) +{} + +VISU::Plot3D_i +::Plot3D_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), + ScalarMap_i(theResult,theSObject), + myPlot3DPL(NULL) +{} VISU::Storable* VISU::Plot3D_i::Create (const char* theMeshName, VISU::Entity theEntity, const char* theFieldName, int theIteration) @@ -72,7 +76,8 @@ VISU::Storable* VISU::Plot3D_i::Create (const char* theMeshName, VISU::Entity th VISU::Storable* VISU::Plot3D_i::Restore (const Storable::TRestoringMap& theMap) { - DoHook(); + TSuperClass::Restore(theMap); + SetOrientation(VISU::Plot3D::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane").toInt()), Storable::FindValue(theMap,"aRot[0]").toDouble(), Storable::FindValue(theMap,"aRot[1]").toDouble()); @@ -82,7 +87,7 @@ VISU::Storable* VISU::Plot3D_i::Restore (const Storable::TRestoringMap& theMap) SetContourPrs(VISU::Storable::FindValue(theMap,"myContourPrs").toInt()); SetNbOfContours(VISU::Storable::FindValue(theMap,"myNbOfContours").toInt()); - return ScalarMap_i::Restore(theMap); + return this; } void VISU::Plot3D_i::ToStream (std::ostringstream& theStr) @@ -179,6 +184,17 @@ void VISU::Plot3D_i::DoHook() ScalarMap_i::DoHook(); } +VISU_Actor* +VISU::Plot3D_i +::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +{ + if(VISU_Actor* anActor = ScalarMap_i::CreateActor(theIO)){ + anActor->SetVTKMapping(true); + return anActor; + } + return NULL; +} + void VISU::Plot3D_i::SetMapScale(double theMapScale) { myPlot3DPL->SetMapScale(theMapScale); diff --git a/src/VISU_I/VISU_Plot3D_i.hh b/src/VISU_I/VISU_Plot3D_i.hh index acd76440..d612af1e 100644 --- a/src/VISU_I/VISU_Plot3D_i.hh +++ b/src/VISU_I/VISU_Plot3D_i.hh @@ -34,6 +34,8 @@ namespace VISU { Plot3D_i(const Plot3D_i&); public: + typedef ScalarMap_i TSuperClass; + explicit Plot3D_i (Result_i* theResult, bool theAddToStudy = true); explicit @@ -86,6 +88,10 @@ namespace VISU { virtual Storable* Restore (const Storable::TRestoringMap& theMap); + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + static const std::string myComment; virtual const char* GetComment() const; virtual QString GenerateName(); diff --git a/src/VISU_I/VISU_Prs3d_i.cc b/src/VISU_I/VISU_Prs3d_i.cc index 7838834f..64bb0bb9 100644 --- a/src/VISU_I/VISU_Prs3d_i.cc +++ b/src/VISU_I/VISU_Prs3d_i.cc @@ -25,49 +25,65 @@ // Module : VISU #include "VISU_PipeLine.hxx" -#include "VISU_Result_i.hh" #include "VISU_Prs3d_i.hh" + +#include "VISU_Result_i.hh" #include "VISU_Actor.h" -#include -#include +#include "SALOME_Event.hxx" + +#include +#include +#include + +#include using namespace VISU; using namespace std; #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 1; #else static int MYDEBUG = 0; #endif -VISU::Prs3d_i:: -Prs3d_i(Result_i* theResult, - SALOMEDS::SObject_ptr theSObject) : + +//---------------------------------------------------------------------------- +VISU::Prs3d_i +::Prs3d_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), - myResult(theResult), mySObject(SALOMEDS::SObject::_duplicate(theSObject)), + myActorCollection(vtkActorCollection::New()), + myResult(theResult), myAddToStudy(true), myPipeLine(NULL) { + if(MYDEBUG) MESSAGE("Prs3d_i::Prs3d_i - this = "<Delete(); myResult->Register(); } -VISU::Prs3d_i:: -Prs3d_i(Result_i* theResult, - bool theAddToStudy) : +VISU::Prs3d_i +::Prs3d_i(Result_i* theResult, + bool theAddToStudy) : PrsObject_i(theResult->GetStudyDocument()), - myResult(theResult), + myActorCollection(vtkActorCollection::New()), mySObject(SALOMEDS::SObject::_nil()), myAddToStudy(theAddToStudy), + myResult(theResult), myPipeLine(NULL) { + if(MYDEBUG) MESSAGE("Prs3d_i::Prs3d_i - this = "<Delete(); myResult->Register(); } -void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin) +void +VISU::Prs3d_i +::SameAs(const Prs3d_i* theOrigin) { if (Prs3d_i* aOrigin = const_cast(theOrigin)) { myPipeLine->SameAs(aOrigin->GetPL()); @@ -75,60 +91,20 @@ void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin) } } -VISU::Prs3d_i::~Prs3d_i() { - if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<setIO(anIO); - } - // } - theActor->SetPipeLine(GetPipeLine()); - theActor->SetPrs3d(this); - theActor->SetPosition(myOffset); - }catch(std::bad_alloc& ex){ - throw std::runtime_error("CreateActor >> No enough memory"); - throw ex; - } catch(std::exception& ex){ - throw ex; - }catch(...) { - throw std::runtime_error("CreateActor >> unexpected exception was caught!!!"); - } -} - -void VISU::Prs3d_i::UpdateActor(VISU_Actor* theActor) { - if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor() - this = "<GetMapper(); - vtkDataSet *aDataSet = aMapper->GetInput(); - if (!aDataSet) - throw std::runtime_error("There is no input data !!!"); - aDataSet->Update(); - static float eps = VTK_LARGE_FLOAT * 0.1 ; - if (!aDataSet->GetNumberOfCells()) - throw std::runtime_error("There is no visible elements"); - if (aDataSet->GetLength() > eps) - throw std::runtime_error("Diagonal of the actor is too large !!!"); - // fix for bug 9808 END - - //theActor->GetMapper()->ShallowCopy(myPipeLine->GetMapper()); - theActor->GetMapper()->ShallowCopy(aMapper); - theActor->SetPosition(myOffset); - theActor->Modified(); -} - -VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap) +//---------------------------------------------------------------------------- +VISU::Storable* +VISU::Prs3d_i +::Restore(const Storable::TRestoringMap& theMap) { myName = VISU::Storable::FindValue(theMap,"myName").latin1(); myOffset[0] = VISU::Storable::FindValue(theMap,"myOffset[0]").toFloat(); @@ -137,15 +113,51 @@ VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap) return this; } -void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){ +void +VISU::Prs3d_i +::ToStream(std::ostringstream& theStr) +{ Storable::DataToStream( theStr, "myName", myName.c_str() ); Storable::DataToStream( theStr, "myOffset[0]", myOffset[0] ); Storable::DataToStream( theStr, "myOffset[1]", myOffset[1] ); Storable::DataToStream( theStr, "myOffset[2]", myOffset[2] ); } -void VISU::Prs3d_i::Update() { - if(MYDEBUG) MESSAGE("Prs3d_i::Update() - this = "<GetStudyDocument(); + CORBA::String_var anIOR = GetID(); + mySObject = aStudy->FindObjectIOR(anIOR); + } + return mySObject; +} + +Result_i* +VISU::Prs3d_i +::GetResult() const +{ + return myResult; +} + +const std::string& +VISU::Prs3d_i +::GetMeshName() const +{ + return myMeshName; +} + + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::Update() +{ + if(MYDEBUG) MESSAGE("Prs3d_i::Update - this = "<Update(); }catch(...){ @@ -153,84 +165,241 @@ void VISU::Prs3d_i::Update() { } } -VISU_PipeLine* VISU::Prs3d_i::GetPipeLine(){ + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::CheckDataSet() +{ + vtkMapper *aMapper = myPipeLine->GetMapper(); + vtkDataSet *aDataSet = aMapper->GetInput(); + if (!aDataSet) + throw std::runtime_error("There is no input data !!!"); + aDataSet->Update(); + static float eps = VTK_LARGE_FLOAT * 0.1 ; + if (!aDataSet->GetNumberOfCells()) + throw std::runtime_error("There are no visible elements"); + if (aDataSet->GetLength() > eps) + throw std::runtime_error("Diagonal of the actor is too large !!!"); +} + +void +VISU::Prs3d_i +::RemoveFromStudy() +{ + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Prs3d_i* myRemovable; + typedef boost::signal0 TRemoveFromStudySignal; + const TRemoveFromStudySignal& myRemoveFromStudySignal; + + TRemoveFromStudy(VISU::Prs3d_i* theRemovable, + const TRemoveFromStudySignal& theRemoveFromStudySignal): + myRemovable(theRemovable), + myRemoveFromStudySignal(theRemoveFromStudySignal) + {} + + virtual + void + Execute() + { + myRemoveFromStudySignal(); + myRemovable->Destroy(); + } + }; + + ProcessVoidEvent(new TRemoveFromStudy(this,myRemoveActorsFromRendererSignal)); +} + + +//---------------------------------------------------------------------------- +VISU_PipeLine* +VISU::Prs3d_i +::GetPipeLine() +{ return GetPL(); } -VISU_PipeLine* VISU::Prs3d_i::GetPL(){ +VISU_PipeLine* +VISU::Prs3d_i +::GetPL() +{ return myPipeLine; } -vtkUnstructuredGrid* VISU::Prs3d_i::GetInput(){ +vtkUnstructuredGrid* +VISU::Prs3d_i:: +GetInput() +{ return myPipeLine->GetInput(); } -SALOMEDS::SObject_var VISU::Prs3d_i::GetSObject(){ - if (CORBA::is_nil(mySObject.in())) { - const SALOMEDS::Study_var& aStudy = myResult->GetStudyDocument(); - CORBA::String_var anIOR = GetID(); - mySObject = aStudy->FindObjectIOR(anIOR); +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO) +{ + try{ + Handle(SALOME_InteractiveObject) anIO = theIO; + if(anIO.IsNull() && (!mySObject->_is_nil())){ + anIO = new SALOME_InteractiveObject(mySObject->GetID(),"VISU",GetName()); + theActor->setIO(anIO); + } + + Update(); + CheckDataSet(); + + theActor->SetPrs3d(this); + theActor->SetShrinkFactor(); + theActor->SetPosition(myOffset); + theActor->SetPipeLine(GetPipeLine()); + + theActor->SetFactory(this); + myUpdateActorsSignal.connect(boost::bind(&VISU_Actor::UpdateFromFactory,theActor)); + myRemoveActorsFromRendererSignal.connect(boost::bind(&VISU_Actor::RemoveFromRender,theActor)); + + myActorCollection->AddItem(theActor); + theActor->Delete(); + + }catch(std::bad_alloc& ex){ + throw std::runtime_error("CreateActor >> No enough memory"); + throw ex; + } catch(std::exception& ex){ + throw ex; + }catch(...) { + throw std::runtime_error("CreateActor >> unexpected exception was caught!!!"); } - return mySObject; } -void VISU::Prs3d_i::GetBounds(float aBounds[6]){ - myPipeLine->GetMapper()->GetBounds(aBounds); +void +VISU::Prs3d_i +::RemoveActor(VISU_Actor* theActor) +{ + if(MYDEBUG) MESSAGE("Prs3d_i::RemoveActor - this = "< +#include +#include class VISU_PipeLine; class VISU_Actor; class vtkPlane; +class vtkActorCollection; class vtkUnstructuredGrid; -namespace VISU{ +namespace VISU +{ class Result_i; + //---------------------------------------------------------------------------- + //! Base class for all VTK 3D presentations. + /*! + It is a root class for a middle level of VISU functionality. + Almost all functionality of the the class implemented through redirection + external requestes to its VISU_PipeLine. + It define an interface and implement the following topics: + - provide persistent mechanism; + - implement basic actor management (CreateActor, UpdateActor, UpdateActors, RemoveActor and RemoveActors); + - implement common 3D functionality like "clipping planes" and offset. + */ class Prs3d_i : public virtual POA_VISU::Prs3d, public virtual SALOME::GenericObj_i, + public virtual TActorFactory, public virtual PrsObject_i { @@ -53,70 +71,178 @@ namespace VISU{ Prs3d_i(const Prs3d_i&); public: + //---------------------------------------------------------------------------- + //! A constructor to create a fresh instance of the class explicit Prs3d_i(Result_i* theResult, bool theAddToStudy); + + //! A constructor to restore an instance of the class explicit Prs3d_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject); - virtual void SameAs(const Prs3d_i* theOrigin); - virtual ~Prs3d_i(); - protected: - bool myAddToStudy; - float myOffset[3]; - Result_i *myResult; - VISU_PipeLine *myPipeLine; - SALOMEDS::SObject_var mySObject; - std::string myMeshName; + //! To create a deep copy from another instance of the class + virtual + void + SameAs(const Prs3d_i* theOrigin); - void CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO = NULL); - virtual VISU_PipeLine* GetPipeLine(); + virtual + ~Prs3d_i(); - public: - virtual void Update() ; - VISU_PipeLine* GetPL(); + //---------------------------------------------------------------------------- + //! To generate an unique type name for the class (used into persistent functionality) + virtual + const char* + GetComment() const = 0; + + //! To generate an unique name for the instance of the class + virtual + QString + GenerateName() = 0; + + //! To restore paramters of the instance from Storable::TRestoringMap + virtual + Storable* + Restore(const Storable::TRestoringMap& theMap); + + //! To save paramters of the instance to std::ostringstream + virtual + void + ToStream(std::ostringstream& theStr); + + //---------------------------------------------------------------------------- + //! Get corresponding Result_i + Result_i* + GetResult() const; - vtkUnstructuredGrid* GetInput(); + //! Get corresponding SALOMEDS::SObject + virtual + SALOMEDS::SObject_var + GetSObject(); - void GetBounds(float aBounds[6]); + const std::string& + GetMeshName() const; - void SetOffset(const float* theOffsets); - virtual void SetOffset(float theDx, float theDy, float theDz); + //---------------------------------------------------------------------------- + //! To update is internal state + virtual + void + Update(); - void GetOffset(float* theOffsets); - virtual void GetOffset(float& theDx, float& theDy, float& theDz); + //! To remove the instance from study + virtual + void + RemoveFromStudy(); - virtual const char* GetComment() const = 0; - virtual QString GenerateName() = 0; + //---------------------------------------------------------------------------- + //! Get corresponding VISU_PipeLine + VISU_PipeLine* + GetPL(); - virtual Storable* Restore(const Storable::TRestoringMap& theMap); + //! Get input of the VISU_PipeLine + vtkUnstructuredGrid* + GetInput(); - virtual void ToStream(std::ostringstream& theStr); + //---------------------------------------------------------------------------- + //! To define a way to create VTK representation of the instance + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) = 0; - virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) = 0; + //! To unregister the pointed actor + virtual + void + RemoveActor(VISU_Actor* theActor); - virtual void UpdateActor(VISU_Actor* theActor) ; + //! To unregister all actors of the instance + virtual + void + RemoveActors(); - Result_i* GetResult() const { return myResult;} - virtual SALOMEDS::SObject_var GetSObject(); - const std::string& GetMeshName() const { return myMeshName; } + //! To update the pointed actor + virtual + void + UpdateActor(VISU_Actor* theActor); + //! To update all actors of the instance + virtual + void + UpdateActors(); + + //---------------------------------------------------------------------------- // Clipping planes - void RemoveAllClippingPlanes(); - vtkIdType GetNumberOfClippingPlanes() const; - bool AddClippingPlane(vtkPlane* thePlane); - vtkPlane* GetClippingPlane(vtkIdType theID) const; + void + RemoveAllClippingPlanes(); + + bool + AddClippingPlane(vtkPlane* thePlane); + + vtkIdType + GetNumberOfClippingPlanes() const; + + vtkPlane* + GetClippingPlane(vtkIdType theID) const; + + void + SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane); + + //---------------------------------------------------------------------------- + void + GetBounds(float aBounds[6]); + + void + SetOffset(const float* theOffsets); + + virtual + void + SetOffset(float theDx, float theDy, float theDz); + + void + GetOffset(float* theOffsets); + + virtual + void + GetOffset(float& theDx, float& theDy, float& theDz); + + //---------------------------------------------------------------------------- + protected: + void + CreateActor(VISU_Actor* theActor, + const Handle(SALOME_InteractiveObject)& theIO = NULL); + + virtual + VISU_PipeLine* + GetPipeLine(); + + //! To check dataset validity, throws std::exception if not valid + virtual + void + CheckDataSet(); + + bool myAddToStudy; + float myOffset[3]; + Result_i *myResult; + VISU_PipeLine *myPipeLine; + SALOMEDS::SObject_var mySObject; + std::string myMeshName; + + boost::signal0 myUpdateActorsSignal; + boost::signal0 myRemoveActorsFromRendererSignal; + vtkSmartPointer myActorCollection; - void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane); }; - Result_i* GetResult(SALOMEDS::SObject_ptr theSObject); + //---------------------------------------------------------------------------- + Result_i* + GetResult(SALOMEDS::SObject_ptr theSObject); + //---------------------------------------------------------------------------- template - Storable* Restore(SALOMEDS::SObject_ptr theSObject, - const std::string& thePrefix, - const Storable::TRestoringMap& theMap) + Storable* + Restore(SALOMEDS::SObject_ptr theSObject, + const std::string& thePrefix, + const Storable::TRestoringMap& theMap) { VISU::Result_i* pResult = GetResult(theSObject); if(pResult != NULL){ @@ -125,6 +251,7 @@ namespace VISU{ } return NULL; } + //---------------------------------------------------------------------------- } #endif diff --git a/src/VISU_I/VISU_Result_i.cc b/src/VISU_I/VISU_Result_i.cc index 167c412b..2a85df81 100644 --- a/src/VISU_I/VISU_Result_i.cc +++ b/src/VISU_I/VISU_Result_i.cc @@ -28,6 +28,7 @@ #include "VISU_Convertor_impl.hxx" #include "VISU_CorbaMedConvertor.hxx" +#include "VISU_ConvertorUtils.hxx" #include "VISU_PipeLine.hxx" #include "SUIT_ResourceMgr.h" @@ -35,9 +36,22 @@ #include "SALOMEDS_Tool.hxx" #include "HDFascii.hxx" +#include "SUIT_Session.h" +#include "SALOME_Event.hxx" +#include "SalomeApp_Study.h" +#include "SalomeApp_Application.h" + +#include +#include + +#include +#include + // QT Includes #include #include +#include +#include // VTK Includes #include @@ -51,101 +65,786 @@ using namespace std; #ifdef _DEBUG_ static int MYDEBUG = 0; +static int MYTIMEDEBUG = 0; #else static int MYDEBUG = 0; +static int MYTIMEDEBUG = 0; #endif -VISU::Result_var VISU::FindResult (SALOMEDS::SObject_ptr theSObject) + +namespace VISU { - SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent(); - SALOMEDS::SObject_var aFather = theSObject->GetFather(); - CORBA::String_var aComponentID (aSComponent->GetID()); - CORBA::String_var aFatherID (aFather->GetID()); - VISU::Result_var aResult; - while (strcmp(aComponentID, aFatherID) != 0) { - CORBA::Object_var anObject = VISU::SObjectToObject(aFather); - if (!CORBA::is_nil(anObject)) { - aResult = VISU::Result::_narrow(anObject); - if (!aResult->_is_nil()) return aResult; - } - aFather = aFather->GetFather(); - aFatherID = aFather->GetID(); + //--------------------------------------------------------------- + Result_var + FindResult (SALOMEDS::SObject_ptr theSObject) + { + SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent(); + SALOMEDS::SObject_var aFather = theSObject->GetFather(); + CORBA::String_var aComponentID (aSComponent->GetID()); + CORBA::String_var aFatherID (aFather->GetID()); + Result_var aResult; + while (strcmp(aComponentID, aFatherID) != 0) { + CORBA::Object_var anObject = SObjectToObject(aFather); + if (!CORBA::is_nil(anObject)) { + aResult = Result::_narrow(anObject); + if (!aResult->_is_nil()) return aResult; + } + aFather = aFather->GetFather(); + aFatherID = aFather->GetID(); + } + return aResult; } - return aResult; -} -QString GenerateName (const char* theName) -{ - typedef map TNameMap; - static TNameMap aMap; - TNameMap::const_iterator i = aMap.find(theName); - QString tmp; - if (i == aMap.end()) { - aMap[theName] = 0; - tmp = theName; - } else { - tmp = VISU::GenerateName(theName,++aMap[theName]); + + //--------------------------------------------------------------- + typedef boost::recursive_mutex TMutex; + typedef TMutex::scoped_lock TLock; + + static TMutex myMutex; + + //--------------------------------------------------------------- + struct TGetStudy: public SALOME_Event + { + typedef _PTR(Study) TResult; + TResult myResult; + int myStudyId; + + TGetStudy(const int theStudyId): + myStudyId(theStudyId) + {} + + virtual + void + Execute() + { + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList anApplications = aSession->applications(); + QPtrListIterator anIter (anApplications); + while (SUIT_Application* aSApp = anIter.current()) { + if(SalomeApp_Application* anApp = dynamic_cast(aSApp)){ + if(SalomeApp_Study* aStudy = dynamic_cast(anApp->activeStudy())) { + if(_PTR(Study) aStudyDS = aStudy->studyDS()){ + if(aStudyDS->StudyId() == myStudyId){ + myResult = aStudy->studyDS(); + break; + } + } + } + } + ++anIter; + } + } + }; + + + //--------------------------------------------------------------- + QString + GenerateName (const char* theName) + { + TLock aLock(myMutex); + + typedef map TNameMap; + static TNameMap aMap; + + TNameMap::const_iterator i = aMap.find(theName); + QString tmp; + if (i == aMap.end()) { + aMap[theName] = 0; + tmp = theName; + } else { + tmp = GenerateName(theName,++aMap[theName]); + } + if(MYDEBUG) MESSAGE("GenerateName - "<GetFatherComponent(); + CORBA::String_var aDataType = aCompRefSObj->ComponentDataType(); + return aDataType.in(); + } + + + //--------------------------------------------------------------- + void + CreateReference (SALOMEDS::Study_ptr theStudyDocument, + const string& theFatherEntry, + const string& theRefEntry) + { + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder(); + SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str()); + SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather); + SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str()); + aStudyBuilder->Addreference(newObj,aRefSObj); + } + + + //--------------------------------------------------------------- + void + CreateReference (_PTR(Study) theStudyDocument, + const string& theFatherEntry, + const string& theRefEntry) + { + TLock aLock(myMutex); + + _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder(); + _PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry); + _PTR(SObject) aNewObj = aStudyBuilder->NewObject(aFather); + _PTR(SObject) aRefSObj = theStudyDocument->FindObjectID(theRefEntry); + aStudyBuilder->Addreference(aNewObj,aRefSObj); + } + + string + CreateAttributes(_PTR(Study) theStudyDocument, + const string& theFatherEntry, + const string& theIOR, + const string& theName, + const string& thePersistentRef, + const string& theComment, + CORBA::Boolean theCreateNew) + { + TLock aLock(myMutex); + + _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder(); + _PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry); + + _PTR(SObject) aNewObj; + if(theCreateNew) + aNewObj = aStudyBuilder->NewObject(aFather); + else + aNewObj = aFather; + + _PTR(GenericAttribute) anAttr; + if (theIOR != "") { + anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeIOR"); + _PTR(AttributeIOR) anIOR (anAttr); + anIOR->SetValue(theIOR); + } + if (theName != "") { + anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeName"); + _PTR(AttributeName) aName (anAttr); + aName->SetValue(theName); + } + if (thePersistentRef != "") { + anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributePersistentRef"); + _PTR(AttributePersistentRef) aPRef (anAttr); + aPRef->SetValue(thePersistentRef); + } + if (theComment != "") { + anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeComment"); + _PTR(AttributeComment) aCmnt (anAttr); + aCmnt->SetValue(theComment); + } + return aNewObj->GetID(); + } + + //--------------------------------------------------------------- + struct TResultManager + { + Result_i* myResult; + + TResultManager(Result_i* theResult): + myResult(theResult) + { + myResult->Register(); + } + + ~TResultManager() + { + myResult->Destroy(); + } + }; + + + //--------------------------------------------------------------- + struct TTransactionManager + { + _PTR(StudyBuilder) myStudyBuilder; + + TTransactionManager(_PTR(Study) theStudyDocument): + myStudyBuilder(theStudyDocument->NewBuilder()) + { + TLock aLock(myMutex); + myStudyBuilder->NewCommand(); + } + + ~TTransactionManager() + { + TLock aLock(myMutex); + myStudyBuilder->CommitCommand(); + } + }; + + + //--------------------------------------------------------------- + struct TUpdateObjBrowser: public SALOME_Event + { + int myStudyId; + CORBA::Boolean* myIsDone; + TUpdateObjBrowser(const int theStudyId, + CORBA::Boolean* theIsDone): + myStudyId(theStudyId), + myIsDone(theIsDone) + {} + + virtual + void + Execute() + { + TLock aLock(myMutex); + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList anApplications = aSession->applications(); + QPtrListIterator anIter (anApplications); + while (SUIT_Application* aSApp = anIter.current()) { + if(SalomeApp_Application* anApp = dynamic_cast(aSApp)){ + if (SalomeApp_Study* aStudy = dynamic_cast(anApp->activeStudy())) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + if (myStudyId == aCStudy->StudyId()) { + TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::updateObjectBrowser"); + anApp->updateObjectBrowser(); + *myIsDone = true; + break; + } + } + } + } + ++anIter; + } + } + }; + + + //--------------------------------------------------------------- + void + BuildEntities(Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean* theIsDone, + std::string theResultEntry, + _PTR(Study) theStudy) + { + if(*theIsDone) + return; + + TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildEntities"); + TResultManager aResultManager(theResult); + TTransactionManager aTransactionManager(theStudy); + + { + TTimerLog aTimerLog(MYTIMEDEBUG,"theInput->BuildEntities"); + theInput->BuildEntities(); + } + + QString aComment; + const TMeshMap& aMeshMap = theInput->GetMeshMap(); + TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + const string& aMeshName = aMeshMapIter->first; + const PMesh& aMesh = aMeshMapIter->second; + const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + if(aMeshOnEntityMap.empty()) + continue; + + aComment.sprintf("myComment=MESH;myName=%s;myDim=%d", + aMeshName.c_str(), + aMesh->myDim); + aMesh->myEntry = + CreateAttributes(theStudy, + theResultEntry, + "", + aMeshName, + "", + aComment.latin1(), + true); + + aComment.sprintf("myComment=FAMILIES;myMeshName=%s", + aMeshName.c_str()); + string aSubMeshesEntry = + CreateAttributes(theStudy, + aMesh->myEntry, + "", + "Families", + "", + aComment.latin1(), + true); + //Import entities + TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const TEntity& anEntity = aMeshOnEntityMapIter->first; + const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + + string anEntityName; + switch(anEntity){ + case NODE_ENTITY: + anEntityName = "onNodes"; + break; + case EDGE_ENTITY: + anEntityName = "onEdges"; + break; + case FACE_ENTITY: + anEntityName = "onFaces"; + break; + case CELL_ENTITY: + anEntityName = "onCells"; + break; + default: + continue; + } + + aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d", + VISU::TENTITY, + aMeshName.c_str(), + anEntity); + + aMeshOnEntity->myEntry = + CreateAttributes(theStudy, + aSubMeshesEntry, + "", + anEntityName.c_str(), + "", + aComment.latin1(), + true); + } + } + + ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(),theIsDone)); + } + + //--------------------------------------------------------------- + void + BuildGroups(Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean* theIsDone, + CORBA::Boolean theIsBuild, + _PTR(Study) theStudy) + { + if(!theIsBuild || *theIsDone) + return; + + TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildGroups"); + TResultManager aResultManager(theResult); + TTransactionManager aTransactionManager(theStudy); + + { + TTimerLog aTimerLog(MYTIMEDEBUG,"theInput->BuildGroups"); + theInput->BuildGroups(); + } + + QString aComment; + const TMeshMap& aMeshMap = theInput->GetMeshMap(); + TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + const string& aMeshName = aMeshMapIter->first; + const PMesh& aMesh = aMeshMapIter->second; + + const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + if(aMeshOnEntityMap.empty()) + continue; + + TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const TEntity& anEntity = aMeshOnEntityMapIter->first; + const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + + const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; + TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const string& aFamilyName = aFamilyMapIter->first; + const PFamily& aFamily = aFamilyMapIter->second; + aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", + TFAMILY, + aMeshName.c_str(), + anEntity, + aFamilyName.c_str()); + aFamily->myEntry = + CreateAttributes(theStudy, + aMeshOnEntity->myEntry, + "", + aFamilyName, + "", + aComment.latin1(), + true); + } + } + //Importing groups + const TGroupMap& aGroupMap = aMesh->myGroupMap; + if(!aGroupMap.empty()){ + aComment.sprintf("myComment=GROUPS;myMeshName=%s", + aMeshName.c_str()); + string aGroupsEntry = + CreateAttributes(theStudy, + aMesh->myEntry, + "", + "Groups", + "", + aComment.latin1(), + true); + TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); + for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){ + const string& aGroupName = aGroupMapIter->first; + const PGroup& aGroup = aGroupMapIter->second; + aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s", + TGROUP,aMeshName.c_str(),aGroupName.c_str()); + aGroup->myEntry = + CreateAttributes(theStudy, + aGroupsEntry, + "", + aGroupName, + "", + aComment.latin1(), + true); + const TFamilySet& aFamilySet = aGroup->myFamilySet; + TFamilySet::const_iterator aFamilyIter = aFamilySet.begin(); + for(; aFamilyIter != aFamilySet.end(); aFamilyIter++){ + const PFamily& aFamily = *aFamilyIter; + CreateReference(theStudy, + aGroup->myEntry, + aFamily->myEntry); + } + } + } + } + + ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(),theIsDone)); + } + + + //--------------------------------------------------------------- + void + BuildFields(Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean* theIsDone, + CORBA::Boolean theIsBuild, + _PTR(Study) theStudy) + { + if(!theIsBuild || *theIsDone) + return; + + TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildFields"); + TResultManager aResultManager(theResult); + TTransactionManager aTransactionManager(theStudy); + + { + TTimerLog aTimerLog(MYTIMEDEBUG,"theInput->BuildFields"); + theInput->BuildFields(); + } + + QString aComment; + const TMeshMap& aMeshMap = theInput->GetMeshMap(); + TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + const string& aMeshName = aMeshMapIter->first; + const PMesh& aMesh = aMeshMapIter->second; + + const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + if(aMeshOnEntityMap.empty()) + continue; + + //Import fields + string aFieldsEntry; + bool anIsFieldsEntryCreated = false; + + TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const TEntity& anEntity = aMeshOnEntityMapIter->first; + const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + const TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; + TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); + for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ + if(!anIsFieldsEntryCreated){ + aComment.sprintf("myComment=FIELDS;myMeshName=%s", + aMeshName.c_str()); + aFieldsEntry = + CreateAttributes(theStudy, + aMesh->myEntry, + "", + "Fields", + "", + aComment.latin1(), + true); + anIsFieldsEntryCreated = true; + } + const string& aFieldName = aFieldMapIter->first; + const PField& aField = aFieldMapIter->second; + const TValField& aValField = aField->myValField; + QString aFieldNameWithUnit = GenerateFieldName(aFieldName,aField->myUnitNames[0]); + aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d", + TFIELD, + aMeshName.c_str(), + anEntity, + aFieldName.c_str(), + aValField.size(), + aField->myNbComp); + aField->myEntry = + CreateAttributes(theStudy, + aFieldsEntry, + "", + aFieldNameWithUnit.latin1(), + "", + aComment.latin1(), + true); + CreateReference(theStudy, + aField->myEntry, + aMeshOnEntity->myEntry); + TValField::const_iterator aValFieldIter = aValField.begin(); + for(; aValFieldIter != aValField.end(); aValFieldIter++){ + int aTimeStamp = aValFieldIter->first; + const PValForTime& aValForTime = aValFieldIter->second; + aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + TTIMESTAMP, + aMeshName.c_str(), + anEntity, + aFieldName.c_str(), + aTimeStamp, + aField->myNbComp); + string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime); + aValForTime->myEntry = + CreateAttributes(theStudy, + aField->myEntry, + "", + aTimeStampId, + "", + aComment.latin1(), + true); + } + } + } + } + + ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(),theIsDone)); + } + + + //--------------------------------------------------------------- + void + BuildMinMax(Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean* theIsDone, + CORBA::Boolean theIsBuild, + Result_i::TUpdateMinMaxSignal* theUpdateMinMaxSignal) + { + if(!theIsBuild || *theIsDone) + return; + + TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildMinMax"); + TResultManager aResultManager(theResult); + + theInput->BuildMinMax(); + + *theIsDone = true; + + (*theUpdateMinMaxSignal)(); + } + + + //--------------------------------------------------------------- + void + BuildFieldDataTree(Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean* theIsFieldsDone, + CORBA::Boolean theIsBuildFields, + CORBA::Boolean* theIsMinMaxDone, + CORBA::Boolean theIsBuildMinMax, + Result_i::TUpdateMinMaxSignal* theUpdateMinMaxSignal, + _PTR(Study) theStudy) + { + BuildFields(theResult, + theInput, + theIsFieldsDone, + theIsBuildFields, + theStudy); + + BuildMinMax(theResult, + theInput, + theIsMinMaxDone, + theIsBuildMinMax, + theUpdateMinMaxSignal); + } + + + //--------------------------------------------------------------- + struct TBuildArgs + { + Result_i* myResult; + VISU_Convertor* myInput; + CORBA::Boolean* myIsEntitiesDone; + std::string myResultEntry; + CORBA::Boolean* myIsFieldsDone; + CORBA::Boolean myIsBuildFields; + CORBA::Boolean* myIsMinMaxDone; + CORBA::Boolean myIsBuildMinMax; + Result_i::TUpdateMinMaxSignal* myUpdateMinMaxSignal; + CORBA::Boolean* myIsGroupsDone; + CORBA::Boolean myIsBuildGroups; + _PTR(Study) myStudy; + + TBuildArgs(Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean* theIsEntitiesDone, + std::string theResultEntry, + CORBA::Boolean* theIsFieldsDone, + CORBA::Boolean theIsBuildFields, + CORBA::Boolean* theIsMinMaxDone, + CORBA::Boolean theIsBuildMinMax, + Result_i::TUpdateMinMaxSignal* theUpdateMinMaxSignal, + CORBA::Boolean* theIsGroupsDone, + CORBA::Boolean theIsBuildGroups, + _PTR(Study) theStudy): + myResult(theResult), + myInput(theInput), + myIsEntitiesDone(theIsEntitiesDone), + myResultEntry(theResultEntry), + myIsFieldsDone(theIsFieldsDone), + myIsBuildFields(theIsBuildFields), + myIsMinMaxDone(theIsMinMaxDone), + myIsBuildMinMax(theIsBuildMinMax), + myUpdateMinMaxSignal(theUpdateMinMaxSignal), + myIsGroupsDone(theIsGroupsDone), + myIsBuildGroups(theIsBuildGroups), + myStudy(theStudy) + {} + + }; + + //--------------------------------------------------------------- + void + BuildDataTree(TBuildArgs theBuildArgs) + { + BuildEntities(theBuildArgs.myResult, + theBuildArgs.myInput, + theBuildArgs.myIsEntitiesDone, + theBuildArgs.myResultEntry, + theBuildArgs.myStudy); + { + boost::thread aThread(boost::bind(&BuildGroups, + theBuildArgs.myResult, + theBuildArgs.myInput, + theBuildArgs.myIsGroupsDone, + theBuildArgs.myIsBuildGroups, + theBuildArgs.myStudy)); + } + { + boost::thread aThread(boost::bind(&BuildFieldDataTree, + theBuildArgs.myResult, + theBuildArgs.myInput, + theBuildArgs.myIsFieldsDone, + theBuildArgs.myIsBuildFields, + theBuildArgs.myIsMinMaxDone, + theBuildArgs.myIsBuildMinMax, + theBuildArgs.myUpdateMinMaxSignal, + theBuildArgs.myStudy)); + } + } + } -void CreateReference (SALOMEDS::Study_ptr theStudyDocument, - const string& theFatherEntry, const string& theRefEntry) + +//--------------------------------------------------------------- +VISU::MinMaxCunsomer +::MinMaxCunsomer(): + myMinMaxIsInitilized(false) +{} + +bool +VISU::MinMaxCunsomer +::IsMinMaxInitilized() { - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder(); - SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str()); - SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather); - SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str()); - aStudyBuilder->Addreference(newObj,aRefSObj); + return myMinMaxIsInitilized; } -string GetComponentDataType (SALOMEDS::SObject_ptr theSObject) +void +VISU::MinMaxCunsomer +::UpdateMinMax() { - SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent(); - CORBA::String_var aDataType = aCompRefSObj->ComponentDataType(); - return aDataType.in(); + myMinMaxIsInitilized = true; } -//============================================================================== +//--------------------------------------------------------------- const string VISU::Result_i::myComment = "RESULT"; const char* VISU::Result_i::GetComment() const { return myComment.c_str();} -VISU::Result_i::Result_i (SALOMEDS::Study_ptr theStudy, - const ESourceId& theSourceId, - const ECreationId& theCreationId): +//--------------------------------------------------------------- +VISU::Result_i +::Result_i (SALOMEDS::Study_ptr theStudy, + const ESourceId& theSourceId, + const ECreationId& theCreationId, + CORBA::Boolean theIsBuildImmediately): myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)), myCreationId(theCreationId), mySourceId(theSourceId), + myIsBuildImmediately(theIsBuildImmediately), myInput(NULL), - myIsDone(0) + myIsEntitiesDone(false), + myIsFieldsDone(false), + myIsGroupsDone(false), + myIsMinMaxDone(false), + myIsBuildFields(true), + myIsBuildGroups(true), + myIsBuildMinMax(true), + myIsAllDone(false) { + myStudy = ProcessEvent(new TGetStudy(myStudyDocument->StudyId())); } -void VISU::Result_i::RemoveFromStudy() +//--------------------------------------------------------------- +void +VISU::Result_i +::RemoveFromStudy() { + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Result_i* myRemovable; + TRemoveFromStudy(VISU::Result_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + VISU::RemoveFromStudy(myRemovable->GetSObject(),false); + myRemovable->Destroy(); + } + }; + // Remove the result with all presentations and other possible sub-objects - VISU::RemoveFromStudy(mySObject,false); + ProcessVoidEvent(new TRemoveFromStudy(this)); } +//--------------------------------------------------------------- +void +VISU::Result_i +::MinMaxConnect(VISU::MinMaxCunsomer* theMinMaxCunsomer) +{ + myUpdateMinMaxSignal.connect(boost::bind(&MinMaxCunsomer::UpdateMinMax,theMinMaxCunsomer)); +} + + +//--------------------------------------------------------------- int -VISU::Result_i:: -IsPossible() +VISU::Result_i +::IsPossible() { try{ float aSize = myInput->GetSize(); @@ -161,13 +860,16 @@ IsPossible() } +//--------------------------------------------------------------- CORBA::Boolean -VISU::Result_i:: -BuildAll() +VISU::Result_i +::BuildAll() { - if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<NewBuilder(); - aStudyBuilder->NewCommand(); // There is a transaction - - try { - const TMeshMap& aMeshMap = myInput->GetMeshMap(); - if (aMeshMap.empty()) - throw std::runtime_error("Build - There is no any mesh information in the file !!!"); - - mySComponent = FindOrCreateVisuComponent(myStudyDocument); - CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID()); - string aRefFatherEntry = GetRefFatherEntry(); + if(Build(SALOMEDS::SObject::_nil(),theIsAtOnce)){ + if(theIsBuildAll) + return BuildAll(); + return true; + } - QString aComment; - aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s", - GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(), - myInitFileName.c_str()); // Restoring of Python dump - string aResultEntry = - CreateAttributes(myStudyDocument, aSComponentEntry, aRefFatherEntry.c_str(), - anIOR, myName.c_str(), "", aComment.latin1(), true); + return false; +} - mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str()); - if (mySObject->_is_nil()) - throw std::runtime_error("Build - There is no SObject for the Result !!!"); - if (!CORBA::is_nil(theSObject)) { - CORBA::String_var aString = theSObject->GetID(); - CreateReference(myStudyDocument, aResultEntry, aString.in()); - } +//--------------------------------------------------------------- +VISU::Storable* +VISU::Result_i +::Build(SALOMEDS::SObject_ptr theSObject, + CORBA::Boolean theIsAtOnce) +{ + if(!myInput) + return NULL; - TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); - for (; aMeshMapIter != aMeshMap.end(); aMeshMapIter++) { - const string& aMeshName = aMeshMapIter->first; - const VISU::PMesh aMesh = aMeshMapIter->second; - aComment.sprintf("myComment=MESH;myName=%s;myDim=%d", - aMeshName.c_str(), aMesh->myDim); - string aMeshEntry = - CreateAttributes(myStudyDocument, aResultEntry.c_str(), aRefFatherEntry.c_str(), - "", aMeshName.c_str(), "", aComment.latin1(), true); + if(IsDone()) + return this; - const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; - if (aMeshOnEntityMap.empty()) continue; - - aComment.sprintf("myComment=FAMILIES;myMeshName=%s", aMeshName.c_str()); - string aSubMeshesEntry = - CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(), - "", "Families", "", aComment.latin1(), true); - - //Import entities and according families - typedef std::map TComment2EntryMap; - typedef std::map TEntity2EntryMap; - TComment2EntryMap aComment2EntryMap; - TEntity2EntryMap aEntity2EntryMap; - - VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); - for (; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) { - const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; - aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d", - VISU::TENTITY, aMeshName.c_str(), anEntity); - string anEntityName; - switch (anEntity) { - case VISU::NODE_ENTITY : anEntityName = "onNodes"; break; - case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break; - case VISU::FACE_ENTITY : anEntityName = "onFaces"; break; - case VISU::CELL_ENTITY : anEntityName = "onCells"; break; - default: - throw std::runtime_error("Build >> Value of entity is incorrect!"); - } - aEntity2EntryMap[anEntity] = CreateAttributes - (myStudyDocument, aSubMeshesEntry.c_str(), aRefFatherEntry.c_str(), - "", anEntityName.c_str(), "", aComment.latin1(), true); + mySComponent = FindOrCreateVisuComponent(myStudyDocument); + CORBA::String_var aSComponentEntry = mySComponent->GetID(); + CORBA::String_var anIOR(GetID()); + QString aComment; + aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s", + GetComment(), + VISU::TRESULT, + myFileInfo.filePath().latin1(), + myInitFileName.c_str()); // Restoring of Python dump + string aResultEntry = + CreateAttributes(myStudy, + aSComponentEntry.in(), + anIOR.in(), + myName, + "", + aComment.latin1(), + true); + mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str()); + if(!CORBA::is_nil(theSObject)){ + CORBA::String_var aString = theSObject->GetID(); + CreateReference(myStudyDocument,aResultEntry,aString.in()); + } - const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second; - const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; - VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); - for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++) { - const string& aFamilyName = aFamilyMapIter->first; - aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", - VISU::TFAMILY, aMeshName.c_str(), anEntity, aFamilyName.c_str()); - aComment2EntryMap[aComment.latin1()] = - CreateAttributes(myStudyDocument, aEntity2EntryMap[anEntity].c_str(), aRefFatherEntry.c_str(), - "", aFamilyName.c_str(), "", aComment.latin1(), true); - } - } + if(theIsAtOnce){ + BuildEntities(this, + myInput, + &myIsEntitiesDone, + aResultEntry, + myStudy); + + BuildGroups(this, + myInput, + &myIsGroupsDone, + myIsBuildGroups, + myStudy); + + BuildFields(this, + myInput, + &myIsFieldsDone, + myIsBuildFields, + myStudy); + + BuildMinMax(this, + myInput, + &myIsMinMaxDone, + myIsBuildMinMax, + &myUpdateMinMaxSignal); + + }else{ + TBuildArgs aBuildArgs(this, + myInput, + &myIsEntitiesDone, + aResultEntry, + &myIsFieldsDone, + myIsBuildFields, + &myIsMinMaxDone, + myIsBuildMinMax, + &myUpdateMinMaxSignal, + &myIsGroupsDone, + myIsBuildGroups, + myStudy); + boost::thread aThread(boost::bind(&BuildDataTree, + aBuildArgs)); + } - //Importing groups - const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap; - if (aGroupMap.size() > 0) { - aComment.sprintf("myComment=GROUPS;myMeshName=%s", aMeshName.c_str()); - string aGroupsEntry = - CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(), - "", "Groups", "", aComment.latin1(), true); + return this; +} - VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); - for (; aGroupMapIter != aGroupMap.end(); aGroupMapIter++) { - const string& aGroupName = aGroupMapIter->first; - aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s", - VISU::TGROUP, aMeshName.c_str(), aGroupName.c_str()); - string aGroupEntry = - CreateAttributes(myStudyDocument, aGroupsEntry.c_str(), aRefFatherEntry.c_str(), - "", aGroupName.c_str(), "", aComment.latin1(), true); - - const VISU::PGroup aGroup = aGroupMapIter->second; - const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet; - VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin(); - for (; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++) { - const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; - const string& aFamilyName = aFamilyAndEntity.first; - const VISU::TEntity& anEntity = aFamilyAndEntity.second; - aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", - VISU::TFAMILY, aMeshName.c_str(), anEntity, aFamilyName.c_str()); - if (aComment2EntryMap.count(aComment.latin1()) > 0) - CreateReference(myStudyDocument, aGroupEntry, aComment2EntryMap[aComment.latin1()]); - } - } - } - //Import fields - string aFieldsEntry; - bool isFieldEntryCreated = 0; - aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); - for (; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) { - const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; - const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second; - const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; - VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); - for (; aFieldMapIter != aFieldMap.end(); aFieldMapIter++) { - if (!isFieldEntryCreated) { - aComment.sprintf("myComment=FIELDS;myMeshName=%s", aMeshName.c_str()); - aFieldsEntry = - CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(), - "", "Fields", "", aComment.latin1(), true); - isFieldEntryCreated = true; - } - const string& aFieldName = aFieldMapIter->first; - const VISU::PField aField = aFieldMapIter->second; - const VISU::TValField& aValField = aField->myValField; - QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]); - aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;" - "myNbTimeStamps=%d;myNumComponent=%d", - VISU::TFIELD, aMeshName.c_str(), anEntity, aFieldName.c_str(), - aValField.size(), aField->myNbComp); - string aFieldEntry = - CreateAttributes(myStudyDocument, aFieldsEntry.c_str(), aRefFatherEntry.c_str(), - "", aFieldNameWithUnit.latin1(), "", aComment.latin1(), true); - CreateReference(myStudyDocument, aFieldEntry, aEntity2EntryMap[anEntity]); - - VISU::TValField::const_iterator aValFieldIter = aValField.begin(); - for (; aValFieldIter != aValField.end(); aValFieldIter++) { - int aTimeStamp = aValFieldIter->first; - const VISU::PValForTime aValForTime = aValFieldIter->second; - aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;" - "myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", - VISU::TTIMESTAMP, aMeshName.c_str(), anEntity, - aFieldName.c_str(), aTimeStamp, aField->myNbComp); - string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime); - CreateAttributes(myStudyDocument, aFieldEntry.c_str(), aRefFatherEntry.c_str(), - "", aTimeStampId.c_str(), "", aComment.latin1(), true); - } - } - } - } - bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false); - if (isBuildAll) BuildAll(); - } catch(std::exception& exc) { +//--------------------------------------------------------------- +VISU::Storable* +VISU::Result_i +::BuildAll(SALOMEDS::SObject_ptr theSObject) +{ + if(MYDEBUG) MESSAGE("Result_i::Build"); + try{ + Build(theSObject); + BuildAll(); + }catch(std::exception& exc){ INFOS("Follow exception was occured :\n"<CommitCommand(); + return this; } +//--------------------------------------------------------------- VISU::Storable* VISU::Result_i:: Create(const char* theFileName) @@ -446,9 +1089,11 @@ Create(const char* theFileName) myFileInfo.setFile(QString(aTmpDir.c_str()) + myFileInfo.fileName()); } myInput = CreateConvertor(myFileInfo.absFilePath().latin1()); - if(!myInput) - throw std::runtime_error("Create - Cannot create a Convertor for this file!!!"); - return Build(); + if(myInput){ + if(myIsBuildImmediately) + Build(SALOMEDS::SObject::_nil()); + return this; + } }catch(std::exception& exc){ INFOS("Follow exception was occured :\n"<Build(); + string aCompDataType = GetComponentDataType(theMedSObject); myFileInfo.setFile(aCompDataType.c_str()); myInitFileName = aCompDataType; myName = ::GenerateName("aResult").latin1(); - VISU::Storable* aStorable = Build(theMedSObject); - return aStorable; + return Build(theMedSObject); }catch(std::exception& exc){ INFOS("Follow exception was occured :\n"<Build(); + string aCompDataType = "MED"; myFileInfo.setFile(aCompDataType.c_str()); myInitFileName = aCompDataType; @@ -503,8 +1154,7 @@ Create(SALOME_MED::FIELD_ptr theField) CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField); SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR); - VISU::Storable* aStorable = Build(aFieldSObject); - return aStorable; + return Build(aFieldSObject); }catch(std::exception& exc){ INFOS("Follow exception was occured :\n"<NewBuilder(); SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp); aStudyBuilder->LoadWith(aCompRefSObj, aDriver); - if (strcmp(aDataType, "MED") == 0) { + if (strcmp(aDataType, "MED") == 0){ // create field or MED converter CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj); SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject); @@ -551,8 +1202,8 @@ Restore(SALOMEDS::SObject_ptr theSObject, myInput = CreateMEDFieldConvertor(aField); else myInput = CreateMEDConvertor(aTargetRefSObj); - } - else + myInput->Build(); + }else throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!"); } else { myFileInfo.setFile(thePrefix.c_str()); @@ -607,6 +1258,7 @@ Restore(SALOMEDS::SObject_ptr theSObject, } if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId); myInput = CreateConvertor(myFileInfo.filePath().latin1()); + myInput->Build(); QString aComment; aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s", GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(), @@ -629,21 +1281,91 @@ Restore(SALOMEDS::SObject_ptr theSObject, return NULL; } -VISU::Result_i::TInput* VISU::Result_i::GetInput() { +//--------------------------------------------------------------- +VISU::Result_i::TInput* +VISU::Result_i +::GetInput() +{ return myInput; } -void VISU::Result_i::ToStream(std::ostringstream& theStr){ +//--------------------------------------------------------------- +CORBA::Boolean +VISU::Result_i +::IsDone() +{ + return + myIsEntitiesDone && + (myIsBuildFields? myIsFieldsDone: true) && + (myIsBuildMinMax? myIsMinMaxDone: true) && + (myIsBuildGroups? myIsGroupsDone: true); +} + +CORBA::Boolean +VISU::Result_i +::IsEntitiesDone() +{ + return myIsEntitiesDone; +} + +void +VISU::Result_i +::SetBuildFields(CORBA::Boolean theIsBuildFields, + CORBA::Boolean theIsCalculateMinMax) +{ + myIsBuildFields = theIsBuildFields; + if(theIsBuildFields) + myIsBuildMinMax = theIsCalculateMinMax; + else + myIsBuildMinMax = false; +} + +void +VISU::Result_i +::SetBuildGroups(CORBA::Boolean theIsBuildGroups) +{ + myIsBuildGroups = theIsBuildGroups; +} + +CORBA::Boolean +VISU::Result_i +::IsFieldsDone() +{ + return myIsFieldsDone; +} + +CORBA::Boolean +VISU::Result_i +::IsGroupsDone() +{ + return myIsGroupsDone; +} + +CORBA::Boolean +VISU::Result_i +::IsMinMaxDone() +{ + return myIsMinMaxDone; +} + +//--------------------------------------------------------------- +void +VISU::Result_i +::ToStream(std::ostringstream& theStr) +{ if(MYDEBUG) MESSAGE(GetComment()); Storable::DataToStream(theStr,"myName",myName.c_str()); Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str()); Storable::DataToStream(theStr,"myCreationId",myCreationId); } + +//--------------------------------------------------------------- VISU::Storable* -VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject, - const string& thePrefix, - const Storable::TRestoringMap& theMap) +VISU::Result_i +::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, + const Storable::TRestoringMap& theMap) { SALOMEDS::Study_var aStudy = theSObject->GetStudy(); @@ -659,25 +1381,55 @@ VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject, return pResult->Restore(theSObject,theMap,thePrefix); } -string VISU::Result_i::GetRefFatherEntry() { - //return QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry(); + +//--------------------------------------------------------------- +string +VISU::Result_i +::GetRefFatherEntry() +{ return ""; } -string VISU::Result_i::GetEntry(){ +string +VISU::Result_i +::GetEntry() +{ CORBA::String_var anEntry = mySObject->GetID(); return string(anEntry); } -const SALOMEDS::SObject_var& VISU::Result_i::GetSObject() const { return mySObject;} -const SALOMEDS::Study_var& VISU::Result_i::GetStudyDocument() const { return myStudyDocument;} -const SALOMEDS::SComponent_var& VISU::Result_i::GetSComponent() const { return mySComponent;} -std::string VISU::Result_i::GetEntry(const std::string& theComment) +const SALOMEDS::SObject_var& +VISU::Result_i +::GetSObject() const +{ + return mySObject; +} + +const SALOMEDS::Study_var& +VISU::Result_i +::GetStudyDocument() const +{ + return myStudyDocument; +} + +const SALOMEDS::SComponent_var& +VISU::Result_i +::GetSComponent() const +{ + return mySComponent; +} + +std::string +VISU::Result_i +::GetEntry(const std::string& theComment) { return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str()); } -VISU::Result_i::~Result_i() + +//--------------------------------------------------------------- +VISU::Result_i +::~Result_i() { MESSAGE("Result_i::~Result_i() - this = "<* Result_i::GetAxisInfo(const string& theMeshName, MESSAGE("No mesh named " << theMeshName ); return components; } - VISU_Convertor::TOutput* vtkMesh = myInput->GetMeshOnEntity (theMeshName, - CELL_ENTITY); - if ( !vtkMesh || vtkMesh->GetNumberOfCells() == 0 ) { + + VISU::PIDMapper anIDMapper = myInput->GetMeshOnEntity(theMeshName, + CELL_ENTITY); + VISU::TVTKOutput* aMesh = anIDMapper->GetVTKOutput(); + + if ( !aMesh || aMesh->GetNumberOfCells() == 0 ) { MESSAGE( "No cells in the mesh: " << theMeshName ); return components; } @@ -734,9 +1489,9 @@ const vector< float >* Result_i::GetAxisInfo(const string& theMeshName, gp_Vec axDirs[ nbAxes ]; float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX }; bool axesComputed = false; - for ( vtkIdType iCell = 0; iCell < vtkMesh->GetNumberOfCells(); ++iCell ) + for ( vtkIdType iCell = 0; iCell < aMesh->GetNumberOfCells(); ++iCell ) { - vtkCell* cell = vtkMesh->GetCell( iCell ); + vtkCell* cell = aMesh->GetCell( iCell ); int nbPnt = cell->GetNumberOfPoints(); if ( nbPnt != 8 ) continue; @@ -784,8 +1539,8 @@ const vector< float >* Result_i::GetAxisInfo(const string& theMeshName, // on axis direction; define bnd box set< float > comps[ 3 ]; Bnd_Box box; - vtkPoints * points = vtkMesh->GetPoints(); - vtkIdType iP, nbP = vtkMesh->GetNumberOfPoints(); + vtkPoints * points = aMesh->GetPoints(); + vtkIdType iP, nbP = aMesh->GetNumberOfPoints(); for ( iP = 0; iP < nbP; ++iP ) { float* coo = points->GetPoint( iP ); diff --git a/src/VISU_I/VISU_Result_i.hh b/src/VISU_I/VISU_Result_i.hh index beb1e558..ee903de6 100644 --- a/src/VISU_I/VISU_Result_i.hh +++ b/src/VISU_I/VISU_Result_i.hh @@ -30,13 +30,35 @@ #include "VISUConfig.hh" #include "SALOME_GenericObj_i.hh" -#include +#include +#include +#include #include class VISU_Convertor; -namespace VISU{ +namespace VISU +{ + //---------------------------------------------------------------------------- + class MinMaxCunsomer: public virtual boost::bsignals::trackable + { + protected: + bool myMinMaxIsInitilized; + MinMaxCunsomer(); + + public: + virtual + bool + IsMinMaxInitilized(); + + virtual + void + UpdateMinMax(); + }; + + + //---------------------------------------------------------------------------- class Result_i : public virtual POA_VISU::Result, public virtual RemovableObject_i, public virtual SALOME::GenericObj_i @@ -50,7 +72,8 @@ namespace VISU{ Result_i(SALOMEDS::Study_ptr theStudy, const ESourceId& theSourceId, - const ECreationId& theCreationId); + const ECreationId& theCreationId, + CORBA::Boolean theIsBuildImmediately = true); virtual ~Result_i(); virtual void RemoveFromStudy(); @@ -58,6 +81,27 @@ namespace VISU{ virtual VISU::VISUType GetType() { return VISU::TRESULT;} virtual CORBA::Boolean BuildAll(); + virtual CORBA::Boolean Build(CORBA::Boolean theIsBuildAll, + CORBA::Boolean theIsAtOnce); + virtual CORBA::Boolean IsDone(); + + virtual CORBA::Boolean IsEntitiesDone(); + + virtual void SetBuildFields(CORBA::Boolean theIsBuildFields, + CORBA::Boolean theIsCalculateMinMax); + virtual CORBA::Boolean IsFieldsDone(); + + virtual void SetBuildGroups(CORBA::Boolean theIsBuildGroups); + virtual CORBA::Boolean IsGroupsDone(); + + virtual CORBA::Boolean IsMinMaxDone(); + + virtual + void + MinMaxConnect(MinMaxCunsomer* theMinMaxCunsomer); + + typedef boost::signal0 TUpdateMinMaxSignal; + typedef VISU_Convertor TInput; private: @@ -65,12 +109,29 @@ namespace VISU{ ECreationId myCreationId; TInput *myInput; - CORBA::Boolean myIsDone; std::string myName, myInitFileName; QFileInfo myFileInfo; protected: - virtual Storable* Build(SALOMEDS::SObject_ptr theSObject = SALOMEDS::SObject::_nil()) ; + virtual Storable* Build(SALOMEDS::SObject_ptr theSObject, + CORBA::Boolean theIsAtOnce = true) ; + virtual Storable* BuildAll(SALOMEDS::SObject_ptr theSObject) ; + + _PTR(Study) myStudy; + CORBA::Boolean myIsBuildImmediately; + + CORBA::Boolean myIsEntitiesDone; + CORBA::Boolean myIsFieldsDone; + CORBA::Boolean myIsGroupsDone; + CORBA::Boolean myIsMinMaxDone; + + CORBA::Boolean myIsBuildFields; + CORBA::Boolean myIsBuildGroups; + + CORBA::Boolean myIsBuildMinMax; + TUpdateMinMaxSignal myUpdateMinMaxSignal; + + CORBA::Boolean myIsAllDone; public: virtual int IsPossible(); diff --git a/src/VISU_I/VISU_ScalarMapOnDeformedShape_i.cc b/src/VISU_I/VISU_ScalarMapOnDeformedShape_i.cc new file mode 100644 index 00000000..3246f8f2 --- /dev/null +++ b/src/VISU_I/VISU_ScalarMapOnDeformedShape_i.cc @@ -0,0 +1,283 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_ScalarMapOnDeformedShape_i.cc +// Author : Eugeny Nikolaev +// Module : VISU + +#include "VISU_ScalarMapOnDeformedShapePL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_ScalarMap_i.hh" +#include "VISU_ScalarMapOnDeformedShape_i.hh" +#include "VISU_Convertor.hxx" +#include "VISU_ScalarMapAct.h" + +#include +#include +#include + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +static int INCMEMORY = 4+12; + +int VISU::ScalarMapOnDeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration, int isMemoryCheck) +{ + bool aResult = false; + try{ + aResult = VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false); + if(isMemoryCheck && aResult){ + float aSize = INCMEMORY* + theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration); + aResult = VISU_PipeLine::CheckAvailableMemory(aSize); + MESSAGE("ScalarMapOnDeformedShape_i::IsPossible - CheckAvailableMemory = "<GetStudyDocument()), + Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), + ScalarMap_i(theResult,theAddToStudy), + myScalarMapOnDeformedShapePL(NULL), + myScalarIteration(1) +{ +} + +VISU::ScalarMapOnDeformedShape_i:: +ScalarMapOnDeformedShape_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), + ScalarMap_i(theResult,theSObject), + myScalarMapOnDeformedShapePL(NULL), + myScalarIteration(1) +{ +} + +VISU::Storable* VISU::ScalarMapOnDeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + myIsColored = true; + myColor.R = myColor.G = myColor.B = 0.5; + VISU::Storable* aRes = TSuperClass::Create(theMeshName,theEntity,theFieldName,theIteration); + SetScalarFieldName(theFieldName); + SetScalarIteration(theIteration); + SetScalarMeshName(theMeshName); + int anEntity = theEntity; + SetScalarEntity(VISU::TEntity(anEntity)); + SetScalarField(myScalarMeshName.c_str(),myScalarFieldName.c_str(),myScalarIteration,myScalarEntity); + return aRes; +} + +VISU::Storable* VISU::ScalarMapOnDeformedShape_i::Restore(const Storable::TRestoringMap& theMap) +{ + TSuperClass::Restore(theMap); + + SetScalarFieldName(VISU::Storable::FindValue(theMap,"myScalarFieldName")); + SetScalarMeshName(VISU::Storable::FindValue(theMap,"myScalarMeshName")); + SetScalarIteration(VISU::Storable::FindValue(theMap,"myScalarIteration").toInt()); + SetScalarEntity(VISU::TEntity(VISU::Storable::FindValue(theMap,"myScalarEntity").toInt())); + SetScalarField(GetScalarMeshName().c_str(), + GetScalarFieldName().c_str(), + GetScalarIteration(), + GetScalarEntity()); + + SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble()); + myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt(); + myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble(); + myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble(); + myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble(); + + return this; +} + +void VISU::ScalarMapOnDeformedShape_i::ToStream(std::ostringstream& theStr) +{ + TSuperClass::ToStream(theStr); + + Storable::DataToStream( theStr, "myScalarFieldName", myScalarFieldName.c_str()); + Storable::DataToStream( theStr, "myScalarMeshName", myScalarMeshName.c_str()); + Storable::DataToStream( theStr, "myScalarIteration", myScalarIteration); + Storable::DataToStream( theStr, "myScalarEntity", int(myScalarEntity)); + + Storable::DataToStream( theStr, "myFactor", GetScale() ); + Storable::DataToStream( theStr, "myIsColored", myIsColored ); + Storable::DataToStream( theStr, "myColor.R", myColor.R ); + Storable::DataToStream( theStr, "myColor.G", myColor.G ); + Storable::DataToStream( theStr, "myColor.B", myColor.B ); + +} + +VISU::ScalarMapOnDeformedShape_i::~ScalarMapOnDeformedShape_i(){ + if(MYDEBUG) MESSAGE("ScalarMapOnDeformedShape_i::~ScalarMapOnDeformedShape_i()"); +} + +void +VISU::ScalarMapOnDeformedShape_i +::SameAs(const Prs3d_i* theOrigin) +{ + TSuperClass::SameAs(theOrigin); + + if(const ScalarMapOnDeformedShape_i* aPrs3d = dynamic_cast(theOrigin)){ + ScalarMapOnDeformedShape_i* anOrigin = const_cast(aPrs3d); + + // increment the scalar iteration for using in VISU_TimeAnimation class implementation. + this->SetScalarField(anOrigin->GetScalarMeshName().c_str(), + anOrigin->GetScalarFieldName().c_str(), + anOrigin->GetScalarIteration() + 1, + anOrigin->GetScalarEntity()); + Update(); + } +} + +void VISU::ScalarMapOnDeformedShape_i::SetScale(CORBA::Double theScale) { + myScalarMapOnDeformedShapePL->SetScale(theScale); +} + +CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetScale(){ + return myScalarMapOnDeformedShapePL->GetScale(); +} + +void VISU::ScalarMapOnDeformedShape_i::SetSourceRange(CORBA::Double theMinRange,CORBA::Double theMaxRange){ + float aRange[2]; + aRange[0] = float(theMinRange); + aRange[1] = float(theMaxRange); + myScalarMapOnDeformedShapePL->SetScalarRange(aRange); +} + +CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetSourceRangeMin(){ + float aRange[2]; + myScalarMapOnDeformedShapePL->GetSourceRange(aRange); + return aRange[0]; +} + +CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetSourceRangeMax(){ + float aRange[2]; + myScalarMapOnDeformedShapePL->GetSourceRange(aRange); + return aRange[1]; +} + +void VISU::ScalarMapOnDeformedShape_i::DoHook() +{ + if(!myPipeLine) + myPipeLine = VISU_ScalarMapOnDeformedShapePL::New(); + + myScalarMapOnDeformedShapePL = dynamic_cast(myPipeLine); + myPipeLine->GetMapper()->SetScalarVisibility(IsColored()); + + TSuperClass::DoHook(); +} + +VISU_Actor* VISU::ScalarMapOnDeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +{ + VISU_Actor* anActor = TSuperClass::CreateActor(theIO); + anActor->SetRepresentation(2); + anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B); + anActor->SetVTKMapping(false); + return anActor; +} + + +void VISU::ScalarMapOnDeformedShape_i::UpdateActor(VISU_Actor* theActor) { + if(VISU_ScalarMapAct* anActor = dynamic_cast(theActor)){ + if(IsColored()){ + anActor->SetBarVisibility(true); + myPipeLine->GetMapper()->SetScalarVisibility(1); + }else{ + anActor->SetBarVisibility(false); + myPipeLine->GetMapper()->SetScalarVisibility(0); + anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B); + } + TSuperClass::UpdateActor(theActor); + } +} + +void VISU::ScalarMapOnDeformedShape_i::SetScalarField(const char* theMeshName, + const char* theFieldName, + const int theIteration, + const VISU::TEntity theEntity) +{ + if (myScalarMapOnDeformedShapePL){ + myField = myResult->GetInput()->GetField(theMeshName,theEntity,theFieldName); + TVTKOutput* aOut = myResult->GetInput()->GetTimeStampOnMesh(theMeshName, + theEntity, + theFieldName, + theIteration)->GetVTKOutput(); + myScalarMapOnDeformedShapePL->SetScalars(aOut); + } + this->SetScalarMeshName(theMeshName); + this->SetScalarFieldName(theFieldName); + this->SetScalarIteration(theIteration); + this->SetScalarEntity(theEntity); +} + + +void VISU::ScalarMapOnDeformedShape_i::SetScalarMeshName(const char* theName){ + myScalarMeshName = theName; +} +std::string VISU::ScalarMapOnDeformedShape_i::GetScalarMeshName(){ + return myScalarMeshName; +} + +void VISU::ScalarMapOnDeformedShape_i::SetScalarFieldName(const char* theName){ + myScalarFieldName = theName; +} +std::string VISU::ScalarMapOnDeformedShape_i::GetScalarFieldName(){ + return myScalarFieldName; +} + +void VISU::ScalarMapOnDeformedShape_i::SetScalarIteration(const int theValue){ + myScalarIteration = theValue; +} +int VISU::ScalarMapOnDeformedShape_i::GetScalarIteration(){ + return myScalarIteration; +} + +void VISU::ScalarMapOnDeformedShape_i::SetScalarEntity(const VISU::TEntity theValue){ + myScalarEntity = theValue; +} +VISU::TEntity VISU::ScalarMapOnDeformedShape_i::GetScalarEntity(){ + return myScalarEntity; +} diff --git a/src/VISU_I/VISU_ScalarMapOnDeformedShape_i.hh b/src/VISU_I/VISU_ScalarMapOnDeformedShape_i.hh new file mode 100644 index 00000000..b7433720 --- /dev/null +++ b/src/VISU_I/VISU_ScalarMapOnDeformedShape_i.hh @@ -0,0 +1,133 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_ScalarMapOnDeformedShape_i.hh +// Author: Eugeny Nikolaev +// Module : VISU + +#ifndef VISU_ScalarMapOnDeformedShape_i_HeaderFile +#define VISU_ScalarMapOnDeformedShape_i_HeaderFile + +#include "VISU_ScalarMap_i.hh" + +class VISU_ScalarMapOnDeformedShapePL; + +namespace VISU{ + + //! Class of Scalar Map on Deformed Shape presentation. + class ScalarMapOnDeformedShape_i : public virtual POA_VISU::ScalarMapOnDeformedShape, + public virtual ScalarMap_i + { + static int myNbPresent; + ScalarMapOnDeformedShape_i(); + ScalarMapOnDeformedShape_i(const ScalarMapOnDeformedShape_i&); + + public: + + typedef ScalarMap_i TSuperClass; + + explicit + ScalarMapOnDeformedShape_i(Result_i* theResult, + bool theAddToStudy); + explicit + ScalarMapOnDeformedShape_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject); + + virtual ~ScalarMapOnDeformedShape_i(); + + virtual VISU::VISUType GetType() + { + return VISU::TSCALARMAPONDEFORMEDSHAPE; + }; + + typedef VISU::ScalarMapOnDeformedShape TInterface; + + virtual void SetScale(CORBA::Double theScale); + virtual CORBA::Double GetScale(); + + virtual CORBA::Boolean IsColored() { return myIsColored; } + virtual void ShowColored(CORBA::Boolean theColored) { myIsColored = theColored; } + + virtual SALOMEDS::Color GetColor() { return myColor;} + virtual void SetColor(const SALOMEDS::Color& theColor) { myColor = theColor;} + + virtual void SetSourceRange(CORBA::Double theMinRange,CORBA::Double theMaxRange); + virtual CORBA::Double GetSourceRangeMin(); + virtual CORBA::Double GetSourceRangeMax(); + + virtual + void + SameAs(const Prs3d_i* theOrigin); + + VISU_ScalarMapOnDeformedShapePL* GetScalarMapOnDeformedShapePL(){ return myScalarMapOnDeformedShapePL;} + + protected: + + virtual + void + DoHook(); + + VISU_ScalarMapOnDeformedShapePL *myScalarMapOnDeformedShapePL; + SALOMEDS::Color myColor; + bool myIsColored; + std::string myScalarMeshName; + std::string myScalarFieldName; + VISU::TEntity myScalarEntity; + int myScalarIteration; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration, int isMemoryCheck = true); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + virtual void ToStream(std::ostringstream& theStr); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap); + + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const std::string& thePrefix, const Storable::TRestoringMap& theMap); + + static const std::string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + + virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + + virtual void UpdateActor(VISU_Actor* theActor) ; + + virtual void SetScalarField(const char* theMeshName, + const char* theFieldName, + const int theIteration, + const VISU::TEntity theEntity); + + virtual void SetScalarFieldName(const char* theName); + virtual std::string GetScalarFieldName(); + virtual void SetScalarIteration(const int theValue); + virtual int GetScalarIteration(); + virtual void SetScalarMeshName(const char* theName); + virtual std::string GetScalarMeshName(); + virtual void SetScalarEntity(const VISU::TEntity theValue); + virtual VISU::TEntity GetScalarEntity(); + }; +} +#endif diff --git a/src/VISU_I/VISU_ScalarMap_i.cc b/src/VISU_I/VISU_ScalarMap_i.cc index ee0d28ed..19bdd8da 100644 --- a/src/VISU_I/VISU_ScalarMap_i.cc +++ b/src/VISU_I/VISU_ScalarMap_i.cc @@ -29,8 +29,9 @@ #include "VISU_Result_i.hh" #include "VISU_ViewManager_i.hh" -#include "VISU_ScalarMapPL.hxx" #include "VISU_ScalarMapAct.h" +#include "VISU_ScalarMapPL.hxx" +#include "VISU_Convertor.hxx" #include "SUIT_ResourceMgr.h" @@ -48,8 +49,14 @@ static int MYDEBUG = 0; static int INCMEMORY = 4; -int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, int theIteration, int isMemoryCheck) + +//============================================================================ +int +VISU::ScalarMap_i +::IsPossible(Result_i* theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, int theIteration, int isMemoryCheck) { try{ float aSize = INCMEMORY* @@ -68,166 +75,95 @@ int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, return 0; } -int VISU::ScalarMap_i::myNbPresent = 0; -QString VISU::ScalarMap_i::GenerateName() { return VISU::GenerateName("ScalarMap",myNbPresent++);} +//---------------------------------------------------------------------------- +int +VISU::ScalarMap_i +::myNbPresent = 0; + +QString +VISU::ScalarMap_i +::GenerateName() +{ + return VISU::GenerateName("ScalarMap",myNbPresent++); +} + +const string +VISU::ScalarMap_i +::myComment = "SCALARMAP"; + +const char* +VISU::ScalarMap_i +::GetComment() const { + return myComment.c_str(); +} + -const string VISU::ScalarMap_i::myComment = "SCALARMAP"; -const char* VISU::ScalarMap_i::GetComment() const { return myComment.c_str();} +//---------------------------------------------------------------------------- VISU::ScalarMap_i:: ScalarMap_i(Result_i* theResult, bool theAddToStudy) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theAddToStudy), - myScalarMapPL(NULL) -{ -} - + ColoredPrs3d_i(theResult,theAddToStudy) +{} VISU::ScalarMap_i:: ScalarMap_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theSObject), - myScalarMapPL(NULL) -{ -} + ColoredPrs3d_i(theResult,theSObject) +{} +VISU::ScalarMap_i +::~ScalarMap_i() +{} -void VISU::ScalarMap_i::RemoveFromStudy() -{ - VISU::DeleteActors(this); - VISU::RemoveFromStudy(mySObject,false); -} - -void VISU::ScalarMap_i::SameAs(const Prs3d_i* theOrigin) +//---------------------------------------------------------------------------- +void +VISU::ScalarMap_i +::SameAs(const Prs3d_i* theOrigin) { - DoHook(); - VISU::Prs3d_i::SameAs(theOrigin); - - const ScalarMap_i* aConstScalarMap = dynamic_cast(theOrigin); - if (!aConstScalarMap) return; - - ScalarMap_i* aScalarMap = const_cast(aConstScalarMap); - myField = aScalarMap->GetField(); - myMeshName = myField->myMeshName; - myEntity = myField->myEntity; - myIteration = aScalarMap->GetIteration(); - myFieldName = aScalarMap->GetFieldName(); - - SetScalarMode(aScalarMap->GetScalarMode()); - - SetRange(aScalarMap->GetMin(), aScalarMap->GetMax()); - myIsFixedRange = aScalarMap->IsRangeFixed(); - - SetScaling(aScalarMap->GetScaling()); - - SetBarOrientation(aScalarMap->GetBarOrientation()); - SetPosition(aScalarMap->GetPosX(), aScalarMap->GetPosY()); - SetSize(aScalarMap->GetWidth(), aScalarMap->GetHeight()); - SetNbColors(aScalarMap->GetNbColors()); - SetLabels(aScalarMap->GetLabels()); - SetTitle(aScalarMap->GetTitle()); - - SetBoldTitle(aScalarMap->IsBoldTitle()); - SetItalicTitle(aScalarMap->IsItalicTitle()); - SetShadowTitle(aScalarMap->IsShadowTitle()); - SetTitFontType(aScalarMap->GetTitFontType()); - float r,g,b; - aScalarMap->GetTitleColor(&r,&g,&b); - SetTitleColor(r,g,b); - - SetBoldLabel(aScalarMap->IsBoldLabel()); - SetItalicLabel(aScalarMap->IsItalicLabel()); - SetShadowLabel(aScalarMap->IsShadowLabel()); - SetLblFontType(aScalarMap->GetLblFontType()); - aScalarMap->GetLabelColor(&r,&g,&b); - SetLabelColor(r,g,b); - - Build(-1); - Update(); -} + TSuperClass::SameAs(theOrigin); -void VISU::ScalarMap_i::SameAsParams (const ScalarMap_i* theOrigin) -{ - int time = GetIteration(); - SameAs(theOrigin); - myIteration = time; + if(const ScalarMap_i* aPrs3d = dynamic_cast(theOrigin)){ + ScalarMap_i* anOrigin = const_cast(aPrs3d); + + SetRange(anOrigin->GetMin(), anOrigin->GetMax()); + myIsFixedRange = anOrigin->IsRangeFixed(); - //??Build(true); - Build(-1); - Update(); + SetScaling(anOrigin->GetScaling()); + + Update(); + } } +//---------------------------------------------------------------------------- /** * Creates Scalar Map and initialises it from resources */ -VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, int theIteration) +VISU::Storable* +VISU::ScalarMap_i +::Create(const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + int theIteration) { - DoHook(); + TSuperClass::Create(theMeshName,theEntity,theFieldName,theIteration); SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); - int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0); - SetScalarMode(aScalarMode); - - // Orientation - int orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0); - if (orient == 1) - myOrientation = VISU::ScalarMap::HORIZONTAL; - else - myOrientation = VISU::ScalarMap::VERTICAL; - - // Scalar Bar origin - QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" ); - - float aXorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.01 : 0.2; - aXorigin = aResourceMgr->doubleValue("VISU", propertyName + "x", aXorigin); - myPosition[0] = aXorigin; - - float aYorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.1 : 0.012; - aYorigin = aResourceMgr->doubleValue("VISU", propertyName + "y", aYorigin); - myPosition[1] = aYorigin; - - // Scalar Bar size - myWidth = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.1 : 0.6; - myWidth = aResourceMgr->doubleValue("VISU", propertyName + "width", myWidth); - - myHeight = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12; - myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight); + // Scalar Range + int aRangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0); + myIsFixedRange = (aRangeType == 1) ? true : false; - // scalar bar default position - bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0); - int aPlace = 1; - if (anIsArrangeBar){ - aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0); + if(myIsFixedRange){ + float aMin = aResourceMgr->doubleValue("VISU", "scalar_range_min", 0); + float aMax = aResourceMgr->doubleValue("VISU", "scalar_range_max", 0); + SetRange(aMin,aMax); } - if(myOrientation == VISU::ScalarMap::HORIZONTAL){ - myPosition[1] += myHeight*(aPlace-1); - } else { - myPosition[0] += myWidth*(aPlace-1); - } - - - // Nb of Colors - int aNumberOfColors = aResourceMgr->integerValue( "VISU", "scalar_bar_num_colors", 64 ); - SetNbColors(aNumberOfColors); - - // Nb of Labels - myNumberOfLabels = aResourceMgr->integerValue( "VISU", "scalar_bar_num_labels", 5 ); - - // Scalar Range - int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0); - myIsFixedRange = (rangeType == 1) ? true : false; - - if (myIsFixedRange) - { - float aMin = aResourceMgr->doubleValue("VISU", "scalar_range_min", 0); - float aMax = aResourceMgr->doubleValue("VISU", "scalar_range_max", 0); - SetRange(aMin,aMax); - } bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false); @@ -236,280 +172,143 @@ VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity else SetScaling(VISU::LINEAR); - // Fonts properties definition - myIsBoldTitle = myIsItalicTitle = myIsShadowTitle = true; - myTitFontType = VTK_ARIAL; - - if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) ) - { - QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" ); - - if ( f.family() == "Arial" ) - myTitFontType = VTK_ARIAL; - else if ( f.family() == "Courier" ) - myTitFontType = VTK_COURIER; - else if ( f.family() == "Times" ) - myTitFontType = VTK_TIMES; - - myIsBoldTitle = f.bold(); - myIsItalicTitle = f.italic(); - myIsShadowTitle = f.underline(); - } - - QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) ); - - myTitleColor[0] = aTextColor.red() / 255; - myTitleColor[1] = aTextColor.green() / 255; - myTitleColor[2] = aTextColor.blue() / 255; - - /// - - myIsBoldLabel = myIsItalicLabel = myIsShadowLabel = true; - myLblFontType = VTK_ARIAL; - - if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) ) - { - QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" ); - - if ( f.family() == "Arial" ) - myLblFontType = VTK_ARIAL; - else if ( f.family() == "Courier" ) - myLblFontType = VTK_COURIER; - else if ( f.family() == "Times" ) - myLblFontType = VTK_TIMES; - - myIsBoldLabel = f.bold(); - myIsItalicLabel = f.italic(); - myIsShadowLabel = f.underline(); - } - - QColor aLabelColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) ); - - myLabelColor[0] = aLabelColor.red() / 255; - myLabelColor[1] = aLabelColor.green() / 255; - myLabelColor[2] = aLabelColor.blue() / 255; - - - myMeshName = theMeshName; - myEntity = (VISU::TEntity)theEntity; - myFieldName =theFieldName; - myIteration = theIteration; - - return Build(false); + return this; } - -VISU::Storable* VISU::ScalarMap_i::Restore(const Storable::TRestoringMap& theMap) +VISU::Storable* +VISU::ScalarMap_i +::Restore(const Storable::TRestoringMap& theMap) { - DoHook(); - myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1(); - myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt(); - myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1(); - myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt(); + TSuperClass::Restore(theMap); - SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt()); SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt())); + float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble(); float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble(); SetRange(aMin,aMax); + myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt(); - myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1(); - myOrientation = (VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt(); - SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt()); - myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt(); - myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble(); - myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble(); - myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble(); - myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble(); - - myTitFontType = VISU::Storable::FindValue(theMap,"myTitFontType").toInt(); - myIsBoldTitle = VISU::Storable::FindValue(theMap,"myIsBoldTitle").toInt(); - myIsItalicTitle = VISU::Storable::FindValue(theMap,"myIsItalicTitle").toInt(); - myIsShadowTitle = VISU::Storable::FindValue(theMap,"myIsShadowTitle").toInt(); - myTitleColor[0] = VISU::Storable::FindValue(theMap,"myTitleColor[0]").toFloat(); - myTitleColor[1] = VISU::Storable::FindValue(theMap,"myTitleColor[1]").toFloat(); - myTitleColor[2] = VISU::Storable::FindValue(theMap,"myTitleColor[2]").toFloat(); - - myLblFontType = VISU::Storable::FindValue(theMap,"myLblFontType").toInt(); - myIsBoldLabel = VISU::Storable::FindValue(theMap,"myIsBoldLabel").toInt(); - myIsItalicLabel = VISU::Storable::FindValue(theMap,"myIsItalicLabel").toInt(); - myIsShadowLabel = VISU::Storable::FindValue(theMap,"myIsShadowLabel").toInt(); - myLabelColor[0] = VISU::Storable::FindValue(theMap,"myLabelColor[0]").toFloat(); - myLabelColor[1] = VISU::Storable::FindValue(theMap,"myLabelColor[1]").toFloat(); - myLabelColor[2] = VISU::Storable::FindValue(theMap,"myLabelColor[2]").toFloat(); - - Prs3d_i::Restore(theMap); - myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study. - return Build(true); + return this; } +void +VISU::ScalarMap_i +::ToStream(std::ostringstream& theStr) +{ + TSuperClass::ToStream(theStr); -void VISU::ScalarMap_i::ToStream(std::ostringstream& theStr){ - Prs3d_i::ToStream(theStr); - - Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() ); - Storable::DataToStream( theStr, "myEntity", myEntity ); - Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() ); - Storable::DataToStream( theStr, "myIteration", myIteration ); - - Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) ); Storable::DataToStream( theStr, "myScalarRange[0]", GetMin() ); Storable::DataToStream( theStr, "myScalarRange[1]", GetMax() ); Storable::DataToStream( theStr, "myIsFixedRange", myIsFixedRange ); Storable::DataToStream( theStr, "myScaling", GetScaling() ); - - Storable::DataToStream( theStr, "myTitle", myTitle.c_str() ); - Storable::DataToStream( theStr, "myOrientation", myOrientation ); - Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) ); - Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels ); - Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] ); - Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] ); - Storable::DataToStream( theStr, "myWidth", myWidth ); - Storable::DataToStream( theStr, "myHeight", myHeight ); - - Storable::DataToStream( theStr, "myTitFontType", myTitFontType ); - Storable::DataToStream( theStr, "myIsBoldTitle", myIsBoldTitle ); - Storable::DataToStream( theStr, "myIsItalicTitle", myIsItalicTitle ); - Storable::DataToStream( theStr, "myIsShadowTitle", myIsShadowTitle ); - Storable::DataToStream( theStr, "myTitleColor[0]", myTitleColor[0] ); - Storable::DataToStream( theStr, "myTitleColor[1]", myTitleColor[1] ); - Storable::DataToStream( theStr, "myTitleColor[2]", myTitleColor[2] ); - - Storable::DataToStream( theStr, "myLblFontType", myLblFontType ); - Storable::DataToStream( theStr, "myIsBoldLabel", myIsBoldLabel ); - Storable::DataToStream( theStr, "myIsItalicLabel", myIsItalicLabel ); - Storable::DataToStream( theStr, "myIsShadowLabel", myIsShadowLabel ); - Storable::DataToStream( theStr, "myLabelColor[0]", myLabelColor[0] ); - Storable::DataToStream( theStr, "myLabelColor[1]", myLabelColor[1] ); - Storable::DataToStream( theStr, "myLabelColor[2]", myLabelColor[2] ); } -CORBA::Long VISU::ScalarMap_i::GetScalarMode(){ - return myScalarMapPL->GetScalarMode(); -} -void VISU::ScalarMap_i::SetScalarMode(CORBA::Long theScalarMode) { - myScalarMapPL->SetScalarMode(theScalarMode); +//---------------------------------------------------------------------------- +void +VISU::ScalarMap_i +::SetBarOrientation(VISU::ScalarMap::Orientation theOrientation) +{ + TSuperClass::SetBarOrientation(theOrientation); } +VISU::ScalarMap::Orientation +VISU::ScalarMap_i +::GetBarOrientation() +{ + return TSuperClass::GetBarOrientation(); +} -VISU::Scaling VISU::ScalarMap_i::GetScaling(){ +VISU::Scaling +VISU::ScalarMap_i +::GetScaling() +{ return VISU::Scaling(myScalarMapPL->GetScaling()); } -void VISU::ScalarMap_i::SetScaling(VISU::Scaling theScaling){ + +void +VISU::ScalarMap_i +::SetScaling(VISU::Scaling theScaling) +{ myScalarMapPL->SetScaling(theScaling); } - -void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax){ - if(theMin > theMax) return; +void +VISU::ScalarMap_i +::SetRange(CORBA::Double theMin, CORBA::Double theMax) +{ + if(theMin > theMax) + return; float aScalarRange[2] = {theMin, theMax}; myScalarMapPL->SetScalarRange(aScalarRange); myIsFixedRange = true; } -CORBA::Double VISU::ScalarMap_i::GetMin(){ - return myScalarMapPL->GetScalarRange()[0]; -} - -CORBA::Double VISU::ScalarMap_i::GetMax(){ - return myScalarMapPL->GetScalarRange()[1]; -} - -void VISU::ScalarMap_i::SetNbColors(CORBA::Long theNbColors){ - myScalarMapPL->SetNbColors(theNbColors); -} - -CORBA::Long VISU::ScalarMap_i::GetNbColors(){ - return myScalarMapPL->GetNbColors(); -} +//---------------------------------------------------------------------------- +void +VISU::ScalarMap_i +::DoSetInput(Result_i* theResult) +{ + VISU::Result_i::TInput* anInput = theResult->GetInput(); + if(!anInput) + throw std::runtime_error("Mesh_i::Build - theResult->GetInput() == NULL !!!"); + myField = anInput->GetField(myMeshName,myEntity,myFieldName); + if(!myField) + throw std::runtime_error("There is no Field with the parameters !!!"); -VISU::ScalarMap_i::~ScalarMap_i(){} + VISU::PIDMapper anIDMapper = + anInput->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration); + if(!anIDMapper) + throw std::runtime_error("There is no TimeStamp with the parameters !!!"); -VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){ - if(MYDEBUG) - MESSAGE("ScalarMap_i::Build - "<Init(); - if(!myIsFixedRange) myScalarMapPL->SetSourceRange(); - const VISU::TValField& aValField = myField->myValField; - const VISU::PValForTime aValForTime = aValField.find(myIteration)->second; - aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime->myTime).c_str()); - if (theRestoring == 0) myTitle = aComment.simplifyWhiteSpace().latin1(); - } - if(myAddToStudy){ - myName = GenerateName().latin1(); - aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", - VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); - string aResultEntry = myResult->GetEntry(); - string aRefFatherEntry = myResult->GetRefFatherEntry(); - string anEntry = myResult->GetEntry(aComment.latin1()); - if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!"); - aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", - GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); - CORBA::String_var anIOR = GetID(); - CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true); - mySObject = myStudy->FindObjectIOR(anIOR); - } - }catch(std::exception& exc){ - INFOS("Follow exception was occured :\n"<CommitCommand(); - return this; + myScalarMapPL->SetIDMapper(anIDMapper); + myScalarMapPL->Init(); + myScalarMapPL->Build(); } - -void VISU::ScalarMap_i::DoSetInput(Result_i* theResult){ - if(theResult->GetInput() == NULL) - throw std::runtime_error("Mesh_i::Build - theResult->GetInput() == NULL !!!"); - myField = theResult->GetInput()->GetField(myMeshName,myEntity,myFieldName); - if(myField == NULL) - throw std::runtime_error("There is no Field with the parameters !!!"); - VISU_Convertor::TOutput *anOutput = - theResult->GetInput()->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration); - if(anOutput == NULL) - throw std::runtime_error("There is no TimeStamp with the parameters !!!"); - myScalarMapPL->SetInput(anOutput); - myScalarMapPL->Build(); +void +VISU::ScalarMap_i +::Update() +{ + TSuperClass::Update(); } -void VISU::ScalarMap_i::DoHook(){ - if(MYDEBUG) MESSAGE("ScalarMap_i::DoHook() - "<GetMapper()->SetScalarVisibility(1); - } - myScalarMapPL = dynamic_cast(myPipeLine); +//---------------------------------------------------------------------------- +void +VISU::ScalarMap_i +::SetMapScale(double theMapScale) +{ + myScalarMapPL->SetMapScale(theMapScale); } -void VISU::ScalarMap_i::Update() { - VISU::Prs3d_i::Update(); +bool +VISU::ScalarMap_i +::IsRangeFixed() +{ + return myIsFixedRange; } -void VISU::ScalarMap_i::SetMapScale(double theMapScale){ - myScalarMapPL->SetMapScale(theMapScale); +void +VISU::ScalarMap_i +::SetSourceRange() +{ + myScalarMapPL->SetSourceRange(); + myIsFixedRange = false; } -VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +//---------------------------------------------------------------------------- +VISU_Actor* +VISU::ScalarMap_i +::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) { VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New(); try{ - VISU::Prs3d_i::CreateActor(anActor,theIO); + TSuperClass::CreateActor(anActor,theIO); anActor->SetBarVisibility(true); anActor->SetRepresentation(2); SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); @@ -523,9 +322,11 @@ VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject return anActor; } -void VISU::ScalarMap_i::UpdateActor(VISU_Actor* theActor) { +void +VISU::ScalarMap_i +::UpdateActor(VISU_Actor* theActor) +{ if(VISU_ScalarMapAct* anActor = dynamic_cast(theActor)){ - VISU::Prs3d_i::UpdateActor(theActor); VISU_ScalarBarActor *aScalarBar = anActor->GetScalarBar(); aScalarBar->SetLookupTable(myScalarMapPL->GetBarTable()); aScalarBar->SetTitle(myTitle.c_str()); @@ -552,10 +353,5 @@ void VISU::ScalarMap_i::UpdateActor(VISU_Actor* theActor) { aScalarBar->Modified(); } -} - - -void VISU::ScalarMap_i::SetSourceRange(){ - myScalarMapPL->SetSourceRange(); - myIsFixedRange = false; + TSuperClass::UpdateActor(theActor); } diff --git a/src/VISU_I/VISU_ScalarMap_i.hh b/src/VISU_I/VISU_ScalarMap_i.hh index a1b3f0a5..8506e463 100644 --- a/src/VISU_I/VISU_ScalarMap_i.hh +++ b/src/VISU_I/VISU_ScalarMap_i.hh @@ -27,178 +27,134 @@ #ifndef VISU_ScalarMap_i_HeaderFile #define VISU_ScalarMap_i_HeaderFile -#include "VISU_Prs3d_i.hh" +#include "VISU_ColoredPrs3d_i.hh" -class VISU_ScalarMapPL; -namespace VISU{ +namespace VISU +{ + //============================================================================ class ScalarMap_i : public virtual POA_VISU::ScalarMap, - public virtual Prs3d_i + public virtual ColoredPrs3d_i { static int myNbPresent; ScalarMap_i(); ScalarMap_i(const ScalarMap_i&); public: + //---------------------------------------------------------------------------- + typedef ColoredPrs3d_i TSuperClass; + explicit ScalarMap_i(Result_i* theResult, bool theAddToStudy); explicit ScalarMap_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject); - virtual void SameAs(const Prs3d_i* theOrigin); - virtual ~ScalarMap_i(); - virtual void RemoveFromStudy(); - - virtual VISU::VISUType GetType() { return VISU::TSCALARMAP;}; - - virtual CORBA::Long GetScalarMode(); - virtual void SetScalarMode(CORBA::Long theScalarMode); - - virtual VISU::Scaling GetScaling(); - virtual void SetScaling(VISU::Scaling theScaling); - - virtual void SetRange(CORBA::Double theMin, CORBA::Double theMax); - virtual CORBA::Double GetMin(); - virtual CORBA::Double GetMax(); - - virtual void SetNbColors(CORBA::Long theNbColors); - virtual CORBA::Long GetNbColors(); - - virtual void SetBarOrientation(VISU::ScalarMap::Orientation theOrientation){ - myOrientation = theOrientation; + virtual + ~ScalarMap_i(); + + virtual + VISU::VISUType + GetType() + { + return VISU::TSCALARMAP; } - virtual VISU::ScalarMap::Orientation GetBarOrientation() { return myOrientation;} - - virtual void SetPosition(CORBA::Double X, CORBA::Double Y) { myPosition[0] = X; myPosition[1] = Y;} - virtual CORBA::Double GetPosX() { return myPosition[0];} - virtual CORBA::Double GetPosY() { return myPosition[1];} - - virtual void SetSize(CORBA::Double theWidth, CORBA::Double theHeight) { - myWidth = theWidth; myHeight = theHeight; - } - virtual CORBA::Double GetWidth() { return myWidth;} - virtual CORBA::Double GetHeight() { return myHeight;} - - virtual void SetLabels(CORBA::Long theNbLabels) { myNumberOfLabels = theNbLabels;} - virtual CORBA::Long GetLabels() { return myNumberOfLabels;} - virtual void SetTitle(const char* theName) { myTitle = theName;} - virtual char* GetTitle() { return CORBA::string_dup(myTitle.c_str());} + virtual + VISU::Scaling + GetScaling(); - virtual bool IsBoldTitle() { return myIsBoldTitle;} - virtual void SetBoldTitle(bool isBold) { myIsBoldTitle = isBold;} + virtual + void + SetScaling(VISU::Scaling theScaling); - virtual bool IsItalicTitle() { return myIsItalicTitle;} - virtual void SetItalicTitle(bool isItalic) { myIsItalicTitle = isItalic;} + virtual + void + SetRange(CORBA::Double theMin, CORBA::Double theMax); - virtual bool IsShadowTitle() { return myIsShadowTitle;} - virtual void SetShadowTitle(bool isShadow) { myIsShadowTitle = isShadow;} + // To provide backward compatibility + virtual + void + SetBarOrientation(VISU::ScalarMap::Orientation theOrientation); - virtual int GetTitFontType() { return myTitFontType;} - virtual void SetTitFontType(int theType) { myTitFontType = theType;} - - virtual void GetTitleColor(float* theR, float* theG, float* theB) - {*theR = myTitleColor[0]; *theG = myTitleColor[1]; *theB = myTitleColor[2];} - virtual void SetTitleColor(float theR, float theG, float theB) - {myTitleColor[0] = theR; myTitleColor[1] = theG; myTitleColor[2] = theB; } - - ///// - virtual bool IsBoldLabel() { return myIsBoldLabel;} - virtual void SetBoldLabel(bool isBold) { myIsBoldLabel = isBold;} - - virtual bool IsItalicLabel() { return myIsItalicLabel;} - virtual void SetItalicLabel(bool isItalic) { myIsItalicLabel = isItalic;} - - virtual bool IsShadowLabel() { return myIsShadowLabel;} - virtual void SetShadowLabel(bool isShadow) {myIsShadowLabel = isShadow;} - - virtual int GetLblFontType() { return myLblFontType;} - virtual void SetLblFontType(int theType) { myLblFontType = theType;} - - virtual void GetLabelColor(float* theR, float* theG, float* theB) - {*theR = myLabelColor[0]; *theG = myLabelColor[1]; *theB = myLabelColor[2];} - virtual void SetLabelColor(float theR, float theG, float theB) - {myLabelColor[0] = theR; myLabelColor[1] = theG; myLabelColor[2] = theB; } + virtual + VISU::ScalarMap::Orientation + GetBarOrientation(); typedef VISU::ScalarMap TInterface; - VISU_ScalarMapPL* GetScalarMapPL(){ return myScalarMapPL;} - - /*! - * \brief Works like SameAs() method, but keep myIteration value unchanged. - * - * Is used in VISU_TimeAnimation class implementation. - */ - void SameAsParams (const ScalarMap_i* theOrigin); protected: - Storable* Build(int theRestoring); - virtual void DoSetInput(Result_i* theResult); - virtual void DoHook(); - - VISU_ScalarMapPL* myScalarMapPL; - PField myField; - - // std::string myMeshName; move it to Prs3d_i - TEntity myEntity; - std::string myFieldName; - int myIteration; - - bool myIsFixedRange; - - std::string myTitle; - int myNumberOfLabels; - float myPosition[2], myWidth, myHeight; - VISU::ScalarMap::Orientation myOrientation; - - //Font management - bool myIsBoldTitle; - bool myIsItalicTitle; - bool myIsShadowTitle; - int myTitFontType; - float myTitleColor[3]; - - bool myIsBoldLabel; - bool myIsItalicLabel; - bool myIsShadowLabel; - int myLblFontType; - float myLabelColor[3]; + virtual + void + DoSetInput(Result_i* theResult); public: - static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, int theIteration, int isMemoryCheck = true); - virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, int theIteration); + static + int + IsPossible(Result_i* theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + int theIteration, + int isMemoryCheck = true); + virtual + Storable* + Create(const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + int theIteration); + + virtual + void + ToStream(std::ostringstream& theStr); - const std::string& GetMeshName() const { return myMeshName;} - VISU::Entity GetEntity() const { return VISU::Entity(myEntity);} - const string& GetFieldName() const { return myFieldName;} - //int GetIteration() const { return myIteration;} + static const std::string myComment; - virtual void ToStream(std::ostringstream& theStr); + virtual + const char* + GetComment() const; - static const std::string myComment; - virtual const char* GetComment() const; - virtual QString GenerateName(); + virtual + QString + GenerateName(); + + virtual + Storable* + Restore(const Storable::TRestoringMap& theMap); - virtual Storable* Restore(const Storable::TRestoringMap& theMap); + static + Storable* + Restore(SALOMEDS::SObject_ptr theSObject, + const std::string& thePrefix, + const Storable::TRestoringMap& theMap); - static Storable* Restore(SALOMEDS::SObject_ptr theSObject, - const std::string& thePrefix, const Storable::TRestoringMap& theMap); + virtual + void + Update() ; - virtual void Update() ; - virtual void SetMapScale(double theMapScale = 1.0); + virtual + void + SetMapScale(double theMapScale = 1.0); - const VISU::PField GetField() const { return myField;} + virtual + bool + IsRangeFixed(); - virtual bool IsRangeFixed() { return myIsFixedRange; } - virtual void SetSourceRange(); + virtual + void + SetSourceRange(); - virtual int GetIteration() { return myIteration; } + virtual + void + SameAs(const Prs3d_i* theOrigin); - virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); - virtual void UpdateActor(VISU_Actor* theActor) ; + virtual + void + UpdateActor(VISU_Actor* theActor); }; } diff --git a/src/VISU_I/VISU_StreamLines_i.cc b/src/VISU_I/VISU_StreamLines_i.cc index 418d20cb..fbeeb75f 100644 --- a/src/VISU_I/VISU_StreamLines_i.cc +++ b/src/VISU_I/VISU_StreamLines_i.cc @@ -24,10 +24,12 @@ // Author : Alexey PETROV // Module : VISU -#include "VISU_StreamLinesPL.hxx" -#include "VISU_Result_i.hh" #include "VISU_StreamLines_i.hh" +#include "VISU_Result_i.hh" + #include "VISU_Actor.h" +#include "VISU_StreamLinesPL.hxx" +#include "VISU_Convertor.hxx" #include #include @@ -46,10 +48,13 @@ int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName const char* theFieldName, int theIteration, int isMemoryCheck) { try{ - if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false)) return 0; - VISU_Convertor::TOutput *anOutput = + if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false)) + return 0; + + VISU::PIDMapper anIDMapper = theResult->GetInput()->GetTimeStampOnMesh(theMeshName,VISU::TEntity(theEntity),theFieldName,theIteration); - bool aResult = VISU_StreamLinesPL::IsPossible(anOutput); + VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); + bool aResult = VISU_StreamLinesPL::IsPossible(aDataSet); MESSAGE("StreamLines_i::IsPossible - aResult = "<GetStudyDocument()), Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), ScalarMap_i(theResult,theAddToStudy), DeformedShape_i(theResult,theAddToStudy), myStreamLinesPL(NULL), @@ -87,6 +93,7 @@ StreamLines_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), ScalarMap_i(theResult,theSObject), DeformedShape_i(theResult,theSObject), myStreamLinesPL(NULL), @@ -97,11 +104,11 @@ StreamLines_i(Result_i* theResult, void VISU::StreamLines_i::SameAs(const Prs3d_i* theOrigin) { - VISU::DeformedShape_i::SameAs(theOrigin); + TSuperClass::SameAs(theOrigin); - if (const StreamLines_i* aConstStreamLines = dynamic_cast(theOrigin)) { - StreamLines_i* aStreamLines = const_cast(aConstStreamLines); - SetSource(aStreamLines->GetSource()); + if(const StreamLines_i* aPrs3d = dynamic_cast(theOrigin)) { + StreamLines_i* anOrigin = const_cast(aPrs3d); + SetSource(anOrigin->GetSource()); } } @@ -115,8 +122,7 @@ VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entit VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap) { - DoHook(); - VISU::Storable* aStorable = DeformedShape_i::Restore(theMap); + TSuperClass::Restore(theMap); double anIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble(); double aPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble(); @@ -131,7 +137,7 @@ VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theM VISU::StreamLines::Direction(aDirection)); mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1(); - return aStorable; + return this; } @@ -259,9 +265,15 @@ void VISU::StreamLines_i::Update() { } -VISU_Actor* VISU::StreamLines_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +VISU_Actor* +VISU::StreamLines_i +::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) { - return VISU::DeformedShape_i::CreateActor(theIO); + if(VISU_Actor* anActor = VISU::DeformedShape_i::CreateActor(theIO)){ + anActor->SetVTKMapping(true); + return anActor; + } + return NULL; } diff --git a/src/VISU_I/VISU_StreamLines_i.hh b/src/VISU_I/VISU_StreamLines_i.hh index a5a1a253..31c9fe7d 100644 --- a/src/VISU_I/VISU_StreamLines_i.hh +++ b/src/VISU_I/VISU_StreamLines_i.hh @@ -39,7 +39,10 @@ namespace VISU{ static int myNbPresent; StreamLines_i(); StreamLines_i(const StreamLines_i&); + public: + typedef DeformedShape_i TSuperClass; + explicit StreamLines_i(Result_i* theResult, bool theAddToStudy); @@ -93,7 +96,9 @@ namespace VISU{ virtual void Update(); - virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); virtual void UpdateActor(VISU_Actor* theActor); diff --git a/src/VISU_I/VISU_Table_i.cc b/src/VISU_I/VISU_Table_i.cc index dfe598c1..4f0151bf 100644 --- a/src/VISU_I/VISU_Table_i.cc +++ b/src/VISU_I/VISU_Table_i.cc @@ -30,6 +30,7 @@ #include "VISU_Result_i.hh" #include "VISU_ViewManager_i.hh" +#include "SALOME_Event.hxx" #include "SPlot2d_Curve.h" #include @@ -38,6 +39,7 @@ #include #include +#include #include using namespace std; @@ -269,10 +271,26 @@ const char* VISU::Table_i::GetTableTitle() return ""; } +//--------------------------------------------------------------- void VISU::Table_i::RemoveFromStudy() { + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Table_i* myRemovable; + TRemoveFromStudy(VISU::Table_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + VISU::RemoveFromStudy(myRemovable->GetSObject(),false); + } + }; + // Remove the table with all curves - VISU::RemoveFromStudy(mySObj,false); + ProcessVoidEvent(new TRemoveFromStudy(this)); } //---------------------------------------------------------------- @@ -669,8 +687,23 @@ VISU::Storable* VISU::Curve_i::Restore(SALOMEDS::SObject_ptr theSObject, void VISU::Curve_i::RemoveFromStudy() { - VISU::DeleteActors(this); - VISU::RemoveFromStudy(mySObj,false); + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Curve_i* myRemovable; + TRemoveFromStudy(VISU::Curve_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + VISU::DeleteActors(myRemovable); + VISU::RemoveFromStudy(myRemovable->GetSObject(),false); + } + }; + + ProcessVoidEvent(new TRemoveFromStudy(this)); } SALOMEDS::SObject_var VISU::Curve_i::GetSObject() @@ -943,7 +976,27 @@ VISU::Storable* VISU::Container_i::Restore(SALOMEDS::SObject_ptr theSObject, void VISU::Container_i::RemoveFromStudy() { - VISU::RemoveFromStudy(mySObj,false); + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Container_i* myRemovable; + TRemoveFromStudy(VISU::Container_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + VISU::RemoveFromStudy(myRemovable->GetSObject(),false); + } + }; + + ProcessVoidEvent(new TRemoveFromStudy(this)); +} + +SALOMEDS::SObject_var VISU::Container_i::GetSObject() +{ + return mySObj; } //------------------------------------------------------------- @@ -1108,7 +1161,8 @@ void ImportTables(const char* theFileName, TTableCont& theTableCont){ aRow.myTitle = cmt.latin1(); if(MYDEBUG) cout << "......ROW TITLE is: " << cmt.latin1() << endl; } - QStringList aValList = QStringList::split( " ", data ); + QString datar1 = data.replace(QRegExp("\t"), " "); + QStringList aValList = QStringList::split( " ", datar1 ); for ( int i = 0; i < aValList.count(); i++ ) { if ( aValList[i].stripWhiteSpace() != "" ) { TValue aVal = aValList[i].stripWhiteSpace().latin1(); diff --git a/src/VISU_I/VISU_Table_i.hh b/src/VISU_I/VISU_Table_i.hh index ed911dcf..608f5dfe 100644 --- a/src/VISU_I/VISU_Table_i.hh +++ b/src/VISU_I/VISU_Table_i.hh @@ -177,6 +177,8 @@ namespace VISU{ virtual void RemoveFromStudy(); + virtual SALOMEDS::SObject_var GetSObject(); + protected: Storable* Build(int theRestoring); diff --git a/src/VISU_I/VISU_TimeAnimation.cxx b/src/VISU_I/VISU_TimeAnimation.cxx index c16e1f87..34023596 100644 --- a/src/VISU_I/VISU_TimeAnimation.cxx +++ b/src/VISU_I/VISU_TimeAnimation.cxx @@ -16,11 +16,13 @@ #include "VISU_ScalarMap_i.hh" #include "VISU_IsoSurfaces_i.hh" #include "VISU_DeformedShape_i.hh" +#include "VISU_ScalarMapOnDeformedShape_i.hh" #include "VISU_CutPlanes_i.hh" #include "VISU_Plot3D_i.hh" #include "VISU_CutLines_i.hh" #include "VISU_Vectors_i.hh" #include "VISU_StreamLines_i.hh" +#include "VISU_GaussPoints_i.hh" #include "VISU_ViewManager_i.hh" #include "VISU_View_i.hh" @@ -48,7 +50,7 @@ using namespace std; -//************************************************************************ +//------------------------------------------------------------------------ VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy, VISU::View3D_ptr theView3D) { @@ -77,16 +79,21 @@ VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy, } -//************************************************************************ +//------------------------------------------------------------------------ VISU_TimeAnimation::~VISU_TimeAnimation() { + if (!myView) { + MESSAGE("Viewer is not defined for animation"); + return; + } + for (int i = 0; i < getNbFields(); i++) { clearData(myFieldsLst[i]); } } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::addField (_PTR(SObject) theField) { FieldData aNewData; @@ -109,7 +116,7 @@ void VISU_TimeAnimation::addField (_PTR(SObject) theField) } } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField) { SALOMEDS::SObject_var theFieldDup = SALOMEDS::SObject::_duplicate(theField); @@ -118,18 +125,18 @@ void VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField) } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::clearData(FieldData& theData) { - if( !myView ) + if (!myView) { + MESSAGE("Viewer is not defined for animation"); return; - + } theData.myTiming.clear(); vtkRenderer* aRen = myView->getRenderer(); if (!theData.myActors.empty()) { for (int i = 0, iEnd = theData.myActors.size(); i < iEnd; i++) { if (theData.myActors[i] != 0) { theData.myActors[i]->RemoveFromRender(aRen); - theData.myActors[i]->Delete(); } } theData.myActors.clear(); @@ -146,146 +153,125 @@ void VISU_TimeAnimation::clearData(FieldData& theData) { } -//************************************************************************ +namespace +{ + //------------------------------------------------------------------------ + template + void + GeneratePresentations(_PTR(Study) theStudy, + FieldData& theData, + VISU::Result_i* theResult, + bool theIsRangeDefined, + CORBA::Double theMinVal, + CORBA::Double theMaxVal) + { + double aMin = VTK_LARGE_FLOAT, aMax = -VTK_LARGE_FLOAT; + _PTR(ChildIterator) anIter = theStudy->NewChildIterator(theData.myField); + anIter->Next(); // First is reference on support + + long aFrameId = 0; + for(; anIter->More(); anIter->Next()){ + if (aFrameId == theData.myNbTimes) { + MESSAGE("There are extra timestamps in field"); + return; + } + _PTR(SObject) aTimeStamp = anIter->Value(); + if(!aTimeStamp) + continue; + + theData.myTiming[aFrameId] = VISU_TimeAnimation::getTimeValue(aTimeStamp); + if (theIsRangeDefined) { + if (theData.myTiming[aFrameId] < theMinVal) + continue; + if (theData.myTiming[aFrameId] > theMaxVal) + break; + } + + VISU::Storable::TRestoringMap aTimeMap = VISU_TimeAnimation::getMapOfValue(aTimeStamp); + QString aMeshName = VISU::Storable::FindValue(aTimeMap,"myMeshName"); + VISU::Entity anEntity = (VISU::Entity) VISU::Storable::FindValue(aTimeMap,"myEntityId").toInt(); + QString aFieldName = VISU::Storable::FindValue(aTimeMap,"myFieldName"); + int aTimeStampId = VISU::Storable::FindValue(aTimeMap,"myTimeStampId").toInt(); + + TPrs3d* aPresent = new TPrs3d(theResult, false); + aPresent->Create(aMeshName.latin1(), anEntity, + aFieldName.latin1(), aTimeStampId); + theData.myPrs[aFrameId++] = aPresent; + + aMin = std::min(aPresent->GetMin(),aMin); + aMax = std::min(aPresent->GetMax(),aMax); + } + theData.myNbFrames = aFrameId; + + if (theData.myPrsType != VISU::TGAUSSPOINTS){ + int aRangeType = VISU::GetResourceMgr()->integerValue("VISU" , "scalar_range_type", 0); + if( aRangeType != 1 ){ + for(long aFrameId = 0; aFrameId < theData.myNbFrames; aFrameId++) { + if (VISU::ScalarMap_i* aPrs = dynamic_cast(theData.myPrs[aFrameId])){ + aPrs->SetRange(aMin, aMax); + aPrs->SetOffset(theData.myOffset); + } + } + } + if (theData.myPrsType == VISU::TISOSURFACE) + for (long aFrameId = 0; aFrameId < theData.myNbFrames; aFrameId++) + if (VISU::IsoSurfaces_i* aPrs = dynamic_cast(theData.myPrs[aFrameId])) + aPrs->SetSubRange(aMin, aMax); + } + } +} + void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum) { FieldData& aData = myFieldsLst[theFieldNum]; // Delete previous presentations clearData(aData); - VISU::Result_i* pResult = createPresent(aData.myField); + VISU::Result_i* aResult = createPresent(aData.myField); VISU::Storable::TRestoringMap aMap = getMapOfValue(aData.myField); aData.myNbFrames = aData.myNbTimes; - //VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong(); + //VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong(); aData.myPrs.resize(aData.myNbTimes,NULL); aData.myTiming.resize(aData.myNbTimes); - _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aData.myField); - _PTR(SObject) aTimeStamp; - anIter->Next(); // First is reference on support - long i = 0; - double aMin = VTK_LARGE_FLOAT, aMax = -VTK_LARGE_FLOAT; - for (; anIter->More(); anIter->Next()) { - if (i == aData.myNbTimes) { - MESSAGE("There are extra timestamps in field"); - return; - } - aTimeStamp = anIter->Value(); - if (!aTimeStamp) continue; - - aData.myTiming[i] = getTimeValue(aTimeStamp); - if (isRangeDefined()) { - if (aData.myTiming[i] < myMinVal) continue; - if (aData.myTiming[i] > myMaxVal) break; - } - - VISU::Storable::TRestoringMap aTimeMap = getMapOfValue(aTimeStamp); - QString aMeshName = VISU::Storable::FindValue(aTimeMap,"myMeshName"); - VISU::Entity anEntity = (VISU::Entity) VISU::Storable::FindValue(aTimeMap,"myEntityId").toInt(); - QString aFieldName = VISU::Storable::FindValue(aTimeMap,"myFieldName"); - int aTimeStampId = VISU::Storable::FindValue(aTimeMap,"myTimeStampId").toInt(); - - switch (aData.myPrsType) { - case VISU::TSCALARMAP: // ScalarMap - { - VISU::ScalarMap_i* aPresent = new VISU::ScalarMap_i(pResult, false); - aPresent->Create(aMeshName.latin1(), anEntity, - aFieldName.latin1(), aTimeStampId); - //VISU::ScalarMap_var aTmp = aPresent->_this(); - //aPresent->_remove_ref(); - aData.myPrs[i] = aPresent; - } - break; - - case VISU::TISOSURFACE: // Iso Surfaces - { - VISU::IsoSurfaces_i* aPresent = new VISU::IsoSurfaces_i(pResult, false); - aPresent->Create(aMeshName.latin1(), anEntity, - aFieldName.latin1(), aTimeStampId); - //VISU::IsoSurfaces_var aTmp = aPresent->_this(); - //aPresent->_remove_ref(); - aData.myPrs[i] = aPresent; - } - break; - - case VISU::TCUTPLANES: // Cut Planes - { - VISU::CutPlanes_i* aPresent = new VISU::CutPlanes_i(pResult, false); - aPresent->Create(aMeshName.latin1(), anEntity, - aFieldName.latin1(), aTimeStampId); - //VISU::CutPlanes_var aTmp = aPresent->_this(); - //aPresent->_remove_ref(); - aData.myPrs[i] = aPresent; - } - break; - - case VISU::TPLOT3D: // Plot3d - { - VISU::Plot3D_i* aPresent = new VISU::Plot3D_i (pResult, false); - aPresent->Create(aMeshName.latin1(), anEntity, - aFieldName.latin1(), aTimeStampId); - aData.myPrs[i] = aPresent; - } - break; - - case VISU::TDEFORMEDSHAPE: // Deformed Shape - { - VISU::DeformedShape_i* aPresent = new VISU::DeformedShape_i(pResult, false); - aPresent->Create(aMeshName.latin1(), anEntity, - aFieldName.latin1(), aTimeStampId); - //VISU::DeformedShape_var aTmp = aPresent->_this(); - //aPresent->_remove_ref(); - aData.myPrs[i] = aPresent; - } - break; - - case VISU::TVECTORS: // Vectors - { - VISU::Vectors_i* aPresent = new VISU::Vectors_i(pResult, false); - aPresent->Create(aMeshName.latin1(), anEntity, - aFieldName.latin1(), aTimeStampId); - //VISU::Vectors_var aTmp = aPresent->_this(); - //aPresent->_remove_ref(); - aData.myPrs[i] = aPresent; - } - break; - - case VISU::TSTREAMLINES: // Stream Lines - { - VISU::StreamLines_i* aPresent = new VISU::StreamLines_i(pResult, false); - aPresent->Create(aMeshName.latin1(), anEntity, - aFieldName.latin1(), aTimeStampId); - //VISU::StreamLines_var aTmp = aPresent->_this(); - //aPresent->_remove_ref(); - aData.myPrs[i] = aPresent; - } - break; - default: - MESSAGE("Not implemented for this presentation type: " << aData.myPrsType); - return; - } - if (aData.myPrs[i]->GetMin() < aMin) aMin = aData.myPrs[i]->GetMin(); - if (aData.myPrs[i]->GetMax() > aMax) aMax = aData.myPrs[i]->GetMax(); - i++; - } - aData.myNbFrames = i; - - int rangeType = VISU::GetResourceMgr()->integerValue("VISU" , "scalar_range_type", 0); - if ( rangeType != 1 ) { - for (i = 0; i < aData.myNbFrames; i++) { - aData.myPrs[i]->SetRange(aMin, aMax); - aData.myPrs[i]->SetOffset(aData.myOffset); - } - if (aData.myPrsType == VISU::TISOSURFACE) - for (i = 0; i < aData.myNbFrames; i++) - if (VISU::IsoSurfaces_i* aPrs = dynamic_cast(aData.myPrs[i])) - aPrs->SetSubRange(aMin, aMax); + using namespace VISU; + switch (aData.myPrsType) { + case VISU::TSCALARMAP: // ScalarMap + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + case VISU::TISOSURFACE: // Iso Surfaces + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + case VISU::TCUTPLANES: // Cut Planes + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + case VISU::TPLOT3D: // Plot3d + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + case VISU::TDEFORMEDSHAPE: // Deformed Shape + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + case VISU::TVECTORS: // Vectors + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + case VISU::TSTREAMLINES: // Stream Lines + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + case VISU::TGAUSSPOINTS: // Gauss Points + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + case VISU::TSCALARMAPONDEFORMEDSHAPE: // Scalar map on deformed shape + GeneratePresentations(myStudy,aData,aResult,isRangeDefined(),myMinVal,myMaxVal); + break; + default: + MESSAGE("Not implemented for this presentation type: " << aData.myPrsType); + return; } } -//************************************************************************ +//------------------------------------------------------------------------ CORBA::Boolean VISU_TimeAnimation::generateFrames() { if (!myView) { MESSAGE("Viewer is not defined for animation"); @@ -324,7 +310,7 @@ CORBA::Boolean VISU_TimeAnimation::generateFrames() { return aNoError; } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::clearView() { if (!myView) { MESSAGE("Viewer is not defined for animation"); @@ -337,7 +323,6 @@ void VISU_TimeAnimation::clearView() { for (int i = 0, iEnd = aData.myActors.size(); i < iEnd; i++) { if (aData.myActors[i] != 0) { aData.myActors[i]->RemoveFromRender(aRen); - aData.myActors[i]->Delete(); } } aData.myActors.clear(); @@ -346,12 +331,12 @@ void VISU_TimeAnimation::clearView() { VISU::RepaintView(myView); } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::stopAnimation() { myIsActive = false; } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::startAnimation() { if (!myIsActive) { myIsActive = true; @@ -359,11 +344,12 @@ void VISU_TimeAnimation::startAnimation() { } } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::nextFrame() { - if( !myView ) + if (!myView) { + MESSAGE("Viewer is not defined for animation"); return; - + } stopAnimation(); if (myFrame < (myFieldsLst[0].myNbFrames-1)) { int i; @@ -381,10 +367,12 @@ void VISU_TimeAnimation::nextFrame() { } } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::prevFrame() { - if( !myView ) + if (!myView) { + MESSAGE("Viewer is not defined for animation"); return; + } stopAnimation(); if (myFrame > 0) { int i; @@ -402,11 +390,12 @@ void VISU_TimeAnimation::prevFrame() { } } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::firstFrame() { - if( !myView ) + if (!myView) { + MESSAGE("Viewer is not defined for animation"); return; - + } stopAnimation(); int i; for (i = 0; i < getNbFields(); i++) @@ -424,11 +413,12 @@ void VISU_TimeAnimation::firstFrame() { } } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::lastFrame() { - if( !myView ) + if (!myView) { + MESSAGE("Viewer is not defined for animation"); return; - + } stopAnimation(); int i; for (i = 0; i < getNbFields(); i++) @@ -445,10 +435,14 @@ void VISU_TimeAnimation::lastFrame() { } -//************************************************************************ +//------------------------------------------------------------------------ // For Batchmode using void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) { - if ((theFrame < 0) || (theFrame > (getNbFrames()-1)) || !myView ) + if (!myView) { + MESSAGE("Viewer is not defined for animation"); + return; + } + if ((theFrame < 0) || (theFrame > (getNbFrames()-1))) return; stopAnimation(); qApp->lock(); @@ -471,23 +465,23 @@ void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) { } -//************************************************************************ -VISU::ScalarMap_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) { +//------------------------------------------------------------------------ +VISU::ColoredPrs3d_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) { if ((theField > getNbFields()) || (theField < 0)) - return VISU::ScalarMap::_nil(); + return VISU::ColoredPrs3d::_nil(); if ((theFrame < 0) || (theFrame > (myFieldsLst[theField].myNbFrames - 1))) - return VISU::ScalarMap::_nil(); + return VISU::ColoredPrs3d::_nil(); return myFieldsLst[theField].myPrs[theFrame]->_this(); } -//************************************************************************ +//------------------------------------------------------------------------ CORBA::Long VISU_TimeAnimation::getNbFrames() { return (getNbFields() > 0)? myFieldsLst[0].myNbFrames : 0; } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::run() { if (!myView) { @@ -543,6 +537,11 @@ void VISU_TimeAnimation::run() qApp->lock(); if (isDumping) { + // We must unlock mutex for some time before grabbing to allow view updating + qApp->unlock(); + msleep(100); + qApp->lock(); + QPixmap px = QPixmap::grabWindow(myView->winId()); QString aFile(myDumpPath); QString aName = QString("%1").arg(myFieldsLst[0].myTiming[myFrame]); @@ -572,7 +571,7 @@ void VISU_TimeAnimation::run() QThread::exit(); } -//************************************************************************ +//------------------------------------------------------------------------ VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField) { _PTR(SObject) aSObj = theField->GetFather(); @@ -583,7 +582,7 @@ VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField) return dynamic_cast(VISU::GetServant(anObject).in()); } -//************************************************************************ +//------------------------------------------------------------------------ VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (_PTR(SObject) theSObject) { VISU::Storable::TRestoringMap aMap; @@ -599,7 +598,7 @@ VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (_PTR(SObject) t return aMap; } -//************************************************************************ +//------------------------------------------------------------------------ double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp) { _PTR(GenericAttribute) anAttr; @@ -615,7 +614,7 @@ double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp) return -1.0; } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed) { mySpeed = (theSpeed<1)? 1 : theSpeed; @@ -641,7 +640,7 @@ QString VISU_TimeAnimation::GenerateName() return VISU::GenerateName("Animation", myNBAnimations++); } -//************************************************************************ +//------------------------------------------------------------------------ std::string GetPresentationComment (VISU::VISUType thePrsType) { std::string aPrsCmt; @@ -667,6 +666,12 @@ std::string GetPresentationComment (VISU::VISUType thePrsType) case VISU::TSTREAMLINES: aPrsCmt = VISU::StreamLines_i::myComment; break; + case VISU::TGAUSSPOINTS: + aPrsCmt = VISU::GaussPoints_i::myComment; + break; + case VISU::TSCALARMAPONDEFORMEDSHAPE: + aPrsCmt = VISU::ScalarMapOnDeformedShape_i::myComment; + break; default: aPrsCmt = "Unknown presentation"; break; @@ -674,7 +679,7 @@ std::string GetPresentationComment (VISU::VISUType thePrsType) return aPrsCmt; } -//************************************************************************ +//------------------------------------------------------------------------ SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy() { if (myStudy->GetProperties()->IsLocked()) @@ -714,7 +719,7 @@ SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy() return VISU::GetSObject(aAnimSObject); } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::saveAnimation() { if (myStudy->GetProperties()->IsLocked()) return; @@ -775,7 +780,7 @@ void VISU_TimeAnimation::saveAnimation() aStudyBuilder->CommitCommand(); } -//************************************************************************ +//------------------------------------------------------------------------ void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField) { _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy); @@ -831,6 +836,10 @@ void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField) aData.myPrsType = VISU::TVECTORS; else if (strName == VISU::StreamLines_i::myComment.c_str()) aData.myPrsType = VISU::TSTREAMLINES; + else if (strName == VISU::GaussPoints_i::myComment.c_str()) + aData.myPrsType = VISU::TGAUSSPOINTS; + else if (strName == VISU::ScalarMapOnDeformedShape_i::myComment.c_str()) + aData.myPrsType = VISU::TSCALARMAPONDEFORMEDSHAPE; else continue; generatePresentations(getNbFields()-1); @@ -848,7 +857,8 @@ void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField) aData.myPrs[0]->GetOffset(aData.myOffset); for (int i = 1; i < aData.myNbFrames; i++) { //jfa 03.08.2005:aData.myPrs[i]->SameAs(aData.myPrs[0]); - aData.myPrs[i]->SameAsParams(aData.myPrs[0]);//jfa 03.08.2005 + //enk 06.02.2006:aData.myPrs[i]->SameAsParams(aData.myPrs[0]);//jfa 03.08.2005 + aData.myPrs[i]->SameAsParams(aData.myPrs[i-1]);//enk 06.02.2006: initializing from previous presentation } } string aStr = aAnimSObject->GetID(); @@ -997,7 +1007,7 @@ CORBA::Long VISU_TimeAnimation_i::getCurrentFrame() return myAnim->getCurrentFrame(); } -VISU::ScalarMap_ptr VISU_TimeAnimation_i::getPresentation +VISU::ColoredPrs3d_ptr VISU_TimeAnimation_i::getPresentation (CORBA::Long theField, CORBA::Long theFrame) { return myAnim->getPresentation(theField,theFrame); diff --git a/src/VISU_I/VISU_TimeAnimation.h b/src/VISU_I/VISU_TimeAnimation.h index f6496cc5..315415c8 100644 --- a/src/VISU_I/VISU_TimeAnimation.h +++ b/src/VISU_I/VISU_TimeAnimation.h @@ -22,7 +22,7 @@ class VISU_Actor; namespace VISU{ class Result_i; - class ScalarMap_i; + class ColoredPrs3d_i; } struct FieldData @@ -31,7 +31,7 @@ struct FieldData _PTR(SObject) myField; // field label long myNbTimes; // number of Timestamps long myNbFrames; // number of created Frames - std::vector myPrs; // Presentations + std::vector myPrs; // Presentations std::vector myActors; // Actors std::vector myTiming; // time values float myOffset[3]; @@ -80,7 +80,7 @@ class VISU_TimeAnimation: public QObject, public QThread CORBA::Boolean isRunning() { return myIsActive; } CORBA::Long getCurrentFrame() { return myFrame; } - VISU::ScalarMap_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame); + VISU::ColoredPrs3d_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame); void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType) { myFieldsLst[theFieldNum].myPrsType = theType; } @@ -188,7 +188,7 @@ public: virtual CORBA::Boolean isRunning(); virtual CORBA::Long getCurrentFrame(); - virtual VISU::ScalarMap_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame); + virtual VISU::ColoredPrs3d_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame); virtual void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType); virtual VISU::VISUType getPresentationType(CORBA::Long theFieldNum); diff --git a/src/VISU_I/VISU_Vectors_i.cc b/src/VISU_I/VISU_Vectors_i.cc index 3fb10780..071ba811 100644 --- a/src/VISU_I/VISU_Vectors_i.cc +++ b/src/VISU_I/VISU_Vectors_i.cc @@ -24,10 +24,14 @@ // Author : Alexey PETROV // Module : VISU -#include "VISU_VectorsPL.hxx" -#include "VISU_Result_i.hh" #include "VISU_Vectors_i.hh" +#include "VISU_Result_i.hh" + #include "VISU_VectorsAct.h" +#include "VISU_VectorsPL.hxx" +#include "VISU_Convertor.hxx" + +#include using namespace VISU; using namespace std; @@ -74,6 +78,7 @@ Vectors_i(Result_i* theResult, bool theAddToStudy) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theAddToStudy), + ColoredPrs3d_i(theResult,theAddToStudy), ScalarMap_i(theResult,theAddToStudy), DeformedShape_i(theResult,theAddToStudy), myVectorsPL(NULL) @@ -86,6 +91,7 @@ Vectors_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), Prs3d_i(theResult,theSObject), + ColoredPrs3d_i(theResult,theSObject), ScalarMap_i(theResult,theSObject), DeformedShape_i(theResult,theSObject), myVectorsPL(NULL) @@ -95,11 +101,11 @@ Vectors_i(Result_i* theResult, void VISU::Vectors_i::SameAs(const VISU::Prs3d_i* theOrigin) { - VISU::DeformedShape_i::SameAs(theOrigin); + TSuperClass::SameAs(theOrigin); - if (const VISU::Vectors_i* aConstVec = dynamic_cast(theOrigin)) { - VISU::Vectors_i* aVectors = const_cast(aConstVec); - SetLineWidth(aVectors->GetLineWidth()); + if(const Vectors_i* aPrs3d = dynamic_cast(theOrigin)){ + Vectors_i* anOrigin = const_cast(aPrs3d); + SetLineWidth(anOrigin->GetLineWidth()); } } @@ -114,12 +120,13 @@ VISU::Storable* VISU::Vectors_i::Create(const char* theMeshName, VISU::Entity th VISU::Storable* VISU::Vectors_i::Restore(const Storable::TRestoringMap& theMap) { - DoHook(); + TSuperClass::Restore(theMap); + SetGlyphType(VISU::Vectors::GlyphType(VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt())); SetGlyphPos(VISU::Vectors::GlyphPos(VISU::Storable::FindValue(theMap,"myPosGlyph").toInt())); SetLineWidth(VISU::Storable::FindValue(theMap,"myLineWidth").toDouble()); - return DeformedShape_i::Restore(theMap); + return this; } @@ -171,6 +178,7 @@ void VISU::Vectors_i::DoHook(){ VISU_PipeLine* VISU::Vectors_i::GetPipeLine(){ VISU_PipeLine* aPipeLine = VISU_VectorsPL::New(); + aPipeLine->SetIDMapper(myPipeLine->GetIDMapper()); aPipeLine->ShallowCopy(myPipeLine); aPipeLine->Update(); return aPipeLine; @@ -182,6 +190,7 @@ VISU_Actor* VISU::Vectors_i::CreateActor(const Handle(SALOME_InteractiveObject)& VISU_VectorsAct* anActor = VISU_VectorsAct::New(); try{ VISU::Prs3d_i::CreateActor(anActor,theIO); + anActor->SetVTKMapping(true); anActor->SetBarVisibility(true); anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B); anActor->GetProperty()->SetLineWidth(GetLineWidth()); diff --git a/src/VISU_I/VISU_Vectors_i.hh b/src/VISU_I/VISU_Vectors_i.hh index 7c167ae0..88143087 100644 --- a/src/VISU_I/VISU_Vectors_i.hh +++ b/src/VISU_I/VISU_Vectors_i.hh @@ -38,7 +38,10 @@ namespace VISU{ static int myNbPresent; Vectors_i(); Vectors_i(const Vectors_i&); + public: + typedef DeformedShape_i TSuperClass; + explicit Vectors_i(Result_i* theResult, bool theAddToStudy); @@ -83,7 +86,9 @@ namespace VISU{ virtual const char* GetComment() const; virtual QString GenerateName(); - virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + virtual + VISU_Actor* + CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); virtual void UpdateActor(VISU_Actor* theActor) ; }; diff --git a/src/VISU_I/VISU_ViewManager_i.cc b/src/VISU_I/VISU_ViewManager_i.cc index 670656c1..c86ac5d8 100644 --- a/src/VISU_I/VISU_ViewManager_i.cc +++ b/src/VISU_I/VISU_ViewManager_i.cc @@ -36,7 +36,6 @@ #include "SUIT_ViewWindow.h" #include "SUIT_ViewManager.h" -#include "SVTK_RenderWindow.h" #include "SVTK_ViewWindow.h" #include "SVTK_ViewModel.h" #include "SPlot2d_Curve.h" @@ -128,11 +127,11 @@ namespace VISU { struct TCurrentViewEvent: public SALOME_Event { - const SalomeApp_Application* myApplication; + SalomeApp_Application* myApplication; typedef VISU::View_ptr TResult; TResult myResult; - TCurrentViewEvent(const SalomeApp_Application* theApplication): + TCurrentViewEvent(SalomeApp_Application* theApplication): myApplication(theApplication), myResult(VISU::View::_nil()) {} @@ -141,16 +140,9 @@ namespace VISU { void Execute() { - //if (SUIT_ViewManager *aViewManager = myApplication->activeViewManager()) { - // if (aViewManager->getType() == "VTKViewer") { - // if (SUIT_ViewWindow *aViewWindow = aViewManager->getActiveView()) { - VISU::View3D_i* pView = - new View3D_i ((SalomeApp_Application*)myApplication); - if (pView->Create(0)) - myResult = pView->_this(); - // } - // } - //} + VISU::View3D_i* aView = new View3D_i (myApplication); + if (aView->Create(0)) + myResult = aView->_this(); } }; @@ -284,7 +276,7 @@ namespace VISU { { SVTK_ViewWindow* vf = GetViewWindow(theViewWindow); vf->getRenderer()->ResetCameraClippingRange(); - vf->getRenderWindow()->getRenderWindow()->Render(); + vf->getRenderWindow()->Render(); } VISU_Actor* UpdateViewer (SUIT_ViewWindow* theStudyFrame, int theDisplaing, Prs3d_i* thePrs) @@ -300,7 +292,7 @@ namespace VISU { if(anActor->IsA("VISU_Actor")){ anVISUActor = VISU_Actor::SafeDownCast(anActor); if (thePrs == anVISUActor->GetPrs3d()) { - aResActor = anVISUActor->GetParent(); + aResActor = anVISUActor; if(theDisplaing < eErase) aResActor->VisibilityOn(); else @@ -461,7 +453,7 @@ namespace VISU { while (vtkActor *anActor = anActColl->GetNextActor()) if (VISU_Actor* anVISUActor = dynamic_cast(anActor)) if (thePrs3d == anVISUActor->GetPrs3d()) - return anVISUActor->GetParent(); + return anVISUActor; return NULL; } @@ -693,13 +685,12 @@ namespace VISU { for (; !anActor && aVTKActor; aVTKActor = anActColl->GetNextActor()) { if (VISU_Actor* anVISUActor = dynamic_cast(aVTKActor)) { if (thePrs == anVISUActor->GetPrs3d()) { - anActor = anVISUActor->GetParent(); + anActor = anVISUActor; } } } if (anActor) { vw->RemoveActor(anActor); - anActor->Delete(); } } } diff --git a/src/VISU_I/VISU_View_i.cc b/src/VISU_I/VISU_View_i.cc index 5e25633f..43224cd7 100644 --- a/src/VISU_I/VISU_View_i.cc +++ b/src/VISU_I/VISU_View_i.cc @@ -46,7 +46,6 @@ #include "SVTK_ViewWindow.h" #include "SVTK_ViewModel.h" -#include "SVTK_RenderWindow.h" #include "SPlot2d_ViewModel.h" #include "Plot2d_ViewFrame.h" @@ -1335,7 +1334,7 @@ namespace VISU { const int mode, const double xMin, const double xMax, const double yMin, const double yMax): - myView(theView), + myView(theView), myMode(mode), myXMin(xMin),myXMax(xMax), myYMin(yMin),myYMax(yMax) @@ -1352,7 +1351,7 @@ namespace VISU { const double myYMax; Plot2d_ViewFrame* myView; }; - + void XYPlot_i::FitXRange(const CORBA::Double xMin,const CORBA::Double xMax) { const CORBA::Long mode = 1; @@ -1375,7 +1374,7 @@ namespace VISU { const CORBA::Long mode = 0; ProcessVoidEvent(new TFitRangeEvent(myView,mode,xMin,xMax,yMin,yMax)); } - + void XYPlot_i::GetFitRanges(double& xMin, double& xMax, double& yMin, double& yMax) { double y2Min,y2Max; @@ -1485,14 +1484,17 @@ namespace VISU { struct TCreateView3dEvent: public SALOME_Event { + SalomeApp_Application *myApplication; View3D_i * myView3D; int myNew; typedef SUIT_ViewWindow* TResult; TResult myResult; - TCreateView3dEvent (View3D_i * theView3D, + TCreateView3dEvent (SalomeApp_Application *theApplication, + View3D_i * theView3D, const int theNew): + myApplication(theApplication), myView3D(theView3D), myNew(theNew), myResult(NULL) @@ -1502,35 +1504,41 @@ namespace VISU { void Execute() { - if (!myView3D->myApplication) + if (!myApplication) return; - SUIT_ViewManager * aViewMgr = - myView3D->myApplication->getViewManager(SVTK_Viewer::Type(), false); - - if (aViewMgr) { - if (myNew) { - myResult = aViewMgr->createViewWindow(); - } else { - myResult = aViewMgr->getActiveView(); + if(myNew){ + if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),false)){ + myResult = aViewManager->createViewWindow(); + myView3D->myViewManager = aViewManager; + }else{ + if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),true)){ + myResult = aViewManager->getActiveView(); + myView3D->myViewManager = aViewManager; + } } - } else { - if (myNew) { - aViewMgr = myView3D->myApplication->getViewManager(SVTK_Viewer::Type(), true); - myResult = aViewMgr->getActiveView(); - } else { - return; // there are no current 3D view + }else{ + if(SUIT_ViewManager* aViewManager = myApplication->activeViewManager()){ + if(SUIT_ViewWindow* aView = aViewManager->getActiveView()){ + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aView)){ + myView3D->myViewManager = aViewManager; + myResult = aViewManager->getActiveView(); + } + } + }else{ + if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),false)){ + myView3D->myViewManager = aViewManager; + myResult = aViewManager->getActiveView(); + } } } - - myView3D->myViewManager = aViewMgr; } }; Storable* View3D_i::Create (int theNew) { if (MYDEBUG) MESSAGE("View3D_i::Create"); - SUIT_ViewWindow* aVW = ProcessEvent(new TCreateView3dEvent(this, theNew)); + SUIT_ViewWindow* aVW = ProcessEvent(new TCreateView3dEvent(myApplication, this, theNew)); if (aVW) { SetViewWindow(aVW); return this; @@ -1731,8 +1739,9 @@ namespace VISU { SetViewUp(theViewWindow,aViewUp); SetFocalPoint(theViewWindow,aFocalPnt); SetParallelScale(theViewWindow,aParallelScale); - SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(theViewWindow); - aViewWindow->SetScale(aScaleFactor); + ScaleView(theViewWindow,VISU::View3D::XAxis,aScaleFactor[0]); + ScaleView(theViewWindow,VISU::View3D::YAxis,aScaleFactor[1]); + ScaleView(theViewWindow,VISU::View3D::ZAxis,aScaleFactor[2]); } diff --git a/src/VISU_SWIG/Makefile.in b/src/VISU_SWIG/Makefile.in index 30d837a1..93d34b31 100644 --- a/src/VISU_SWIG/Makefile.in +++ b/src/VISU_SWIG/Makefile.in @@ -51,7 +51,10 @@ EXPORT_SHAREDPYSCRIPTS = VISU_shared_modules.py LIB_CLIENT_IDL = CPPFLAGS += -ftemplate-depth-32 $(PYTHON_INCLUDES) $(HDF5_INCLUDES) $(QT_INCLUDES) \ - $(VTK_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) + $(VTK_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ + -I${MED_ROOT_DIR}/include/salome \ + $(BOOST_CPPFLAGS) + LDFLAGS += $(PYTHON_LIBS) -lVisuConvertor -lVisuPipeLine @CONCLUDE@ diff --git a/src/VISU_SWIG/VISU_Gen_s.cc b/src/VISU_SWIG/VISU_Gen_s.cc index 1a499def..ddad586a 100644 --- a/src/VISU_SWIG/VISU_Gen_s.cc +++ b/src/VISU_SWIG/VISU_Gen_s.cc @@ -48,8 +48,9 @@ ScalarMap::ScalarMap(Convertor* theConvertor, const char* theMeshName, int theEn : myScalarMap(NULL) { if(VISU_Convertor* aConvertor = theConvertor->GetImpl()){ - vtkUnstructuredGrid* aDataSet = + VISU::PIDMapper anIDMapper = aConvertor->GetTimeStampOnMesh(theMeshName,VISU::TEntity(theEntity),theFieldName,theIteration); + VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); if(aDataSet){ myScalarMap = VISU_ScalarMapPL::New(); myScalarMap->SetInput(aDataSet); diff --git a/src/VISU_SWIG/visu.py b/src/VISU_SWIG/visu.py index 037cc764..daadf7aa 100644 --- a/src/VISU_SWIG/visu.py +++ b/src/VISU_SWIG/visu.py @@ -184,7 +184,7 @@ def SObjectToObject(theSObject) : print "SObjectToObject - IOR = ''" return anObj; -def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) : +def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) : # try: global myLifeCycleCORBA print "lcc.FindOrLoadComponent...", @@ -204,8 +204,12 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict aResult = theVisu.ImportMed(aMedSObj) if aResult is None : raise RuntimeError, "Error" else : print "OK" - aVISUObjList.append(aResult) - aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt)) + + aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete)) + if theIsAutoDelete : + aResult.RemoveFromStudy() + else : + aVISUObjList.append(aResult) aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather()); while aFolderIter.More() : @@ -249,8 +253,12 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict aResult = theVisu.ImportMed(aFieldSObj) if aResult is None : raise RuntimeError, "Error" else : print "OK" - aVISUObjList.append(aResult) - aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt)) + + aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete)) + if theIsAutoDelete : + aResult.RemoveFromStudy() + else : + aVISUObjList.append(aResult) aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj); if aTimeStampIter.More() : @@ -268,15 +276,19 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict aResult = theVisu.ImportMedField(aMedField) if aResult is None : raise RuntimeError, "Error" else : print "OK" - aVISUObjList.append(aResult) - aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt)) + + aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete)) + if theIsAutoDelete : + aResult.RemoveFromStudy() + else : + aVISUObjList.append(aResult) return aVISUObjList # except Exception, e: # print str(e) -def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) : +def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) : # try: aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName) @@ -285,17 +297,27 @@ def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePic if aResult is None : raise RuntimeError, "Error" else : print "OK" - aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt)) - + aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete)) + + if theIsAutoDelete : + aResult.RemoveFromStudy() + else : + aVISUObjList.append(aResult) + return aVISUObjList # except Exception, e: # print str(e) -def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt) : - aVISUObjList = [] +def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) : + aVISUObjList = None + if theIsAutoDelete is not None : + aVISUObjList = [] + pass + print "CreatePrsForResult - myLocalStudy.FindObjectIOR...", myLocalStudy = theVisu.GetCurrentStudy() + aSObj = myLocalStudy.FindObjectIOR(theResult.GetID()) if aSObj is None : raise RuntimeError, "Error" else : print "OK" @@ -356,7 +378,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName); theView.SavePicture(aPictureName) - aVISUObjList.append(aMesh) + if theIsAutoDelete : + aMesh.RemoveFromStudy() + else : + aVISUObjList.append(aMesh) anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj); while anFamilyIter.More() : @@ -376,7 +401,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName); theView.SavePicture(aPictureName) - aVISUObjList.append(aMesh) + if theIsAutoDelete : + aMesh.RemoveFromStudy() + else : + aVISUObjList.append(aMesh) if aFolderName == 'Groups' : aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj); @@ -397,7 +425,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName); theView.SavePicture(aPictureName) - aVISUObjList.append(aMesh) + if theIsAutoDelete : + aMesh.RemoveFromStudy() + else : + aVISUObjList.append(aMesh) if aFolderName == 'Fields' : aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj); @@ -446,8 +477,11 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName); theView.SavePicture(aPictureName) - aVISUObjList.append(aPrsObj) - + if theIsAutoDelete : + aPrsObj.RemoveFromStudy() + else : + aVISUObjList.append(aPrsObj) + if HasValue(thePrsTypeList,VISU.TISOSURFACE) : print " Creating IsoSurfacesOnField", aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId) @@ -459,7 +493,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName); theView.SavePicture(aPictureName) - aVISUObjList.append(aPrsObj) + if theIsAutoDelete : + aPrsObj.RemoveFromStudy() + else : + aVISUObjList.append(aPrsObj) if HasValue(thePrsTypeList,VISU.TCUTPLANES) : print " Creating CutPlanesOnField", @@ -473,7 +510,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName) theView.SavePicture(aPictureName) - aVISUObjList.append(aPrsObj) + if theIsAutoDelete : + aPrsObj.RemoveFromStudy() + else : + aVISUObjList.append(aPrsObj) if HasValue(thePrsTypeList,VISU.TCUTLINES) : print " Creating CutLinesOnField", @@ -488,7 +528,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName) theView.SavePicture(aPictureName) - aVISUObjList.append(aPrsObj) + if theIsAutoDelete : + aPrsObj.RemoveFromStudy() + else : + aVISUObjList.append(aPrsObj) if HasValue(thePrsTypeList,VISU.TPLOT3D) : print " Creating Plot3DOnField", @@ -505,7 +548,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName) theView.SavePicture(aPictureName) - aVISUObjList.append(aPrsObj) + if theIsAutoDelete : + aPrsObj.RemoveFromStudy() + else : + aVISUObjList.append(aPrsObj) aNumComponent = atoi(aMap["myNumComponent"]) if aNumComponent > 1 : @@ -520,7 +566,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName) theView.SavePicture(aPictureName) - aVISUObjList.append(aPrsObj) + if theIsAutoDelete : + aPrsObj.RemoveFromStudy() + else : + aVISUObjList.append(aPrsObj) if HasValue(thePrsTypeList,VISU.TVECTORS) : print " Creating VectorsOnField", @@ -533,7 +582,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName) theView.SavePicture(aPictureName) - aVISUObjList.append(aPrsObj) + if theIsAutoDelete : + aPrsObj.RemoveFromStudy() + else : + aVISUObjList.append(aPrsObj) if HasValue(thePrsTypeList,VISU.TSTREAMLINES) : print " Creating StreamLinesOnField", @@ -546,8 +598,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt aPictureName = re.sub("\s+","_", aPictureName) theView.SavePicture(aPictureName) - aVISUObjList.append(aPrsObj) - + if theIsAutoDelete : + aPrsObj.RemoveFromStudy() + else : + aVISUObjList.append(aPrsObj) return aVISUObjList @@ -688,7 +742,7 @@ def dump_deformedshape_parameters(theObject): # ---------------------- def try_cutplanes_parameters(thePattern) : - if thePattern is None : return aList + if thePattern is None : return None import copy import random diff --git a/src/VVTK/Makefile.in b/src/VVTK/Makefile.in new file mode 100755 index 00000000..66b48653 --- /dev/null +++ b/src/VVTK/Makefile.in @@ -0,0 +1,80 @@ +# File : Makefile.in +# Author : Alexander Solovyov(OCN) +# Module : VVTK +# $Header: + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@ + + +@COMMENCE@ + +# header files +EXPORT_HEADERS = \ + VVTK.h \ + VVTK_ViewManager.h \ + VVTK_ViewModel.h \ + VVTK_InteractorStyle.h \ + VVTK_PickingDlg.h \ + VVTK_SegmentationCursorDlg.h \ + VVTK_PrimitiveBox.h \ + VVTK_SizeBox.h \ + VVTK_ViewWindow.h \ + VVTK_MainWindow.h \ + VVTK_ImageWriter.h \ + VVTK_ImageWriterMgr.h \ + VVTK_RecorderDlg.h \ + VVTK_Recorder.h + +# Libraries targets +LIB = libVVTK.la + +LIB_SRC = \ + VVTK_ViewManager.cxx \ + VVTK_ViewModel.cxx \ + VVTK_InteractorStyle.cxx \ + VVTK_PickingDlg.cxx \ + VVTK_SegmentationCursorDlg.cxx \ + VVTK_PrimitiveBox.cxx \ + VVTK_SizeBox.cxx \ + VVTK_ViewWindow.cxx \ + VVTK_Renderer.cxx \ + VVTK_MainWindow.cxx \ + VVTK_ImageWriter.cxx \ + VVTK_ImageWriterMgr.cxx \ + VVTK_RecorderDlg.cxx \ + VVTK_Recorder.cxx + +LIB_MOC = \ + VVTK_ViewWindow.h \ + VVTK_ViewModel.h \ + VVTK_ViewManager.h \ + VVTK_PickingDlg.h \ + VVTK_SegmentationCursorDlg.h \ + VVTK_RecorderDlg.h \ + VVTK_PrimitiveBox.h \ + VVTK_SizeBox.h \ + VVTK_MainWindow.h + +CPPFLAGS += \ + $(QT_INCLUDES) \ + $(OCC_INCLUDES) \ + $(VTK_INCLUDES) \ + $(BOOST_CPPFLAGS) \ + -I$(KERNEL_ROOT_DIR)/include/salome \ + -I$(GUI_ROOT_DIR)/include/salome \ + -I${MED_ROOT_DIR}/include/salome + +LDFLAGS += \ + $(QT_MT_LIBS) \ + $(OCC_LIBS) \ + $(VTK_LIBS) \ + -L$(KERNEL_ROOT_DIR)/lib/salome \ + -L$(GUI_ROOT_DIR)/lib/salome + +LIBS+= -lsuit -lCAM -lSalomeObject -lSVTK -lOpUtil + + +@CONCLUDE@ diff --git a/src/VVTK/VVTK.h b/src/VVTK/VVTK.h new file mode 100755 index 00000000..d6dd0648 --- /dev/null +++ b/src/VVTK/VVTK.h @@ -0,0 +1,13 @@ +#ifdef WNT +#ifdef SVTK_EXPORTS +#define VVTK_EXPORT __declspec(dllexport) +#else +#define VVTK_EXPORT __declspec(dllimport) +#endif +#else +#define VVTK_EXPORT +#endif + +#if defined WNT +#pragma warning ( disable: 4251 ) +#endif diff --git a/src/VVTK/VVTK_ImageWriter.cxx b/src/VVTK/VVTK_ImageWriter.cxx new file mode 100755 index 00000000..9d047598 --- /dev/null +++ b/src/VVTK/VVTK_ImageWriter.cxx @@ -0,0 +1,112 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "VVTK_ImageWriter.h" + +#include + +#include +#include +#include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +//---------------------------------------------------------------------------- +VVTK_ImageWriter +::VVTK_ImageWriter(QSemaphore* theSemaphore, + vtkImageData* theImageData, + const std::string& theName, + int theProgressive, + int theQuality): + mySemaphore(theSemaphore), + myImageData(theImageData), + myName(theName), + myProgressive(theProgressive), + myQuality(theQuality), + myConstraint16Flag(true) +{} + +//---------------------------------------------------------------------------- +VVTK_ImageWriter +::~VVTK_ImageWriter() +{ + if(MYDEBUG) cout<<"VVTK_ImageWriter::~VVTK_ImageWriter - this = "< anImageClip; + // + if(myConstraint16Flag){ + int uExtent[6]; + myImageData->GetUpdateExtent(uExtent); + unsigned int width = uExtent[1] - uExtent[0] + 1; + unsigned int height = uExtent[3] - uExtent[2] + 1; + width = (width / 16) * 16; + height= (height / 16) * 16; + uExtent[1] = uExtent[0] + width - 1; + uExtent[3] = uExtent[2] + height - 1; + // + anImageClip = vtkImageClip::New(); + anImageClip->Delete(); + + anImageClip->SetInput(myImageData); + anImageClip->SetOutputWholeExtent(uExtent); + anImageClip->ClipDataOn(); + anImageData = anImageClip->GetOutput(); + } + // + aWriter->WriteToMemoryOff(); + aWriter->SetFileName(myName.c_str()); + aWriter->SetQuality(myQuality); + aWriter->SetProgressive(myProgressive); + aWriter->SetInput(anImageData); + aWriter->Write(); + + aWriter->Delete(); + myImageData->Delete(); + + if(MYDEBUG) cout<<"VVTK_ImageWriter::run "<< + "- this = "< + +#include + +#include + + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +//---------------------------------------------------------------------------- +VVTK_ImageWriterMgr +::VVTK_ImageWriterMgr() +{ + int aMax = std::numeric_limits::max() / 2; + mySemaphore = new QSemaphore(aMax); + *mySemaphore += aMax; + if(MYDEBUG) cout<<"VVTK_ImageWriterMgr::VVTK_ImageWriterMgr "<< + "- total = "<total()<< + "; available = "<available()<start(); + +} + + +//---------------------------------------------------------------------------- +void +VVTK_ImageWriterMgr +::Stop() +{ + if(MYDEBUG) cout<<"VVTK_ImageWriterMgr::Stop "<< + "- total = "<total()<< + "; available = "<available()< +#include +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(VVTK_InteractorStyle); +//---------------------------------------------------------------------------- + +VVTK_InteractorStyle +::VVTK_InteractorStyle(): + myIsMidButtonDown( false ), + myIsLeftButtonDown( false ), + mySMDecreaseMagnificationBtn(10), + mySMIncreaseMagnificationBtn(11) +{ +} + +//---------------------------------------------------------------------------- +VVTK_InteractorStyle +::~VVTK_InteractorStyle() +{ +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::OnLeftButtonDown(int ctrl, int shift, + int x, int y) +{ + myIsLeftButtonDown = true; + + if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) { + this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL); + return; + } + this->FindPokedRenderer(x, y); + if (this->CurrentRenderer == NULL) { + return; + } + myShiftState = shift; + // finishing current viewer operation + if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + onFinishOperation(); + startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); + } + myOtherPoint = myPoint = QPoint(x, y); + if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + startOperation(ForcedState); + } + else { + if (!(ctrl||shift)){ + if (myIsMidButtonDown){ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + } + else{ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE); + } + } + } + return; +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::OnMiddleButtonDown(int ctrl, + int shift, + int x, int y) +{ + myIsMidButtonDown = true; + + if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) { + this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL); + return; + } + this->FindPokedRenderer(x, y); + if (this->CurrentRenderer == NULL) { + return; + } + myShiftState = shift; + // finishing current viewer operation + if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + onFinishOperation(); + startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); + } + myOtherPoint = myPoint = QPoint(x, y); + if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + startOperation(ForcedState); + } + else { + if (!(ctrl||shift)){ + if ( myIsLeftButtonDown ){ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + } + else{ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN); + } + } + } +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::OnLeftButtonUp(int ctrl, int shift, int x, int y) +{ + myIsLeftButtonDown = false; + SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y ); + + if ( myIsMidButtonDown ) + OnMiddleButtonDown( ctrl, shift, x, y ); +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::OnMiddleButtonUp(int ctrl, int shift, int x, int y) +{ + myIsMidButtonDown = false; + SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y ); + + if ( myIsLeftButtonDown ) + OnLeftButtonDown( ctrl, shift, x, y ); +} +//---------------------------------------------------------------------------- +void VVTK_InteractorStyle::onFinishOperation() +{ + Superclass::onFinishOperation(); +} + + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::SetInteractor( vtkRenderWindowInteractor* theInteractor ) +{ + // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc) + Superclass::SetInteractor( theInteractor ); + + if(theInteractor){ + theInteractor->AddObserver( VISU::SetSMDecreaseMagnificationEvent, EventCallbackCommand, Priority ); + theInteractor->AddObserver( VISU::SetSMIncreaseMagnificationEvent, EventCallbackCommand, Priority ); + } +} + + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::ProcessEvents( vtkObject* object, + unsigned long event, + void* clientData, + void* callData ) +{ + if ( clientData ) { + vtkObject* anObject = reinterpret_cast( clientData ); + VVTK_InteractorStyle* self = dynamic_cast( anObject ); + if( self ){ + switch ( event ) { + case VISU::SetSMDecreaseMagnificationEvent: + self->mySMDecreaseMagnificationBtn = *((int*)callData); + return; + case VISU::SetSMIncreaseMagnificationEvent: + self->mySMIncreaseMagnificationBtn = *((int*)callData); + return; + } + } + } + + Superclass::ProcessEvents( object, event, clientData, callData ); +} + + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::onSpaceMouseButton( int button ) +{ + if( mySMDecreaseMagnificationBtn == button ) + DecreaseGaussPointMagnification(); + if( mySMIncreaseMagnificationBtn == button ) + IncreaseGaussPointMagnification(); + + Superclass::onSpaceMouseButton( button ); +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::DecreaseGaussPointMagnification() +{ + Interactor->InvokeEvent(VISU::SetSMDecreaseMagnificationEvent,NULL); +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::IncreaseGaussPointMagnification() +{ + Interactor->InvokeEvent(VISU::SetSMIncreaseMagnificationEvent,NULL); +} +//============================================================================ +// +// Controllers +// +vtkStandardNewMacro(VVTK_ControllerIncrement); +//---------------------------------------------------------------------------- +VVTK_ControllerIncrement::VVTK_ControllerIncrement() +{ + myIncrement=10; +} +//---------------------------------------------------------------------------- +VVTK_ControllerIncrement::~VVTK_ControllerIncrement() +{ +} +//---------------------------------------------------------------------------- +int VVTK_ControllerIncrement::Increase() +{ + myIncrement*=2; + return myIncrement; +} +//---------------------------------------------------------------------------- +int VVTK_ControllerIncrement::Decrease() +{ + myIncrement/=2; + if (!myIncrement){ + myIncrement=1; + } + return myIncrement; +} +// +vtkStandardNewMacro(VVTK_ControllerOnKeyDown); +//---------------------------------------------------------------------------- +VVTK_ControllerOnKeyDown::VVTK_ControllerOnKeyDown() +{ +} +//---------------------------------------------------------------------------- +VVTK_ControllerOnKeyDown::~VVTK_ControllerOnKeyDown() +{ +} +//---------------------------------------------------------------------------- +bool VVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS) +{ + SVTK_InteractorStyle *pIS=dynamic_cast(theIS); + if (pIS){ + if(pIS->GetSelector()->SelectionMode()==GaussPointSelection){ + char key = pIS->GetInteractor()->GetKeyCode(); + // + if (key == 'S') { + pIS->ActionPicking(); + return false; + } + } + } + return Superclass::OnKeyDown(theIS); +} diff --git a/src/VVTK/VVTK_InteractorStyle.h b/src/VVTK/VVTK_InteractorStyle.h new file mode 100644 index 00000000..9e33bfa7 --- /dev/null +++ b/src/VVTK/VVTK_InteractorStyle.h @@ -0,0 +1,149 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_InteractorStyle.h +// Author : Christophe ATTANASIO +// Module : SALOME +// $Header$ + +#ifndef __VVTK_InteractorStyle_h +#define __VVTK_InteractorStyle_h + + +#include "VVTK.h" + +#include "SVTK_InteractorStyle.h" +// +//------------------------------------------- +//! Control the value of increment in new style of interaction. +/*! + This class controls of value of increment, + for pan/rotate/zoom operations in new style + of interaction +*/ +class VVTK_ControllerIncrement : public SVTK_ControllerIncrement { + public: + vtkTypeMacro(VVTK_ControllerIncrement,SVTK_ControllerIncrement); + static VVTK_ControllerIncrement* New(); + + //! Increace the increment value by multiplying on 2 + virtual int Increase(); + + //! Decreace the increment value by division on 2 + virtual int Decrease(); + + protected: + VVTK_ControllerIncrement(); + virtual ~VVTK_ControllerIncrement(); + // + private: + VVTK_ControllerIncrement(const VVTK_ControllerIncrement&); //Not implemented + void operator=(const VVTK_ControllerIncrement&); //Not implemented +}; +// +//------------------------------------------- +//! Control the behaviour of KeyDown event in new style of interaction. +/*! + This class controls of behaviour of of KeyDown event + in new style of interaction. +*/ +class VVTK_ControllerOnKeyDown : public SVTK_ControllerOnKeyDown{ + public: + vtkTypeMacro(VVTK_ControllerOnKeyDown, SVTK_ControllerOnKeyDown); + static VVTK_ControllerOnKeyDown* New(); + + //! Provides the action on event + virtual bool OnKeyDown(vtkInteractorStyle* ); + + protected: + VVTK_ControllerOnKeyDown(); + virtual ~VVTK_ControllerOnKeyDown(); + + private: + VVTK_ControllerOnKeyDown(const VVTK_ControllerOnKeyDown&);//Not implemented + void operator=(const VVTK_ControllerOnKeyDown&); //Not implemented +}; + + +//! Introduce new style of interaction (keyboard free) +class VVTK_EXPORT VVTK_InteractorStyle : public SVTK_InteractorStyle +{ + public: + static VVTK_InteractorStyle *New(); + vtkTypeMacro(VVTK_InteractorStyle,SVTK_InteractorStyle); + + //! Redefined from SVTK_InteractorStyle::SetInteractor in order to add an observer (callback) for custorm event (space mouse event) + virtual + void + SetInteractor( vtkRenderWindowInteractor* ); + + protected: + VVTK_InteractorStyle(); + ~VVTK_InteractorStyle(); + + VVTK_InteractorStyle(const VVTK_InteractorStyle&); // Not implemented + void operator=(const VVTK_InteractorStyle&); // Not implemented + + // Generic event bindings must be overridden in subclasses + + //! Redefine SVTK_InteractorStyle::OnLeftButtonDown + virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnMiddleButtonDown + virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnLeftButtonUp + virtual void OnLeftButtonUp(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnMiddleButtonUp + virtual void OnMiddleButtonUp(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::onFinishOperation + virtual void onFinishOperation(); + + //! Main process VTK event method + static + void + ProcessEvents(vtkObject* object, + unsigned long event, + void* clientData, + void* callData ); + + //! Redefine SVTK_InteractorStyle::onSpaceMouseButton + virtual void onSpaceMouseButton( int button ); + + //! To decrease magnification of the Gauss Points + void DecreaseGaussPointMagnification(); + + //! To increase magnification of the Gauss Points + void IncreaseGaussPointMagnification(); + + //! SpaceMouse short cuts + int mySMDecreaseMagnificationBtn; + int mySMIncreaseMagnificationBtn; + + bool myIsMidButtonDown; + bool myIsLeftButtonDown; +}; + +#endif diff --git a/src/VVTK/VVTK_MainWindow.cxx b/src/VVTK/VVTK_MainWindow.cxx new file mode 100644 index 00000000..de0ebfd0 --- /dev/null +++ b/src/VVTK/VVTK_MainWindow.cxx @@ -0,0 +1,537 @@ +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "VVTK_MainWindow.h" +#include "VVTK_InteractorStyle.h" +#include "VVTK_Recorder.h" +#include "VVTK_RecorderDlg.h" +#include "VISU_WidgetCtrl.hxx" +#include "VISU_GaussPtsAct.h" +#include "VISU_Event.h" + +#include "SVTK_RenderWindowInteractor.h" +#include "VVTK_Renderer.h" +#include "VVTK_PickingDlg.h" +#include "VVTK_SegmentationCursorDlg.h" + +#include "SUIT_Application.h" +#include "SUIT_Session.h" +#include "SUIT_Tools.h" +#include "SUIT_ViewWindow.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_ToolButton.h" +#include "SUIT_Accel.h" +#include "QtxAction.h" + +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +VVTK_MainWindow +::VVTK_MainWindow(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow): + SVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow), + myInteractorStyle(VVTK_InteractorStyle::New()), + myControllerIncrement(VVTK_ControllerIncrement::New()), + myControllerOnKeyDown(VVTK_ControllerOnKeyDown::New()) +{ + myInteractorStyle->SetControllerIncrement(myControllerIncrement.GetPointer()); + myControllerIncrement->Delete(); + + myInteractorStyle->SetControllerOnKeyDown(myControllerOnKeyDown.GetPointer()); + myControllerOnKeyDown->Delete(); + + myInteractorStyle->Delete(); + + moveDockWindow(myToolBar,Qt::DockLeft); + myActionsMap[NonIsometric]->removeFrom(myToolBar); + + // Recording + myRecordingToolBar = new QToolBar(this); + myRecordingToolBar->setCloseMode(QDockWindow::Undocked); + myRecordingToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + moveDockWindow(myRecordingToolBar,Qt::DockLeft); + + myStartAction = new QtxAction(tr("MNU_VVTK_RECORDING_START"), + theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_START" ) ), + tr( "MNU_VVTK_RECORDING_START" ), 0, this); + myStartAction->setStatusTip(tr("DSC_VVTK_RECORDING_START")); + myStartAction->addTo( myRecordingToolBar ); + connect( myStartAction, SIGNAL( activated() ), this, SLOT( OnStartRecording() ) ); + + myPlayAction = new QtxAction(tr("MNU_VVTK_RECORDING_PLAY"), + theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_PLAY" ) ), + tr( "MNU_VVTK_RECORDING_PLAY" ), 0, this); + myPlayAction->setStatusTip(tr("DSC_VVTK_RECORDING_PLAY")); + myPlayAction->setEnabled( false ); + myPlayAction->addTo( myRecordingToolBar ); + connect( myPlayAction, SIGNAL( activated() ), this, SLOT( OnPlayRecording() ) ); + + myPauseAction = new QtxAction(tr("MNU_VVTK_RECORDING_PAUSE"), + theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_PAUSE" ) ), + tr( "MNU_VVTK_RECORDING_PAUSE" ), 0, this); + myPauseAction->setStatusTip(tr("DSC_VVTK_RECORDING_PAUSE")); + myPauseAction->setEnabled( false ); + myPauseAction->addTo( myRecordingToolBar ); + connect( myPauseAction, SIGNAL( activated() ), this, SLOT( OnPauseRecording() ) ); + + myStopAction = new QtxAction(tr("MNU_VVTK_RECORDING_STOP"), + theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_STOP" ) ), + tr( "MNU_VVTK_RECORDING_STOP" ), 0, this); + myStopAction->setStatusTip(tr("DSC_VVTK_RECORDING_STOP")); + myStopAction->setEnabled( false ); + myStopAction->addTo( myRecordingToolBar ); + connect( myStopAction, SIGNAL( activated() ), this, SLOT( OnStopRecording() ) ); + + myRecorder = VVTK_Recorder::New(); + myRecorder->CheckExistAVIMaker(); + if(myRecorder->ErrorStatus()) + myRecordingToolBar->setEnabled(false); +} + +//---------------------------------------------------------------------------- +void +VVTK_MainWindow +::Initialize(SVTK_RenderWindowInteractor* theInteractor) +{ + vtkInteractorStyle* aStyle = theInteractor->GetInteractorStyle(); + if(SVTK_InteractorStyle *anInteractorStyle = dynamic_cast(aStyle)){ + anInteractorStyle->SetControllerIncrement(myControllerIncrement.GetPointer()); + anInteractorStyle->SetControllerOnKeyDown(myControllerOnKeyDown.GetPointer()); + } + + myRecorder->SetNbFPS(17.3); + myRecorder->SetQuality(100); + myRecorder->SetProgressiveMode(true); + myRecorder->SetUseSkippedFrames(true); + myRecorder->SetRenderWindow(theInteractor->getRenderWindow()); + + disconnect( myActionsMap[ DumpId ], SIGNAL( activated() ), + myViewWindow, SLOT( onDumpView() ) ); + + connect( myActionsMap[ DumpId ], SIGNAL( activated() ), + this, SLOT( onDumpView() ) ); + + SVTK_MainWindow::Initialize(theInteractor); +} + +VVTK_MainWindow::~VVTK_MainWindow() +{ + if(myRecorder) + myRecorder->Delete(); +} + +//---------------------------------------------------------------------------- +void VVTK_MainWindow::onDumpView() +{ + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + QString fileName = app->getFileName( false, QString::null, + tr( "TLT_IMAGE_FILES" ), + tr( "TLT_DUMP_VIEW" ), 0 ); + if( fileName.isEmpty() ) + return; + + QImage img = dumpView(); + if( img.isNull() ) + return; + + QString fmt = SUIT_Tools::extension( fileName ).upper(); + if( fmt.isEmpty() ) + fmt = QString( "BMP" ); // default format + else if( fmt == "JPG" ) + fmt = "JPEG"; + + QApplication::setOverrideCursor( Qt::waitCursor ); + bool res = img.save( fileName, fmt.latin1() ); + QApplication::restoreOverrideCursor(); +} + +//---------------------------------------------------------------------------- +void +VVTK_MainWindow +::OnInteractorStyleSwitch(bool theIsGaussStyleOn) +{ + if ( theIsGaussStyleOn ) + this->PushInteractorStyle(myInteractorStyle.GetPointer()); + else + this->PopInteractorStyle(); +} + +//---------------------------------------------------------------------------- +void VVTK_MainWindow::OnStartRecording() +{ + VVTK_RecorderDlg* aRecorderDlg = new VVTK_RecorderDlg( this, myRecorder ); + + if( !aRecorderDlg->exec() ) + return; + + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( true ); + myStopAction->setEnabled( true ); + + myRecorder->Record(); +} + +//---------------------------------------------------------------------------- +void VVTK_MainWindow::OnPlayRecording() +{ + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( true ); + myStopAction->setEnabled( true ); + // + myRecorder->Pause(); +} + +//---------------------------------------------------------------------------- +void VVTK_MainWindow::OnPauseRecording() +{ + myStartAction->setEnabled( false ); + myPlayAction->setEnabled( true ); + myPauseAction->setEnabled( false ); + myStopAction->setEnabled( true ); + // + myRecorder->Pause(); +} + +//---------------------------------------------------------------------------- +void VVTK_MainWindow::OnStopRecording() +{ + myStartAction->setEnabled( true ); + myPlayAction->setEnabled( false ); + myPauseAction->setEnabled( false ); + myStopAction->setEnabled( false ); + // + myRecorder->Stop(); +} + +//---------------------------------------------------------------------------- +int +convertAction( const int accelAction ); + +void +VVTK_MainWindow +::action( const int accelAction ) +{ + if ( accelAction == SUIT_Accel::ZoomFit ) + onFitAll(); + else { + int anEvent = convertAction( accelAction ); + InvokeEvent( anEvent, 0 ); + } +} + +//---------------------------------------------------------------------------- +VVTK_MainWindow1 +::VVTK_MainWindow1(QSplitter* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow): + VVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow), + myStyleSwitchAction(NULL), + mySplitter(theParent), + myPickingDlg(NULL) +{ + myPtsToolBar = new QToolBar(this); + myPtsToolBar->setCloseMode(QDockWindow::Undocked); + myPtsToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + moveDockWindow(myPtsToolBar,Qt::DockLeft); + + QPixmap aPixmap; + QtxAction* anAction; + + aPixmap = theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_INTERACTOR_STYLE_SWITCH" ) ); + anAction = new QtxAction(tr("MNU_VVTK_INTERACTOR_STYLE_SWITCH"), + aPixmap, + tr( "MNU_VVTK_INTERACTOR_STYLE_SWITCH" ), + 0, + this, + "VVTK/SVTK StyleSwitch", + true); + anAction->setToggleAction(true); + anAction->setStatusTip(tr("DSC_VVTK_INTERACTOR_STYLE_SWITCH")); + + anAction->addTo( myPtsToolBar ); + myStyleSwitchAction = anAction; + + if( theResourceMgr->integerValue( "VISU", "mouse_behaviour", true ) == 1 ) + myStyleSwitchAction->toggle(); + + aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_SELECTION_MODE_SWITCH")); + myPickingAction = new QtxAction(tr("MNU_VVTK_SELECTION_MODE_SWITCH"), + aPixmap, + tr( "MNU_VVTK_SELECTION_MODE_SWITCH" ), + 0, + this, + "VVTK/SVTK SelectionSwitch", + true); + myPickingAction->setToggleAction(true); + myPickingAction->setStatusTip(tr("DSC_VVTK_SELECTION_MODE_SWITCH")); + myPickingAction->addTo( myPtsToolBar ); + connect(myPickingAction, SIGNAL(toggled(bool)), this, SLOT(OnSelectionModeSwitch(bool))); + + myPickingDlg = new VVTK_PickingDlg( this, "PickingDlg" ); + myPickingDlg->SetAction( myPickingAction ); + + // Plane/Sphere Segmentation + aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_PLANE_SEGMENTATION_SWITCH")); + myPlaneSegmentationAction = new QtxAction(tr("MNU_VVTK_PLANE_SEGMENTATION_SWITCH"), + aPixmap, + tr( "MNU_VVTK_PLANE_SEGMENTATION_SWITCH" ), + 0, + this, + "VVTK/SVTK PlaneSegmentationSwitch", + true); + myPlaneSegmentationAction->setToggleAction(true); + myPlaneSegmentationAction->setStatusTip(tr("DSC_VVTK_PLANE_SEGMENTATION_SWITCH")); + //myPlaneSegmentationAction->addTo( myPtsToolBar ); + connect( myPlaneSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) ); + + aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_SPHERE_SEGMENTATION_SWITCH")); + mySphereSegmentationAction = new QtxAction(tr("MNU_VVTK_SPHERE_SEGMENTATION_SWITCH"), + aPixmap, + tr( "MNU_VVTK_SPHERE_SEGMENTATION_SWITCH" ), + 0, + this, + "VVTK/SVTK SphereSegmentationSwitch", + true); + mySphereSegmentationAction->setToggleAction(true); + mySphereSegmentationAction->setStatusTip(tr("DSC_VVTK_SPHERE_SEGMENTATION_SWITCH")); + //mySphereSegmentationAction->addTo( myPtsToolBar ); + connect( mySphereSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) ); + + mySegmentationCursorDlg = new VVTK_SegmentationCursorDlg( this, "SegmentationCursorDlg" ); + mySegmentationCursorDlg->SetPlaneAction( myPlaneSegmentationAction ); + mySegmentationCursorDlg->SetSphereAction( mySphereSegmentationAction ); + connect( mySegmentationCursorDlg, SIGNAL( scgClose() ), this, SLOT( OnSegmentationSwitch() ) ); + + SUIT_ToolButton* aSegmentationButton = new SUIT_ToolButton( myPtsToolBar ); + aSegmentationButton->AddAction( myPlaneSegmentationAction ); + aSegmentationButton->AddAction( mySphereSegmentationAction ); +} + +void +VVTK_MainWindow1 +::Initialize(SVTK_RenderWindowInteractor* theInteractor, + VVTK_Renderer1* theRenderer) +{ + myRenderer = theRenderer; + VVTK_MainWindow::Initialize(theInteractor); + + if( myStyleSwitchAction->isOn() ) + PushInteractorStyle(myInteractorStyle.GetPointer()); + connect(myStyleSwitchAction, SIGNAL(toggled(bool)), this, SLOT(OnInteractorStyleSwitch(bool))); + + mySegmentationCursorDlg->SetWidgetCtrl( theRenderer->GetWidgetCtrl() ); + mySegmentationCursorDlg->SetInteractor( theInteractor ); + + connect( theInteractor, SIGNAL( selectionChanged() ), SLOT( OnSelectionChanged() ) ); + myPickingDlg->SetInteractor( theInteractor ); +} + +VVTK_MainWindow1 +::~VVTK_MainWindow1() +{} + +//---------------------------------------------------------------------------- +VVTK_MainWindow2* +VVTK_MainWindow1 +::CreateMainWindow2(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow) +{ + myMainWindow2 = new VVTK_MainWindow2(theParent, + theName, + theResourceMgr, + theViewWindow, + myStyleSwitchAction); + return myMainWindow2; +} + + +//---------------------------------------------------------------------------- +void +VVTK_MainWindow1 +::OnSelectionModeSwitch(bool theIsSelectionOn) +{ + Selection_Mode aSelectionMode = SelectionMode(); + if(theIsSelectionOn && aSelectionMode != GaussPointSelection) + SetSelectionMode(GaussPointSelection); + else if(!theIsSelectionOn && aSelectionMode == GaussPointSelection) + SetSelectionMode(ActorSelection); + + if( theIsSelectionOn ) + { + myPickingDlg->Update(); + myPickingDlg->show(); + } + else + myPickingDlg->hide(); +} + +void +VVTK_MainWindow1 +::OnSelectionChanged() +{ + Selection_Mode aSelectionMode = SelectionMode(); + if(myPickingAction->isOn() && aSelectionMode != GaussPointSelection) + myPickingAction->setOn(false); + else if(!myPickingAction->isOn() && aSelectionMode == GaussPointSelection) + myPickingAction->setOn(true); +} + + +//---------------------------------------------------------------------------- +VISU_WidgetCtrl* +VVTK_MainWindow1 +::GetWidgetCtrl() +{ + return myRenderer->GetWidgetCtrl(); +} + +VISU_InsideCursorSettings* +VVTK_MainWindow1 +::GetInsideCursorSettings() +{ + return mySegmentationCursorDlg->GetInsideCursorSettings(); +} + +VISU_OutsideCursorSettings* +VVTK_MainWindow1 +::GetOutsideCursorSettings() +{ + return mySegmentationCursorDlg->GetOutsideCursorSettings(); +} + +VISU_PickingSettings* +VVTK_MainWindow1 +::GetPickingSettings() +{ + return myPickingDlg->GetPickingSettings(); +} + +//---------------------------------------------------------------------------- +void +VVTK_MainWindow1 +::SetPlanesSegementation(bool theIsOn) +{ + myPlaneSegmentationAction->setOn( theIsOn ); + OnSegmentationSwitch(myPlaneSegmentationAction); +} + +void +VVTK_MainWindow1 +::SetSphereSegementation(bool theIsOn) +{ + mySphereSegmentationAction->setOn( theIsOn ); + OnSegmentationSwitch(mySphereSegmentationAction); +} + +void +VVTK_MainWindow1 +::OnSegmentationSwitch(QtxAction* theAction) +{ + bool anIsSegmentationOn = myPlaneSegmentationAction->isOn() || + mySphereSegmentationAction->isOn(); + + if( !theAction ) + return; + + VISU_WidgetCtrl *aWidgetCtrl = myRenderer->GetWidgetCtrl(); + + if (anIsSegmentationOn) { + int anIndex = (theAction == myPlaneSegmentationAction) ? 0 : 1; + aWidgetCtrl->SetActiveIndex(anIndex); + } + aWidgetCtrl->SetEnabled(anIsSegmentationOn); + + if( theAction == myPlaneSegmentationAction && anIsSegmentationOn ) + mySphereSegmentationAction->setOn( false ); + else if( theAction == mySphereSegmentationAction && anIsSegmentationOn ) + myPlaneSegmentationAction->setOn( false ); + + if( anIsSegmentationOn ) + { + myMainWindow2->show(); + mySegmentationCursorDlg->SetIsPlaneSegmentation( theAction == myPlaneSegmentationAction ); + mySegmentationCursorDlg->UpdateSegmentation(); + mySegmentationCursorDlg->UpdateInsideGaussPoints(); + mySegmentationCursorDlg->UpdateOutsideGaussPoints(); + mySegmentationCursorDlg->show(); + } + else + { + myMainWindow2->hide(); + mySegmentationCursorDlg->hide(); + } +} + +void +VVTK_MainWindow1 +::OnSegmentationSwitch() +{ + QtxAction* anAction = ( QtxAction* )sender(); + OnSegmentationSwitch(anAction); +} + + +//---------------------------------------------------------------------------- +VVTK_MainWindow2 +::VVTK_MainWindow2(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow, + QtxAction* theStyleSwitchAction): + VVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow), + myStyleSwitchAction(theStyleSwitchAction) +{} + +VVTK_MainWindow2 +::~VVTK_MainWindow2() +{} + + +//---------------------------------------------------------------------------- +void +VVTK_MainWindow2 +::Initialize(SVTK_RenderWindowInteractor* theInteractor) +{ + VVTK_MainWindow::Initialize(theInteractor); + + if( myStyleSwitchAction->isOn() ) + PushInteractorStyle(myInteractorStyle.GetPointer()); + connect(myStyleSwitchAction, SIGNAL(toggled(bool)), this, SLOT(OnInteractorStyleSwitch(bool))); +} + diff --git a/src/VVTK/VVTK_MainWindow.h b/src/VVTK/VVTK_MainWindow.h new file mode 100644 index 00000000..1d0b0bc3 --- /dev/null +++ b/src/VVTK/VVTK_MainWindow.h @@ -0,0 +1,222 @@ +#ifndef VVTK_MAINWINDOW_H +#define VVTK_MAINWINDOW_H + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +#include "VVTK.h" +#include "SVTK_MainWindow.h" + +class QSplitter; + +class VISU_WidgetCtrl; +class VVTK_SegmentationCursorDlg; +class VISU_InsideCursorSettings; +class VISU_OutsideCursorSettings; +class VISU_PickingSettings; +class VVTK_InteractorStyle; +class VVTK_ControllerIncrement; +class VVTK_ControllerOnKeyDown; +class VVTK_PickingDlg; +class VVTK_MainWindow2; +class VVTK_Renderer1; +class VVTK_Renderer2; +class VVTK_Recorder; + +//---------------------------------------------------------------------------- +//! Customize SVTK_MainWindow to provide VVTK functionality +class VVTK_EXPORT VVTK_MainWindow: public SVTK_MainWindow +{ + Q_OBJECT; + +public: + //! Construct instance of the class + VVTK_MainWindow(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow); + + //! Reimplement SVTK_MainWindow::Initialize + virtual + void + Initialize(SVTK_RenderWindowInteractor* theInteractor); + + //! Destroy instance of the class + virtual + ~VVTK_MainWindow(); + + public slots: + + virtual + void + onDumpView(); + + //! To change active interactor style at run-time + virtual + void + OnInteractorStyleSwitch(bool theIsGaussStyleOn); + + virtual + void + action( const int ); + + virtual + void + OnStartRecording(); + + virtual + void + OnPlayRecording(); + + virtual + void + OnPauseRecording(); + + virtual + void + OnStopRecording(); + + protected: + vtkSmartPointer myInteractorStyle; + vtkSmartPointer myControllerIncrement; + vtkSmartPointer myControllerOnKeyDown; + + QToolBar* myRecordingToolBar; + QtxAction* myStartAction; + QtxAction* myPlayAction; + QtxAction* myPauseAction; + QtxAction* myStopAction; + + VVTK_Recorder *myRecorder; +}; + + +//---------------------------------------------------------------------------- +//! Extend VVTK_MainWindow to implement functionality for base view +class VVTK_EXPORT VVTK_MainWindow1: public VVTK_MainWindow +{ + Q_OBJECT; + +public: + //! Construct instance of the class + VVTK_MainWindow1(QSplitter* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow); + + //! Reimplement VVTK_MainWindow::Initialize + virtual + void + Initialize(SVTK_RenderWindowInteractor* theInteractor, + VVTK_Renderer1* theRenderer); + + //! Destroy instance of the class + virtual + ~VVTK_MainWindow1(); + + //! Create instance of the segmented VVTK_MainWindow + /*! + The two views (VVTK_MainWindow1 and VVTK_MainWindow2) should change its behaviour in the same time. + So, it is necessary to synhronize them through sharing some common pointers. + */ + VVTK_MainWindow2* + CreateMainWindow2(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow); + + VISU_WidgetCtrl* GetWidgetCtrl(); + + void + SetPlanesSegementation(bool theIsOn); + + void + SetSphereSegementation(bool theIsOn); + + VISU_InsideCursorSettings* + GetInsideCursorSettings(); + + //! Get contained VISU_OutsideCursorSettings + VISU_OutsideCursorSettings* + GetOutsideCursorSettings(); + + //! Get contained VISU_PickingSettings + VISU_PickingSettings* + GetPickingSettings(); + + public slots: + //! To activate/ deactivate the segementation cursor at run-time + void + OnSegmentationSwitch();//bool theIsSegmentationOn); + + void + OnSegmentationSwitch(QtxAction* theAction);//bool theIsSegmentationOn); + + //! To change active selection mode at run-time + virtual + void + OnSelectionModeSwitch(bool theIsSelectionOn); + + //! To adjust to the current selection mode + virtual + void + OnSelectionChanged(); + + protected: + VVTK_Renderer1* myRenderer; //!< Keeps extended version of SVTK_Renderer + + VVTK_MainWindow2* myMainWindow2; //!< Refer to segmented view + + QtxAction* myStyleSwitchAction; //!< Action for switch interactor style + QToolBar* myPtsToolBar; //!< Additional tool bar + + //! To implement show/hide segmented view on acttivate/ deactivate segementation cursor + QSplitter* mySplitter; + + QtxAction* myPickingAction; //!< Action for switch selection mode + QtxAction* myPlaneSegmentationAction; //!< Action for switch segmentation mode to plane + QtxAction* mySphereSegmentationAction; //!< Action for switch segmentation mode to sphere + + //! Keep reference to VVTK_SegmentationCursorDlg + VVTK_SegmentationCursorDlg* mySegmentationCursorDlg; + VVTK_PickingDlg* myPickingDlg; //!< Keep reference to VVTK_PickingDlg +}; + + +//---------------------------------------------------------------------------- +//! Extend VVTK_MainWindow to implement functionality for segmented view +class VVTK_EXPORT VVTK_MainWindow2: public VVTK_MainWindow +{ + Q_OBJECT; + + friend class VVTK_MainWindow1; + + //! Construct instance of the class + VVTK_MainWindow2(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr, + SUIT_ViewWindow* theViewWindow, + QtxAction* theStyleSwitchAction); +public: + //! Destroy instance of the class + virtual + ~VVTK_MainWindow2(); + + //! Reimplement SVTK_MainWindow::Initialize + virtual + void + Initialize(SVTK_RenderWindowInteractor* theInteractor); + + protected: + // Refer to the VVTK_MainWindow1::myStyleSwitchAction instance + QtxAction* myStyleSwitchAction; + +}; + + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/VVTK/VVTK_PickingDlg.cxx b/src/VVTK/VVTK_PickingDlg.cxx new file mode 100644 index 00000000..06e1dabb --- /dev/null +++ b/src/VVTK/VVTK_PickingDlg.cxx @@ -0,0 +1,378 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VVTK_PickingDlg.cxx +// Author : Oleg Uvarov +// Module : VISU + +#include "VVTK_PickingDlg.h" + +#include "VISU_GaussPtsAct.h" +#include "VISU_GaussPtsSettings.h" + +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" + +#include "SVTK_RenderWindowInteractor.h" + +#include +#include +#include +#include +#include +#include + +#include "utilities.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "QtxAction.h" +#include "QtxDblSpinBox.h" +#include "QtxIntSpinBox.h" + +using namespace std; + +VVTK_PickingDlg::VVTK_PickingDlg( QWidget* parent, const char* name ) + :QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ), + myEventCallbackCommand( vtkCallbackCommand::New() ), + myPickingSettings( VISU_PickingSettings::New() ) +{ + myPriority = 0.0; + myEventCallbackCommand->Delete(); + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(VVTK_PickingDlg::ProcessEvents); + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + setCaption( tr( "PICKING_DLG_TITLE" ) ); + setSizeGripEnabled(TRUE); + + QVBoxLayout* TopLayout = new QVBoxLayout( this ); + TopLayout->setSpacing(6); + TopLayout->setMargin(11); + + QVBox* aBox = new QVBox( this ); + aBox->setMargin(0); + aBox->setSpacing(6); + + // Cursor + QGroupBox* CursorGroup = new QGroupBox( tr( "CURSOR_TITLE" ), aBox, "CursorGroup" ); + CursorGroup->setColumnLayout(0, Qt::Vertical ); + CursorGroup->layout()->setSpacing( 0 ); + CursorGroup->layout()->setMargin( 0 ); + + QGridLayout* CursorGroupLayout = new QGridLayout (CursorGroup->layout()); + CursorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + CursorGroupLayout->setSpacing(6); + CursorGroupLayout->setMargin(11); + + QLabel* CursorSizeLabel = new QLabel( tr( "CURSOR_SIZE" ), CursorGroup ); + myCursorSizeSpinBox = new QtxDblSpinBox( 0, 1, 0.1, CursorGroup ); + myCursorSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + QLabel* PyramidHeightLabel = new QLabel( tr( "PYRAMID_HEIGHT" ), CursorGroup ); + double aHeightMin=1.e-7; + double aHeightMax=10.; + double aHeightStep=0.1; + myPyramidHeightSpinBox = new QtxDblSpinBox(aHeightMin, aHeightMax, aHeightStep, CursorGroup ); + myPyramidHeightSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + QLabel* SelectionColorLabel = new QLabel( tr( "SELECTION_COLOR" ), CursorGroup ); + mySelectionColorButton = new QPushButton( CursorGroup ); + mySelectionColorButton->setPaletteBackgroundColor( Qt::blue ); + mySelectionColorButton->setPaletteForegroundColor( Qt::blue ); + connect( mySelectionColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) ); + + CursorGroupLayout->addWidget( CursorSizeLabel, 0, 0 ); + CursorGroupLayout->addWidget( myCursorSizeSpinBox, 0, 1 ); + CursorGroupLayout->addWidget( PyramidHeightLabel, 1, 0 ); + CursorGroupLayout->addWidget( myPyramidHeightSpinBox, 1, 1 ); + CursorGroupLayout->addWidget( SelectionColorLabel, 2, 0 ); + CursorGroupLayout->addWidget( mySelectionColorButton, 2, 1 ); + + // Tolerance + QGroupBox* ToleranceGroup = new QGroupBox( tr( "TOLERANCE_TITLE" ), aBox, "ToleranceGroup" ); + ToleranceGroup->setColumnLayout(0, Qt::Vertical ); + ToleranceGroup->layout()->setSpacing( 0 ); + ToleranceGroup->layout()->setMargin( 0 ); + + QGridLayout* ToleranceGroupLayout = new QGridLayout (ToleranceGroup->layout()); + ToleranceGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + ToleranceGroupLayout->setSpacing(6); + ToleranceGroupLayout->setMargin(11); + + QLabel* PointToleranceLabel = new QLabel( tr( "POINT_TOLERANCE" ), ToleranceGroup ); + myPointToleranceSpinBox = new QtxDblSpinBox( 0.001, 10.0, 0.01, ToleranceGroup ); + myPointToleranceSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + ToleranceGroupLayout->addWidget( PointToleranceLabel, 0, 0 ); + ToleranceGroupLayout->addWidget( myPointToleranceSpinBox, 0, 1 ); + + // Information window + QGroupBox* InfoWindowGroup = new QGroupBox( tr( "INFO_WINDOW_TITLE" ), aBox, "InfoWindowGroup" ); + InfoWindowGroup->setColumnLayout(0, Qt::Vertical ); + InfoWindowGroup->layout()->setSpacing( 0 ); + InfoWindowGroup->layout()->setMargin( 0 ); + + QGridLayout* InfoWindowGroupLayout = new QGridLayout (InfoWindowGroup->layout()); + InfoWindowGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + InfoWindowGroupLayout->setSpacing(6); + InfoWindowGroupLayout->setMargin(11); + + QLabel* TransparencyLabel = new QLabel( tr( "TRANSPARENCY" ), InfoWindowGroup ); + myTransparencySpinBox = new QtxIntSpinBox( 0, 100, 10, InfoWindowGroup ); + myTransparencySpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 ); + InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 ); + + QLabel* PositionLabel = new QLabel( tr( "POSITION" ), InfoWindowGroup ); + myPositionComboBox = new QComboBox( InfoWindowGroup ); + myPositionComboBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + myPositionComboBox->insertItem( tr( "BELOW_POINT" ) ); + myPositionComboBox->insertItem( tr( "TOP_LEFT_CORNER" ) ); + + InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 ); + InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 ); + InfoWindowGroupLayout->addWidget( PositionLabel, 1, 0 ); + InfoWindowGroupLayout->addWidget( myPositionComboBox, 1, 1 ); + + // Movement of the camera + QGroupBox* CameraGroup = new QGroupBox( tr( "CAMERA_TITLE" ), aBox, "CameraGroup" ); + CameraGroup->setColumnLayout(0, Qt::Vertical ); + CameraGroup->layout()->setSpacing( 0 ); + CameraGroup->layout()->setMargin( 0 ); + + QGridLayout* CameraGroupLayout = new QGridLayout (CameraGroup->layout()); + CameraGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + CameraGroupLayout->setSpacing(6); + CameraGroupLayout->setMargin(11); + + QLabel* ZoomFactorLabel = new QLabel( tr( "ZOOM_FACTOR" ), CameraGroup ); + myZoomFactorSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1, CameraGroup ); + myZoomFactorSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + QLabel* StepNumberLabel = new QLabel( tr( "STEP_NUMBER" ), CameraGroup ); + myStepNumberSpinBox = new QtxIntSpinBox( 1, 100, 1, CameraGroup ); + myStepNumberSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + CameraGroupLayout->addWidget( ZoomFactorLabel, 0, 0 ); + CameraGroupLayout->addWidget( myZoomFactorSpinBox, 0, 1 ); + CameraGroupLayout->addWidget( StepNumberLabel, 1, 0 ); + CameraGroupLayout->addWidget( myStepNumberSpinBox, 1, 1 ); + + // Display parent mesh element + QGroupBox* ParentMeshGroup = new QGroupBox( tr( "PARENT_MESH_TITLE" ), aBox, "ParentMeshGroup" ); + ParentMeshGroup->setColumnLayout(0, Qt::Vertical ); + ParentMeshGroup->layout()->setSpacing( 0 ); + ParentMeshGroup->layout()->setMargin( 0 ); + + QGridLayout* ParentMeshGroupLayout = new QGridLayout (ParentMeshGroup->layout()); + ParentMeshGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); + ParentMeshGroupLayout->setSpacing(6); + ParentMeshGroupLayout->setMargin(11); + + myDisplayParentMeshCheckBox = new QCheckBox( tr( "DISPLAY_PARENT_MESH" ), ParentMeshGroup ); + ParentMeshGroupLayout->addWidget( myDisplayParentMeshCheckBox, 0, 0 ); + + // Common buttons =========================================================== + QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); + GroupButtons->setColumnLayout(0, Qt::Vertical ); + GroupButtons->layout()->setSpacing( 0 ); + GroupButtons->layout()->setMargin( 0 ); + QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setSpacing( 6 ); + GroupButtonsLayout->setMargin( 11 ); + + QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" ); + buttonApply->setAutoDefault( TRUE ); + buttonApply->setDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonApply, 0, 0 ); + GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" ); + buttonClose->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonClose, 0, 2 ); + + TopLayout->addWidget( aBox ); + TopLayout->addWidget( GroupButtons ); + + connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) ); + connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) ); +} + +VVTK_PickingDlg::~VVTK_PickingDlg() +{ +} + +void VVTK_PickingDlg::AddActor( VISU_GaussPtsAct* theActor ) +{ + theActor->SetPickingSettings( myPickingSettings.GetPointer() ); +} + +void VVTK_PickingDlg::RemoveActor( VISU_GaussPtsAct* theActor ) +{ + theActor->SetPickingSettings( NULL ); +} + +void VVTK_PickingDlg::Update() +{ + float aCursorSize = 0.5; + float aPyramidHeight = 10.0; + float aPointTolerance = 0.1; + QColor aColor = Qt::yellow; + int anInfoWindowTransparency = 50; + int anInfoWindowPosition = VISU_PickingSettings::BelowPoint; + float aZoomFactor = 1.5; + int aStepNumber = 10; + bool aDisplayParentMesh = false; + + if( !myPickingSettings->GetInitial() ) + { + myCursorSizeSpinBox->setValue( myPickingSettings->GetCursorSize() ); + myPyramidHeightSpinBox->setValue( myPickingSettings->GetPyramidHeight() ); + myPointToleranceSpinBox->setValue( myPickingSettings->GetPointTolerance() ); + myTransparencySpinBox->setValue( int(myPickingSettings->GetInfoWindowTransparency() * 100.0) ); + myPositionComboBox->setCurrentItem( myPickingSettings->GetInfoWindowPosition() ); + myZoomFactorSpinBox->setValue( myPickingSettings->GetZoomFactor() ); + myStepNumberSpinBox->setValue( myPickingSettings->GetStepNumber() ); + myDisplayParentMeshCheckBox->setChecked( myPickingSettings->GetDisplayParentMesh() ); + + float* aColor = myPickingSettings->GetColor(); + mySelectionColorButton->setPaletteBackgroundColor( QColor( ( int )( aColor[0] * 255.0 ), + ( int )( aColor[1] * 255.0 ), + ( int )( aColor[2] * 255.0 ) ) ); + + return; + } + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + aCursorSize = aResourceMgr->doubleValue( "VISU", "picking_cursor_size", aCursorSize ); + myCursorSizeSpinBox->setValue( aCursorSize ); + + aPyramidHeight = aResourceMgr->doubleValue( "VISU", "picking_pyramid_height", aPyramidHeight ); + myPyramidHeightSpinBox->setValue( aPyramidHeight ); + + aPointTolerance = aResourceMgr->doubleValue( "VISU", "picking_point_tolerance", aPointTolerance ); + myPointToleranceSpinBox->setValue( aPointTolerance ); + + aColor = aResourceMgr->colorValue( "VISU", "picking_selection_color", aColor ); + mySelectionColorButton->setPaletteBackgroundColor( aColor ); + + anInfoWindowTransparency = aResourceMgr->integerValue( "VISU", "picking_transparency", anInfoWindowTransparency ); + myTransparencySpinBox->setValue( anInfoWindowTransparency ); + + anInfoWindowPosition = aResourceMgr->integerValue( "VISU", "picking_position", anInfoWindowPosition ); + myPositionComboBox->setCurrentItem( anInfoWindowPosition ); + + aZoomFactor = aResourceMgr->doubleValue( "VISU", "picking_zoom_factor", aZoomFactor ); + myZoomFactorSpinBox->setValue( aZoomFactor ); + + aStepNumber = aResourceMgr->integerValue( "VISU", "picking_step_number", aStepNumber ); + myStepNumberSpinBox->setValue( aStepNumber ); + + aDisplayParentMesh = aResourceMgr->booleanValue( "VISU", "picking_display_parent_mesh", aDisplayParentMesh ); + myDisplayParentMeshCheckBox->setChecked( aDisplayParentMesh ); + + onClickApply(); +} + + +VISU_PickingSettings* +VVTK_PickingDlg +::GetPickingSettings() +{ + return myPickingSettings.GetPointer(); +} + +void VVTK_PickingDlg::SetInteractor( SVTK_RenderWindowInteractor* theInteractor ) +{ + myInteractor = theInteractor; + + theInteractor->GetDevice()->AddObserver(vtkCommand::KeyPressEvent, + myEventCallbackCommand.GetPointer(), + myPriority); +} + + +void VVTK_PickingDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + VVTK_PickingDlg* self = reinterpret_cast(theClientData); + + switch(theEvent){ + case vtkCommand::KeyPressEvent: + self->KeyPressed(); + break; + } +} + +void VVTK_PickingDlg::KeyPressed() +{ + if( myInteractor->GetDevice()->GetKeyCode() == 'P' ) + { + bool aDisplayParentMesh = !myPickingSettings->GetDisplayParentMesh(); + myPickingSettings->SetDisplayParentMesh( aDisplayParentMesh ); + + myDisplayParentMeshCheckBox->setChecked( aDisplayParentMesh ); + + myPickingSettings->InvokeEvent(VISU::UpdatePickingSettingsEvent,NULL); + } +} + +void VVTK_PickingDlg::onClickApply() +{ + myPickingSettings->SetInitial( false ); + + myPickingSettings->SetCursorSize( myCursorSizeSpinBox->value() ); + myPickingSettings->SetPyramidHeight( myPyramidHeightSpinBox->value() ); + myPickingSettings->SetPointTolerance( myPointToleranceSpinBox->value() ); + myPickingSettings->SetInfoWindowTransparency( myTransparencySpinBox->value() / 100.0 ); + myPickingSettings->SetInfoWindowPosition( myPositionComboBox->currentItem() ); + myPickingSettings->SetZoomFactor( myZoomFactorSpinBox->value() ); + myPickingSettings->SetStepNumber( myStepNumberSpinBox->value() ); + myPickingSettings->SetDisplayParentMesh( myDisplayParentMeshCheckBox->isChecked() ); + + QColor aButtonColor = mySelectionColorButton->paletteBackgroundColor(); + float aColor[3]; + aColor[0] = aButtonColor.red() / 255.0; + aColor[1] = aButtonColor.green() / 255.0; + aColor[2] = aButtonColor.blue() / 255.0; + myPickingSettings->SetColor( aColor ); + + myPickingSettings->InvokeEvent(VISU::UpdatePickingSettingsEvent,NULL); +} + +void VVTK_PickingDlg::onClickClose() +{ + myAction->setOn( false ); + reject(); +} + +void VVTK_PickingDlg::done( int r ) +{ + myAction->setOn( false ); + QDialog::done( r ); +} + +void VVTK_PickingDlg::onColorButtonPressed() +{ + QColor aColor = QColorDialog::getColor( mySelectionColorButton->paletteBackgroundColor(), this ); + if( aColor.isValid() ) + mySelectionColorButton->setPaletteBackgroundColor( aColor ); +} diff --git a/src/VVTK/VVTK_PickingDlg.h b/src/VVTK/VVTK_PickingDlg.h new file mode 100644 index 00000000..72d3a4ec --- /dev/null +++ b/src/VVTK/VVTK_PickingDlg.h @@ -0,0 +1,100 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VVTK_PickingDlg.h +// Author : Oleg Uvarov +// Module : VISU + +#ifndef VVTK_PICKINGDLG_H +#define VVTK_PICKINGDLG_H + +#include + +#include +#include + +class vtkActorCollection; +class vtkCallbackCommand; +class vtkImageData; + +class QLabel; +class QComboBox; +class QCheckBox; +class QPushButton; + +class QtxAction; +class QtxDblSpinBox; +class QtxIntSpinBox; + +class VISU_GaussPtsAct; +class VISU_PickingSettings; + +class SVTK_RenderWindowInteractor; + +//! Picking Dialog. +/*! + * Uses for set up picking preferenses and apply + * them to all actors in the current renderer. + */ +class VVTK_PickingDlg : public QDialog +{ + Q_OBJECT + +public: + VVTK_PickingDlg( QWidget* parent = 0, const char* name = 0 ); + ~VVTK_PickingDlg(); + + //! Used to switch toggle state of the Picking action. + void SetAction( QtxAction* theAction ) { myAction = theAction; } + + //! Make an actor to listen the event of Update Picking Settings event. + void AddActor( VISU_GaussPtsAct* ); + void RemoveActor( VISU_GaussPtsAct* ); + + //! Update dialog contents. + void Update(); + + VISU_PickingSettings* GetPickingSettings(); + + void SetInteractor( SVTK_RenderWindowInteractor* ); + +protected slots: + virtual void done( int ); + + void onClickApply(); + void onClickClose(); + + void onColorButtonPressed(); + +private: + static void ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + + void KeyPressed(); + +private: + QtxDblSpinBox* myCursorSizeSpinBox; + QtxDblSpinBox* myPyramidHeightSpinBox; + QPushButton* mySelectionColorButton; + QtxDblSpinBox* myPointToleranceSpinBox; + QtxIntSpinBox* myTransparencySpinBox; + QComboBox* myPositionComboBox; + QtxDblSpinBox* myZoomFactorSpinBox; + QtxIntSpinBox* myStepNumberSpinBox; + QCheckBox* myDisplayParentMeshCheckBox; + + QtxAction* myAction; + vtkSmartPointer myPickingSettings; + + SVTK_RenderWindowInteractor* myInteractor; + + float myPriority; + vtkSmartPointer myEventCallbackCommand; +}; + +#endif diff --git a/src/VVTK/VVTK_PrimitiveBox.cxx b/src/VVTK/VVTK_PrimitiveBox.cxx new file mode 100644 index 00000000..84ef52b9 --- /dev/null +++ b/src/VVTK/VVTK_PrimitiveBox.cxx @@ -0,0 +1,358 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_PrimitiveBox.cxx +// Author : Oleg UVAROV +// Module : VISU + +#include "VVTK_PrimitiveBox.h" + +#include "VISU_OpenGLPointSpriteMapper.hxx" + +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" + +#include "QtxDblSpinBox.h" +#include "QtxIntSpinBox.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; + +VVTK_PrimitiveBox::VVTK_PrimitiveBox( QWidget* parent ) : + QGroupBox( parent ) +{ + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + setTitle( tr( "PRIMITIVE_TITLE" ) ); + setColumnLayout(0, Qt::Vertical ); + layout()->setSpacing( 0 ); + layout()->setMargin( 0 ); + + QGridLayout* aLayout = new QGridLayout( layout() ); + aLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + aLayout->setSpacing(6); + aLayout->setMargin(11); + + myPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite; + + QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/"; + myMainTexture = aRootDir + "sprite_texture.bmp"; + myAlphaTexture = aRootDir + "sprite_alpha.bmp"; + + // Primitive Type + QButtonGroup* aPrimitiveTypeGroup = new QButtonGroup( 3, Qt::Horizontal, this, "PrimitiveTypeGroup" ); + aPrimitiveTypeGroup->setMinimumWidth( 450 ); + aPrimitiveTypeGroup->setRadioButtonExclusive( true ); + aPrimitiveTypeGroup->setFrameStyle( QFrame::NoFrame ); + aPrimitiveTypeGroup->layout()->setMargin( 0 ); + + myPointSpriteButton = new QRadioButton( tr( "POINT_SPRITE" ), aPrimitiveTypeGroup ); + myOpenGLPointButton = new QRadioButton( tr( "OPENGL_POINT" ), aPrimitiveTypeGroup ); + myGeomSphereButton = new QRadioButton( tr( "GEOMETRICAL_SPHERE" ), aPrimitiveTypeGroup ); + + aLayout->addMultiCellWidget( aPrimitiveTypeGroup, 0, 0, 0, 2 ); + + // Clamp ( Point Sprite & OpenGL Point ) + myClampLabel = new QLabel( tr( "CLAMP" ), this ); + myClampSpinBox = new QtxDblSpinBox( 1.0, 512.0, 1.0, this ); + myClampSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + aLayout->addWidget( myClampLabel, 1, 0 ); + aLayout->addMultiCellWidget( myClampSpinBox, 1, 1, 1, 2 ); + + // Main Texture ( Point Sprite ) + myMainTextureLabel = new QLabel( tr( "MAIN_TEXTURE" ), this ); + myMainTextureLineEdit = new QLineEdit( this ); + myMainTextureButton = new QPushButton( this ); + myMainTextureButton->setAutoDefault( false ); + myMainTextureButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) ); + connect( myMainTextureButton, SIGNAL( clicked() ), this, SLOT( onBrowseMainTexture() ) ); + + aLayout->addWidget( myMainTextureLabel, 2, 0 ); + aLayout->addWidget( myMainTextureLineEdit, 2, 1 ); + aLayout->addWidget( myMainTextureButton, 2, 2 ); + + // Alpha Texture ( Point Sprite ) + myAlphaTextureLabel = new QLabel( tr( "ALPHA_TEXTURE" ), this ); + myAlphaTextureLineEdit = new QLineEdit( this ); + myAlphaTextureButton = new QPushButton( this ); + myAlphaTextureButton->setAutoDefault( false ); + myAlphaTextureButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) ); + connect( myAlphaTextureButton, SIGNAL( clicked() ), this, SLOT( onBrowseAlphaTexture() ) ); + + aLayout->addWidget( myAlphaTextureLabel, 3, 0 ); + aLayout->addWidget( myAlphaTextureLineEdit, 3, 1 ); + aLayout->addWidget( myAlphaTextureButton, 3, 2 ); + + // Alpha Threshold ( Point Sprite ) + myAlphaThresholdLabel = new QLabel( tr( "ALPHA_THRESHOLD" ), this ); + myAlphaThresholdSpinBox = new QtxDblSpinBox( 0.0, 1.0, 0.1, this ); + myAlphaThresholdSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + aLayout->addWidget( myAlphaThresholdLabel, 4, 0 ); + aLayout->addMultiCellWidget( myAlphaThresholdSpinBox, 4, 4, 1, 2 ); + + // Resolution ( Geometrical Sphere ) + myResolutionLabel = new QLabel( tr( "RESOLUTION" ), this ); + myResolutionSpinBox = new QtxIntSpinBox( 3, 100, 1, this ); + myResolutionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + connect( myResolutionSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onResolutionChanged( int ) ) ); + + aLayout->addWidget( myResolutionLabel, 1, 0 ); + aLayout->addMultiCellWidget( myResolutionSpinBox, 1, 1, 1, 2 ); + + // Number of faces ( Geometrical Sphere ) + myFaceNumberLabel = new QLabel( tr( "FACE_NUMBER" ), this ); + myFaceNumberLineEdit = new QLineEdit( this ); + myFaceNumberLineEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myFaceNumberLineEdit->setEnabled( false ); + //myFaceNumberLineEdit->setReadOnly( true ); + + aLayout->addWidget( myFaceNumberLabel, 2, 0 ); + aLayout->addMultiCellWidget( myFaceNumberLineEdit, 2, 2, 1, 2 ); + + // Notification ( Geometrical Sphere ) + myFaceLimitLabel = new QLabel( tr( "FACE_LIMIT" ), this ); + myFaceLimitSpinBox = new QtxIntSpinBox( 10, 1000000, 10, this ); + myFaceLimitSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + aLayout->addWidget( myFaceLimitLabel, 3, 0 ); + aLayout->addMultiCellWidget( myFaceLimitSpinBox, 3, 3, 1, 2 ); + + connect( myPointSpriteButton, SIGNAL( clicked() ), this, SLOT( onTogglePointSprite() ) ); + connect( myOpenGLPointButton, SIGNAL( clicked() ), this, SLOT( onToggleOpenGLPoint() ) ); + connect( myGeomSphereButton, SIGNAL( clicked() ), this, SLOT( onToggleGeomSphere() ) ); +} + +void VVTK_PrimitiveBox::onTogglePointSprite() +{ + myPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite; + + myClampLabel->show(); + myClampSpinBox->show(); + + myMainTextureLabel->show(); + myMainTextureLineEdit->show(); + myMainTextureButton->show(); + + myAlphaTextureLabel->show(); + myAlphaTextureLineEdit->show(); + myAlphaTextureButton->show(); + + myAlphaThresholdLabel->show(); + myAlphaThresholdSpinBox->show(); + + myResolutionLabel->hide(); + myResolutionSpinBox->hide(); + + myFaceNumberLabel->hide(); + myFaceNumberLineEdit->hide(); + + myFaceLimitLabel->hide(); + myFaceLimitSpinBox->hide(); +} + +void VVTK_PrimitiveBox::onToggleOpenGLPoint() +{ + myPrimitiveType = VISU_OpenGLPointSpriteMapper::OpenGLPoint; + + myClampLabel->show(); + myClampSpinBox->show(); + + myMainTextureLabel->hide(); + myMainTextureLineEdit->hide(); + myMainTextureButton->hide(); + + myAlphaTextureLabel->hide(); + myAlphaTextureLineEdit->hide(); + myAlphaTextureButton->hide(); + + myAlphaThresholdLabel->hide(); + myAlphaThresholdSpinBox->hide(); + + myResolutionLabel->hide(); + myResolutionSpinBox->hide(); + + myFaceNumberLabel->hide(); + myFaceNumberLineEdit->hide(); + + myFaceLimitLabel->hide(); + myFaceLimitSpinBox->hide(); +} + +void VVTK_PrimitiveBox::onToggleGeomSphere() +{ + myPrimitiveType = VISU_OpenGLPointSpriteMapper::GeomSphere; + + myClampLabel->hide(); + myClampSpinBox->hide(); + + myMainTextureLabel->hide(); + myMainTextureLineEdit->hide(); + myMainTextureButton->hide(); + + myAlphaTextureLabel->hide(); + myAlphaTextureLineEdit->hide(); + myAlphaTextureButton->hide(); + + myAlphaThresholdLabel->hide(); + myAlphaThresholdSpinBox->hide(); + + myResolutionLabel->show(); + myResolutionSpinBox->show(); + + myFaceNumberLabel->show(); + myFaceNumberLineEdit->show(); + + myFaceLimitLabel->show(); + myFaceLimitSpinBox->show(); +} + +void VVTK_PrimitiveBox::onResolutionChanged( int theResolution ) +{ + setFaceNumber( 2 * theResolution * ( theResolution - 2 ) ); +} + +void VVTK_PrimitiveBox::setPrimitiveType( int theType ) +{ + myPrimitiveType = theType; + + switch( myPrimitiveType ) + { + case VISU_OpenGLPointSpriteMapper::PointSprite : + myPointSpriteButton->setChecked( true ); + onTogglePointSprite(); + break; + case VISU_OpenGLPointSpriteMapper::OpenGLPoint : + myOpenGLPointButton->setChecked( true ); + onToggleOpenGLPoint(); + break; + case VISU_OpenGLPointSpriteMapper::GeomSphere : + myGeomSphereButton->setChecked( true ); + onToggleGeomSphere(); + break; + default : break; + } +} + +float VVTK_PrimitiveBox::getClamp() const +{ + return myClampSpinBox->value(); +} + +void VVTK_PrimitiveBox::setClamp( float theClamp ) +{ + myClampSpinBox->setValue( theClamp ); +} + +void VVTK_PrimitiveBox::setClampMaximum( float theClampMaximum ) +{ + myClampSpinBox->setMaxValue( theClampMaximum ); +} + +void VVTK_PrimitiveBox::setMainTexture( const QString& theMainTexture ) +{ + myMainTexture = theMainTexture; + myMainTextureLineEdit->setText( theMainTexture.section( '/', -1 ) ); +} + +void VVTK_PrimitiveBox::setAlphaTexture( const QString& theAlphaTexture ) +{ + myAlphaTexture = theAlphaTexture; + myAlphaTextureLineEdit->setText( theAlphaTexture.section( '/', -1 ) ); +} + +float VVTK_PrimitiveBox::getAlphaThreshold() const +{ + return myAlphaThresholdSpinBox->value(); +} + +void VVTK_PrimitiveBox::setAlphaThreshold( float theAlphaThreshold ) +{ + myAlphaThresholdSpinBox->setValue( theAlphaThreshold ); +} + +int VVTK_PrimitiveBox::getResolution() const +{ + return myResolutionSpinBox->value(); +} + +void VVTK_PrimitiveBox::setResolution( int theResolution ) +{ + myResolutionSpinBox->setValue( theResolution ); +} + +int VVTK_PrimitiveBox::getFaceNumber() const +{ + int aResolution = getResolution(); + return 2 * aResolution * ( aResolution - 2 ); + //return myFaceNumberLineEdit->text().toInt(); +} + +void VVTK_PrimitiveBox::setFaceNumber( int theFaceNumber ) +{ + myFaceNumberLineEdit->setText( QString::number( theFaceNumber ) ); +} + +int VVTK_PrimitiveBox::getFaceLimit() const +{ + return myFaceLimitSpinBox->value(); +} + +void VVTK_PrimitiveBox::setFaceLimit( int theFaceLimit ) +{ + myFaceLimitSpinBox->setValue( theFaceLimit ); +} + +void VVTK_PrimitiveBox::onBrowseMainTexture() +{ + QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/"; + QString aFileName = QFileDialog::getOpenFileName( aRootDir, "Bitmap (*.bmp *.jpg *.png)", this ); + + if( aFileName.isNull() ) + return; + + myMainTexture = aFileName; + myMainTextureLineEdit->setText( aFileName.section( '/', -1 ) ); +} + +void VVTK_PrimitiveBox::onBrowseAlphaTexture() +{ + QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/"; + QString aFileName = QFileDialog::getOpenFileName( aRootDir, "Bitmap (*.bmp *.jpg *.png)", this ); + + if( aFileName.isNull() ) + return; + + myAlphaTexture = aFileName; + myAlphaTextureLineEdit->setText( aFileName.section( '/', -1 ) ); +} diff --git a/src/VVTK/VVTK_PrimitiveBox.h b/src/VVTK/VVTK_PrimitiveBox.h new file mode 100644 index 00000000..a6b8a0af --- /dev/null +++ b/src/VVTK/VVTK_PrimitiveBox.h @@ -0,0 +1,121 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_PrimitiveBox.h +// Author : Oleg UVAROV +// Module : VISU + +#ifndef VVTK_PRIMITIVEBOX_H +#define VVTK_PRIMITIVEBOX_H + +#include + +class QLabel; +class QLineEdit; +class QPushButton; +class QRadioButton; + +class QtxDblSpinBox; +class QtxIntSpinBox; + +class VVTK_PrimitiveBox : public QGroupBox +{ + Q_OBJECT + +public: + VVTK_PrimitiveBox( QWidget* ); + ~VVTK_PrimitiveBox() {} + +public: + int getPrimitiveType() const { return myPrimitiveType; } + void setPrimitiveType( int ); + + float getClamp() const; + void setClamp( float ); + void setClampMaximum( float ); + + QString getMainTexture() const { return myMainTexture; } + void setMainTexture( const QString& ); + + QString getAlphaTexture() const { return myAlphaTexture; } + void setAlphaTexture( const QString& ); + + float getAlphaThreshold() const; + void setAlphaThreshold( float ); + + int getResolution() const; + void setResolution( int ); + + int getFaceNumber() const; + void setFaceNumber( int ); + + int getFaceLimit() const; + void setFaceLimit( int ); + +protected slots: + void onTogglePointSprite(); + void onToggleOpenGLPoint(); + void onToggleGeomSphere(); + + void onBrowseMainTexture(); + void onBrowseAlphaTexture(); + + void onResolutionChanged( int ); + +private: + int myPrimitiveType; + + QRadioButton* myPointSpriteButton; + QRadioButton* myOpenGLPointButton; + QRadioButton* myGeomSphereButton; + + QString myMainTexture; + QString myAlphaTexture; + + QLabel* myClampLabel; + QtxDblSpinBox* myClampSpinBox; + + QLabel* myMainTextureLabel; + QLineEdit* myMainTextureLineEdit; + QPushButton* myMainTextureButton; + + QLabel* myAlphaTextureLabel; + QLineEdit* myAlphaTextureLineEdit; + QPushButton* myAlphaTextureButton; + + QLabel* myAlphaThresholdLabel; + QtxDblSpinBox* myAlphaThresholdSpinBox; + + QLabel* myResolutionLabel; + QtxIntSpinBox* myResolutionSpinBox; + + QLabel* myFaceNumberLabel; + QLineEdit* myFaceNumberLineEdit; + + QLabel* myFaceLimitLabel; + QtxIntSpinBox* myFaceLimitSpinBox; +}; + + + +#endif diff --git a/src/VVTK/VVTK_Recorder.cxx b/src/VVTK/VVTK_Recorder.cxx new file mode 100755 index 00000000..e9c734e9 --- /dev/null +++ b/src/VVTK/VVTK_Recorder.cxx @@ -0,0 +1,464 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "VVTK_Recorder.h" + +#include "VVTK_ImageWriter.h" +#include "VVTK_ImageWriterMgr.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +namespace +{ + //---------------------------------------------------------------------------- + inline + void + GetNameJPEG(const std::string& thePreffix, + const int theIndex, + std::string& theName) + { + using namespace std; + ostringstream aStream; + aStream<SetClientData(this); + myCommand->SetCallback(VVTK_Recorder::ProcessEvents); +} + + +//---------------------------------------------------------------------------- +VVTK_Recorder +::~VVTK_Recorder() +{ + myCommand->Delete(); + myFilter->Delete(); + delete myWriterMgr; +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::CheckExistAVIMaker() +{ + myErrorStatus = 0; + using namespace std; + ostringstream aStream; + aStream<<"which "<& /dev/null"; + std::string anAVIMakeCheck = aStream.str(); + int iErr = system(anAVIMakeCheck.c_str()); + if(iErr != 0) + myErrorStatus = 127; +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::SetName(const char* theName) +{ + myName = theName; +} + +const char* +VVTK_Recorder::Name() const +{ + return myName.c_str(); +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::SetNbFPS(const double theNbFPS) +{ + myNbFPS = theNbFPS; +} + +double +VVTK_Recorder +::NbFPS() const +{ + return myNbFPS; +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::SetQuality(int theQuality) +{ + myQuality = theQuality; +} + +int +VVTK_Recorder +::GetQuality() const +{ + return myQuality; +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::SetRenderWindow(vtkRenderWindow* theRenderWindow) +{ + myRenderWindow = theRenderWindow; +} + +vtkRenderWindow* +VVTK_Recorder +::RenderWindow() +{ + return myRenderWindow; +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::SetProgressiveMode(bool theProgressiveMode) +{ + myProgressiveMode = theProgressiveMode; +} + +bool +VVTK_Recorder +::GetProgressiveMode() const +{ + return myProgressiveMode; +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::SetUseSkippedFrames(bool theUseSkippedFrames) +{ + myUseSkippedFrames = theUseSkippedFrames; +} + +bool +VVTK_Recorder +::UseSkippedFrames() const +{ + return myUseSkippedFrames; +} + + +//---------------------------------------------------------------------------- +int +VVTK_Recorder +::ErrorStatus() const +{ + return myErrorStatus; +} + +int +VVTK_Recorder +::State() const +{ + return myState; +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + if(vtkObject* anObj = reinterpret_cast(theClientData)){ + if(VVTK_Recorder* aSelf = dynamic_cast(anObj)){ + if(theEvent==vtkCommand::EndEvent){ + if(aSelf->State() == VVTK_Recorder::VVTK_Recorder_Record){ + aSelf->DoRecord(); + } + } + } + } +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::Record() +{ + if(myState == VVTK_Recorder_Stop){ + if(myRenderWindow){ + myState = VVTK_Recorder_Record; + myFilter->SetInput(myRenderWindow); + myFrameIndex = -1; + myNbWrittenFrames = 0; + myRenderWindow->RemoveObserver(myCommand); + myRenderWindow->AddObserver(vtkCommand::EndEvent, + myCommand, + myPriority); + myRenderWindow->Render(); + } + } +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::Stop() +{ + QApplication::setOverrideCursor( Qt::waitCursor ); + + if(myState == VVTK_Recorder_Record){ + if(!myPaused) + DoRecord(); + + myWriterMgr->Stop(); + + if(myUseSkippedFrames) + AddSkippedFrames(); + + myFrameIndexes.clear(); + + MakeFileAVI(); + } + myState = VVTK_Recorder_Stop; + myPaused = 0; + + QApplication::restoreOverrideCursor(); +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::Pause() +{ + myPaused = myPaused ? 0 : 1; + if(myPaused && !myFrameIndexes.empty()){ + size_t aLastId = myFrameIndexes.size() - 1; + myFrameIndexes[aLastId] *= -1; + } +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::DoRecord() +{ + if(myPaused) + return; + + if(myFrameIndex < 0){ + myFrameIndex = 0; + myTimeStart = vtkTimerLog::GetCurrentTime(); + }else{ + double aTimeNow = vtkTimerLog::GetCurrentTime(); + double aDelta = aTimeNow - myTimeStart; + if(aDelta < 0.0) + return; + + int aFrameIndex = int(aDelta*myNbFPS); + if(aFrameIndex == myFrameIndex) + return; + + myFrameIndex = aFrameIndex; + } + + myFrameIndexes.push_back(myFrameIndex); + if(MYDEBUG) cout<<"VVTK_Recorder::DoRecord - myFrameIndex = "<RemoveObserver(myCommand); + myFilter->Modified(); + + std::string aName; + GetNameJPEG(myName,myFrameIndex,aName); + + PreWrite(); + + vtkImageData *anImageData = vtkImageData::New(); + anImageData->DeepCopy(myFilter->GetOutput()); + + myWriterMgr->StartImageWriter(anImageData,aName,myProgressiveMode,myQuality); + myNbWrittenFrames++; + + myRenderWindow->AddObserver(vtkCommand::EndEvent, + myCommand, + myPriority); +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::PreWrite() +{ + vtkImageData *anImageData = myFilter->GetOutput(); + // + if(!anImageData){ + myErrorStatus = 20; + return; + } + anImageData->UpdateInformation(); + int *anExtent = anImageData->GetWholeExtent(); + anImageData->SetUpdateExtent(anExtent[0], anExtent[1], + anExtent[2], anExtent[3], + 0,0); + anImageData->UpdateData(); +} + + +//---------------------------------------------------------------------------- +void +VVTK_Recorder +::AddSkippedFrames() +{ + myErrorStatus = 0; + + if(myFrameIndexes.size() < 2) + return; + + size_t anId = 0, anEnd = myFrameIndexes.size() - 1; + for(; anId < anEnd; anId++){ + int aStartIndex = myFrameIndexes[anId]; + if(aStartIndex < 0) + continue; + + int aFinishIndex = abs(myFrameIndexes[anId + 1]); + if(aStartIndex + 1 == aFinishIndex) + continue; + + std::string anInitialName; + std::ostringstream aStream; + GetNameJPEG(myName,aStartIndex,anInitialName); + for(int anIndex = aStartIndex + 1; anIndex < aFinishIndex; anIndex++){ + myNbWrittenFrames++; + std::string anCurrentName; + GetNameJPEG(myName,anIndex,anCurrentName); + aStream<<"ln -s "<< anInitialName<<" "< +#include +#include + +#include + +class vtkRenderWindow; +class vtkCallbackCommand; +class vtkWindowToImageFilter; +class VVTK_ImageWriterMgr; +// +class VVTK_Recorder : public vtkObject +{ + protected: + enum State { + VVTK_Recorder_Unknown=0, + VVTK_Recorder_Record, + VVTK_Recorder_Stop + }; + + public: + static VVTK_Recorder *New(); + vtkTypeRevisionMacro(VVTK_Recorder,vtkObject); + + void + SetRenderWindow(vtkRenderWindow* theRenderWindow); + + vtkRenderWindow* + RenderWindow(); + + void + SetName(const char *theName); + + const char* + Name() const; + + void + SetNbFPS(const double theNbFPS); + + double + NbFPS() const; + + void + SetQuality(int theQuality); + + int + GetQuality() const; + + void + SetProgressiveMode(bool theProgressiveMode); + + bool + GetProgressiveMode() const; + + void + SetUseSkippedFrames(bool theUseSkippedFrames); + + bool + UseSkippedFrames() const; + + void + Record(); + + void + Pause(); + + void + Stop(); + + int + State() const; + + int + ErrorStatus() const; + + void + CheckExistAVIMaker(); + +protected : + VVTK_Recorder(); + + ~VVTK_Recorder(); + + void + DoRecord(); + + void + MakeFileAVI(); + + void + AddSkippedFrames(); + + void + PreWrite(); + + static + void + ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + +protected : + int myState; + int myPaused; + int myErrorStatus; + + float myPriority; + double myTimeStart; + + int myFrameIndex; + int myNbWrittenFrames; + + double myNbFPS; + int myQuality; + bool myProgressiveMode; + + typedef std::vector TFrameIndexes; + TFrameIndexes myFrameIndexes; + bool myUseSkippedFrames; + + std::string myName; + std::string myNameAVIMaker; + + vtkCallbackCommand *myCommand; + vtkRenderWindow *myRenderWindow; + vtkWindowToImageFilter *myFilter; + VVTK_ImageWriterMgr *myWriterMgr; + + +private: + VVTK_Recorder(const VVTK_Recorder&); //Not implemented + void operator=(const VVTK_Recorder&); //Not implemented +}; +#endif diff --git a/src/VVTK/VVTK_RecorderDlg.cxx b/src/VVTK/VVTK_RecorderDlg.cxx new file mode 100644 index 00000000..b188c99e --- /dev/null +++ b/src/VVTK/VVTK_RecorderDlg.cxx @@ -0,0 +1,183 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_RecorderDlg.cxx +// Author : Oleg UVAROV +// Module : VISU + +#include "VVTK_RecorderDlg.h" +#include "VVTK_Recorder.h" + +#include "SUIT_FileDlg.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" + +#include "QtxDblSpinBox.h" +#include "QtxIntSpinBox.h" + +#include +#include +#include +#include +#include +#include +#include + +/*! + * Constructor + */ +VVTK_RecorderDlg::VVTK_RecorderDlg( QWidget* theParent, VVTK_Recorder* theRecorder ): + QDialog( theParent, "VVTK_RecorderDlg", false ), + myRecorder( theRecorder ) +{ + setCaption( tr( "DLG_RECORDER_TITLE" ) ); + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + QVBoxLayout* aTopLayout = new QVBoxLayout( this ); + aTopLayout->setSpacing( 6 ); + aTopLayout->setMargin( 6 ); + aTopLayout->setAutoAdd( true ); + + // Settings + QGroupBox* mySettingsBox = new QGroupBox( tr( "SETTINGS" ), this ); + mySettingsBox->setColumnLayout( 0, Qt::Vertical ); + mySettingsBox->layout()->setSpacing( 0 ); + mySettingsBox->layout()->setMargin( 0 ); + + QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox->layout() ); + aSettingsLayout->setSpacing( 6 ); + aSettingsLayout->setMargin( 11 ); + + QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox ); + myFileNameLineEdit = new QLineEdit( mySettingsBox ); + myFileNameLineEdit->setMinimumWidth( 250 ); + myFileNameLineEdit->setReadOnly( true ); + /* + QPushButton* aFileNameButton = new QPushButton( mySettingsBox ); + aFileNameButton->setAutoDefault( false ); + aFileNameButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) ); + connect( aFileNameButton, SIGNAL( clicked() ), this, SLOT( onBrowseFile() ) ); + */ + QLabel* aRecordingModeLabel = new QLabel( tr( "RECORDING_MODE" ), mySettingsBox ); + myRecordingModeComboBox = new QComboBox( mySettingsBox ); + myRecordingModeComboBox->insertItem( tr( "SKIPPED_FRAMES" ) ); + myRecordingModeComboBox->insertItem( tr( "ALL_DISLPAYED_FRAMES" ) ); + myRecordingModeComboBox->setCurrentItem( aResourceMgr->integerValue( "VISU", "recorder_mode", 1 ) ); + + QLabel* aFPSLabel = new QLabel( tr( "FPS" ), mySettingsBox ); + myFPSSpinBox = new QtxDblSpinBox( 0.1, 100.0, 1.0, mySettingsBox ); + myFPSSpinBox->setValue( aResourceMgr->doubleValue( "VISU", "recorder_fps", 10.0 ) ); + + QLabel* aQualityLabel = new QLabel( tr( "QUALITY" ), mySettingsBox ); + myQualitySpinBox = new QtxIntSpinBox( 1, 100, 1, mySettingsBox ); + myQualitySpinBox->setValue( aResourceMgr->integerValue( "VISU", "recorder_quality", 80 ) ); + + myProgressiveCheckBox = new QCheckBox( tr( "PROGRESSIVE" ), mySettingsBox ); + myProgressiveCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "recorder_progressive", false ) ); + + aSettingsLayout->addWidget( aFileNameLabel, 0, 0 ); + aSettingsLayout->addMultiCellWidget( myFileNameLineEdit, 1, 1, 0, 1 ); + //aSettingsLayout->addWidget( aFileNameButton, 1, 2 ); + aSettingsLayout->addWidget( aRecordingModeLabel, 2, 0 ); + aSettingsLayout->addWidget( myRecordingModeComboBox, 2, 1 ); + aSettingsLayout->addWidget( aFPSLabel, 3, 0 ); + aSettingsLayout->addWidget( myFPSSpinBox, 3, 1 ); + aSettingsLayout->addWidget( aQualityLabel, 4, 0 ); + aSettingsLayout->addWidget( myQualitySpinBox, 4, 1 ); + aSettingsLayout->addWidget( myProgressiveCheckBox, 5, 0 ); + + // Start / Close + QGroupBox* CommonGroup = new QGroupBox( this ); + CommonGroup->setColumnLayout(0, Qt::Vertical ); + CommonGroup->layout()->setSpacing( 0 ); + CommonGroup->layout()->setMargin( 0 ); + QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup->layout() ); + CommonGroupLayout->setAlignment( Qt::AlignTop ); + CommonGroupLayout->setSpacing( 6 ); + CommonGroupLayout->setMargin( 11 ); + + QPushButton* aStartButton = new QPushButton( tr( "START" ), CommonGroup ); + aStartButton->setAutoDefault( true ); + aStartButton->setDefault( true ); + CommonGroupLayout->addWidget( aStartButton, 0, 0 ); + CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup ); + aCloseButton->setAutoDefault( true ); + CommonGroupLayout->addWidget( aCloseButton, 0, 2 ); + + connect( aStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) ); + connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) ); +} + +VVTK_RecorderDlg::~VVTK_RecorderDlg() +{ +} + +void VVTK_RecorderDlg::show() +{ + if( onBrowseFile() ) + QWidget::show(); +} + +void VVTK_RecorderDlg::onStart() +{ + if( myFileName.isNull() ) + return; + + myRecorder->SetName( myFileName.latin1() ); + + myRecorder->SetUseSkippedFrames( myRecordingModeComboBox->currentItem() == 0 ); + myRecorder->SetNbFPS( myFPSSpinBox->value() ); + myRecorder->SetQuality( myQualitySpinBox->value() ); + myRecorder->SetProgressiveMode( myProgressiveCheckBox->isChecked() ); + + accept(); + +} + +void VVTK_RecorderDlg::onClose() +{ + reject(); +} + +bool VVTK_RecorderDlg::onBrowseFile() +{ + QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ); + + QStringList aFilter; + aFilter.append( tr( "FLT_AVI_FILES" ) ); + aFilter.append( tr( "FLT_ALL_FILES" ) ); + + QString aFileName = SUIT_FileDlg::getFileName( this, getenv( "HOME" ), aFilter, + tr( "FILE_NAME" ), false ); + + if( aFileName.isNull() ) + return false; + + myFileName = aFileName; + myFileNameLineEdit->setText( aFileName.section( '/', -1 ) ); + + return true; +} diff --git a/src/VVTK/VVTK_RecorderDlg.h b/src/VVTK/VVTK_RecorderDlg.h new file mode 100644 index 00000000..f46ef1b1 --- /dev/null +++ b/src/VVTK/VVTK_RecorderDlg.h @@ -0,0 +1,80 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_RecorderDlg.h +// Author : Oleg UVAROV +// Module : VISU +// $Header$ + +#ifndef VVTK_RECORDERDLG_H +#define VVTK_RECORDERDLG_H + +#include +#include + +class QCheckBox; +class QComboBox; +class QGroupBox; +class QLCDNumber; +class QLineEdit; +class QPushButton; +class QTimer; + +class QtxDblSpinBox; +class QtxIntSpinBox; + +class VVTK_Recorder; + +//! Recorder Dialog. +class VVTK_RecorderDlg : public QDialog +{ + Q_OBJECT + +public: + VVTK_RecorderDlg( QWidget*, VVTK_Recorder* ); + ~VVTK_RecorderDlg(); + + virtual void show(); + + QString fileName() const { return myFileName; } + +protected slots: + void onStart(); + void onClose(); + + bool onBrowseFile(); + +private: + VVTK_Recorder* myRecorder; + QString myFileName; + + QLineEdit* myFileNameLineEdit; + + QComboBox* myRecordingModeComboBox; + QtxDblSpinBox* myFPSSpinBox; + QtxIntSpinBox* myQualitySpinBox; + QCheckBox* myProgressiveCheckBox; + +}; + +#endif diff --git a/src/VVTK/VVTK_Renderer.cxx b/src/VVTK/VVTK_Renderer.cxx new file mode 100644 index 00000000..484eff95 --- /dev/null +++ b/src/VVTK/VVTK_Renderer.cxx @@ -0,0 +1,432 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "VVTK_Renderer.h" + +#include "VISU_GaussPtsAct.h" +#include "VISU_GaussPointsPL.hxx" +#include "VISU_WidgetCtrl.hxx" +#include "VISU_PlanesWidget.hxx" +#include "VISU_SphereWidget.hxx" + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +//====================================================================== +class VISU_FPSActor : public vtkTextActor +{ +public: + vtkTypeMacro( VISU_FPSActor, vtkTextActor); + static + VISU_FPSActor* + New(); + + virtual + int + RenderOpaqueGeometry(vtkViewport *theViewport); +}; + +//====================================================================== +vtkStandardNewMacro(VISU_FPSActor); + +//====================================================================== +// function: RenderOpaqueGeometry +// purpose : +//====================================================================== +int +VISU_FPSActor +::RenderOpaqueGeometry(vtkViewport *theViewport) +{ + // It's impossible to render opaque geometry of text actor + // if the size of the viewport is less than 1.0 + int *size = theViewport->GetSize(); + if( size[0] <= 1.0 || size[1] <= 1.0 ) + return 1; + + if(vtkRenderer *aRenderer = dynamic_cast(theViewport)){ + static float aTol = 1.e-6; + float aLastRenderTimeInSeconds = aRenderer->GetLastRenderTimeInSeconds(); + if(aLastRenderTimeInSeconds > aTol){ + size_t aNumberOfCells = 0; + if(vtkActorCollection *anActorCollection = aRenderer->GetActors()){ + anActorCollection->InitTraversal(); + while(vtkActor *anActor = anActorCollection->GetNextActor()){ + if(anActor->GetVisibility()){ + if(SALOME_Actor *aSActor = dynamic_cast(anActor)){ + if(vtkMapper *aMapper = aSActor->GetMapper()){ + if(vtkDataSet *aDataSet = aMapper->GetInput()){ + aNumberOfCells += aDataSet->GetNumberOfCells(); + } + } + } + } + } + } + std::ostringstream aStr; + float aFPS = 1.0 / aLastRenderTimeInSeconds; + aStr<<"FPS: "<Delete(); + + vtkTextMapper* aTextMapper = vtkTextMapper::New(); + vtkTextProperty *aTextProperty = aTextMapper->GetTextProperty(); + aTextProperty->SetJustificationToRight(); + aTextProperty->SetVerticalJustificationToTop(); + aTextProperty->SetFontSize(10); + + myFPSActor->SetPickable(false); + myFPSActor->ScaledTextOff(); + myFPSActor->SetAlignmentPoint(8); + myFPSActor->SetPosition2 (1., 1.); + myFPSActor->SetMapper(aTextMapper); + aTextMapper->Delete(); + + GetDevice()->AddActor2D(myFPSActor.GetPointer()); + + myGaussPointPicker->Delete(); + + myGaussPreHighlightProperty->Delete(); + myGaussPreHighlightProperty->SetColor(0,1,1); + + myGaussHighlightProperty->Delete(); + myGaussHighlightProperty->SetColor(1,1,0); + +} + +VVTK_Renderer +::~VVTK_Renderer() +{ + if(MYDEBUG) INFOS("~VVTK_Renderer() - "<(theActor)){ + anActor->SetPointPicker(myGaussPointPicker.GetPointer()); + anActor->SetPreHighlightProperty(myGaussPreHighlightProperty.GetPointer()); + anActor->SetHighlightProperty(myGaussHighlightProperty.GetPointer()); + + anActor->SetInsideCursorSettings(myInsideCursorSettings); + anActor->SetPickingSettings(myPickingSettings); + } +} + +//---------------------------------------------------------------------------- +void +VVTK_Renderer +::RemoveActor(VTKViewer_Actor* theActor) +{ + Superclass::RemoveActor(theActor); + if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ + anActor->SetPointPicker(NULL); + anActor->SetPreHighlightProperty(NULL); + anActor->SetHighlightProperty(NULL); + + anActor->SetInsideCursorSettings(NULL); + anActor->SetPickingSettings(NULL); + } +} + +//---------------------------------------------------------------------------- +void +VVTK_Renderer +::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings) +{ + myInsideCursorSettings = theInsideCursorSettings; +} + +//---------------------------------------------------------------------------- +void +VVTK_Renderer +::SetPickingSettings(VISU_PickingSettings* thePickingSettings) +{ + myPickingSettings = thePickingSettings; +} + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(VVTK_Renderer1); + +//---------------------------------------------------------------------------- +VVTK_Renderer1::VVTK_Renderer1(): + //myImplicitFunctionWidget(VISU_ImplicitFunctionWidget::New()), + myWidgetCtrl(VISU_WidgetCtrl::New()), + myOutsideCursorSettings(NULL) +{ + if(MYDEBUG) INFOS("VVTK_Renderer1() - "<SetPlaceFactor(1.1); + myWidgetCtrl->SetPlaceFactor(1.1); + // + VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget(); + pPlanesWidget->SetOutlineTranslation(false); + vtkProperty* aSelectedPlaneProperty = pPlanesWidget->GetSelectedPlaneProperty(); + vtkProperty* aPlaneProperty = pPlanesWidget->GetPlaneProperty(); + aPlaneProperty->SetOpacity(aSelectedPlaneProperty->GetOpacity()*1.5); + // + myWidgetCtrl->Delete(); +} + +VVTK_Renderer1 +::~VVTK_Renderer1() +{ + if(MYDEBUG) INFOS("~VVTK_Renderer1() - "<SetInteractor(NULL); +} + +//---------------------------------------------------------------------------- +void +VVTK_Renderer1 +::AddActor(VTKViewer_Actor* theActor) +{ + Superclass::AddActor(theActor); + if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ + anActor->SetWidgetCtrl(GetWidgetCtrl()); + anActor->SetOutsideCursorSettings(myOutsideCursorSettings); + AdjustWidgetCtrl(); + } +} + +//---------------------------------------------------------------------------- +void +VVTK_Renderer1 +::RemoveActor(VTKViewer_Actor* theActor) +{ + Superclass::RemoveActor(theActor); + if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ + anActor->SetWidgetCtrl(NULL); + anActor->SetOutsideCursorSettings(NULL); + AdjustWidgetCtrl(); + } +} +//---------------------------------------------------------------------------- +void VVTK_Renderer1::AdjustWidgetCtrl() +{ + if(SVTK_Renderer::OnAdjustActors()){ + VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget(); + pPlanesWidget->InitialPlaceWidget(myBndBox); + pPlanesWidget->SetOrigin(0.5*(myBndBox[1] + myBndBox[0]), + 0.5*(myBndBox[3] + myBndBox[2]), + 0.5*(myBndBox[5] + myBndBox[4])); + // + VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget(); + pSphereWidget->SetCenter(0.5*(myBndBox[1] + myBndBox[0]), + 0.5*(myBndBox[3] + myBndBox[2]), + 0.5*(myBndBox[5] + myBndBox[4])); + float dX, dXmin=1.e20; + for (int i=0; i<3; ++i) { + dX=myBndBox[2*i+1]-myBndBox[2*i]; + if (dXSetRadius(dXmin); + } +} +//---------------------------------------------------------------------------- +void +VVTK_Renderer1 +::Initialize(vtkRenderWindowInteractor* theInteractor, + SVTK_Selector* theSelector) +{ + SVTK_Renderer::Initialize(theInteractor,theSelector); + myWidgetCtrl->SetInteractor(theInteractor); +} + +//---------------------------------------------------------------------------- +void +VVTK_Renderer1 +::SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings) +{ + myOutsideCursorSettings = theOutsideCursorSettings; +} + +//---------------------------------------------------------------------------- +VISU_WidgetCtrl* VVTK_Renderer1::GetWidgetCtrl() +{ + return myWidgetCtrl.GetPointer(); +} + +//---------------------------------------------------------------------------- +bool +VVTK_Renderer1 +::OnAdjustActors() +{ + return SVTK_Renderer::OnAdjustActors(); +} + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(VVTK_Renderer2); + +//---------------------------------------------------------------------------- +VVTK_Renderer2 +::VVTK_Renderer2(): + myEventCallbackCommand(vtkCallbackCommand::New()) +{ + if(MYDEBUG) INFOS("VVTK_Renderer2() - "<Delete(); + + myPriority = 0.0; + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(VVTK_Renderer2::ProcessEvents); +} + +VVTK_Renderer2 +::~VVTK_Renderer2() +{ + if(MYDEBUG) INFOS("~VVTK_Renderer2() - "<AddObserver(vtkCommand::EndInteractionEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + theWidgetCtrl->AddObserver(vtkCommand::EnableEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + theWidgetCtrl->AddObserver(vtkCommand::DisableEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + myWidgetCtrl = theWidgetCtrl; +} + +void +VVTK_Renderer2 +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + VVTK_Renderer2* self = reinterpret_cast(theClientData); + + switch(theEvent){ + case vtkCommand::EnableEvent: + case vtkCommand::EndInteractionEvent: + self->OnEndInteractionEvent(); + break; + } +} + +void +VVTK_Renderer2 +::OnEndInteractionEvent() +{ + AdjustActors(); + myInteractor->Render(); +} + + +//---------------------------------------------------------------------------- +void VVTK_Renderer2::AddActor(VTKViewer_Actor* theActor) +{ + if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ + if(VISU::TGaussPtsActorFactory* aFactory = anActor->GetGaussPtsFactory()){ + if(VISU_GaussPtsAct2* anActor2 = aFactory->CloneActor(anActor)){ + anActor2->SetWidgetCtrl(myWidgetCtrl); + Superclass::AddActor(anActor2); + } + } + } +} + +//---------------------------------------------------------------------------- +void +VVTK_Renderer2 +::RemoveActor(VTKViewer_Actor* theActor) +{ + using namespace VISU; + if(VISU_GaussPtsAct2* anActor = dynamic_cast(theActor)){ + anActor->SetWidgetCtrl(NULL); + Superclass::RemoveActor(theActor); + } +} diff --git a/src/VVTK/VVTK_Renderer.h b/src/VVTK/VVTK_Renderer.h new file mode 100644 index 00000000..1f566884 --- /dev/null +++ b/src/VVTK/VVTK_Renderer.h @@ -0,0 +1,179 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef VVTK_Renderer_h +#define VVTK_Renderer_h + +#include "VVTK.h" + +#include "SVTK_Renderer.h" + +class VISU_WidgetCtrl; +class VISU_InsideCursorSettings; +class VISU_OutsideCursorSettings; +class VISU_PickingSettings; +class VISU_FPSActor; + +class vtkPointPicker; +class vtkImplicitFunction; + +//---------------------------------------------------------------------------- +//! To customize SVTK_Renderer according to VVTK functionality +class VVTK_EXPORT VVTK_Renderer : public SVTK_Renderer +{ + public: + vtkTypeMacro(VVTK_Renderer,SVTK_Renderer); + static VVTK_Renderer* New(); + + //! Reimplement SVTK_Renderer::AddActor + /*! + Perform an additional action - apply picking settings on the published VISU_GaussPtsAct actors + */ + virtual + void + AddActor(VTKViewer_Actor* theActor); + + //! Reimplement SVTK_Renderer::RemoveActor (remove additional settings) + virtual + void + RemoveActor(VTKViewer_Actor* theActor); + + //! To set VISU_PickingSettings to share them among all VISU_GaussPtsAct actors published into the view + void + SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings); + + void + SetPickingSettings(VISU_PickingSettings* thePickingSettings); + + protected: + VVTK_Renderer(); + ~VVTK_Renderer(); + + VISU_PickingSettings* myPickingSettings; //! Keeps reference of the VISU_PickingSettings + VISU_InsideCursorSettings* myInsideCursorSettings; //! Keeps reference of the VISU_InsideCursorSettings + vtkSmartPointer myFPSActor; //!< To show FPS of the rendering at run-time + + vtkSmartPointer myGaussPointPicker; + vtkSmartPointer myGaussPreHighlightProperty; + vtkSmartPointer myGaussHighlightProperty; +}; + + +//---------------------------------------------------------------------------- +//! To extend VVTK_Renderer to implement base view functionality +class VVTK_EXPORT VVTK_Renderer1 : public VVTK_Renderer +{ + public: + vtkTypeMacro(VVTK_Renderer1,VVTK_Renderer); + static VVTK_Renderer1* New(); + + //! Reimplement SVTK_Renderer::Initialize + virtual + void + Initialize(vtkRenderWindowInteractor* theInteractor, + SVTK_Selector* theSelector); + + //! Reimplement VVTK_Renderer::AddActor to apply to the actor additional settings + virtual + void + AddActor(VTKViewer_Actor* theActor); + + //! Reimplement VVTK_Renderer::RemoveActor + virtual + void + RemoveActor(VTKViewer_Actor* theActor); + + //! To set VISU_PickingSettings to share them among all VISU_GaussPtsAct1 actors published into the view + void + SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings); + + VISU_WidgetCtrl* GetWidgetCtrl(); + + protected: + VVTK_Renderer1(); + ~VVTK_Renderer1(); + + //! Reimplement VVTK_Renderer::OnAdjustActors + virtual + bool + OnAdjustActors(); + + void AdjustWidgetCtrl(); + + vtkSmartPointer myWidgetCtrl; + VISU_OutsideCursorSettings* myOutsideCursorSettings; + vtkSmartPointer myTextActor; +}; + + +//---------------------------------------------------------------------------- +class VVTK_EXPORT VVTK_Renderer2 : public VVTK_Renderer +{ + public: + vtkTypeMacro(VVTK_Renderer2,VVTK_Renderer); + static VVTK_Renderer2* New(); + + //! Reimplement VVTK_Renderer::AddActor to apply to the actor additional settings + virtual + void + AddActor(VTKViewer_Actor* theActor); + + //! Reimplement VVTK_Renderer::RemoveActor + virtual + void + RemoveActor(VTKViewer_Actor* theActor); + + void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl); + + //! To handle vtkCommand::EndInteractionEvent to redraw the view + void + OnEndInteractionEvent(); + + protected: + VVTK_Renderer2(); + ~VVTK_Renderer2(); + + //! Main process VTK event method + static + void + ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + + //! Used to process VTK events + vtkSmartPointer myEventCallbackCommand; + + //! Priority at which events are processed + float myPriority; + + VISU_WidgetCtrl* myWidgetCtrl; +}; + + +#endif diff --git a/src/VVTK/VVTK_SegmentationCursorDlg.cxx b/src/VVTK/VVTK_SegmentationCursorDlg.cxx new file mode 100644 index 00000000..63487fed --- /dev/null +++ b/src/VVTK/VVTK_SegmentationCursorDlg.cxx @@ -0,0 +1,839 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VVTK_SegmentationCursorDlg.cxx +// Author : Oleg Uvarov +// Module : VISU + +#include "VVTK_SegmentationCursorDlg.h" +#include "VVTK_PrimitiveBox.h" +#include "VVTK_SizeBox.h" + +#include "VISU_GaussPtsAct.h" +#include "VISU_GaussPtsSettings.h" + +#include "VISU_WidgetCtrl.hxx" +#include "VISU_PlanesWidget.hxx" +#include "VISU_SphereWidget.hxx" + +#include "VISU_GaussPointsPL.hxx" +#include "VISU_OpenGLPointSpriteMapper.hxx" + +#include "SUIT_MessageBox.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" + +#include "SVTK_RenderWindowInteractor.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "utilities.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "QtxAction.h" +#include "QtxDblSpinBox.h" +#include "QtxIntSpinBox.h" + +using namespace std; + + +//---------------------------------------------------------------- +namespace VISU +{ + inline + QString + Image2VTI(const QString& theImageFileName) + { + QFileInfo aFileInfo(theImageFileName); + QString aFormat = aFileInfo.extension(FALSE); + QString aVTIName = QString("/tmp/") + getenv("USER") + "-" + aFileInfo.baseName(TRUE) + ".vti"; + QString aCommand = QString( "VISU_img2vti " ) + aFormat + " " + theImageFileName + " " + aVTIName; + + if(system( aCommand.latin1() ) == 0) + return aVTIName; + + return QString::null; + } + + inline + void + RemoveFile(const QString& theFileName) + { + if( !theFileName.isNull() ){ + QString aCommand = QString( "rm -fr " ) + theFileName; + system( aCommand.latin1() ); + } + } + + + TTextureValue + GetTexture(const QString& theMainTexture, + const QString& theAlphaTexture) + { + typedef std::pair TTextureKey; + typedef std::map TTextureMap; + + static TTextureMap aTextureMap; + + TTextureValue aTextureValue; + TTextureKey aTextureKey(theMainTexture,theAlphaTexture); + TTextureMap::const_iterator anIter = aTextureMap.find(aTextureKey); + if(anIter != aTextureMap.end()){ + aTextureValue = anIter->second; + }else{ + QString aMainTextureVTI = Image2VTI(theMainTexture); + QString anAlphaTextureVTI = Image2VTI(theAlphaTexture); + + if( !aMainTextureVTI.isNull() && !anAlphaTextureVTI.isNull() ){ + aTextureValue = + VISU_GaussPointsPL::MakeTexture( aMainTextureVTI.latin1(), + anAlphaTextureVTI.latin1()); + + if( aTextureValue.GetPointer() ) + aTextureMap[aTextureKey] = aTextureValue; + } + + RemoveFile(aMainTextureVTI); + RemoveFile(anAlphaTextureVTI); + } + + return aTextureValue; + } +} + + +//---------------------------------------------------------------- +VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const char* name ) + :QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ), + myEventCallbackCommand( vtkCallbackCommand::New() ), + myInsideCursorSettings( VISU_InsideCursorSettings::New() ), + myOutsideCursorSettings( VISU_OutsideCursorSettings::New() ), + myIsPlaneSegmentation( true ), + myWidgetCtrl(NULL), + myInteractor(NULL) +{ + myPriority = 0.0; + myEventCallbackCommand->Delete(); + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(VVTK_SegmentationCursorDlg::ProcessEvents); + + myInsideCursorSettings->AddObserver(VISU::UpdateFromSettingsEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + setCaption( tr( "SEGMENTATION_CURSOR_DLG_TITLE" ) ); + setSizeGripEnabled(TRUE); + + QVBoxLayout* TopLayout = new QVBoxLayout( this ); + TopLayout->setSpacing(6); + TopLayout->setMargin(11); + + myTabBox = new QTabWidget( this ); + + // Segmentation cursor pane + mySegmentationCursorBox = new QVBox( this ); + mySegmentationCursorBox->setMargin(11); + mySegmentationCursorBox->setSpacing(6); + mySegmentationCursorBox->layout()->setAlignment(Qt::AlignTop); + + // Origin + myOriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), mySegmentationCursorBox, "OriginGroup" ); + myOriginGroup->setColumnLayout( 0, Qt::Vertical ); + myOriginGroup->layout()->setSpacing( 0 ); + myOriginGroup->layout()->setMargin( 0 ); + + QGridLayout* OriginGroupLayout = new QGridLayout( myOriginGroup->layout() ); + OriginGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + OriginGroupLayout->setSpacing(6); + OriginGroupLayout->setMargin(11); + + QLabel* XOriginLabel = new QLabel( tr( "ORIGIN_X" ), myOriginGroup ); + myXOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup ); + myXOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myXOriginSpinBox->setMinimumWidth( 100 ); + myXOriginSpinBox->setValue( 0.0 ); + + QLabel* YOriginLabel = new QLabel( tr( "ORIGIN_Y" ), myOriginGroup ); + myYOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup ); + myYOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myYOriginSpinBox->setMinimumWidth( 100 ); + myYOriginSpinBox->setValue( 0.0 ); + + QLabel* ZOriginLabel = new QLabel( tr( "ORIGIN_Z" ), myOriginGroup ); + myZOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup ); + myZOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myZOriginSpinBox->setMinimumWidth( 100 ); + myZOriginSpinBox->setValue( 0.0 ); + + OriginGroupLayout->addWidget( XOriginLabel, 0, 0 ); + OriginGroupLayout->addWidget( myXOriginSpinBox, 0, 1 ); + OriginGroupLayout->addWidget( YOriginLabel, 0, 2 ); + OriginGroupLayout->addWidget( myYOriginSpinBox, 0, 3 ); + OriginGroupLayout->addWidget( ZOriginLabel, 0, 4 ); + OriginGroupLayout->addWidget( myZOriginSpinBox, 0, 5 ); + + // Direction ( Plane Segmentation ) + myDirectionGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), mySegmentationCursorBox, "DirectionGroup" ); + myDirectionGroup->setColumnLayout( 0, Qt::Vertical ); + myDirectionGroup->layout()->setSpacing( 0 ); + myDirectionGroup->layout()->setMargin( 0 ); + + QGridLayout* DirectionGroupLayout = new QGridLayout( myDirectionGroup->layout() ); + DirectionGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + DirectionGroupLayout->setSpacing(6); + DirectionGroupLayout->setMargin(11); + + QLabel* DXDirectionLabel = new QLabel( tr( "DIRECTION_DX" ), myDirectionGroup ); + myDXDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup ); + myDXDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myDXDirectionSpinBox->setMinimumWidth( 100 ); + myDXDirectionSpinBox->setValue( 0.0 ); + + QLabel* DYDirectionLabel = new QLabel( tr( "DIRECTION_DY" ), myDirectionGroup ); + myDYDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup ); + myDYDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myDYDirectionSpinBox->setMinimumWidth( 100 ); + myDYDirectionSpinBox->setValue( 0.0 ); + + QLabel* DZDirectionLabel = new QLabel( tr( "DIRECTION_DZ" ), myDirectionGroup ); + myDZDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup ); + myDZDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myDZDirectionSpinBox->setMinimumWidth( 100 ); + myDZDirectionSpinBox->setValue( 1.0 ); + + DirectionGroupLayout->addWidget( DXDirectionLabel, 0, 0 ); + DirectionGroupLayout->addWidget( myDXDirectionSpinBox, 0, 1 ); + DirectionGroupLayout->addWidget( DYDirectionLabel, 0, 2 ); + DirectionGroupLayout->addWidget( myDYDirectionSpinBox, 0, 3 ); + DirectionGroupLayout->addWidget( DZDirectionLabel, 0, 4 ); + DirectionGroupLayout->addWidget( myDZDirectionSpinBox, 0, 5 ); + + // Depth ( Plane Segmentation ) + myDepthGroup = new QGroupBox( tr( "DEPTH_TITLE" ), mySegmentationCursorBox, "DepthGroup" ); + myDepthGroup->setColumnLayout( 0, Qt::Vertical ); + myDepthGroup->layout()->setSpacing( 0 ); + myDepthGroup->layout()->setMargin( 0 ); + + QGridLayout* DepthGroupLayout = new QGridLayout( myDepthGroup->layout() ); + DepthGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + DepthGroupLayout->setSpacing(6); + DepthGroupLayout->setMargin(11); + + QLabel* DepthLabel = new QLabel( tr( "DEPTH" ), myDepthGroup ); + myDepthSpinBox = new QtxDblSpinBox( 0.0, VTK_LARGE_FLOAT, 0.1, myDepthGroup ); + myDepthSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myDepthSpinBox->setMinimumWidth( 100 ); + myDepthSpinBox->setValue( 1.0 ); + + DepthGroupLayout->addWidget( DepthLabel, 0, 0 ); + DepthGroupLayout->addWidget( myDepthSpinBox, 0, 1 ); + + // Radius ( Sphere Segmentation ) + myRadiusGroup = new QGroupBox( tr( "RADIUS_TITLE" ), mySegmentationCursorBox, "RadiusGroup" ); + myRadiusGroup->setColumnLayout( 0, Qt::Vertical ); + myRadiusGroup->layout()->setSpacing( 0 ); + myRadiusGroup->layout()->setMargin( 0 ); + + QGridLayout* RadiusGroupLayout = new QGridLayout( myRadiusGroup->layout() ); + RadiusGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + RadiusGroupLayout->setSpacing(6); + RadiusGroupLayout->setMargin(11); + + QLabel* RadiusLabel = new QLabel( tr( "RADIUS" ),myRadiusGroup ); + myRadiusSpinBox = new QtxDblSpinBox( 0.0, 1000.0, 1.0,myRadiusGroup ); + myRadiusSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myRadiusSpinBox->setMinimumWidth( 100 ); + myRadiusSpinBox->setValue( 100.0 ); + + QLabel* RatioLabel = new QLabel( tr( "RATIO" ), myRadiusGroup ); + myRatioSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1,myRadiusGroup ); + myRatioSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myRatioSpinBox->setMinimumWidth( 100 ); + myRatioSpinBox->setValue( 2.0 ); + + RadiusGroupLayout->addWidget( RadiusLabel, 0, 0 ); + RadiusGroupLayout->addWidget( myRadiusSpinBox, 0, 1 ); + RadiusGroupLayout->addWidget( RatioLabel, 0, 2 ); + RadiusGroupLayout->addWidget( myRatioSpinBox, 0, 3 ); + + + myTabBox->addTab( mySegmentationCursorBox, tr( "SEGMENTATION_CURSOR_TAB" ) ); + + + // Gauss points pane + myGaussPointsBox = new QVBox( this ); + myGaussPointsBox->setMargin(11); + myGaussPointsBox->setSpacing(6); + + // Inside Gauss points + QGroupBox* anInsideGroup = new QGroupBox( tr( "INSIDE_GAUSS_POINTS" ), myGaussPointsBox ); + anInsideGroup->setColumnLayout( 0, Qt::Vertical ); + anInsideGroup->layout()->setSpacing( 0 ); + anInsideGroup->layout()->setMargin( 0 ); + + QGridLayout* anInsideGroupLayout = new QGridLayout( anInsideGroup->layout() ); + anInsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + anInsideGroupLayout->setSpacing(6); + anInsideGroupLayout->setMargin(11); + + // Primitive + myInsidePrimitiveBox = new VVTK_PrimitiveBox( anInsideGroup ); + + // Size + myInsideSizeBox = new VVTK_SizeBox( anInsideGroup ); + myInsideSizeBox->setType( VVTK_SizeBox::Inside ); + + anInsideGroupLayout->addWidget( myInsidePrimitiveBox, 0, 0 ); + anInsideGroupLayout->addWidget( myInsideSizeBox, 1, 0 ); + + // Outside Gauss points + QGroupBox* anOutsideGroup = new QGroupBox( tr( "OUTSIDE_GAUSS_POINTS" ), myGaussPointsBox ); + anOutsideGroup->setColumnLayout( 0, Qt::Vertical ); + anOutsideGroup->layout()->setSpacing( 0 ); + anOutsideGroup->layout()->setMargin( 0 ); + + QGridLayout* anOutsideGroupLayout = new QGridLayout( anOutsideGroup->layout() ); + anOutsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + anOutsideGroupLayout->setSpacing(6); + anOutsideGroupLayout->setMargin(11); + + // Primitive + myOutsidePrimitiveBox = new VVTK_PrimitiveBox( anOutsideGroup ); + + // Size + myOutsideSizeBox = new VVTK_SizeBox( anOutsideGroup ); + myOutsideSizeBox->setType( VVTK_SizeBox::Outside ); + + anOutsideGroupLayout->addWidget( myOutsidePrimitiveBox, 0, 0 ); + anOutsideGroupLayout->addWidget( myOutsideSizeBox, 1, 0 ); + + + // Magnification + QGroupBox* MagnificationGroup = new QGroupBox ( tr( "MAGNIFICATION_TITLE" ), myGaussPointsBox, "MagnificationGroup" ); + MagnificationGroup->setColumnLayout(0, Qt::Vertical ); + MagnificationGroup->layout()->setSpacing( 0 ); + MagnificationGroup->layout()->setMargin( 0 ); + + QGridLayout* MagnificationGroupLayout = new QGridLayout (MagnificationGroup->layout()); + MagnificationGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + MagnificationGroupLayout->setSpacing(6); + MagnificationGroupLayout->setMargin(11); + + myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), MagnificationGroup ); + myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, MagnificationGroup ); + myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + MagnificationGroupLayout->addWidget( myMagnificationLabel, 0, 0 ); + MagnificationGroupLayout->addWidget( myMagnificationSpinBox, 0, 1 ); + + // Increment + myIncrementLabel = new QLabel( tr( "INCREMENT" ), MagnificationGroup ); + myIncrementSpinBox = new QtxDblSpinBox( 0.01, 10, 0.1, MagnificationGroup ); + myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + MagnificationGroupLayout->addWidget( myIncrementLabel, 0, 2 ); + MagnificationGroupLayout->addWidget( myIncrementSpinBox, 0, 3 ); + + + myTabBox->addTab( myGaussPointsBox, tr( "GAUSS_POINTS_TAB" ) ); + myTabBox->showPage( myGaussPointsBox ); + + + // Common buttons =========================================================== + QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); + GroupButtons->setColumnLayout(0, Qt::Vertical ); + GroupButtons->layout()->setSpacing( 0 ); + GroupButtons->layout()->setMargin( 0 ); + QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setSpacing( 6 ); + GroupButtonsLayout->setMargin( 11 ); + + QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" ); + buttonApply->setAutoDefault( TRUE ); + buttonApply->setDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonApply, 0, 0 ); + GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" ); + buttonClose->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonClose, 0, 2 ); + + TopLayout->addWidget( myTabBox ); + TopLayout->addWidget( GroupButtons ); + + connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) ); + connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) ); +} + +VVTK_SegmentationCursorDlg::~VVTK_SegmentationCursorDlg() +{ + SetWidgetCtrl(NULL); +} + +float VVTK_SegmentationCursorDlg::getMagnification() const +{ + return myMagnificationSpinBox->value() / 100.0; +} + +void VVTK_SegmentationCursorDlg::setMagnification( float theMagnification ) +{ + myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) ); +} + +float VVTK_SegmentationCursorDlg::getIncrement() const +{ + return myIncrementSpinBox->value(); +} + +void VVTK_SegmentationCursorDlg::setIncrement( float theIncrement ) +{ + myIncrementSpinBox->setValue( theIncrement ); +} + + +void VVTK_SegmentationCursorDlg::SetWidgetCtrl( VISU_WidgetCtrl* theWidgetCtrl ) +{ + if(myWidgetCtrl == theWidgetCtrl) + return; + + if(myWidgetCtrl) + myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer()); + + myWidgetCtrl = theWidgetCtrl; + + if(theWidgetCtrl) + theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent, + myEventCallbackCommand.GetPointer(), + myPriority); +} + +void VVTK_SegmentationCursorDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + VVTK_SegmentationCursorDlg* self = reinterpret_cast(theClientData); + + switch(theEvent){ + case vtkCommand::EndInteractionEvent: + self->UpdateSegmentation(); + break; + case VISU::UpdateFromSettingsEvent: + self->GetOutsideCursorSettings()->SetMagnification( self->GetInsideCursorSettings()->GetMagnification() ); + self->GetOutsideCursorSettings()->SetIncrement( self->GetInsideCursorSettings()->GetIncrement() ); + + self->UpdateInsideGaussPoints(); + self->UpdateOutsideGaussPoints(); + + self->GetInsideCursorSettings()->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL); + self->GetOutsideCursorSettings()->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL); + break; + } +} + +void VVTK_SegmentationCursorDlg::UpdateSegmentation() +{ + if( myIsPlaneSegmentation ) + { + myDirectionGroup->show(); + myDepthGroup->show(); + myRadiusGroup->hide(); + + VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget(); + float origin[3]; + pPlanesWidget->GetOrigin( origin ); + myXOriginSpinBox->setValue( origin[0] ); + myYOriginSpinBox->setValue( origin[1] ); + myZOriginSpinBox->setValue( origin[2] ); + + float normal[3]; + pPlanesWidget->GetNormal( normal ); + myDXDirectionSpinBox->setValue( normal[0] ); + myDYDirectionSpinBox->setValue( normal[1] ); + myDZDirectionSpinBox->setValue( normal[2] ); + + myDepthSpinBox->setValue( pPlanesWidget->Distance() ); + } + else + { + myDirectionGroup->hide(); + myDepthGroup->hide(); + myRadiusGroup->show(); + + VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget(); + float origin[3], aRadius; + pSphereWidget->GetCenter(origin); + myXOriginSpinBox->setValue( origin[0] ); + myYOriginSpinBox->setValue( origin[1] ); + myZOriginSpinBox->setValue( origin[2] ); + aRadius=pSphereWidget->GetRadius(); + myRadiusSpinBox->setValue(aRadius); + myRatioSpinBox->setValue(pSphereWidget->GetRatio()); + } +} + +void VVTK_SegmentationCursorDlg::UpdateInsideGaussPoints() +{ + int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite; + float aClamp = 200.0; + QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp"; + QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp"; + float anAlphaThreshold = 0.1; + int aResolution = 8; + int aMinSize = 3; + int aMaxSize = 33; + int aMagnification = 100; + float anIncrement = 2.0; + + if( !myInsideCursorSettings->GetInitial() ) + { + myInsidePrimitiveBox->setPrimitiveType( myInsideCursorSettings->GetPrimitiveType() ); + myInsidePrimitiveBox->setClamp( myInsideCursorSettings->GetClamp() ); + myInsidePrimitiveBox->setMainTexture( myInsideMainTexture ); + myInsidePrimitiveBox->setAlphaTexture( myInsideAlphaTexture ); + myInsidePrimitiveBox->setAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() ); + myInsidePrimitiveBox->setResolution( myInsideCursorSettings->GetResolution() ); + + myInsideSizeBox->setMinSize( myInsideCursorSettings->GetMinSize() ); + myInsideSizeBox->setMaxSize( myInsideCursorSettings->GetMaxSize() ); + + this->setMagnification( myInsideCursorSettings->GetMagnification() ); + this->setIncrement( myInsideCursorSettings->GetIncrement() ); + + return; + } + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + aPrimitiveType = aResourceMgr->integerValue( "VISU", "inside_point_sprite_primitive_type", aPrimitiveType ); + myInsidePrimitiveBox->setPrimitiveType( aPrimitiveType ); + + aClamp = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_clamp", aClamp ); + myInsidePrimitiveBox->setClamp( aClamp ); + + aMainTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_main_texture", aMainTexture ); + myInsidePrimitiveBox->setMainTexture( aMainTexture ); + + anAlphaTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_alpha_texture", anAlphaTexture ); + myInsidePrimitiveBox->setAlphaTexture( anAlphaTexture ); + + anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_alpha_threshold", anAlphaThreshold ); + myInsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold ); + + aResolution = aResourceMgr->integerValue( "VISU", "inside_geom_sphere_resolution", aResolution ); + myInsidePrimitiveBox->setResolution( aResolution ); + + aMinSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_min_size", aMinSize ); + myInsideSizeBox->setMinSize( aMinSize / 100.0 ); + + aMaxSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_max_size", aMaxSize ); + myInsideSizeBox->setMaxSize( aMaxSize / 100.0 ); + + aMagnification = aResourceMgr->integerValue( "VISU", "inside_point_sprite_magnification", aMagnification ); + this->setMagnification( aMagnification / 100.0 ); + + anIncrement = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_increment", anIncrement ); + this->setIncrement( anIncrement ); + + myInsidePrimitiveBox->setFaceLimit( 50000 ); + + ApplyInsideGaussPoints(); +} + +void VVTK_SegmentationCursorDlg::UpdateOutsideGaussPoints() +{ + float aClamp = 256.0; + int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite; + QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp"; + QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp"; + float anAlphaThreshold = 0.1; + int aResolution = 8; + int aSize = 25; + bool aUniform = false; + QColor aColor = Qt::blue; + + if( !myOutsideCursorSettings->GetInitial() ) + { + myOutsidePrimitiveBox->setPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() ); + myOutsidePrimitiveBox->setClamp( myOutsideCursorSettings->GetClamp() ); + myOutsidePrimitiveBox->setMainTexture( myOutsideMainTexture ); + myOutsidePrimitiveBox->setAlphaTexture( myOutsideAlphaTexture ); + myOutsidePrimitiveBox->setAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() ); + myOutsidePrimitiveBox->setResolution( myOutsideCursorSettings->GetResolution() ); + + myOutsideSizeBox->setOutsideSize( myOutsideCursorSettings->GetSize() ); + myOutsideSizeBox->setUniform( myOutsideCursorSettings->GetUniform() ); + + float* aColor = myOutsideCursorSettings->GetColor(); + myOutsideSizeBox->setColor( QColor( ( int )( aColor[0] * 255.0 ), + ( int )( aColor[1] * 255.0 ), + ( int )( aColor[2] * 255.0 ) ) ); + + return; + } + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + aPrimitiveType = aResourceMgr->integerValue( "VISU", "outside_point_sprite_primitive_type", aPrimitiveType ); + myOutsidePrimitiveBox->setPrimitiveType( aPrimitiveType ); + + aClamp = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_clamp", aClamp ); + myOutsidePrimitiveBox->setClamp( aClamp ); + + aMainTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_main_texture", aMainTexture ); + myOutsidePrimitiveBox->setMainTexture( aMainTexture ); + + anAlphaTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_alpha_texture", anAlphaTexture ); + myOutsidePrimitiveBox->setAlphaTexture( anAlphaTexture ); + + anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_alpha_threshold", anAlphaThreshold ); + myOutsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold ); + + aResolution = aResourceMgr->integerValue( "VISU", "outside_geom_sphere_resolution", aResolution ); + myOutsidePrimitiveBox->setResolution( aResolution ); + + aSize = aResourceMgr->integerValue( "VISU", "outside_point_sprite_size", aSize ); + myOutsideSizeBox->setOutsideSize( aSize / 100.0 ); + + aUniform = aResourceMgr->booleanValue( "VISU", "outside_point_sprite_uniform", aUniform ); + myOutsideSizeBox->setUniform( aUniform ); + + aColor = aResourceMgr->colorValue( "VISU", "outside_point_sprite_color", aColor ); + myOutsideSizeBox->setColor( aColor ); + + myOutsidePrimitiveBox->setFaceLimit( 50000 ); + + ApplyOutsideGaussPoints(); +} + +VISU_InsideCursorSettings* VVTK_SegmentationCursorDlg::GetInsideCursorSettings() +{ + return myInsideCursorSettings.GetPointer(); +} + +VISU_OutsideCursorSettings* VVTK_SegmentationCursorDlg::GetOutsideCursorSettings() +{ + return myOutsideCursorSettings.GetPointer(); +} + +VISU::TTextureValue +VVTK_SegmentationCursorDlg +::MakeImageData( bool theInside, + const QString& theMainTexture, + const QString& theAlphaTexture ) +{ + if( theInside ) + { + bool updateMainTexture = myInsideMainTexture != theMainTexture; + bool updateAlphaTexture = myInsideAlphaTexture != theAlphaTexture; + if( !updateMainTexture && !updateAlphaTexture ) + return 0; + + myInsideMainTexture = theMainTexture; + myInsideAlphaTexture = theAlphaTexture; + } + else + { + bool updateMainTexture = myOutsideMainTexture != theMainTexture; + bool updateAlphaTexture = myOutsideAlphaTexture != theAlphaTexture; + if( !updateMainTexture && !updateAlphaTexture ) + return 0; + + myOutsideMainTexture = theMainTexture; + myOutsideAlphaTexture = theAlphaTexture; + } + + return VISU::GetTexture( theMainTexture.latin1(), + theAlphaTexture.latin1()); +} + +void VVTK_SegmentationCursorDlg::onClickApply() +{ + if( myTabBox->currentPage() == mySegmentationCursorBox ) + ApplySegmentationCursor(); + else + { + QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n"; + aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" ); + aWarning.append( "Can you please confirm that you want to continue anyway?" ); + bool toApply = CheckNumberOfFaces() || + SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning, + tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 0; + + if( toApply ) + { + ApplyInsideGaussPoints(); + ApplyOutsideGaussPoints(); + } + } +} + +void VVTK_SegmentationCursorDlg::ApplySegmentationCursor() +{ + if( myIsPlaneSegmentation ) + { + VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget(); + float origin[3]; + origin[0] = myXOriginSpinBox->value(); + origin[1] = myYOriginSpinBox->value(); + origin[2] = myZOriginSpinBox->value(); + pPlanesWidget->SetOrigin( origin ); + + float normal[3]; + normal[0] = myDXDirectionSpinBox->value(); + normal[1] = myDYDirectionSpinBox->value(); + normal[2] = myDZDirectionSpinBox->value(); + + if( normal[0] == 0.0 && normal[1] == 0.0 && normal[2] == 0.0 ) + { + normal[2] = 1.0; + myDZDirectionSpinBox->setValue( 1.0 ); + } + pPlanesWidget->SetNormal( normal ); + + pPlanesWidget->SetDistance( myDepthSpinBox->value() ); + + myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + myWidgetCtrl->GetInteractor()->Render(); + } + else + { + VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget(); + float origin[3], aRadius; + origin[0] = myXOriginSpinBox->value(); + origin[1] = myYOriginSpinBox->value(); + origin[2] = myZOriginSpinBox->value(); + pSphereWidget->SetCenter(origin); + + aRadius=myRadiusSpinBox->value(); + pSphereWidget->SetRadius(aRadius); + + pSphereWidget->SetRatio(myRatioSpinBox->value()); + + myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + myWidgetCtrl->GetInteractor()->Render(); + } +} + +void VVTK_SegmentationCursorDlg::ApplyInsideGaussPoints() +{ + QString anInsideMainTexture = myInsidePrimitiveBox->getMainTexture(); + QString anInsideAlphaTexture = myInsidePrimitiveBox->getAlphaTexture(); + VISU::TTextureValue aTexture = MakeImageData( true, anInsideMainTexture, anInsideAlphaTexture ); + + if( aTexture.GetPointer() ) + myInsideCursorSettings->SetTexture( aTexture.GetPointer() ); + + myInsideCursorSettings->SetInitial( false ); + myInsideCursorSettings->SetPrimitiveType( myInsidePrimitiveBox->getPrimitiveType() ); + myInsideCursorSettings->SetClamp( myInsidePrimitiveBox->getClamp() ); + myInsideCursorSettings->SetAlphaThreshold( myInsidePrimitiveBox->getAlphaThreshold() ); + myInsideCursorSettings->SetResolution( myInsidePrimitiveBox->getResolution() ); + + myInsideCursorSettings->SetMinSize( myInsideSizeBox->getMinSize() ); + myInsideCursorSettings->SetMaxSize( myInsideSizeBox->getMaxSize() ); + + myInsideCursorSettings->SetMagnification( this->getMagnification() ); + myInsideCursorSettings->SetIncrement( this->getIncrement() ); + + myInsideCursorSettings->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL); +} + +void VVTK_SegmentationCursorDlg::ApplyOutsideGaussPoints() +{ + QString anOutsideMainTexture = myOutsidePrimitiveBox->getMainTexture(); + QString anOutsideAlphaTexture = myOutsidePrimitiveBox->getAlphaTexture(); + VISU::TTextureValue aTexture = MakeImageData( false, anOutsideMainTexture, anOutsideAlphaTexture ); + + if( aTexture.GetPointer() ) + myOutsideCursorSettings->SetTexture( aTexture.GetPointer() ); + + myOutsideCursorSettings->SetInitial( false ); + myOutsideCursorSettings->SetPrimitiveType( myOutsidePrimitiveBox->getPrimitiveType() ); + myOutsideCursorSettings->SetClamp( myOutsidePrimitiveBox->getClamp() ); + myOutsideCursorSettings->SetAlphaThreshold( myOutsidePrimitiveBox->getAlphaThreshold() ); + myOutsideCursorSettings->SetResolution( myOutsidePrimitiveBox->getResolution() ); + + myOutsideCursorSettings->SetSize( myOutsideSizeBox->getOutsideSize() ); + myOutsideCursorSettings->SetUniform( myOutsideSizeBox->getUniform() ); + + QColor aButtonColor = myOutsideSizeBox->getColor(); + float aColor[3]; + aColor[0] = aButtonColor.red() / 255.0; + aColor[1] = aButtonColor.green() / 255.0; + aColor[2] = aButtonColor.blue() / 255.0; + myOutsideCursorSettings->SetColor( aColor ); + + myOutsideCursorSettings->SetMagnification( this->getMagnification() ); + myOutsideCursorSettings->SetIncrement( this->getIncrement() ); + + myOutsideCursorSettings->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL); +} + +void VVTK_SegmentationCursorDlg::onClickClose() +{ + myPlaneAction->setOn( false ); + mySphereAction->setOn( false ); + + emit scgClose(); + + reject(); +} + +void VVTK_SegmentationCursorDlg::done( int r ) +{ + myPlaneAction->setOn( false ); + mySphereAction->setOn( false ); + + emit scgClose(); + + QDialog::done( r ); +} + +bool VVTK_SegmentationCursorDlg::CheckNumberOfFaces() +{ + if( !myInteractor ) + return false; + + vtkRenderer* aRenderer = myInteractor->getRenderer(); + + if( !aRenderer ) + return false; + + int aNumberOfPoints = 0; + + vtkActor* anActor; + vtkActorCollection* anActColl = aRenderer->GetActors(); + for( anActColl->InitTraversal(); ( anActor = anActColl->GetNextActor() ) != NULL; ) + { + if( VISU_GaussPtsAct1* aGaussActor = VISU_GaussPtsAct1::SafeDownCast( anActor ) ) + aNumberOfPoints += aGaussActor->GetInput()->GetNumberOfCells(); + } + return !( myInsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere && + aNumberOfPoints * myInsidePrimitiveBox->getFaceNumber() * 2 > myInsidePrimitiveBox->getFaceLimit() || + myOutsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere && + aNumberOfPoints * myOutsidePrimitiveBox->getFaceNumber() > myOutsidePrimitiveBox->getFaceLimit() ); +} diff --git a/src/VVTK/VVTK_SegmentationCursorDlg.h b/src/VVTK/VVTK_SegmentationCursorDlg.h new file mode 100644 index 00000000..edac2165 --- /dev/null +++ b/src/VVTK/VVTK_SegmentationCursorDlg.h @@ -0,0 +1,182 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VVTK_SegmentationCursorDlg.h +// Author : Oleg Uvarov +// Module : VISU + +#ifndef VVTK_SEGMENTATIONCURSORDLG_H +#define VVTK_SEGMENTATIONCURSORDLG_H + +#include + +#include +#include + +class vtkActorCollection; +class vtkCallbackCommand; +class vtkImageData; + +class QLabel; +class QLineEdit; +class QPushButton; +class QRadioButton; +class QTabWidget; +class QGroupBox; +class QVBox; + +class QtxAction; +class QtxDblSpinBox; +class QtxIntSpinBox; + +class VISU_GaussPtsAct1; +class VISU_InsideCursorSettings; +class VISU_OutsideCursorSettings; +class VISU_WidgetCtrl; + +class VVTK_PrimitiveBox; +class VVTK_SizeBox; + +class SVTK_RenderWindowInteractor; + +namespace VISU +{ + typedef vtkSmartPointer TTextureValue; + + TTextureValue + GetTexture(const QString& theMainTexture, + const QString& theAlphaTexture); +} + +//! Segmentation Cursor Dialog. +/*! + * Uses for set up Segmentation and Outside Cursor Gauss Points preferenses + * and apply them to all actors in the current renderer. + */ +class VVTK_SegmentationCursorDlg : public QDialog +{ + Q_OBJECT + +public: + VVTK_SegmentationCursorDlg( QWidget* parent = 0, const char* name = 0 ); + ~VVTK_SegmentationCursorDlg(); + + void SetWidgetCtrl( VISU_WidgetCtrl* ); + void SetPlaneAction( QtxAction* theAction ) { myPlaneAction = theAction; } + void SetSphereAction( QtxAction* theAction ) { mySphereAction = theAction; } + + bool GetIsPlaneSegmentation() const { return myIsPlaneSegmentation; } + void SetIsPlaneSegmentation( bool on ) { myIsPlaneSegmentation = on; } + + //! Update contents of the Segmentation tab. + void UpdateSegmentation(); + void UpdateInsideGaussPoints(); + void UpdateOutsideGaussPoints(); + + //! Update contents of the Outside Cursor tab. + void UpdateOutsideCursor(); + + VISU_InsideCursorSettings* GetInsideCursorSettings(); + VISU_OutsideCursorSettings* GetOutsideCursorSettings(); + + vtkSmartPointer GetEventCallbackCommand() { return myEventCallbackCommand; } + + void SetInteractor( SVTK_RenderWindowInteractor* theInteractor ) { myInteractor = theInteractor; } + +public: + float getMagnification() const; + void setMagnification( float ); + + float getIncrement() const; + void setIncrement( float ); + +protected: + void ApplySegmentationCursor(); + void ApplyInsideGaussPoints(); + void ApplyOutsideGaussPoints(); + + bool CheckNumberOfFaces(); + + VISU::TTextureValue + MakeImageData( bool theInside, + const QString& theMainTexture, + const QString& theAlphaTexture ); + +private: + static void ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + +protected slots: + virtual void done( int ); + + void onClickApply(); + void onClickClose(); + +signals: + void scgClose(); + +private: + SVTK_RenderWindowInteractor* myInteractor; + + QTabWidget* myTabBox; + + // Segmentation cursor + QVBox* mySegmentationCursorBox; + + QGroupBox* myOriginGroup; + QtxDblSpinBox* myXOriginSpinBox; + QtxDblSpinBox* myYOriginSpinBox; + QtxDblSpinBox* myZOriginSpinBox; + + QGroupBox* myDirectionGroup; + QtxDblSpinBox* myDXDirectionSpinBox; + QtxDblSpinBox* myDYDirectionSpinBox; + QtxDblSpinBox* myDZDirectionSpinBox; + + QGroupBox* myDepthGroup; + QtxDblSpinBox* myDepthSpinBox; + + QGroupBox* myRadiusGroup; + QtxDblSpinBox* myRadiusSpinBox; + QtxDblSpinBox* myRatioSpinBox; + + bool myIsPlaneSegmentation; + + float myPriority; + vtkSmartPointer myEventCallbackCommand; + + VISU_WidgetCtrl* myWidgetCtrl; + QtxAction* myPlaneAction; + QtxAction* mySphereAction; + + // Gauss Points + QVBox* myGaussPointsBox; + + VVTK_PrimitiveBox* myInsidePrimitiveBox; + VVTK_SizeBox* myInsideSizeBox; + + QString myInsideMainTexture; + QString myInsideAlphaTexture; + + vtkSmartPointer myInsideCursorSettings; + + VVTK_PrimitiveBox* myOutsidePrimitiveBox; + VVTK_SizeBox* myOutsideSizeBox; + + QString myOutsideMainTexture; + QString myOutsideAlphaTexture; + + vtkSmartPointer myOutsideCursorSettings; + + QLabel* myMagnificationLabel; + QtxIntSpinBox* myMagnificationSpinBox; + QLabel* myIncrementLabel; + QtxDblSpinBox* myIncrementSpinBox; +}; + +#endif diff --git a/src/VVTK/VVTK_SizeBox.cxx b/src/VVTK/VVTK_SizeBox.cxx new file mode 100644 index 00000000..654b69a7 --- /dev/null +++ b/src/VVTK/VVTK_SizeBox.cxx @@ -0,0 +1,350 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_SizeBox.cxx +// Author : Oleg UVAROV +// Module : VISU + +#include "VVTK_SizeBox.h" + +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" + +#include "QtxDblSpinBox.h" +#include "QtxIntSpinBox.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +VVTK_SizeBox::VVTK_SizeBox( QWidget* parent ) : + QVBox( parent ) +{ + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + layout()->setSpacing( 0 ); + layout()->setMargin( 0 ); + + // Size + QGroupBox* SizeGroup = new QGroupBox ( tr( "SIZE_TITLE" ), this, "SizeGroup" ); + SizeGroup->setColumnLayout(0, Qt::Vertical ); + SizeGroup->layout()->setSpacing( 0 ); + SizeGroup->layout()->setMargin( 0 ); + + QGridLayout* SizeGroupLayout = new QGridLayout (SizeGroup->layout()); + SizeGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); + SizeGroupLayout->setSpacing(6); + SizeGroupLayout->setMargin(11); + + // Outside Size + myOutsideSizeLabel = new QLabel( tr( "OUTSIDE_SIZE" ), SizeGroup ); + myOutsideSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup ); + myOutsideSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + SizeGroupLayout->addWidget( myOutsideSizeLabel, 0, 0 ); + SizeGroupLayout->addWidget( myOutsideSizeSpinBox, 0, 1 ); + + // Geometry Size + myGeomSizeLabel = new QLabel( tr( "GEOM_SIZE" ), SizeGroup ); + myGeomSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup ); + myGeomSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + SizeGroupLayout->addWidget( myGeomSizeLabel, 0, 0 ); + SizeGroupLayout->addWidget( myGeomSizeSpinBox, 0, 1 ); + + // Min Size + myMinSizeLabel = new QLabel( tr( "MIN_SIZE" ), SizeGroup ); + myMinSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup ); + myMinSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + SizeGroupLayout->addWidget( myMinSizeLabel, 1, 0 ); + SizeGroupLayout->addWidget( myMinSizeSpinBox, 1, 1 ); + + // Max Size + myMaxSizeLabel = new QLabel( tr( "MAX_SIZE" ), SizeGroup ); + myMaxSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup ); + myMaxSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + SizeGroupLayout->addWidget( myMaxSizeLabel, 1, 2 ); + SizeGroupLayout->addWidget( myMaxSizeSpinBox, 1, 3 ); + + // Magnification + myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), SizeGroup ); + myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, SizeGroup ); + myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + SizeGroupLayout->addWidget( myMagnificationLabel, 2, 0 ); + SizeGroupLayout->addWidget( myMagnificationSpinBox, 2, 1 ); + + // Increment + myIncrementLabel = new QLabel( tr( "INCREMENT" ), SizeGroup ); + myIncrementSpinBox = new QtxDblSpinBox( 0.01, 10, 0.1, SizeGroup ); + myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + SizeGroupLayout->addWidget( myIncrementLabel, 2, 2 ); + SizeGroupLayout->addWidget( myIncrementSpinBox, 2, 3 ); + + + // Color + myColorGroup = new QGroupBox ( tr( "COLOR_TITLE" ), this, "ColorGroup" ); + myColorGroup->setColumnLayout(0, Qt::Vertical ); + myColorGroup->layout()->setSpacing( 0 ); + myColorGroup->layout()->setMargin( 0 ); + + QGridLayout* ColorGroupLayout = new QGridLayout (myColorGroup->layout()); + ColorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); + ColorGroupLayout->setSpacing(6); + ColorGroupLayout->setMargin(11); + + myUniformCheckBox = new QCheckBox( tr( "UNIFORM_COLOR" ), myColorGroup ); + + myColorLabel = new QLabel( tr( "COLOR" ), myColorGroup ); + myColorButton = new QPushButton( myColorGroup ); + + ColorGroupLayout->addWidget( myUniformCheckBox, 0, 0 ); + ColorGroupLayout->addWidget( myColorLabel, 0, 1 ); + ColorGroupLayout->addWidget( myColorButton, 0, 2 ); + + connect( myUniformCheckBox, SIGNAL( toggled( bool ) ), myColorButton, SLOT( setEnabled( bool ) ) ); + connect( myColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) ); + + setType( VVTK_SizeBox::Results ); +} + +void VVTK_SizeBox::onToggleResults() +{ + myType = VVTK_SizeBox::Results; + + myOutsideSizeLabel->hide(); + myOutsideSizeSpinBox->hide(); + + myGeomSizeLabel->hide(); + myGeomSizeSpinBox->hide(); + + myMinSizeLabel->show(); + myMinSizeSpinBox->show(); + + myMaxSizeLabel->show(); + myMaxSizeSpinBox->show(); + + myMagnificationLabel->show(); + myMagnificationSpinBox->show(); + + myIncrementLabel->show(); + myIncrementSpinBox->show(); + + myColorGroup->hide(); + + myUniformCheckBox->hide(); +} + +void VVTK_SizeBox::onToggleGeometry() +{ + myType = VVTK_SizeBox::Geometry; + + myOutsideSizeLabel->hide(); + myOutsideSizeSpinBox->hide(); + + myGeomSizeLabel->show(); + myGeomSizeSpinBox->show(); + + myMinSizeLabel->hide(); + myMinSizeSpinBox->hide(); + + myMaxSizeLabel->hide(); + myMaxSizeSpinBox->hide(); + + myMagnificationLabel->show(); + myMagnificationSpinBox->show(); + + myIncrementLabel->show(); + myIncrementSpinBox->show(); + + myColorGroup->show(); + + myUniformCheckBox->hide(); +} + +void VVTK_SizeBox::onToggleInside() +{ + myType = VVTK_SizeBox::Inside; + + myOutsideSizeLabel->hide(); + myOutsideSizeSpinBox->hide(); + + myGeomSizeLabel->hide(); + myGeomSizeSpinBox->hide(); + + myMinSizeLabel->show(); + myMinSizeSpinBox->show(); + + myMaxSizeLabel->show(); + myMaxSizeSpinBox->show(); + + myMagnificationLabel->hide(); + myMagnificationSpinBox->hide(); + + myIncrementLabel->hide(); + myIncrementSpinBox->hide(); + + myColorGroup->hide(); + + myUniformCheckBox->hide(); +} + +void VVTK_SizeBox::onToggleOutside() +{ + myType = VVTK_SizeBox::Outside; + + myOutsideSizeLabel->show(); + myOutsideSizeSpinBox->show(); + + myGeomSizeLabel->hide(); + myGeomSizeSpinBox->hide(); + + myMinSizeLabel->hide(); + myMinSizeSpinBox->hide(); + + myMaxSizeLabel->hide(); + myMaxSizeSpinBox->hide(); + + myMagnificationLabel->hide(); + myMagnificationSpinBox->hide(); + + myIncrementLabel->hide(); + myIncrementSpinBox->hide(); + + myColorGroup->show(); + + myUniformCheckBox->show(); +} + +void VVTK_SizeBox::setType( int theType ) +{ + myType = theType; + + switch( myType ) + { + case VVTK_SizeBox::Results : onToggleResults(); break; + case VVTK_SizeBox::Geometry : onToggleGeometry(); break; + case VVTK_SizeBox::Inside : onToggleInside(); break; + case VVTK_SizeBox::Outside : onToggleOutside(); break; + default : break; + } +} + +float VVTK_SizeBox::getOutsideSize() const +{ + return myOutsideSizeSpinBox->value() / 100.0; +} + +void VVTK_SizeBox::setOutsideSize( float theOutsideSize ) +{ + myOutsideSizeSpinBox->setValue( ( int )( theOutsideSize * 100 ) ); +} + +float VVTK_SizeBox::getGeomSize() const +{ + return myGeomSizeSpinBox->value() / 100.0; +} + +void VVTK_SizeBox::setGeomSize( float theGeomSize ) +{ + myGeomSizeSpinBox->setValue( ( int )( theGeomSize * 100 ) ); +} + +float VVTK_SizeBox::getMinSize() const +{ + return myMinSizeSpinBox->value() / 100.0; +} + +void VVTK_SizeBox::setMinSize( float theMinSize ) +{ + myMinSizeSpinBox->setValue( ( int )( theMinSize * 100 ) ); +} + +float VVTK_SizeBox::getMaxSize() const +{ + return myMaxSizeSpinBox->value() / 100.0; +} + +void VVTK_SizeBox::setMaxSize( float theMaxSize ) +{ + myMaxSizeSpinBox->setValue( ( int )( theMaxSize * 100 ) ); +} + +float VVTK_SizeBox::getMagnification() const +{ + return myMagnificationSpinBox->value() / 100.0; +} + +void VVTK_SizeBox::setMagnification( float theMagnification ) +{ + myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) ); +} + +float VVTK_SizeBox::getIncrement() const +{ + return myIncrementSpinBox->value(); +} + +void VVTK_SizeBox::setIncrement( float theIncrement ) +{ + myIncrementSpinBox->setValue( theIncrement ); +} + +bool VVTK_SizeBox::getUniform() const +{ + return myUniformCheckBox->isChecked(); +} + +void VVTK_SizeBox::setUniform( bool theUniform ) +{ + myUniformCheckBox->setChecked( theUniform ); + myColorButton->setEnabled( theUniform ); +} + +QColor VVTK_SizeBox::getColor() const +{ + return myColorButton->paletteBackgroundColor(); +} + +void VVTK_SizeBox::setColor( const QColor& theColor ) +{ + myColorButton->setPaletteBackgroundColor( theColor ); +} + +void VVTK_SizeBox::onColorButtonPressed() +{ + QColor aColor = QColorDialog::getColor( myColorButton->paletteBackgroundColor(), this ); + if( aColor.isValid() ) + myColorButton->setPaletteBackgroundColor( aColor ); +} diff --git a/src/VVTK/VVTK_SizeBox.h b/src/VVTK/VVTK_SizeBox.h new file mode 100644 index 00000000..a47f342c --- /dev/null +++ b/src/VVTK/VVTK_SizeBox.h @@ -0,0 +1,119 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_SizeBox.h +// Author : Oleg UVAROV +// Module : VISU + +#ifndef VVTK_SIZEBOX_H +#define VVTK_SIZEBOX_H + +#include + +class QLabel; +class QLineEdit; +class QPushButton; +class QCheckBox; +class QGroupBox; + +class QtxDblSpinBox; +class QtxIntSpinBox; + +class VVTK_SizeBox : public QVBox +{ + Q_OBJECT + +public: + enum { Results = 0, Geometry, Inside, Outside }; + +public: + VVTK_SizeBox( QWidget* ); + ~VVTK_SizeBox() {} + +public: + int getType() const { return myType; } + void setType( int ); + + float getOutsideSize() const; + void setOutsideSize( float ); + + float getGeomSize() const; + void setGeomSize( float ); + + float getMinSize() const; + void setMinSize( float ); + + float getMaxSize() const; + void setMaxSize( float ); + + float getMagnification() const; + void setMagnification( float ); + + float getIncrement() const; + void setIncrement( float ); + + bool getUniform() const; + void setUniform( bool ); + + QColor getColor() const; + void setColor( const QColor& ); + +protected slots: + void onToggleResults(); + void onToggleGeometry(); + void onToggleInside(); + void onToggleOutside(); + + void onColorButtonPressed(); + +private: + int myType; + + QLabel* myOutsideSizeLabel; + QtxIntSpinBox* myOutsideSizeSpinBox; + + QLabel* myGeomSizeLabel; + QtxIntSpinBox* myGeomSizeSpinBox; + + QLabel* myMinSizeLabel; + QtxIntSpinBox* myMinSizeSpinBox; + + QLabel* myMaxSizeLabel; + QtxIntSpinBox* myMaxSizeSpinBox; + + QLabel* myMagnificationLabel; + QtxIntSpinBox* myMagnificationSpinBox; + + QLabel* myIncrementLabel; + QtxDblSpinBox* myIncrementSpinBox; + + QCheckBox* myUniformCheckBox; + + QGroupBox* myColorGroup; + QLabel* myColorLabel; + QPushButton* myColorButton; +}; + + + +#endif diff --git a/src/VVTK/VVTK_ViewManager.cxx b/src/VVTK/VVTK_ViewManager.cxx new file mode 100644 index 00000000..8c3cb03b --- /dev/null +++ b/src/VVTK/VVTK_ViewManager.cxx @@ -0,0 +1,26 @@ +#include "VVTK_ViewManager.h" +#include "VVTK_ViewModel.h" + +int VVTK_ViewManager::_VVTKViewMgr_Id = 0; + +//*************************************************************** +VVTK_ViewManager +::VVTK_ViewManager( SUIT_Study* study, + SUIT_Desktop* theDesktop ) +: SUIT_ViewManager( study, theDesktop ) +{ + myId = ++_VVTKViewMgr_Id; + setViewModel( new VVTK_Viewer() ); +} + +//*************************************************************** +VVTK_ViewManager::~VVTK_ViewManager() +{ +} + +//*************************************************************** +void VVTK_ViewManager::setViewName(SUIT_ViewWindow* theView) +{ + int aPos = myViews.find(theView); + theView->setCaption( tr( "VTK_VIEW_TITLE" ).arg( myId ).arg( aPos + 1 ) ); +} diff --git a/src/VVTK/VVTK_ViewManager.h b/src/VVTK/VVTK_ViewManager.h new file mode 100644 index 00000000..101fa583 --- /dev/null +++ b/src/VVTK/VVTK_ViewManager.h @@ -0,0 +1,28 @@ +#ifndef VVTK_VIEWMANAGER_H +#define VVTK_VIEWMANAGER_H + +#include "SUIT_ViewManager.h" +#include "VVTK.h" + +class SUIT_Desktop; + +//! Extend SUIT_ViewManager to deal with VVTK_Viewer +class VVTK_EXPORT VVTK_ViewManager : public SUIT_ViewManager +{ + Q_OBJECT; +public: + //! Construct the view manager + VVTK_ViewManager( SUIT_Study* study, SUIT_Desktop* ); + + //! Destroy the view manager + virtual ~VVTK_ViewManager(); + +protected: + void setViewName( SUIT_ViewWindow* theView ); + +private: + int myId; + static int _VVTKViewMgr_Id; +}; + +#endif diff --git a/src/VVTK/VVTK_ViewModel.cxx b/src/VVTK/VVTK_ViewModel.cxx new file mode 100644 index 00000000..e3778816 --- /dev/null +++ b/src/VVTK/VVTK_ViewModel.cxx @@ -0,0 +1,208 @@ +#include +#include + +#include "VVTK_ViewModel.h" +#include "VVTK_ViewWindow.h" + +#include "SVTK_View.h" +#include "SVTK_MainWindow.h" +#include "SVTK_RenderWindowInteractor.h" + +#include "VTKViewer_ViewModel.h" + +//========================================================== +VVTK_Viewer +::VVTK_Viewer() +{ + myTrihedronSize = 105; +} + +VVTK_Viewer +::~VVTK_Viewer() +{} + + +//========================================================== +void +VVTK_Viewer +::setViewManager(SUIT_ViewManager* theViewManager) +{ + SUIT_ViewModel::setViewManager(theViewManager); + + if ( !theViewManager ) + return; + + connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + + connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*))); + + connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); +} + + +//========================================================== +SUIT_ViewWindow* +VVTK_Viewer +::createView( SUIT_Desktop* theDesktop ) +{ + TViewWindow* aViewWindow = new TViewWindow(theDesktop); + aViewWindow->Initialize(this); + + aViewWindow->setBackgroundColor( backgroundColor() ); + aViewWindow->SetTrihedronSize( trihedronSize() ); + + return aViewWindow; +} + + +//========================================================== +void +VVTK_Viewer +::contextMenuPopup( QPopupMenu* thePopup ) +{ + thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); + thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) ); + + thePopup->insertSeparator(); + + if(TViewWindow* aView = dynamic_cast(myViewManager->getActiveView())){ + if ( !aView->getMainWindow()->getToolBar()->isVisible() ){ + thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); + } + } +} + + +//========================================================== +void +VVTK_Viewer +::Repaint() +{ + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + if(TViewWindow* aView = dynamic_cast(aViews.at(i))){ + aView->getMainWindow()->Repaint(); + } + } +} + + +//========================================================== +bool +VVTK_Viewer +::isVisible( const Handle(SALOME_InteractiveObject)& io ) +{ + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) + if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) + if(TViewWindow* aView = dynamic_cast(aViewWindow)) + if(!aView->getView()->isVisible( io )) + return false; + + return true; +} + + +//========================================================== +void +VVTK_Viewer +::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) +{} + +void +VVTK_Viewer +::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event) +{} + +void +VVTK_Viewer +::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) +{} + + +//========================================================== +QColor +VVTK_Viewer +::backgroundColor() const +{ + return myBgColor; +} + +void +VVTK_Viewer +::setBackgroundColor( const QColor& theColor ) +{ + if ( !theColor.isValid() ) + return; + + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){ + if(TViewWindow* aView = dynamic_cast(aViewWindow)){ + aView->setBackgroundColor(theColor); + } + } + } + + myBgColor = theColor; +} + +//========================================================== +int +VVTK_Viewer +::trihedronSize() const +{ + return myTrihedronSize; +} + +void +VVTK_Viewer +::setTrihedronSize( const int theSize ) +{ + myTrihedronSize = theSize; + if(SUIT_ViewManager* aViewManager = getViewManager()){ + QPtrVector aViews = aViewManager->getViews(); + for ( int i = 0; i < aViews.count(); i++ ){ + if(TViewWindow* aView = dynamic_cast(aViews.at( i ))){ + aView->getMainWindow()->SetTrihedronSize( theSize ); + } + } + } +} + +//========================================================== +void +VVTK_Viewer +::onDumpView() +{ + if(SUIT_ViewWindow* aView = myViewManager->getActiveView()) + aView->onDumpView(); +} + +//========================================================== +void +VVTK_Viewer +::onChangeBgColor() +{ + if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){ + QColor aColor = QColorDialog::getColor( backgroundColor(), aView); + setBackgroundColor(aColor); + } +} + +//========================================================== +void +VVTK_Viewer +::onShowToolbar() +{ + QPtrVector aViews = myViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + if(TViewWindow* aView = dynamic_cast(aViews.at(i))){ + aView->getMainWindow()->getToolBar()->show(); + } + } +} + diff --git a/src/VVTK/VVTK_ViewModel.h b/src/VVTK/VVTK_ViewModel.h new file mode 100644 index 00000000..0846edcd --- /dev/null +++ b/src/VVTK/VVTK_ViewModel.h @@ -0,0 +1,70 @@ +#ifndef VVTK_VIEWMODEL_H +#define VVTK_VIEWMODEL_H + +#include + +#include "VVTK.h" +#include "SVTK_ViewModelBase.h" + +#include "SALOME_Prs.h" +#include "SALOME_InteractiveObject.hxx" + +class VVTK_ViewWindow; + +//! Extends two interfaces #SVTK_ViewModelBase and #SALOME_View +class VVTK_EXPORT VVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View +{ + Q_OBJECT; + +public: + typedef VVTK_ViewWindow TViewWindow; + static QString Type() { return "VVTK"; } + + VVTK_Viewer(); + virtual ~VVTK_Viewer(); + + //! Redefine SUIT_ViewModel::createView + virtual SUIT_ViewWindow* createView(SUIT_Desktop*); + + //! Redefine SUIT_ViewModel::setViewManager + virtual void setViewManager(SUIT_ViewManager* theViewManager); + //! Redefine SUIT_ViewModel::contextMenuPopup + virtual void contextMenuPopup( QPopupMenu* ); + //! See SUIT_ViewModel::getType + virtual QString getType() const { return Type(); } + + //! Redefine SALOME_View::Repaint + virtual void Repaint(); + + //! Redefine SALOME_View::isVisible + virtual bool isVisible( const Handle(SALOME_InteractiveObject)& ); + + //! Get background color of the viewer + QColor backgroundColor() const; + + //! Set background color to the viewer + void setBackgroundColor( const QColor& ); + + //! Get size of trihedron of the viewer (see SVTK_Renderer::SetTrihedronSize) + int trihedronSize() const; + + //! Set size of trihedron of the viewer (see SVTK_Renderer::SetTrihedronSize) + void setTrihedronSize( const int ); + +protected slots: + void onMousePress(SUIT_ViewWindow*, QMouseEvent*); + void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); + void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*); + + void onDumpView(); + void onShowToolbar(); + void onChangeBgColor(); + +private: + QColor myBgColor; + int myTrihedronSize; + bool mySelectionEnabled; + bool myMultiSelectionEnabled; +}; + +#endif diff --git a/src/VVTK/VVTK_ViewWindow.cxx b/src/VVTK/VVTK_ViewWindow.cxx new file mode 100755 index 00000000..a181ad6a --- /dev/null +++ b/src/VVTK/VVTK_ViewWindow.cxx @@ -0,0 +1,297 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "VVTK_ViewWindow.h" +#include "VVTK_ViewModel.h" +#include "VVTK_MainWindow.h" +#include "SVTK_View.h" + +#include "SUIT_Session.h" + +#include "VVTK_Renderer.h" +#include "SVTK_Selector.h" +#include "SVTK_InteractorStyle.h" +#include "SVTK_RenderWindowInteractor.h" +#include "SVTK_GenericRenderWindowInteractor.h" + +#include +#include +#include + +//---------------------------------------------------------------------------- +VVTK_ViewWindow +::VVTK_ViewWindow(SUIT_Desktop* theDesktop): + SVTK_ViewWindow(theDesktop), + myMainWindow1(NULL), + myMainWindow2(NULL), + myView2(NULL) +{} + +//---------------------------------------------------------------------------- +void VVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) +{ + if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ + QWidget* aWidget = new QWidget(this); + setCentralWidget(aWidget); + + QBoxLayout* aLayout = new QVBoxLayout(aWidget); + aLayout->setAutoAdd(true); + QSplitter* aSplitter = new QSplitter(Qt::Vertical,aWidget); + //aSplitter->setChildrenCollapsible(true); + + VISU_WidgetCtrl* aWidgetCtrl = NULL; + VISU_InsideCursorSettings* anInsideCursorSettings = NULL; + VISU_OutsideCursorSettings* anOutsideCursorSettings = NULL; + VISU_PickingSettings* aPickingSettings = NULL; + SVTK_Selector* aSelector = SVTK_Selector::New(); + { + myMainWindow1 = new VVTK_MainWindow1(aSplitter, + "VVTK_MainWindow", + aResourceMgr, + this); + + anInsideCursorSettings = myMainWindow1->GetInsideCursorSettings(); + anOutsideCursorSettings = myMainWindow1->GetOutsideCursorSettings(); + aPickingSettings = myMainWindow1->GetPickingSettings(); + + SVTK_RenderWindowInteractor* anIteractor = + new SVTK_RenderWindowInteractor(myMainWindow1,"SVTK_RenderWindowInteractor1"); + + SVTK_GenericRenderWindowInteractor* aDevice = + SVTK_GenericRenderWindowInteractor::New(); + aDevice->SetRenderWidget(anIteractor); + aDevice->SetSelector(aSelector); + + VVTK_Renderer1* aRenderer = VVTK_Renderer1::New(); + aRenderer->Initialize(aDevice,aSelector); + + aWidgetCtrl = aRenderer->GetWidgetCtrl(); + + aRenderer->SetInsideCursorSettings(anInsideCursorSettings); + aRenderer->SetOutsideCursorSettings(anOutsideCursorSettings); + aRenderer->SetPickingSettings(aPickingSettings); + + anIteractor->Initialize(aDevice,aRenderer,aSelector); + + SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); + anIteractor->PushInteractorStyle(aStyle); + aStyle->Delete(); + + aDevice->Delete(); + aRenderer->Delete(); + + myMainWindow1->Initialize(anIteractor,aRenderer); + + myView1 = new SVTK_View(myMainWindow1); + SVTK_ViewWindow::Initialize(myView1,theModel); + } + { + myMainWindow2 = myMainWindow1->CreateMainWindow2(aSplitter, + "VVTK_SegmantationWindow", + aResourceMgr, + this); + SVTK_RenderWindowInteractor* anIteractor = + new SVTK_RenderWindowInteractor(myMainWindow2,"SVTK_RenderWindowInteractor1"); + + SVTK_GenericRenderWindowInteractor* aDevice = + SVTK_GenericRenderWindowInteractor::New(); + aDevice->SetRenderWidget(anIteractor); + aDevice->SetSelector(aSelector); + + VVTK_Renderer2* aRenderer = VVTK_Renderer2::New(); + aRenderer->Initialize(aDevice,aSelector); + + aRenderer->SetWidgetCtrl(aWidgetCtrl); + + aRenderer->SetInsideCursorSettings(anInsideCursorSettings); + aRenderer->SetPickingSettings(aPickingSettings); + + anIteractor->Initialize(aDevice,aRenderer,aSelector); + + SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); + anIteractor->PushInteractorStyle(aStyle); + aStyle->Delete(); + + aDevice->Delete(); + aRenderer->Delete(); + + myMainWindow2->Initialize(anIteractor); + + myView2 = new SVTK_View(myMainWindow2); + SVTK_ViewWindow::Initialize(myView2,theModel); + } + aSelector->Delete(); + + int h = height() / 2; + QValueList aSizes; + aSizes.append( h ); + aSizes.append( h ); + aSplitter->setSizes( aSizes ); + myMainWindow2->hide(); + + myMainWindow = myMainWindow1; + myView = myView1; + } +} + +//---------------------------------------------------------------------------- +VVTK_ViewWindow +::~VVTK_ViewWindow() +{} + + +//---------------------------------------------------------------------------- +VVTK_MainWindow1* +VVTK_ViewWindow +::getMainWindow1() +{ + return myMainWindow1; +} + +VVTK_MainWindow2* +VVTK_ViewWindow +::getMainWindow2() +{ + return myMainWindow2; +} + + +//---------------------------------------------------------------------------- +void +VVTK_ViewWindow +::AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate) +{ + myMainWindow1->AddActor(theActor,theIsUpdate); + myMainWindow2->AddActor(theActor,theIsUpdate); +} + +//---------------------------------------------------------------------------- +void +VVTK_ViewWindow +::RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate) +{ + myMainWindow1->RemoveActor(theActor,theIsUpdate); + myMainWindow2->RemoveActor(theActor,theIsUpdate); +} + +//---------------------------------------------------------------------------- +void +VVTK_ViewWindow +::Repaint(bool theUpdateTrihedron) +{ + myMainWindow1->Repaint(theUpdateTrihedron); + myMainWindow2->Repaint(theUpdateTrihedron); +} + +//---------------------------------------------------------------- +void +VVTK_ViewWindow +::unHighlightAll() +{ + myView1->unHighlightAll(); + myView2->unHighlightAll(); +} + +//---------------------------------------------------------------- +void +VVTK_ViewWindow +::highlight(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight, + bool theIsUpdate ) +{ + myView1->highlight( theIO, theIsHighlight, theIsUpdate ); + myView2->highlight( theIO, theIsHighlight, theIsUpdate ); +} + +//---------------------------------------------------------------- +void +VVTK_ViewWindow +::onSelectionChanged() +{ + myView1->onSelectionChanged(); + myView2->onSelectionChanged(); +} + +//---------------------------------------------------------------------------- +void +VVTK_ViewWindow +::onResetView() +{ + myMainWindow1->onResetView(); + myMainWindow2->onResetView(); +} + +//---------------------------------------------------------------------------- +void +VVTK_ViewWindow +::onFitAll() +{ + myMainWindow1->onFitAll(); + myMainWindow2->onFitAll(); +} + +//---------------------------------------------------------------------------- +void +VVTK_ViewWindow +::action( const int accelAction ) +{ + if(myMainWindow1->hasFocus()) + myMainWindow1->action(accelAction); + if(myMainWindow2->hasFocus()) + myMainWindow2->action(accelAction); +} + +//---------------------------------------------------------------------------- +QImage +VVTK_ViewWindow +::dumpView() +{ + if( myMainWindow1->GetInteractor()->hasFocus() ) + return myMainWindow1->dumpView(); + + if( myMainWindow2->GetInteractor()->hasFocus() ) + return myMainWindow2->dumpView(); + + return QImage(); +} + +//---------------------------------------------------------------------------- +void +VVTK_ViewWindow +::setBackgroundColor( const QColor& theColor ) +{ + if( myMainWindow1->GetInteractor()->hasFocus() ) + myMainWindow1->SetBackgroundColor( theColor ); + else if( myMainWindow2->GetInteractor()->hasFocus() ) + myMainWindow2->SetBackgroundColor( theColor ); + else + myMainWindow->SetBackgroundColor( theColor ); +} + diff --git a/src/VVTK/VVTK_ViewWindow.h b/src/VVTK/VVTK_ViewWindow.h new file mode 100755 index 00000000..54e4745d --- /dev/null +++ b/src/VVTK/VVTK_ViewWindow.h @@ -0,0 +1,124 @@ +#ifndef VVTK_VIEWWINDOW_H +#define VVTK_VIEWWINDOW_H + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +#include "VVTK.h" +#include "SVTK_ViewWindow.h" + +#include + +class VVTK_MainWindow1; +class VVTK_MainWindow2; +class SVTK_View; + +//---------------------------------------------------------------------------- +//! Customize the SVTK_ViewWindow in order to manage two SVTK_View (base and segmented one) +class VVTK_EXPORT VVTK_ViewWindow : public SVTK_ViewWindow +{ + Q_OBJECT; + +public: + //! To construct the class + VVTK_ViewWindow(SUIT_Desktop* theDesktop); + + //! Destroy + virtual + ~VVTK_ViewWindow(); + + //! To initialize + virtual + void + Initialize(SVTK_ViewModelBase* theModel); + + //---------------------------------------------------------------------------- + //! Get access to base SVTK_MainWindow + VVTK_MainWindow1* + getMainWindow1(); + + //! Get access to segmented SVTK_MainWindow + VVTK_MainWindow2* + getMainWindow2(); + + //---------------------------------------------------------------------------- + //! Redefine SVTK_ViewWindow::AddActor method + /*! + This is an entry point for publication the presentation into the viewer. + Pointed actor published into the basic MainWindow. If the actor is + a Gauss Points one second actor is created from initial actor and + is put into segemented MainWindow. + */ + virtual + void + AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); + + //! Redefine SVTK_ViewWindow::RemoveActor method + virtual + void + RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate = false); + + //! Redefine SVTK_ViewWindow::Repaint method + virtual + void + Repaint(bool theUpdateTrihedron = true); + + //---------------------------------------------------------------------------- + /* interactive object management */ + //! Redefine SVTK_ViewWindow::highlight method + virtual + void + highlight(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsHighlight = true, + bool theIsUpdate = true); + + //! Redefine SVTK_ViewWindow::unHighlightAll method + virtual + void + unHighlightAll(); + + //! Redefine SVTK_ViewWindow::setBackgroundColor method + virtual + void + setBackgroundColor( const QColor& ); + + //---------------------------------------------------------------------------- +public slots: + //! Redefine SVTK_ViewWindow::onSelectionChanged method + virtual + void + onSelectionChanged(); + + //! Redefine SVTK_ViewWindow::onResetView method + virtual + void + onResetView(); + + //! Redefine SVTK_ViewWindow::onFitAll method + virtual + void + onFitAll(); + + //---------------------------------------------------------------------------- +protected: + virtual + void + action( const int ); + + virtual QImage dumpView(); + + VVTK_MainWindow1* myMainWindow1; //!< The manage base view + SVTK_View* myView1; //!< The manage base view + + VVTK_MainWindow2* myMainWindow2; //!< The manage segmented view + SVTK_View* myView2; //!< The manage segmented view +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif