1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_Mesh_i.hh"
28 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
32 #include "VISU_MeshAct.h"
33 #include "VISU_MeshPL.hxx"
34 #include "VISU_PipeLineUtils.hxx"
35 #include "VISU_Convertor.hxx"
37 #include "SALOME_Event.h"
39 #include "SUIT_ResourceMgr.h"
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
47 static int INCMEMORY = 4;
51 //----------------------------------------------------------------------------
55 IsSameColor(const SALOMEDS::Color& theLeft,
56 const SALOMEDS::Color& theRight)
59 VISU::CheckIsSameValue(theLeft.R, theRight.R) &&
60 VISU::CheckIsSameValue(theLeft.G, theRight.G) &&
61 VISU::CheckIsSameValue(theLeft.B, theRight.B);
65 //----------------------------------------------------------------------------
66 int VISU::Mesh_i::myNbPresent = 0;
68 //----------------------------------------------------------------------------
73 return VISU::GenerateName("Mesh", myNbPresent++);
76 //----------------------------------------------------------------------------
77 const string VISU::Mesh_i::myComment = "MESH";
79 //----------------------------------------------------------------------------
84 return myComment.c_str();
87 //----------------------------------------------------------------------------
90 myMeshPL(VISU_MeshPL::New())
92 SetPipeLine(myMeshPL);
96 //----------------------------------------------------------------------------
99 ::IsPossible(Result_i* theResult,
100 const std::string& theMeshName,
102 const std::string& theFamilyName)
105 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
106 size_t aSize = INCMEMORY*
107 theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity);
108 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
109 MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
111 }catch(std::exception& exc){
112 INFOS("Follow exception was occured :\n"<<exc.what());
114 INFOS("Unknown exception was occured!");
120 //----------------------------------------------------------------------------
123 ::Create(VISU::Result_i* theResult,
124 const std::string& theMeshName,
125 VISU::Entity theEntity,
126 const std::string& theFamilyName)
128 SetCResult(theResult);
129 SetMeshName(theMeshName.c_str());
130 myEntity = int(theEntity);//jfa IPAL9284
131 mySubMeshName = theFamilyName;
132 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
133 myIsShrank = aResourceMgr->booleanValue("VISU", "mesh_shrink", false);
138 //----------------------------------------------------------------------------
141 ::IsPossible(Result_i* theResult,
142 const std::string& theMeshName,
143 const std::string& theGroupName)
146 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
147 size_t aSize = INCMEMORY*
148 theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
149 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
150 INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
152 }catch(std::exception& exc){
153 INFOS("Follow exception was occured :\n"<<exc.what());
155 INFOS("Unknown exception was occured!");
161 //----------------------------------------------------------------------------
164 ::Create(VISU::Result_i* theResult,
165 const std::string& theMeshName,
166 const std::string& theGroupName)
168 SetCResult(theResult);
169 SetMeshName(theMeshName.c_str());
170 myEntity = -1;//jfa IPAL9284
171 mySubMeshName = theGroupName;
176 //----------------------------------------------------------------------------
180 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
184 //----------------------------------------------------------------------------
187 ::Build(int theRestoring)
189 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
190 aStudyBuilder->NewCommand(); // There is a transaction
192 if (GetCResult()->GetInput() == NULL)
193 throw std::runtime_error("Mesh_i::Build - GetCResult()->GetInput() == NULL !!!");
195 myPresentType = VISU::PresentationType(VISU::GetResourceMgr()->integerValue("VISU" , "mesh_represent", 2));
196 myIsShrank = (myPresentType == VISU::SHRINK);
198 if(myEntity == VISU::NODE_ENTITY)
199 myPresentType = VISU::POINT;
200 SetName((const char*)GenerateName().toLatin1(), false);
201 myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0;
202 myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0;
204 QColor aColor = VISU::GetResourceMgr()->colorValue( "VISU", "edge_color", QColor( 255, 255, 255 ) );
205 SALOMEDS::Color aLinkColor;
206 aLinkColor.R = aColor.red()/255.;
207 aLinkColor.G = aColor.green()/255.;
208 aLinkColor.B = aColor.blue()/255.;
209 SetLinkColor(aLinkColor);
211 my2DQuadPrsType = VISU::Quadratic2DPresentationType(VISU::GetResourceMgr()->integerValue( "VISU", "quadratic_mode", 0));
215 if(mySubMeshName == "")
216 myType = VISU::TENTITY;
218 myType = VISU::TFAMILY;
220 myType = VISU::TGROUP;
222 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
223 QString aComment,aTmp;
225 std::string aMeshName = GetCMeshName();
226 VISU::TEntity anEntity = VISU::TEntity(myEntity);
228 VISU::Storable::TRestoringMap aRestoringMap;
229 aRestoringMap["myMeshName"] = GetCMeshName().c_str();
231 VISU::PUnstructuredGridIDMapper anIDMapper;
232 VISU::Result_i::PInput anInput = GetCResult()->GetInput();
235 anIDMapper = anInput->GetMeshOnEntity(aMeshName,
236 anEntity);//jfa IPAL9284
237 aRestoringMap["myComment"] = "ENTITY";
238 aRestoringMap["myId"] = QString::number(anEntity);
241 anIDMapper = anInput->GetFamilyOnEntity(aMeshName,
244 aRestoringMap["myComment"] = "FAMILY";
245 aRestoringMap["myEntityId"] = QString::number(anEntity);
246 aRestoringMap["myName"] = mySubMeshName.c_str();
249 anIDMapper = anInput->GetMeshOnGroup(GetCMeshName(),
251 aRestoringMap["myComment"] = "GROUP";
252 aRestoringMap["myName"] = mySubMeshName.c_str();
256 throw std::runtime_error("Mesh_i::Build - !anIDMapper !!!");
258 myMeshPL->SetUnstructuredGridIDMapper(anIDMapper);
260 string anEntry = GetCResult()->GetEntry(aRestoringMap);
262 throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
263 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(anEntry.c_str());
265 if(!theRestoring) { //Setting IOR on the label
267 string aResultEntry = GetCResult()->GetEntry();
268 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
269 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
270 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
271 CORBA::String_var aString = GetID();
272 anIOR->SetValue(aString);
276 SALOMEDS::GenericAttribute_var anAttr;
277 SALOMEDS::AttributePixMap_var aPixmap;
279 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributePixMap");
280 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
281 aPixmap->SetPixMap("ICON_TREE_MESH");
283 }catch(std::exception& exc){
284 INFOS("Follow exception was occured :\n"<<exc.what());
287 INFOS("Unknown exception was occured!");
290 aStudyBuilder->CommitCommand();
295 //---------------------------------------------------------------
298 ::SameAs(const VISU::Prs3d_i* theOrigin)
300 return; // "SameAs" command for mesh is not valid in current architecture
304 //---------------------------------------------------------------
309 struct TRemoveFromStudy: public SALOME_Event
311 VISU::Mesh_i* myRemovable;
312 TRemoveFromStudy(VISU::Mesh_i* theRemovable):
313 myRemovable(theRemovable)
320 VISU::RemoveFromStudy(myRemovable->GetSObject());
321 myRemovable->TSuperClass::RemoveFromStudy();
326 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
327 aStudyBuilder->RemoveAttribute(GetSObject(), "AttributePixMap");
329 ProcessVoidEvent(new TRemoveFromStudy(this));
333 //----------------------------------------------------------------------------
336 ::SetCellColor(const SALOMEDS::Color& theColor)
338 if(IsSameColor(myCellColor, theColor))
341 VISU::TSetModified aModified(this);
343 myCellColor = theColor;
344 myParamsTime.Modified();
348 //----------------------------------------------------------------------------
357 //----------------------------------------------------------------------------
360 ::SetNodeColor(const SALOMEDS::Color& theColor)
362 if(IsSameColor(myNodeColor, theColor))
365 VISU::TSetModified aModified(this);
367 myNodeColor = theColor;
368 myParamsTime.Modified();
372 //----------------------------------------------------------------------------
381 //----------------------------------------------------------------------------
384 ::SetLinkColor(const SALOMEDS::Color& theColor)
386 if(IsSameColor(myLinkColor, theColor))
389 VISU::TSetModified aModified(this);
391 myLinkColor = theColor;
392 myParamsTime.Modified();
396 //----------------------------------------------------------------------------
405 //----------------------------------------------------------------------------
408 ::SetPresentationType(VISU::PresentationType theType)
410 if(myPresentType == theType)
413 VISU::TSetModified aModified(this);
414 if (theType == VISU::SHRINK) {
417 myPresentType = theType;
418 myParamsTime.Modified();
424 ::SetQuadratic2DPresentationType(VISU::Quadratic2DPresentationType theType)
426 if(my2DQuadPrsType == theType)
429 VISU::TSetModified aModified(this);
430 my2DQuadPrsType = theType;
431 myParamsTime.Modified();
435 //----------------------------------------------------------------------------
436 VISU::PresentationType
438 ::GetPresentationType()
440 return myPresentType;
444 //----------------------------------------------------------------------------
445 VISU::Quadratic2DPresentationType
447 ::GetQuadratic2DPresentationType()
449 return my2DQuadPrsType;
455 //----------------------------------------------------------------------------
460 return VISU::Entity(myEntity);
464 //----------------------------------------------------------------------------
467 ::GetSubMeshName() const
469 return mySubMeshName;
473 //----------------------------------------------------------------------------
476 ::Restore(SALOMEDS::SObject_ptr theSObject,
477 const Storable::TRestoringMap& theMap)
479 if(!TSuperClass::Restore(theSObject, theMap))
482 myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();//jfa IPAL9284
483 mySubMeshName = (const char*)VISU::Storable::FindValue(theMap,"mySubMeshName").toLatin1();
485 myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
487 my2DQuadPrsType = VISU::Quadratic2DPresentationType(VISU::Storable::FindValue(theMap,"my2DQuadPrsType").toInt());
489 myIsShrank = (VISU::Storable::FindValue(theMap,"myIsShrank", "0").toInt() == 1)? true: false;
491 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
492 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
493 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
495 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
496 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
497 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
499 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
500 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
501 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
507 //----------------------------------------------------------------------------
510 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
511 const Storable::TRestoringMap& theMap,
512 const std::string& thePrefix,
513 CORBA::Boolean theIsMultiFile)
515 Mesh_i* aMesh = new Mesh_i();
516 return aMesh->Restore(theSObject, theMap);
520 //----------------------------------------------------------------------------
523 ::ToStream(std::ostringstream& theStr)
525 TSuperClass::ToStream(theStr);
527 Storable::DataToStream( theStr, "myEntity", myEntity );
528 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
530 Storable::DataToStream( theStr, "myPresentType", int(myPresentType) );
532 Storable::DataToStream( theStr, "my2DQuadPrsType", int(my2DQuadPrsType) );
534 Storable::DataToStream( theStr, "myIsShrank", (myIsShrank? "1":"0"));
536 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
537 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
538 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
540 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
541 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
542 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
544 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
545 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
546 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
550 //----------------------------------------------------------------------------
555 VISU_MeshAct* anActor = VISU_MeshAct::New();
557 VISU::Prs3d_i::CreateActor(anActor);
558 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
559 //bool toShrink = aResourceMgr->booleanValue("VISU", "mesh_shrink", false);
560 //if (toShrink) anActor->SetShrink();
561 if (anActor->IsShrunkable()) {
563 anActor->SetShrink();
567 anActor->SetFeatureEdgesAngle( aResourceMgr->doubleValue("VISU", "feature_edges_angle", 0.0) );
568 anActor->SetFeatureEdgesFlags( aResourceMgr->booleanValue("VISU", "show_feature_edges", false),
569 aResourceMgr->booleanValue("VISU", "show_boundary_edges", false),
570 aResourceMgr->booleanValue("VISU", "show_manifold_edges", false),
571 aResourceMgr->booleanValue("VISU", "show_non_manifold_edges", false) );
572 anActor->SetFeatureEdgesColoring( aResourceMgr->booleanValue("VISU", "feature_edges_coloring", false) );
574 if (myType == VISU::TGROUP )
576 anActor->SetIsDisplayNameActor( true );
577 anActor->SetNameActorText( GetSubMeshName().c_str() );
580 UpdateActor(anActor);
589 //----------------------------------------------------------------------------
592 ::UpdateActor(VISU_ActorBase* theActor)
594 if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
595 if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
596 VISU::Prs3d_i::UpdateActor(anActor);
597 anActor->SetRepresentation(myPresentType);
598 if (anActor->IsShrunkable()) {
600 anActor->SetShrink();
604 if(my2DQuadPrsType == VISU::LINES)
605 anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
607 anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
609 anActor->GetSurfaceProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
610 anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
611 anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);
615 //----------------------------------------------------------------------------
618 void VISU::Mesh_i::SetShrink(CORBA::Boolean toShrink)
620 if(toShrink == myIsShrank)
622 VISU::TSetModified aModified(this);
623 myIsShrank = toShrink;
624 myParamsTime.Modified();
627 //----------------------------------------------------------------------------
628 CORBA::Boolean VISU::Mesh_i::IsShrank()