1 // Copyright (C) 2007-2010 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
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_PrsObject_i.cxx
25 // Author : Alexey PETROV
28 #include "VISU_Mesh_i.hh"
29 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Tools.h"
32 #include "VISU_Result_i.hh"
34 #include "VISU_MeshAct.h"
35 #include "VISU_MeshPL.hxx"
36 #include "VISU_PipeLineUtils.hxx"
37 #include "VISU_Convertor.hxx"
39 #include "SALOME_Event.h"
40 #include <SUIT_ResourceMgr.h>
44 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
49 static int INCMEMORY = 4;
53 //----------------------------------------------------------------------------
57 IsSameColor(const SALOMEDS::Color& theLeft,
58 const SALOMEDS::Color& theRight)
61 VISU::CheckIsSameValue(theLeft.R, theRight.R) &&
62 VISU::CheckIsSameValue(theLeft.G, theRight.G) &&
63 VISU::CheckIsSameValue(theLeft.B, theRight.B);
67 //----------------------------------------------------------------------------
68 int VISU::Mesh_i::myNbPresent = 0;
70 //----------------------------------------------------------------------------
75 return VISU::GenerateName("Mesh", myNbPresent++);
78 //----------------------------------------------------------------------------
79 const string VISU::Mesh_i::myComment = "MESH";
81 //----------------------------------------------------------------------------
86 return myComment.c_str();
89 //----------------------------------------------------------------------------
92 myMeshPL(VISU_MeshPL::New())
94 SetPipeLine(myMeshPL);
98 //----------------------------------------------------------------------------
101 ::IsPossible(Result_i* theResult,
102 const std::string& theMeshName,
104 const std::string& theFamilyName)
107 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
108 size_t aSize = INCMEMORY*
109 theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity);
110 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
111 MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
113 }catch(std::exception& exc){
114 INFOS("Follow exception was occured :\n"<<exc.what());
116 INFOS("Unknown exception was occured!");
122 //----------------------------------------------------------------------------
125 ::Create(VISU::Result_i* theResult,
126 const std::string& theMeshName,
127 VISU::Entity theEntity,
128 const std::string& theFamilyName)
130 SetCResult(theResult);
131 SetMeshName(theMeshName.c_str());
132 myEntity = int(theEntity);//jfa IPAL9284
133 mySubMeshName = theFamilyName;
134 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
135 myIsShrank = aResourceMgr->booleanValue("VISU", "mesh_shrink", false);
140 //----------------------------------------------------------------------------
143 ::IsPossible(Result_i* theResult,
144 const std::string& theMeshName,
145 const std::string& theGroupName)
148 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
149 size_t aSize = INCMEMORY*
150 theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
151 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
152 INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
154 }catch(std::exception& exc){
155 INFOS("Follow exception was occured :\n"<<exc.what());
157 INFOS("Unknown exception was occured!");
163 //----------------------------------------------------------------------------
166 ::Create(VISU::Result_i* theResult,
167 const std::string& theMeshName,
168 const std::string& theGroupName)
170 SetCResult(theResult);
171 SetMeshName(theMeshName.c_str());
172 myEntity = -1;//jfa IPAL9284
173 mySubMeshName = theGroupName;
178 //----------------------------------------------------------------------------
182 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
186 //----------------------------------------------------------------------------
189 ::Build(int theRestoring)
191 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
192 aStudyBuilder->NewCommand(); // There is a transaction
194 if (GetCResult()->GetInput() == NULL)
195 throw std::runtime_error("Mesh_i::Build - GetCResult()->GetInput() == NULL !!!");
197 myPresentType = VISU::PresentationType(VISU::GetResourceMgr()->integerValue("VISU" , "mesh_represent", 2));
198 myIsShrank = (myPresentType == VISU::SHRINK);
200 if(myEntity == VISU::NODE_ENTITY)
201 myPresentType = VISU::POINT;
202 SetName((const char*)GenerateName().toLatin1(), false);
203 myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0;
204 myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0;
206 QColor aColor = VISU::GetResourceMgr()->colorValue( "VISU", "edge_color", QColor( 255, 255, 255 ) );
207 SALOMEDS::Color aLinkColor;
208 aLinkColor.R = aColor.red()/255.;
209 aLinkColor.G = aColor.green()/255.;
210 aLinkColor.B = aColor.blue()/255.;
211 SetLinkColor(aLinkColor);
213 my2DQuadPrsType = VISU::Quadratic2DPresentationType(VISU::GetResourceMgr()->integerValue( "VISU", "quadratic_mode", 0));
217 if(mySubMeshName == "")
218 myType = VISU::TENTITY;
220 myType = VISU::TFAMILY;
222 myType = VISU::TGROUP;
224 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
225 QString aComment,aTmp;
227 std::string aMeshName = GetCMeshName();
228 VISU::TEntity anEntity = VISU::TEntity(myEntity);
230 VISU::Storable::TRestoringMap aRestoringMap;
231 aRestoringMap["myMeshName"] = GetCMeshName().c_str();
233 VISU::PUnstructuredGridIDMapper anIDMapper;
234 VISU::Result_i::PInput anInput = GetCResult()->GetInput();
237 anIDMapper = anInput->GetMeshOnEntity(aMeshName,
238 anEntity);//jfa IPAL9284
239 aRestoringMap["myComment"] = "ENTITY";
240 aRestoringMap["myId"] = QString::number(anEntity);
243 anIDMapper = anInput->GetFamilyOnEntity(aMeshName,
246 aRestoringMap["myComment"] = "FAMILY";
247 aRestoringMap["myEntityId"] = QString::number(anEntity);
248 aRestoringMap["myName"] = mySubMeshName.c_str();
251 anIDMapper = anInput->GetMeshOnGroup(GetCMeshName(),
253 aRestoringMap["myComment"] = "GROUP";
254 aRestoringMap["myName"] = mySubMeshName.c_str();
258 throw std::runtime_error("Mesh_i::Build - !anIDMapper !!!");
260 myMeshPL->SetUnstructuredGridIDMapper(anIDMapper);
262 string anEntry = GetCResult()->GetEntry(aRestoringMap);
264 throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
265 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(anEntry.c_str());
267 if(!theRestoring) { //Setting IOR on the label
269 string aResultEntry = GetCResult()->GetEntry();
270 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
271 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
272 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
273 CORBA::String_var aString = GetID();
274 anIOR->SetValue(aString);
278 SALOMEDS::GenericAttribute_var anAttr;
279 SALOMEDS::AttributePixMap_var aPixmap;
281 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributePixMap");
282 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
283 aPixmap->SetPixMap("ICON_TREE_MESH");
285 }catch(std::exception& exc){
286 INFOS("Follow exception was occured :\n"<<exc.what());
289 INFOS("Unknown exception was occured!");
292 aStudyBuilder->CommitCommand();
297 //---------------------------------------------------------------
300 ::SameAs(const VISU::Prs3d_i* theOrigin)
302 return; // "SameAs" command for mesh is not valid in current architecture
306 //---------------------------------------------------------------
311 struct TRemoveFromStudy: public SALOME_Event
313 VISU::Mesh_i* myRemovable;
314 TRemoveFromStudy(VISU::Mesh_i* theRemovable):
315 myRemovable(theRemovable)
322 VISU::RemoveFromStudy(myRemovable->GetSObject());
323 myRemovable->TSuperClass::RemoveFromStudy();
328 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
329 aStudyBuilder->RemoveAttribute(GetSObject(), "AttributePixMap");
331 //Set visibility state to Qtx::UnpresentableState
332 VISU::SetVisibilityState(GetEntry(), Qtx::UnpresentableState);
338 ProcessVoidEvent(new TRemoveFromStudy(this));
342 //----------------------------------------------------------------------------
345 ::SetCellColor(const SALOMEDS::Color& theColor)
347 if(IsSameColor(myCellColor, theColor))
350 VISU::TSetModified aModified(this);
352 myCellColor = theColor;
353 myParamsTime.Modified();
357 //----------------------------------------------------------------------------
366 //----------------------------------------------------------------------------
369 ::SetNodeColor(const SALOMEDS::Color& theColor)
371 if(IsSameColor(myNodeColor, theColor))
374 VISU::TSetModified aModified(this);
376 myNodeColor = theColor;
377 myParamsTime.Modified();
381 //----------------------------------------------------------------------------
390 //----------------------------------------------------------------------------
393 ::SetLinkColor(const SALOMEDS::Color& theColor)
395 if(IsSameColor(myLinkColor, theColor))
398 VISU::TSetModified aModified(this);
400 myLinkColor = theColor;
401 myParamsTime.Modified();
405 //----------------------------------------------------------------------------
414 //----------------------------------------------------------------------------
417 ::SetPresentationType(VISU::PresentationType theType)
419 if(myPresentType == theType)
422 VISU::TSetModified aModified(this);
423 if (theType == VISU::SHRINK) {
426 myPresentType = theType;
427 myParamsTime.Modified();
433 ::SetQuadratic2DPresentationType(VISU::Quadratic2DPresentationType theType)
435 if(my2DQuadPrsType == theType)
438 VISU::TSetModified aModified(this);
439 my2DQuadPrsType = theType;
440 myParamsTime.Modified();
444 //----------------------------------------------------------------------------
445 VISU::PresentationType
447 ::GetPresentationType()
449 return myPresentType;
453 //----------------------------------------------------------------------------
454 VISU::Quadratic2DPresentationType
456 ::GetQuadratic2DPresentationType()
458 return my2DQuadPrsType;
464 //----------------------------------------------------------------------------
469 return VISU::Entity(myEntity);
473 //----------------------------------------------------------------------------
476 ::GetSubMeshName() const
478 return mySubMeshName;
482 //----------------------------------------------------------------------------
485 ::Restore(SALOMEDS::SObject_ptr theSObject,
486 const Storable::TRestoringMap& theMap)
488 if(!TSuperClass::Restore(theSObject, theMap))
491 myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();//jfa IPAL9284
492 mySubMeshName = (const char*)VISU::Storable::FindValue(theMap,"mySubMeshName").toLatin1();
494 myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
496 my2DQuadPrsType = VISU::Quadratic2DPresentationType(VISU::Storable::FindValue(theMap,"my2DQuadPrsType").toInt());
498 myIsShrank = (VISU::Storable::FindValue(theMap,"myIsShrank", "0").toInt() == 1)? true: false;
500 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
501 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
502 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
504 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
505 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
506 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
508 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
509 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
510 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
516 //----------------------------------------------------------------------------
519 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
520 const Storable::TRestoringMap& theMap,
521 const std::string& thePrefix,
522 CORBA::Boolean theIsMultiFile)
524 Mesh_i* aMesh = new Mesh_i();
525 return aMesh->Restore(theSObject, theMap);
529 //----------------------------------------------------------------------------
532 ::ToStream(std::ostringstream& theStr)
534 TSuperClass::ToStream(theStr);
536 Storable::DataToStream( theStr, "myEntity", myEntity );
537 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
539 Storable::DataToStream( theStr, "myPresentType", int(myPresentType) );
541 Storable::DataToStream( theStr, "my2DQuadPrsType", int(my2DQuadPrsType) );
543 Storable::DataToStream( theStr, "myIsShrank", (myIsShrank? "1":"0"));
545 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
546 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
547 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
549 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
550 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
551 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
553 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
554 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
555 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
559 //----------------------------------------------------------------------------
564 VISU_MeshAct* anActor = VISU_MeshAct::New();
566 VISU::Prs3d_i::CreateActor(anActor);
567 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
568 //bool toShrink = aResourceMgr->booleanValue("VISU", "mesh_shrink", false);
569 //if (toShrink) anActor->SetShrink();
570 if (anActor->IsShrunkable()) {
572 anActor->SetShrink();
576 anActor->SetFeatureEdgesAngle( aResourceMgr->doubleValue("VISU", "feature_edges_angle", 0.0) );
577 anActor->SetFeatureEdgesFlags( aResourceMgr->booleanValue("VISU", "show_feature_edges", false),
578 aResourceMgr->booleanValue("VISU", "show_boundary_edges", false),
579 aResourceMgr->booleanValue("VISU", "show_manifold_edges", false),
580 aResourceMgr->booleanValue("VISU", "show_non_manifold_edges", false) );
581 anActor->SetFeatureEdgesColoring( aResourceMgr->booleanValue("VISU", "feature_edges_coloring", false) );
583 if (myType == VISU::TGROUP )
585 anActor->SetIsDisplayNameActor( true );
586 anActor->SetNameActorText( GetSubMeshName().c_str() );
589 UpdateActor(anActor);
598 //----------------------------------------------------------------------------
601 ::UpdateActor(VISU_ActorBase* theActor)
603 if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
604 if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
605 VISU::Prs3d_i::UpdateActor(anActor);
606 anActor->SetRepresentation(myPresentType);
607 if (anActor->IsShrunkable()) {
609 anActor->SetShrink();
613 if(my2DQuadPrsType == VISU::LINES)
614 anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
616 anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
618 anActor->GetSurfaceProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
619 anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
620 anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);
624 //----------------------------------------------------------------------------
627 void VISU::Mesh_i::SetShrink(CORBA::Boolean toShrink)
629 if(toShrink == myIsShrank)
631 VISU::TSetModified aModified(this);
632 myIsShrank = toShrink;
633 myParamsTime.Modified();
636 //----------------------------------------------------------------------------
637 CORBA::Boolean VISU::Mesh_i::IsShrank()