1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_MeshPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_Mesh_i.hh"
30 #include "VISU_MeshAct.h"
36 static int MYDEBUG = 0;
37 static int MYDEBUGWITHFILES = 0;
39 static int MYDEBUG = 0;
40 static int MYDEBUGWITHFILES = 0;
43 static int INCMEMORY = 4;
45 int VISU::Mesh_i::myNbPresent = 0;
47 QString VISU::Mesh_i::GenerateName() { return VISU::GenerateName("Mesh",myNbPresent++);}
49 const string VISU::Mesh_i::myComment = "MESH";
51 const char* VISU::Mesh_i::GetComment() const { return myComment.c_str();}
53 VISU::Mesh_i::Mesh_i(Result_i* theResult) :
54 PrsObject_i(theResult->GetStudyDocument()),
57 myPipeLine = myMeshPL = VISU_MeshPL::New();;
60 void VISU::Mesh_i::SameAs(const Mesh_i* theOrigin){
61 return; // "SameAs" command for mesh is not valid in current architecture
64 void VISU::Mesh_i::Destroy(){
65 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(GetEntry());
66 if(!aSObj->_is_nil()){
67 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
68 aStudyBuilder->RemoveAttribute(aSObj,"AttributeIOR");
73 int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, Entity theEntity, const char* theFamilyName){
75 vtkIdType aSize = INCMEMORY*
76 theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity,theFamilyName);
77 if(MYDEBUG) MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<aSize);
78 if(VISU_PipeLine::CheckAvailableMemory(aSize)) return true;
80 }catch(std::runtime_error& exc){
81 INFOS("Follow exception was accured :\n"<<exc.what());
83 INFOS("Unknown exception was accured!");
88 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, Entity theEntity, const char* theFamilyName){
89 myMeshName = theMeshName;
90 myEntity = VISU::TEntity(theEntity);
91 mySubMeshName = theFamilyName;
96 int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, const char* theGroupName){
98 vtkIdType aSize = INCMEMORY*
99 theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
100 if(MYDEBUG) MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<aSize);
101 if(VISU_PipeLine::CheckAvailableMemory(aSize)) return true;
103 }catch(std::runtime_error& exc){
104 INFOS("Follow exception was accured :\n"<<exc.what());
106 INFOS("Unknown exception was accured!");
110 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, const char* theGroupName){
111 myMeshName = theMeshName;
112 myEntity = VISU::TEntity(-1);
113 mySubMeshName = theGroupName;
117 VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap)
118 throw(std::logic_error&)
120 Prs3d_i::Restore(theMap);
122 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
123 myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
124 mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1();
126 myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
128 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
129 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
130 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
132 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
133 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
134 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
136 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
137 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
138 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
143 void VISU::Mesh_i::ToStream(std::ostringstream& theStr){
144 Prs3d_i::ToStream(theStr);
146 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
147 Storable::DataToStream( theStr, "myEntity", myEntity );
148 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
150 Storable::DataToStream( theStr, "myPresentType", int(myPresentType) );
152 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
153 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
154 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
156 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
157 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
158 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
160 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
161 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
162 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
165 VISU::Storable* VISU::Mesh_i::Restore(SALOMEDS::SObject_ptr theSObject,
166 const string& thePrefix, const Storable::TRestoringMap& theMap)
167 throw(std::logic_error&)
169 VISU::Result_i* pResult = GetResult(theSObject);
171 VISU::Mesh_i* pResent = new VISU::Mesh_i(pResult);
172 return pResent->Restore(theMap);
178 VISU::Mesh_i::~Mesh_i(){
179 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
183 VISU::Storable* VISU::Mesh_i::Build(int theRestoring){
185 if(myResult->GetInput() == NULL)
186 throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
188 myPresentType = VISU::SHADED;
189 myName = GenerateName().latin1();
190 myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0;
191 myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0;
192 myLinkColor.R = myLinkColor.G = myLinkColor.B = 83/255.;
194 if(int(myEntity) >= 0)
195 if(mySubMeshName == "")
196 myType = VISU::TENTITY;
198 myType = VISU::TFAMILY;
200 myType = VISU::TGROUP;
201 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
204 VISU_Convertor::TOutput *anOutput;
207 anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,myEntity);
208 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
209 VISU::TENTITY,myMeshName.c_str(),myEntity);
212 anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,myEntity,mySubMeshName);
213 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
214 VISU::TFAMILY,myMeshName.c_str(),myEntity,mySubMeshName.c_str());
217 anOutput = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName);
218 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
219 VISU::TGROUP,myMeshName.c_str(),mySubMeshName.c_str());
222 if(anOutput == NULL) throw std::runtime_error("Mesh_i::Build - anOutput == NULL !!!");
223 myMeshPL->SetInput(anOutput);
225 if(!theRestoring) { //Setting IOR on the label
227 string aResultEntry = myResult->GetEntry();
228 string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1());
229 if(anEntry == "") throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
230 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(anEntry.c_str());
231 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
232 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObj,"AttributeIOR");
233 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
234 CORBA::String_var aString = GetID();
235 anIOR->SetValue(aString);
238 }catch(std::runtime_error& exc){
239 INFOS("Follow exception was accured :\n"<<exc.what());
241 INFOS("Unknown exception was accured!");
247 VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
248 throw (std::runtime_error&)
250 VISU_MeshAct* anActor = VISU_MeshAct::New();
252 VISU::Prs3d_i::CreateActor(anActor,theIO);
253 UpdateActor(anActor);
254 }catch(std::runtime_error& exc){
261 void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor){
262 if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
263 if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
264 VISU::Prs3d_i::UpdateActor(anActor);
265 anActor->SetRepresentation(myPresentType);
266 anActor->GetProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
267 anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
268 anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);