+ getEditor().GetError().reset();
+ getEditor().CrearLastCreated();
+}
+//================================================================================
+/*!
+ * \brief Return either myEditor or myPreviewEditor depending on myIsPreviewMode.
+ * WARNING: in preview mode call getPreviewMesh() before getEditor()!
+ */
+//================================================================================
+
+::SMESH_MeshEditor& SMESH_MeshEditor_i::getEditor()
+{
+ if ( myIsPreviewMode && !myPreviewEditor ) {
+ if ( !myPreviewMesh ) getPreviewMesh();
+ myPreviewEditor = new ::SMESH_MeshEditor( myPreviewMesh );
+ }
+ return myIsPreviewMode ? *myPreviewEditor : myEditor;
+}
+
+//================================================================================
+/*!
+ * \brief Initialize and return myPreviewMesh
+ * \param previewElements - type of elements to show in preview
+ *
+ * WARNING: call it once par a method!
+ */
+//================================================================================
+
+TPreviewMesh * SMESH_MeshEditor_i::getPreviewMesh(SMDSAbs_ElementType previewElements)
+{
+ if ( !myPreviewMesh || myPreviewMesh->myPreviewType != previewElements )
+ {
+ delete myPreviewEditor;
+ myPreviewEditor = 0;
+ delete myPreviewMesh;
+ myPreviewMesh = new TPreviewMesh( previewElements );
+ }
+ myPreviewMesh->Clear();
+ return myPreviewMesh;
+}
+
+//================================================================================
+/*!
+ * \brief Now does nothing
+ */
+//================================================================================
+
+// void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& )
+// {
+// }
+
+//================================================================================
+/*!
+ * Return data of mesh edition preview
+ */
+//================================================================================
+
+SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
+{
+ const bool hasBadElems = ( getEditor().GetError() && getEditor().GetError()->HasBadElems() );
+
+ if ( myIsPreviewMode || hasBadElems ) { // --- MeshPreviewStruct filling ---
+
+ list<int> aNodesConnectivity;
+ typedef map<int, int> TNodesMap;
+ TNodesMap nodesMap;
+
+ SMESHDS_Mesh* aMeshDS;
+ std::auto_ptr< SMESH_MeshPartDS > aMeshPartDS;
+ if ( hasBadElems ) {
+ aMeshPartDS.reset( new SMESH_MeshPartDS( getEditor().GetError()->myBadElements ));
+ aMeshDS = aMeshPartDS.get();
+ }
+ else {
+ aMeshDS = getEditor().GetMeshDS();
+ }
+ int nbEdges = aMeshDS->NbEdges();
+ int nbFaces = aMeshDS->NbFaces();
+ int nbVolum = aMeshDS->NbVolumes();
+ myPreviewData = new SMESH::MeshPreviewStruct();
+ myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
+
+
+ SMDSAbs_ElementType previewType = SMDSAbs_All;
+ if ( !hasBadElems )
+ if (TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( getEditor().GetMesh() )) {
+ previewType = aPreviewMesh->myPreviewType;
+ 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->elementTypes.length(nbEdges + nbFaces + nbVolum);
+ int i = 0, j = 0;
+ SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator(previewType);
+
+ while ( itMeshElems->more() ) {
+ const SMDS_MeshElement* aMeshElem = itMeshElems->next();
+ 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 = aMeshElem->GetType();
+ bool 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 myPreviewData._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Returns list of it's IDs of created nodes
+ * \retval SMESH::long_array* - list of node ID
+ */
+//================================================================================
+
+SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
+{
+ SMESH::long_array_var myLastCreatedNodes = new SMESH::long_array();
+ const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedNodes();
+ myLastCreatedNodes->length( aSeq.Length() );
+ for (int i = 1; i <= aSeq.Length(); i++)
+ myLastCreatedNodes[i-1] = aSeq.Value(i)->GetID();
+ return myLastCreatedNodes._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Returns list of it's IDs of created elements
+ * \retval SMESH::long_array* - list of elements' ID
+ */
+//================================================================================
+
+SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
+{
+ SMESH::long_array_var myLastCreatedElems = new SMESH::long_array();
+ const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedElems();
+ myLastCreatedElems->length( aSeq.Length() );
+ for ( int i = 1; i <= aSeq.Length(); i++ )
+ myLastCreatedElems[i-1] = aSeq.Value(i)->GetID();
+ return myLastCreatedElems._retn();
+}
+
+//=======================================================================
+/*
+ * Returns description of an error/warning occured during the last operation
+ */
+//=======================================================================
+
+SMESH::ComputeError* SMESH_MeshEditor_i::GetLastError()
+{
+ SMESH::ComputeError_var errOut = new SMESH::ComputeError;
+ SMESH_ComputeErrorPtr& errIn = getEditor().GetError();
+ if ( errIn && !errIn->IsOK() )
+ {
+ errOut->code = -( errIn->myName < 0 ? errIn->myName + 1: errIn->myName ); // -1 -> 0
+ errOut->comment = errIn->myComment.c_str();
+ errOut->subShapeID = -1;
+ errOut->hasBadMesh = !errIn->myBadElements.empty();
+ }
+ else
+ {
+ errOut->code = 0;
+ errOut->subShapeID = -1;
+ errOut->hasBadMesh = false;
+ }
+ return errOut._retn();