#include "SMDS_MeshEdge.hxx"
#include "SMDS_MeshFace.hxx"
#include "SMDS_MeshVolume.hxx"
+#include "SMDS_PolyhedralVolumeOfNodes.hxx"
#include "SMESH_MeshEditor.hxx"
#include <sstream>
-typedef map<const SMDS_MeshElement*,
- list<const SMDS_MeshElement*> > TElemOfElemListMap;
-
using namespace std;
using SMESH::TPythonDump;
+//=============================================================================
+/*!
+ * \brief Mesh to apply modifications for preview purposes
+ */
+//=============================================================================
+
+struct TPreviewMesh: public SMESH_Mesh
+{
+ SMDSAbs_ElementType myPreviewType; // type to show
+
+ TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
+ _isShapeToMesh = _id =_studyId =_idDoc = 0;
+ _myMeshDS = new SMESHDS_Mesh( _id, true );
+ myPreviewType = previewElements;
+ }
+ virtual ~TPreviewMesh() { delete _myMeshDS; }
+ //
+ void Copy( const SMESH::long_array & theIDsOfElements,
+ SMESH_Mesh& theMesh,
+ TIDSortedElemSet& theElements,
+ SMDSAbs_ElementType theSelectType = SMDSAbs_All,
+ SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
+ {
+ SMESHDS_Mesh* aMeshDS = _myMeshDS;
+
+ // loop on theIDsOfElements
+ for ( int i=0; i<theIDsOfElements.length(); ++i )
+ {
+ const SMDS_MeshElement* anElem =
+ theMesh.GetMeshDS()->FindElement(theIDsOfElements[i]);
+ if ( !anElem ) continue;
+ SMDSAbs_ElementType type = anElem->GetType();
+ if ( type == theAvoidType ||
+ ( theSelectType != SMDSAbs_All && type != theSelectType ))
+ continue;
+
+ // copy element nodes
+ int anElemNbNodes = anElem->NbNodes();
+ vector< int > anElemNodesID( anElemNbNodes ) ;
+ SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
+ for ( int i = 0; itElemNodes->more(); i++)
+ {
+ const SMDS_MeshNode* anElemNode =
+ static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
+ _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
+ anElemNode->GetID());
+ anElemNodesID[i] = anElemNode->GetID();
+ }
+
+ // creates a corresponding element on copied nodes
+ const SMDS_MeshElement* anElemCopy = 0;
+ if ( anElem->IsPoly() && type == SMDSAbs_Volume )
+ {
+ const SMDS_PolyhedralVolumeOfNodes* ph =
+ dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
+ if ( ph )
+ anElemCopy = aMeshDS->AddPolyhedralVolumeWithID
+ (anElemNodesID, ph->GetQuanities(),anElem->GetID());
+ }
+ else {
+ anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
+ type,
+ anElem->IsPoly() );
+ }
+ if ( anElemCopy )
+ theElements.insert( anElemCopy );
+ }// loop on theElems
+ }
+
+};// struct TPreviewMesh
+
//=============================================================================
/*!
*
*/
//=============================================================================
-SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh)
+SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh, bool isPreview)
+{
+ _myMesh = theMesh;
+ myPreviewMode = isPreview;
+}
+
+//================================================================================
+/*!
+ * \brief Destructor
+ */
+//================================================================================
+
+SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
{
- _myMesh = theMesh;
+}
+
+//================================================================================
+/*!
+ * \brief Clear members
+ */
+//================================================================================
+
+void SMESH_MeshEditor_i::initData()
+{
+ if ( myPreviewMode ) {
+ myPreviewData = new SMESH::MeshPreviewStruct();
+ }
+ else {
+ myLastCreatedElems = new SMESH::long_array();
+ myLastCreatedNodes = new SMESH::long_array();
+ }
}
//=============================================================================
CORBA::Boolean
SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
::SMESH_MeshEditor anEditor( _myMesh );
list< int > IdList;
CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
::SMESH_MeshEditor anEditor( _myMesh );
list< int > IdList;
CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
int NbNodes = IDsOfNodes.length();
SMDS_MeshElement* elem = 0;
CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
CORBA::Double y, CORBA::Double z)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
int NbNodes = IDsOfNodes.length();
if (NbNodes < 3)
CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
(const SMESH::long_array & IDsOfNodes)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
int NbNodes = IDsOfNodes.length();
std::vector<const SMDS_MeshNode*> nodes (NbNodes);
CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
int NbNodes = IDsOfNodes.length();
vector< const SMDS_MeshNode*> n(NbNodes);
(const SMESH::long_array & IDsOfNodes,
const SMESH::long_array & Quantities)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
int NbNodes = IDsOfNodes.length();
std::vector<const SMDS_MeshNode*> n (NbNodes);
CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
(const SMESH::long_array & IdsOfFaces)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
int NbFaces = IdsOfFaces.length();
std::vector<const SMDS_MeshNode*> poly_nodes;
CORBA::Double y,
CORBA::Double z)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
if ( !node )
CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
CORBA::Long NodeID2)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
CORBA::Long NodeID2)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
- UpdateLastResult(aMeshEditor);
+ StoreResult(aMeshEditor);
return stat;
}
CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
::SMESH_MeshEditor anEditor( _myMesh );
for (int i = 0; i < IDsOfElements.length(); i++)
CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
CORBA::Boolean isDone = Reorient(anElementsId);
SMESH::NumericalFunctor_ptr Criterion,
CORBA::Double MaxAngle)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
TIDSortedElemSet faces;
bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
return stat;
}
SMESH::NumericalFunctor_ptr Criterion,
CORBA::Double MaxAngle)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
SMESH::NumericalFunctor_ptr Criterion)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
TIDSortedElemSet faces;
::SMESH_MeshEditor anEditor( _myMesh );
CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
return stat;
}
CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
SMESH::NumericalFunctor_ptr Criterion)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
CORBA::Boolean Diag13)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
TIDSortedElemSet faces;
::SMESH_MeshEditor anEditor( _myMesh );
CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
return stat;
}
CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
CORBA::Boolean Diag13)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
SMESH::SMESH_MeshEditor::Smooth_Method Method,
bool IsParametric)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
anEditor.Smooth(elements, fixedNodes, method,
MaxNbOfIterations, MaxAspectRatio, IsParametric );
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
// Update Python script
TPythonDump() << "isDone = " << this << "."
SMESH::SMESH_MeshEditor::Smooth_Method Method,
bool IsParametric)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
CORBA::Long theNbOfSteps,
CORBA::Double theTolerance)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
-
- SMESHDS_Mesh* aMesh = GetMeshDS();
+ initData();
TIDSortedElemSet elements;
- ToMap(theIDsOfElements, aMesh, elements);
+ TPreviewMesh tmpMesh( SMDSAbs_Face );
+ SMESH_Mesh* mesh = 0;
+ bool makeWalls=true;
+ if ( myPreviewMode )
+ {
+ SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
+ tmpMesh.Copy( theIDsOfElements, *_myMesh, elements, select, avoid );
+ mesh = &tmpMesh;
+ //makeWalls = false;
+ }
+ else
+ {
+ ToMap(theIDsOfElements, GetMeshDS(), elements);
+ mesh = _myMesh;
+ }
- gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
+ gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
- ::SMESH_MeshEditor anEditor( _myMesh );
+ ::SMESH_MeshEditor anEditor( mesh );
anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
- theNbOfSteps, theTolerance);
+ theNbOfSteps, theTolerance, makeWalls);
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
- // Update Python script
- TPythonDump() << "axis = " << theAxis;
- TPythonDump() << this << ".RotationSweep( "
- << theIDsOfElements
- << ", axis, "
- << theAngleInRadians << ", "
- << theNbOfSteps << ", "
- << theTolerance << " )";
+ if ( !myPreviewMode ) {
+ // Update Python script
+ TPythonDump() << "axis = " << theAxis;
+ TPythonDump() << this << ".RotationSweep( "
+ << theIDsOfElements
+ << ", axis, "
+ << theAngleInRadians << ", "
+ << theNbOfSteps << ", "
+ << theTolerance << " )";
+ }
}
//=======================================================================
CORBA::Long theNbOfSteps,
CORBA::Double theTolerance)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
const SMESH::DirStruct & theStepVector,
CORBA::Long theNbOfSteps)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
#ifdef NO_CAS_CATCH
try {
::SMESH_MeshEditor anEditor( _myMesh );
anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
// Update Python script
TPythonDump() << "stepVector = " << theStepVector;
const SMESH::DirStruct & theStepVector,
CORBA::Long theNbOfSteps)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
const SMESH::DirStruct & theStepVector,
CORBA::Long theNbOfSteps)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
TElemOfElemListMap aHystory;
anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
// Update Python script
TPythonDump() << "stepVector = " << theStepVector;
const SMESH::DirStruct & theStepVector,
CORBA::Long theNbOfSteps)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
TElemOfElemListMap aHystory;
anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
// Update Python script
TPythonDump() << "stepVector = " << theStepVector;
CORBA::Long theExtrFlags,
CORBA::Double theSewTolerance)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
theExtrFlags, theSewTolerance);
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
// Update Python script
TPythonDump() << "stepVector = " << theStepVector;
CORBA::Boolean theHasRefPoint,
const SMESH::PointStruct & theRefPoint)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
theHasAngles, angles,
theHasRefPoint, refPnt ) );
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
return error;
}
CORBA::Boolean theHasRefPoint,
const SMESH::PointStruct & theRefPoint)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
const SMESH::double_array & theAngles)
{
SMESH::double_array_var aResult = new SMESH::double_array();
- // TO BE IMPLEMENTED
return aResult._retn();
}
SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
CORBA::Boolean theCopy)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
anEditor.Transform (elements, aTrsf, theCopy);
if(theCopy) {
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
}
}
SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
CORBA::Boolean theCopy)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
Mirror(anElementsId, theAxis, theMirrorType, theCopy);
const SMESH::DirStruct & theVector,
CORBA::Boolean theCopy)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
anEditor.Transform (elements, aTrsf, theCopy);
if(theCopy) {
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
}
// Update Python script
const SMESH::DirStruct & theVector,
CORBA::Boolean theCopy)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
Translate(anElementsId, theVector, theCopy);
CORBA::Double theAngle,
CORBA::Boolean theCopy)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
anEditor.Transform (elements, aTrsf, theCopy);
if(theCopy) {
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
}
// Update Python script
CORBA::Double theAngle,
CORBA::Boolean theCopy)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESH::long_array_var anElementsId = theObject->GetIDs();
Rotate(anElementsId, theAxis, theAngle, theCopy);
void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
SMESH::array_of_long_array_out GroupsOfNodes)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
::SMESH_MeshEditor anEditor( _myMesh );
void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
void SMESH_MeshEditor_i::MergeEqualElements()
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
::SMESH_MeshEditor anEditor( _myMesh );
anEditor.MergeEqualElements();
CORBA::Boolean CreatePolygons,
CORBA::Boolean CreatePolyedrs)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
CreatePolygons,
CreatePolyedrs) );
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
return error;
}
CORBA::Long FirstNodeID2,
CORBA::Long SecondNodeID2)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
true,
false, false) );
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
return error;
}
CORBA::Boolean CreatePolygons,
CORBA::Boolean CreatePolyedrs)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
CreatePolygons,
CreatePolyedrs) );
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
return error;
}
CORBA::Long NodeID2OfSide1ToMerge,
CORBA::Long NodeID2OfSide2ToMerge)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
SMESHDS_Mesh* aMesh = GetMeshDS();
aSecondNode1ToMerge,
aSecondNode2ToMerge));
- UpdateLastResult(anEditor);
+ StoreResult(anEditor);
return error;
}
CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
const SMESH::long_array& newIDs)
{
- myLastCreatedElems = new SMESH::long_array();
- myLastCreatedNodes = new SMESH::long_array();
+ initData();
const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
if(!elem) return false;
//================================================================================
/*!
- * \brief Update myLastCreatedNodes and myLastCreatedElems
+ * \brief Update myLastCreated* or myPreviewData
* \param anEditor - it contains last modification results
*/
//================================================================================
-void SMESH_MeshEditor_i::UpdateLastResult(::SMESH_MeshEditor& anEditor)
+void SMESH_MeshEditor_i::StoreResult(::SMESH_MeshEditor& anEditor)
{
- // add new elements into myLastCreatedNodes
- SMESH_SequenceOfElemPtr aSeq = anEditor.GetLastCreatedNodes();
- SMESH::long_array_var aResult = new SMESH::long_array;
- aResult->length(aSeq.Length());
- int i=0;
- for(; i<aSeq.Length(); i++) {
- aResult[i] = aSeq.Value(i+1)->GetID();
+ if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
+
+ list<int> aNodesConnectivity;
+ typedef map<int, int> TNodesMap;
+ TNodesMap nodesMap;
+
+ TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
+ SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
+
+ SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
+ int nbEdges = aMeshDS->NbEdges();
+ int nbFaces = aMeshDS->NbFaces();
+ int nbVolum = aMeshDS->NbVolumes();
+ switch ( previewType ) {
+ case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
+ case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
+ case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
+ default:;
+ }
+ myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
+ myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
+ int i = 0, j = 0;
+ SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
+
+ while ( itMeshElems->more() ) {
+ const SMDS_MeshElement* aMeshElem = itMeshElems->next();
+ if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
+ continue;
+
+ SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
+ while ( itElemNodes->more() ) {
+ const SMDS_MeshNode* aMeshNode =
+ static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
+ int aNodeID = aMeshNode->GetID();
+ TNodesMap::iterator anIter = nodesMap.find(aNodeID);
+ if ( anIter == nodesMap.end() ) {
+ // filling the nodes coordinates
+ myPreviewData->nodesXYZ[j].x = aMeshNode->X();
+ myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
+ myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
+ anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
+ j++;
+ }
+ aNodesConnectivity.push_back(anIter->second);
+ }
+
+ // filling the elements types
+ SMDSAbs_ElementType aType;
+ bool isPoly;
+ /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
+ aType = SMDSAbs_Node;
+ isPoly = false;
+ }
+ else*/ {
+ aType = aMeshElem->GetType();
+ isPoly = aMeshElem->IsPoly();
+ }
+
+ myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
+ myPreviewData->elementTypes[i].isPoly = isPoly;
+ myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
+ i++;
+
+ }
+ myPreviewData->nodesXYZ.length( j );
+
+ // filling the elements connectivities
+ list<int>::iterator aConnIter = aNodesConnectivity.begin();
+ myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
+ for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
+ myPreviewData->elementConnectivities[i] = *aConnIter;
+
+ return;
}
- myLastCreatedNodes = aResult._retn();
- // add new elements into myLastCreatedElems
- aSeq = anEditor.GetLastCreatedElems();
- aResult = new SMESH::long_array;
- aResult->length(aSeq.Length());
- i=0;
- for(; i<aSeq.Length(); i++) {
- aResult[i] = aSeq.Value(i+1)->GetID();
+
+ {
+ // add new nodes into myLastCreatedNodes
+ const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
+ myLastCreatedNodes->length(aSeq.Length());
+ for(int i=0; i<aSeq.Length(); i++)
+ myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
+ }
+ {
+ // add new elements into myLastCreatedElems
+ const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
+ myLastCreatedElems->length(aSeq.Length());
+ for(int i=0; i<aSeq.Length(); i++)
+ myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
}
- myLastCreatedElems = aResult._retn();
+}
+
+//================================================================================
+/*!
+ * Return data of mesh edition preview
+ */
+//================================================================================
+
+SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
+{
+ return myPreviewData._retn();
}
//================================================================================
SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
{
- return myLastCreatedNodes.out();
+ return myLastCreatedNodes._retn();
}
//================================================================================
SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
{
- return myLastCreatedElems.out();
+ return myLastCreatedElems._retn();
}
-
//=======================================================================
//function : ConvertToQuadratic
//purpose :
::SMESH_MeshEditor anEditor( _myMesh );
anEditor.ConvertToQuadratic(theForce3d);
// Update Python script
- TPythonDump() << this << ".ConvertToQuadratic( "
- << theForce3d << " )";
+ TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
}
//=======================================================================