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"
38 #include "SUIT_ResourceMgr.h"
44 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
49 static int INCMEMORY = 4;
51 int VISU::Mesh_i::myNbPresent = 0;
53 QString VISU::Mesh_i::GenerateName() { return VISU::GenerateName("Mesh",myNbPresent++);}
55 const string VISU::Mesh_i::myComment = "MESH";
57 const char* VISU::Mesh_i::GetComment() const { return myComment.c_str();}
60 Mesh_i(Result_i* theResult) :
61 PrsObject_i(theResult->GetStudyDocument()),
62 Prs3d_i(theResult,false),
63 myMeshPL(VISU_MeshPL::New())
65 myPipeLine = myMeshPL;
70 Mesh_i(Result_i* theResult,
71 SALOMEDS::SObject_ptr theSObject) :
72 PrsObject_i(theResult->GetStudyDocument()),
73 Prs3d_i(theResult,theSObject),
74 myMeshPL(VISU_MeshPL::New())
76 myPipeLine = myMeshPL;
80 //---------------------------------------------------------------
81 void VISU::Mesh_i::RemoveFromStudy()
83 struct TRemoveFromStudy: public SALOME_Event
85 VISU::Mesh_i* myRemovable;
86 TRemoveFromStudy(VISU::Mesh_i* theRemovable):
87 myRemovable(theRemovable)
94 VISU::RemoveFromStudy(myRemovable->GetSObject());
95 myRemovable->TSuperClass::RemoveFromStudy();
99 ProcessVoidEvent(new TRemoveFromStudy(this));
103 void VISU::Mesh_i::SameAs (const Prs3d_i* theOrigin)
105 return; // "SameAs" command for mesh is not valid in current architecture
110 int VISU::Mesh_i::IsPossible (Result_i* theResult, const char* theMeshName,
111 Entity theEntity, const char* theFamilyName)
114 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
115 float aSize = INCMEMORY*
116 theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity);
117 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
118 MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
120 }catch(std::exception& exc){
121 INFOS("Follow exception was occured :\n"<<exc.what());
123 INFOS("Unknown exception was occured!");
128 VISU::Storable* VISU::Mesh_i::Create (const char* theMeshName,
130 const char* theFamilyName)
132 myMeshName = theMeshName;
133 //jfa IPAL9284:myEntity = VISU::TEntity(theEntity);
134 myEntity = int(theEntity);//jfa IPAL9284
135 mySubMeshName = theFamilyName;
140 int VISU::Mesh_i::IsPossible (Result_i* theResult, const char* theMeshName, const char* theGroupName)
143 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
144 float aSize = INCMEMORY*
145 theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
146 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
147 INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
149 }catch(std::exception& exc){
150 INFOS("Follow exception was occured :\n"<<exc.what());
152 INFOS("Unknown exception was occured!");
158 VISU::Storable* VISU::Mesh_i::Create (const char* theMeshName,
159 const char* theGroupName)
161 myMeshName = theMeshName;
162 //jfa IPAL9284:myEntity = VISU::TEntity(-1);
163 myEntity = -1;//jfa IPAL9284
164 mySubMeshName = theGroupName;
169 VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap)
171 Prs3d_i::Restore(theMap);
173 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
174 //jfa IPAL9284:myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
175 myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();//jfa IPAL9284
176 mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1();
178 myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
180 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
181 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
182 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
184 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
185 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
186 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
188 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
189 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
190 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
196 void VISU::Mesh_i::ToStream(std::ostringstream& theStr){
197 Prs3d_i::ToStream(theStr);
199 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
200 Storable::DataToStream( theStr, "myEntity", myEntity );
201 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
203 Storable::DataToStream( theStr, "myPresentType", int(myPresentType) );
205 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
206 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
207 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
209 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
210 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
211 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
213 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
214 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
215 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
219 VISU::Mesh_i::~Mesh_i(){
220 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
224 VISU::Storable* VISU::Mesh_i::Build (int theRestoring)
226 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
227 aStudyBuilder->NewCommand(); // There is a transaction
229 if (myResult->GetInput() == NULL)
230 throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
232 myPresentType = VISU::PresentationType(VISU::GetResourceMgr()->integerValue("VISU" , "mesh_represent", 2));
233 if(myEntity == VISU::NODE_ENTITY)
234 myPresentType = VISU::POINT;
235 myName = GenerateName().latin1();
236 myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0;
237 myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0;
238 myLinkColor.R = myLinkColor.G = myLinkColor.B = 83/255.;
242 if(mySubMeshName == "")
243 myType = VISU::TENTITY;
245 myType = VISU::TFAMILY;
247 myType = VISU::TGROUP;
249 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
252 VISU::PIDMapper anIDMapper;
255 anIDMapper = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity);//jfa IPAL9284
256 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
257 VISU::TENTITY,myMeshName.c_str(),myEntity);
260 anIDMapper = myResult->GetInput()->GetFamilyOnEntity(myMeshName,(VISU::TEntity)myEntity,mySubMeshName);
261 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
262 VISU::TFAMILY,myMeshName.c_str(),myEntity,mySubMeshName.c_str());
265 anIDMapper = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName);
266 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
267 VISU::TGROUP,myMeshName.c_str(),mySubMeshName.c_str());
271 throw std::runtime_error("Mesh_i::Build - !anIDMapper !!!");
273 myMeshPL->SetIDMapper(anIDMapper);
276 if(!theRestoring) { //Setting IOR on the label
278 string aResultEntry = myResult->GetEntry();
279 string anEntry = myResult->GetEntry(aComment.latin1());
281 throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
282 mySObject = myStudy->FindObjectID(anEntry.c_str());
283 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
284 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(mySObject,"AttributeIOR");
285 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
286 CORBA::String_var aString = GetID();
287 anIOR->SetValue(aString);
289 }catch(std::exception& exc){
290 INFOS("Follow exception was occured :\n"<<exc.what());
293 INFOS("Unknown exception was occured!");
296 aStudyBuilder->CommitCommand();
301 VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
303 VISU_MeshAct* anActor = VISU_MeshAct::New();
305 VISU::Prs3d_i::CreateActor(anActor,theIO);
306 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
307 bool toShrink = aResourceMgr->booleanValue("VISU", "mesh_shrink", false);
308 if (toShrink) anActor->SetShrink();
309 UpdateActor(anActor);
318 void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor) {
319 if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
320 if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
321 VISU::Prs3d_i::UpdateActor(anActor);
322 anActor->SetRepresentation(myPresentType);
323 anActor->GetSurfaceProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
324 anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
325 anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);