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_Mesh_i.hh"
29 #include "VISU_Result_i.hh"
30 #include "VISU_ViewManager_i.hh"
32 #include "VISU_MeshAct.h"
33 #include "VISU_MeshPL.hxx"
34 #include "VISU_Convertor.hxx"
36 #include "SALOME_Event.hxx"
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
47 static int INCMEMORY = 4;
49 int VISU::Mesh_i::myNbPresent = 0;
51 QString VISU::Mesh_i::GenerateName() { return VISU::GenerateName("Mesh",myNbPresent++);}
53 const string VISU::Mesh_i::myComment = "MESH";
55 const char* VISU::Mesh_i::GetComment() const { return myComment.c_str();}
58 Mesh_i(Result_i* theResult) :
59 PrsObject_i(theResult->GetStudyDocument()),
60 Prs3d_i(theResult,false),
61 myMeshPL(VISU_MeshPL::New())
63 myPipeLine = myMeshPL;
68 Mesh_i(Result_i* theResult,
69 SALOMEDS::SObject_ptr theSObject) :
70 PrsObject_i(theResult->GetStudyDocument()),
71 Prs3d_i(theResult,theSObject),
72 myMeshPL(VISU_MeshPL::New())
74 myPipeLine = myMeshPL;
78 //---------------------------------------------------------------
79 void VISU::Mesh_i::RemoveFromStudy()
81 struct TRemoveFromStudy: public SALOME_Event
83 VISU::Mesh_i* myRemovable;
84 TRemoveFromStudy(VISU::Mesh_i* theRemovable):
85 myRemovable(theRemovable)
92 VISU::RemoveFromStudy(myRemovable->GetSObject());
93 myRemovable->TSuperClass::RemoveFromStudy();
97 ProcessVoidEvent(new TRemoveFromStudy(this));
101 void VISU::Mesh_i::SameAs (const Prs3d_i* theOrigin)
103 return; // "SameAs" command for mesh is not valid in current architecture
108 int VISU::Mesh_i::IsPossible (Result_i* theResult, const char* theMeshName,
109 Entity theEntity, const char* theFamilyName)
112 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
113 float aSize = INCMEMORY*
114 theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity);
115 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
116 MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
118 }catch(std::exception& exc){
119 INFOS("Follow exception was occured :\n"<<exc.what());
121 INFOS("Unknown exception was occured!");
126 VISU::Storable* VISU::Mesh_i::Create (const char* theMeshName,
128 const char* theFamilyName)
130 myMeshName = theMeshName;
131 //jfa IPAL9284:myEntity = VISU::TEntity(theEntity);
132 myEntity = int(theEntity);//jfa IPAL9284
133 mySubMeshName = theFamilyName;
138 int VISU::Mesh_i::IsPossible (Result_i* theResult, const char* theMeshName, const char* theGroupName)
141 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
142 float aSize = INCMEMORY*
143 theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
144 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
145 INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
147 }catch(std::exception& exc){
148 INFOS("Follow exception was occured :\n"<<exc.what());
150 INFOS("Unknown exception was occured!");
156 VISU::Storable* VISU::Mesh_i::Create (const char* theMeshName,
157 const char* theGroupName)
159 myMeshName = theMeshName;
160 //jfa IPAL9284:myEntity = VISU::TEntity(-1);
161 myEntity = -1;//jfa IPAL9284
162 mySubMeshName = theGroupName;
167 VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap)
169 Prs3d_i::Restore(theMap);
171 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
172 //jfa IPAL9284:myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
173 myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();//jfa IPAL9284
174 mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1();
176 myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
178 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
179 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
180 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
182 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
183 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
184 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
186 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
187 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
188 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
194 void VISU::Mesh_i::ToStream(std::ostringstream& theStr){
195 Prs3d_i::ToStream(theStr);
197 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
198 Storable::DataToStream( theStr, "myEntity", myEntity );
199 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
201 Storable::DataToStream( theStr, "myPresentType", int(myPresentType) );
203 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
204 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
205 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
207 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
208 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
209 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
211 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
212 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
213 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
217 VISU::Mesh_i::~Mesh_i(){
218 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
222 VISU::Storable* VISU::Mesh_i::Build (int theRestoring)
224 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
225 aStudyBuilder->NewCommand(); // There is a transaction
227 if (myResult->GetInput() == NULL)
228 throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
230 myPresentType = VISU::SHADED;
231 myName = GenerateName().latin1();
232 myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0;
233 myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0;
234 myLinkColor.R = myLinkColor.G = myLinkColor.B = 83/255.;
238 if(mySubMeshName == "")
239 myType = VISU::TENTITY;
241 myType = VISU::TFAMILY;
243 myType = VISU::TGROUP;
245 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
248 VISU::PIDMapper anIDMapper;
251 anIDMapper = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity);//jfa IPAL9284
252 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
253 VISU::TENTITY,myMeshName.c_str(),myEntity);
256 anIDMapper = myResult->GetInput()->GetFamilyOnEntity(myMeshName,(VISU::TEntity)myEntity,mySubMeshName);
257 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
258 VISU::TFAMILY,myMeshName.c_str(),myEntity,mySubMeshName.c_str());
261 anIDMapper = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName);
262 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
263 VISU::TGROUP,myMeshName.c_str(),mySubMeshName.c_str());
267 throw std::runtime_error("Mesh_i::Build - !anIDMapper !!!");
269 myMeshPL->SetIDMapper(anIDMapper);
272 if(!theRestoring) { //Setting IOR on the label
274 string aResultEntry = myResult->GetEntry();
275 string anEntry = myResult->GetEntry(aComment.latin1());
276 if(anEntry == "") throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
277 mySObject = myStudy->FindObjectID(anEntry.c_str());
278 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
279 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(mySObject,"AttributeIOR");
280 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
281 CORBA::String_var aString = GetID();
282 anIOR->SetValue(aString);
284 }catch(std::exception& exc){
285 INFOS("Follow exception was occured :\n"<<exc.what());
288 INFOS("Unknown exception was occured!");
291 aStudyBuilder->CommitCommand();
296 VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
298 VISU_MeshAct* anActor = VISU_MeshAct::New();
300 VISU::Prs3d_i::CreateActor(anActor,theIO);
301 UpdateActor(anActor);
310 void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor) {
311 if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
312 if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
313 VISU::Prs3d_i::UpdateActor(anActor);
314 anActor->SetRepresentation(myPresentType);
315 anActor->GetSurfaceProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
316 anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
317 anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);