#include "BooleanField.hxx"
#include "BooleanStep.hxx"
+#include "XaoUtils.hxx"
#include <Utils_SALOME_Exception.hxx>
BooleanStep* BooleanField::addStep(const int& step, const int& stamp)
{
+ if (hasStep(step))
+ throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
+
BooleanStep* bstep = new BooleanStep(step, stamp, m_nbElements, m_nbComponents);
m_steps.push_back(bstep);
return bstep;
#include <cassert>
+#include <Standard_TypeMismatch.hxx>
+
+#include <BRepTools.hxx>
+#include <BRep_Builder.hxx>
+#include <TopAbs.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <TColStd_HArray1OfInteger.hxx>
-#include <TColStd_HSequenceOfInteger.hxx>
+//#include <TColStd_ListIteratorOfListOfInteger.hxx>
+//#include <TColStd_HArray1OfInteger.hxx>
+//#include <TColStd_HSequenceOfInteger.hxx>
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
-#include <BRep_Tool.hxx>
#include <Utils_SALOME_Exception.hxx>
{
}
-TopoDS_Shape BrepGeometry::getGeometricalElement(TopAbs_ShapeEnum shapeType, const int& shapeIndex)
+const std::string BrepGeometry::getShape()
+{
+ std::ostringstream streamShape;
+ BRepTools::Write(m_shape, streamShape);
+ std::string data = streamShape.str();
+ char* res = new char[data.size()];
+ strcpy(res, data.c_str());
+ return res;
+}
+
+void BrepGeometry::setShape(const std::string& shape)
+{
+ std::istringstream streamBrep(shape.c_str());
+ BRep_Builder builder;
+ BRepTools::Read(m_shape, streamBrep, builder);
+
+ initIds();
+}
+
+TopoDS_Shape BrepGeometry::getTopoDS_Shape()
+{
+ return m_shape;
+}
+
+void BrepGeometry::setTopoDS_Shape(const TopoDS_Shape& shape)
+{
+ m_shape = shape;
+ initIds();
+}
+
+void BrepGeometry::initIds()
+{
+ // intialization of Ids
+ initListIds(TopAbs_VERTEX, m_vertices);
+ initListIds(TopAbs_EDGE, m_edges);
+ initListIds(TopAbs_FACE, m_faces);
+ initListIds(TopAbs_SOLID, m_solids);
+}
+
+void BrepGeometry::initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList)
{
TopTools_MapOfShape mapShape;
TopTools_ListOfShape listShape;
listShape.Append(exp.Current());
}
+ if (listShape.IsEmpty())
+ return;
+
+ TopTools_IndexedMapOfShape indices;
+ TopExp::MapShapes(m_shape, indices);
+
+ std::list<int> indexList;
+ TopTools_ListIteratorOfListOfShape itSub(listShape);
+ for (int index = 1; itSub.More(); itSub.Next(), ++index)
+ {
+ TopoDS_Shape value = itSub.Value();
+ indexList.push_back(indices.FindIndex(value));
+ }
+
+ std::list<int>::iterator it = indexList.begin();
+
+ eltList.setSize(indexList.size());
+ for (int i = 0; it != indexList.end(); it++, i++)
+ eltList.setReference(i, XaoUtils::intToString((*it)));
+}
+
+TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex)
+{
+ TopTools_MapOfShape mapShape;
+ TopTools_ListOfShape listShape;
+
+ TopExp_Explorer exp(mainShape, shapeType);
+ for (; exp.More(); exp.Next())
+ {
+ if (mapShape.Add(exp.Current()))
+ listShape.Append(exp.Current());
+ }
+
if (!listShape.IsEmpty())
{
+ // use main shape indices
TopTools_IndexedMapOfShape indices;
- TopExp::MapShapes(m_shape, indices);
+ TopExp::MapShapes(mainShape, indices);
TopTools_ListIteratorOfListOfShape itSub(listShape);
for (int index = 1; itSub.More(); itSub.Next(), ++index)
{
- TopoDS_Shape value = itSub.Value();
- if (shapeIndex == (int)indices.FindIndex(value))
+ if (shapeIndex + 1 == index)
+ {
+ TopoDS_Shape value = itSub.Value();
return value;
+ }
}
}
- throw SALOME_Exception(MsgBuilder() << "Shape not found: " << shapeIndex);
+ throw SALOME_Exception(MsgBuilder() << "Shape with reference [" << shapeIndex << "] not found.");
}
-const int BrepGeometry::countGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType)
+// -----------------------------
+const int BrepGeometry::countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType)
{
int res = 0;
TopTools_MapOfShape mapShape;
return res;
}
-std::vector<int> BrepGeometry::getGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType)
+std::vector<int> BrepGeometry::getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim)
{
std::vector<int> indexList;
if (!listShape.IsEmpty())
{
+ // use the shape of the geometry for the indices
TopTools_IndexedMapOfShape indices;
- TopExp::MapShapes(shape, indices);
+ TopExp::MapShapes(m_shape, indices);
TopTools_ListIteratorOfListOfShape itSub(listShape);
for (int index = 1; itSub.More(); itSub.Next(), ++index)
{
TopoDS_Shape value = itSub.Value();
- indexList.push_back(indices.FindIndex(value));
+ int id = indices.FindIndex(value);
+ indexList.push_back(findElement(dim, id));
}
}
return indexList;
}
-void BrepGeometry::getEdgeVertices(const int& edge, int& vertexA, int& vertexB)
+void BrepGeometry::getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB)
{
- TopoDS_Shape shape = getGeometricalElement(TopAbs_EDGE, edge);
- std::vector<int> vertices = getGeometricalElements(shape, TopAbs_VERTEX);
+ TopoDS_Shape edge = getSubShape(m_shape, TopAbs_EDGE, edgeIndex);
+ std::vector<int> vertices = getGeometricalElements(edge, TopAbs_VERTEX, XAO::VERTEX);
assert(vertices.size() == 2);
vertexA = vertices[0];
vertexB = vertices[1];
}
-const int BrepGeometry::countFaceWires(const int& face)
+const int BrepGeometry::countFaceWires(const int& faceIndex)
{
- TopoDS_Shape shape = getGeometricalElement(TopAbs_FACE, face);
- return countGeometricalElements(shape, TopAbs_WIRE);
+ TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
+ return countGeometricalElements(face, TopAbs_WIRE);
}
-std::vector<int> BrepGeometry::getFaceWires(const int& face)
+std::vector<int> BrepGeometry::getFaceEdges(const int& faceIndex, const int& wireIndex)
{
- TopoDS_Shape shape = getGeometricalElement(TopAbs_FACE, face);
- return getGeometricalElements(shape, TopAbs_WIRE);
+ // get the face
+ TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
+ // get the wire
+ TopoDS_Shape wire = getSubShape(face, TopAbs_WIRE, wireIndex);
+ return getGeometricalElements(wire, TopAbs_EDGE, XAO::EDGE);
}
-const int BrepGeometry::countSolidShells(const int& solid)
+const int BrepGeometry::countSolidShells(const int& solidIndex)
{
- TopoDS_Shape shape = getGeometricalElement(TopAbs_SOLID, solid);
- return countGeometricalElements(shape, TopAbs_SHELL);
+ TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
+ return countGeometricalElements(solid, TopAbs_SHELL);
}
-std::vector<int> BrepGeometry::getSolidShells(const int& solid)
+std::vector<int> BrepGeometry::getSolidFaces(const int& solidIndex, const int& shellIndex)
{
- TopoDS_Shape shape = getGeometricalElement(TopAbs_SOLID, solid);
- return getGeometricalElements(shape, TopAbs_SHELL);
+ TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
+ TopoDS_Shape shell = getSubShape(solid, TopAbs_SHELL, shellIndex);
+ return getGeometricalElements(shell, TopAbs_FACE, XAO::FACE);
}
-void BrepGeometry::getVertexXYZ(const int& vertex, double& xCoord, double& yCoord, double& zCoord)
+void BrepGeometry::getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord)
{
xCoord = 0.;
yCoord = 0.;
zCoord = 0.;
- TopoDS_Shape shape = getGeometricalElement(TopAbs_VERTEX, vertex);
- if (shape.ShapeType() != TopAbs_VERTEX)
- throw SALOME_Exception(MsgBuilder() << "Shape " << vertex << " is not a point.");
+ TopoDS_Shape vertex = getSubShape(m_shape, TopAbs_VERTEX, vertexIndex);
+ if (vertex.ShapeType() != TopAbs_VERTEX)
+ throw SALOME_Exception(MsgBuilder() << "Shape " << vertexIndex<< " is not a point.");
- TopoDS_Vertex point = TopoDS::Vertex(shape);
+ TopoDS_Vertex point = TopoDS::Vertex(vertex);
if (!point.IsNull())
{
gp_Pnt aPnt = BRep_Tool::Pnt(point);
}
}
-const double BrepGeometry::getEdgeLength(const int& edge)
+// -----------------------------
+const double BrepGeometry::getEdgeLength(const int& edgeIndex)
{
- TopoDS_Shape shape = getGeometricalElement(TopAbs_EDGE, edge);
+ TopoDS_Shape edge = getSubShape(m_shape, TopAbs_EDGE, edgeIndex);
GProp_GProps system;
- BRepGProp::LinearProperties(shape, system);
+ BRepGProp::LinearProperties(edge, system);
return system.Mass();
}
-const double BrepGeometry::getFaceArea(const int& face)
+const double BrepGeometry::getFaceArea(const int& faceIndex)
{
- TopoDS_Shape shape = getGeometricalElement(TopAbs_FACE, face);
+ TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
GProp_GProps system;
- BRepGProp::SurfaceProperties(shape, system);
+ BRepGProp::SurfaceProperties(face, system);
return system.Mass();
}
-const double BrepGeometry::getSolidVolume(const int& solid)
+const double BrepGeometry::getSolidVolume(const int& solidIndex)
{
- TopoDS_Shape shape = getGeometricalElement(TopAbs_SOLID, solid);
+ TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
GProp_GProps system;
- BRepGProp::VolumeProperties(shape, system);
+ BRepGProp::VolumeProperties(solid, system);
return system.Mass();
}
-const int BrepGeometry::getVertexID(const int& vertex)
+// -----------------------------
+const int BrepGeometry::getVertexID(const int& index)
+{
+ return XaoUtils::stringToInt(getVertexReference(index));
+}
+
+const int BrepGeometry::getEdgeID(const int& index)
{
- return XaoUtils::stringToInt(getVertexReference(vertex));
+ return XaoUtils::stringToInt(getEdgeReference(index));
}
-const int BrepGeometry::getEdgeID(const int& edge)
+const int BrepGeometry::getFaceID(const int& index)
{
- return XaoUtils::stringToInt(getEdgeReference(edge));
+ return XaoUtils::stringToInt(getFaceReference(index));
}
-const int BrepGeometry::getFaceID(const int& face)
+const int BrepGeometry::getSolidID(const int& index)
{
- return XaoUtils::stringToInt(getFaceReference(face));
+ return XaoUtils::stringToInt(getSolidReference(index));
}
-const int BrepGeometry::getSolidID(const int& solid)
+// -----------------------------
+void BrepGeometry::setVertexID(const int& index, const int& id)
{
- return XaoUtils::stringToInt(getSolidReference(solid));
+ setVertexReference(index, XaoUtils::intToString(id));
}
-void BrepGeometry::setVertexID(const int& vertex, const int& id)
+void BrepGeometry::setEdgeID(const int& index, const int& id)
{
- setVertexReference(vertex, XaoUtils::intToString(id));
+ setEdgeReference(index, XaoUtils::intToString(id));
}
-void BrepGeometry::setEdgeID(const int& edge, const int& id)
+void BrepGeometry::setFaceID(const int& index, const int& id)
{
- setEdgeReference(edge, XaoUtils::intToString(id));
+ setEdgeReference(index, XaoUtils::intToString(id));
}
-void BrepGeometry::setFaceID(const int& face, const int& id)
+void BrepGeometry::setSolidID(const int& index, const int& id)
{
- setEdgeReference(face, XaoUtils::intToString(id));
+ setEdgeReference(index, XaoUtils::intToString(id));
}
-void BrepGeometry::setSolidID(const int& solid, const int& id)
+// -----------------------------
+const int BrepGeometry::findElement(const XAO::Dimension& dim, const int& id)
{
- setEdgeReference(solid, XaoUtils::intToString(id));
+ if (dim == XAO::VERTEX)
+ return findVertex(id);
+ if (dim == XAO::EDGE)
+ return findEdge(id);
+ if (dim == XAO::FACE)
+ return findFace(id);
+ if (dim == XAO::SOLID)
+ return findSolid(id);
+ throw SALOME_Exception(MsgBuilder() << "Unknown Dimension: " << dim);
}
const int BrepGeometry::findVertex(const int& id)
return getSolidIndexByReference(XaoUtils::intToString(id));
}
+// -----------------------------
const std::string BrepGeometry::findVertexName(const int& id)
{
return getVertexName(findVertex(id));
return getSolidName(findSolid(id));
}
+// -----------------------------
void BrepGeometry::changeVertexName(const int& id, const std::string& name)
{
setVertexName(findVertex(id), name);
#include <string>
#include <vector>
-#include <SALOMEconfig.h>
#include <TopoDS_Shape.hxx>
#include "Xao.hxx"
virtual const XAO::Format getFormat() { return XAO::BREP; }
+ virtual const std::string getShape();
+ virtual void setShape(const std::string& shape);
+
+ TopoDS_Shape getTopoDS_Shape();
+ void setTopoDS_Shape(const TopoDS_Shape& shape);
+
/**
* Gives the two extrimities of an edge.
- * @param edge
+ * @param edgeIndex the index of the edge.
* @param vertexA
* @param vertexB
*/
- void getEdgeVertices(const int& edge, int& vertexA, int& vertexB);
+ void getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB);
/**
* Gets the number of wires of a face (including holes).
- * @param face the index of the face.
+ * @param faceIndex the index of the face.
* @return the number of wires.
*/
- const int countFaceWires(const int& face);
+ const int countFaceWires(const int& faceIndex);
/**
* Gets the indices of the wires of the face.
- * @param face the index of the face.
+ * @param faceIndex the index of the face.
+ * @param wireIndex the index of the wire.
* @return the list of wires for the given face.
*/
- std::vector<int> getFaceWires(const int& face);
+ std::vector<int> getFaceEdges(const int& faceIndex, const int& wireIndex);
/**
* Gets the number of shells of a solid (including cavities).
- * @param solid the index of the solid.
+ * @param solidIndex the index of the solid.
* @return the number of shells.
*/
- const int countSolidShells(const int& solid);
+ const int countSolidShells(const int& solidIndex);
/**
* Gets the indices of the shells of the solids.
- * @param solid the index of the solid.
+ * @param solidIndex the index of the solid.
+ * @param shellIndex the index of the shell (for the given solid).
* @return the list of shells for the given solid.
*/
- std::vector<int> getSolidShells(const int& solid);
+ std::vector<int> getSolidFaces(const int& solidIndex, const int& shellIndex);
/**
* Gets the coordinates of a vertex.
- * @param vertex the index of the vertex.
+ * @param vertexIndex the index of the vertex.
* @param xCoord the X coordinate.
* @param yCoord the Y coordinate.
* @param zCoord the Z coordinate.
*/
- void getVertexXYZ(const int& vertex, double& xCoord, double& yCoord, double& zCoord);
+ void getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord);
/**
* Gets the length of an edge.
* @param edge the index of the edge.
* @return the length of the edge.
*/
- const double getEdgeLength(const int& edge);
+ const double getEdgeLength(const int& index);
/**
* Gets the are of a face.
* @param face the index of a face.
* @return the area of the face.
*/
- const double getFaceArea(const int& face);
+ const double getFaceArea(const int& index);
/**
* Gets the volume of a solid.
* @param solid the index of the solid.
* @return the volume of the solid.
*/
- const double getSolidVolume(const int& solid);
+ const double getSolidVolume(const int& index);
/**
* Gets the ID of a vertex.
* @param vertex the index of the vertex.
* @return the ID of the vertex.
*/
- const int getVertexID(const int& vertex);
+ const int getVertexID(const int& index);
/**
* Gets the ID of an edge.
* @param edge the index of the edge.
* @return the ID of the edge.
*/
- const int getEdgeID(const int& edge);
+ const int getEdgeID(const int& index);
/**
* Gets the ID of a face.
* @param face the index of the face.
* @return the ID of the face.
*/
- const int getFaceID(const int& face);
+ const int getFaceID(const int& index);
/**
* Gets the ID of a solid.
*/
const int getSolidID(const int& solid);
- void setVertexID(const int& vertex, const int& id);
- void setEdgeID(const int& edge, const int& id);
- void setFaceID(const int& face, const int& id);
- void setSolidID(const int& solid, const int& id);
+ void setVertexID(const int& index, const int& id);
+ void setEdgeID(const int& index, const int& id);
+ void setFaceID(const int& index, const int& id);
+ void setSolidID(const int& index, const int& id);
+
+ const int findElement(const XAO::Dimension& dim, const int& id);
/**
* Finds a vertex with its ID.
void changeSolidName(const int& id, const std::string& name);
private:
- TopoDS_Shape getGeometricalElement(TopAbs_ShapeEnum shapeType, const int& shapeIndex);
- const int countGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType);
- std::vector<int> getGeometricalElements(TopoDS_Shape shape, TopAbs_ShapeEnum shapeType);
+ void initIds();
+ void initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList);
+ TopoDS_Shape getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex);
+ const int countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType);
+ std::vector<int> getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim);
+ private:
+ TopoDS_Shape m_shape;
};
}
#include "DoubleField.hxx"
#include "DoubleStep.hxx"
+#include "XaoUtils.hxx"
#include <Utils_SALOME_Exception.hxx>
DoubleStep* DoubleField::addStep(const int& step, const int& stamp)
{
+ if (hasStep(step))
+ throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
+
DoubleStep* bstep = new DoubleStep(step, stamp, m_nbElements, m_nbComponents);
m_steps.push_back(bstep);
return bstep;
return false;
}
+bool Field::hasStep(const int& step)
+{
+ std::vector<Step*>::iterator it = m_steps.begin();
+ for (; it != m_steps.end(); ++it)
+ {
+ Step* current = *it;
+ if (current->getStep() == step)
+ return true;
+ }
+
+ return false;
+}
+
void Field::checkComponent(const int& component)
{
if (component < m_nbComponents && component >= 0)
/**
* Adds a new step of the same type than the field.
- * @param step the index of the step.
+ * @param number the numer of the step.
* @return the new create step.
*/
- virtual Step* addNewStep(const int& step) = 0;
+ virtual Step* addNewStep(const int& number) = 0;
/**
* Remove a step.
* @param step the step to remove.
- * @return true if the step has been removed.
+ * @return true if the step has been removed, false otherwise.
*/
bool removeStep(Step* step);
+ /**
+ * Verifies if the field has a step with the given step number.
+ * @param step the step number.
+ * @return true if the field has a step for the given number.
+ */
+ bool hasStep(const int& step);
+
/**
* Returns the first step.
* @return an iterator on the first step.
#include <Utils_SALOME_Exception.hxx>
#include "GeometricElement.hxx"
+#include "XaoUtils.hxx"
using namespace XAO;
void GeometricElementList::setName(const int& index, const std::string& name)
{
if (m_count == 0 || index > m_count)
- {
throw SALOME_Exception("Problem with number of elements");
- }
m_elements[index].setName(name);
}
const bool GeometricElementList::hasName(const int& index)
{
if (m_count == 0 || index > m_count)
- {
throw SALOME_Exception("Problem with number of elements");
- }
return m_elements[index].hasName();
}
for (int index = 0; index < m_count; ++index)
{
if (ref == m_elements[index].getReference())
- {
return index;
- }
}
- return -1;
+
+ throw SALOME_Exception(MsgBuilder() << "Reference not found: " << ref);
}
//
// Author : Nathalie Gore (OpenCascade)
-#include <Standard_TypeMismatch.hxx>
-
-#include <BRepTools.hxx>
-#include <BRep_Builder.hxx>
-#include <TopAbs.hxx>
-
-//#include <string>
-#include <fstream>
-#include <sstream>
-#include <iostream>
-#include <iosfwd>
-#include <list>
-
-#include <TopTools_MapOfShape.hxx>
-#include <TopTools_ListOfShape.hxx>
-#include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <TopTools_IndexedMapOfShape.hxx>
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <TColStd_HArray1OfInteger.hxx>
-#include <TColStd_HSequenceOfInteger.hxx>
-
#include <Utils_SALOME_Exception.hxx>
#include "XaoUtils.hxx"
{
}
-void Geometry::setShape(const TopoDS_Shape& shape)
-{
- m_shape = shape;
-
- // intialization of Ids
- initListIds(TopAbs_VERTEX);
- initListIds(TopAbs_EDGE);
- initListIds(TopAbs_FACE);
- initListIds(TopAbs_SOLID);
-}
-
-void Geometry::setBREP(const char* brep)
-{
- std::istringstream streamBrep(brep);
- BRep_Builder builder;
- BRepTools::Read(m_shape, streamBrep, builder);
-
- // intialization of Ids
- initListIds(TopAbs_VERTEX);
- initListIds(TopAbs_EDGE);
- initListIds(TopAbs_FACE);
- initListIds(TopAbs_SOLID);
-}
-
-const char* Geometry::getBREP()
-{
- std::ostringstream streamShape;
- BRepTools::Write(m_shape, streamShape);
- std::string data = streamShape.str();
- char* res = new char[data.size()];
- strcpy(res, data.c_str());
- return res;
-}
-
-void Geometry::initListIds(const Standard_Integer shapeType)
-{
- TopTools_MapOfShape mapShape;
- TopTools_ListOfShape listShape;
-
- TopExp_Explorer exp(m_shape, TopAbs_ShapeEnum(shapeType));
- for (; exp.More(); exp.Next())
- {
- if (mapShape.Add(exp.Current()))
- listShape.Append(exp.Current());
- }
-
- if (listShape.IsEmpty())
- return;
-
- TopTools_IndexedMapOfShape indices;
- TopExp::MapShapes(m_shape, indices);
-
- std::list<int> indexList;
- TopTools_ListIteratorOfListOfShape itSub(listShape);
- for (int index = 1; itSub.More(); itSub.Next(), ++index)
- {
- TopoDS_Shape value = itSub.Value();
- indexList.push_back(indices.FindIndex(value));
- }
-
- std::list<int>::iterator it = indexList.begin();
- switch (shapeType)
- {
- case TopAbs_VERTEX:
- {
- m_vertices.setSize(indexList.size());
- for (int i = 0; it != indexList.end(); it++, i++)
- m_vertices.setReference(i, XaoUtils::intToString((*it)));
- break;
- }
- case TopAbs_EDGE:
- {
- m_edges.setSize(indexList.size());
- for (int i = 0; it != indexList.end(); it++, i++)
- m_edges.setReference(i, XaoUtils::intToString((*it)));
- break;
- }
- case TopAbs_FACE:
- {
- m_faces.setSize(indexList.size());
- for (int i = 0; it != indexList.end(); it++, i++)
- m_faces.setReference(i, XaoUtils::intToString((*it)));
- break;
- }
- case TopAbs_SOLID:
- {
- m_solids.setSize(indexList.size());
- for (int i = 0; it != indexList.end(); it++, i++)
- m_solids.setReference(i, XaoUtils::intToString((*it)));
- break;
- }
- }
-}
-
const int Geometry::countElements(const XAO::Dimension& dim)
{
if (dim == XAO::VERTEX)
#include <string>
-#include <SALOMEconfig.h>
-#include <TopoDS_Shape.hxx>
-
#include "Xao.hxx"
#include "GeometricElement.hxx"
*/
virtual const XAO::Format getFormat() = 0;
- /**
- * Gets the shape of the geometry.
- * @return the shape of the geometry.
- */
- TopoDS_Shape getShape()
- {
- return m_shape;
- }
- /**
- * Sets the shape of the geometry.
- * @param shape the shape to set.
- */
- void setShape(const TopoDS_Shape& shape);
-
- const char* getBREP();
- void setBREP(const char* brep);
+ virtual const std::string getShape() = 0;
+ virtual void setShape(const std::string& shape) = 0;
const int countElements(const XAO::Dimension& dim);
const int countVertices() { return m_vertices.getSize(); }
GeometricElementList::iterator begin(const XAO::Dimension& dim);
GeometricElementList::iterator end(const XAO::Dimension& dim);
- private:
- void initListIds(const Standard_Integer shapeType);
-
-
protected:
std::string m_name;
- TopoDS_Shape m_shape;
GeometricElementList m_vertices;
GeometricElementList m_edges;
GeometricElementList m_faces;
#include "IntegerField.hxx"
#include "IntegerStep.hxx"
+#include "XaoUtils.hxx"
#include <Utils_SALOME_Exception.hxx>
IntegerStep* IntegerField::addStep(const int& step, const int& stamp)
{
+ if (hasStep(step))
+ throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
+
IntegerStep* bstep = new IntegerStep(step, stamp, m_nbElements, m_nbComponents);
m_steps.push_back(bstep);
return bstep;
#include "StringField.hxx"
#include "StringStep.hxx"
+#include "XaoUtils.hxx"
#include <Utils_SALOME_Exception.hxx>
StringStep* StringField::addStep(const int& step, const int& stamp)
{
+ if (hasStep(step))
+ throw SALOME_Exception(MsgBuilder() << "Step with number " << step << "already exists.");
+
StringStep* bstep = new StringStep(step, stamp, m_nbElements, m_nbComponents);
m_steps.push_back(bstep);
return bstep;
xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag)
{
xmlNodePtr vertices = xmlNewChild(topology, 0, colTag, 0);
- xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoGeometry->countVertices()).c_str());
+ xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoGeometry->countElements(dim)).c_str());
GeometricElementList::iterator it = xaoGeometry->begin(dim);
for (; it != xaoGeometry->end(dim); it++)
{
xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0);
xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST XaoUtils::shapeFormatToString(xaoGeometry->getFormat()).c_str());
- const char* brep = xaoGeometry->getBREP();
- xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST brep, strlen(brep));
+ std::string txtShape = xaoGeometry->getShape();
+ xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST txtShape.c_str(), txtShape.size());
xmlAddChild(shape, cdata);
xmlNodePtr topology = xmlNewChild(geometry, 0, C_TAG_TOPOLOGY, 0);
xmlChar* data = xmlNodeGetContent(shapeNode->children);
if (data == NULL)
throw SALOME_Exception("Missing BREP");
- geometry->setBREP((char*)data);
+ geometry->setShape((char*)data);
xmlFree(data);
}
else
void readBrep(Geometry* geom, const std::string& fileName)
{
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath(fileName));
- geom->setBREP(txt);
+ geom->setShape(txt);
}
void BrepGeometryTest::testGetIDs()
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
+ // edge of index 23, id = #63
+ // vertex are 47 (#12), 59 (#15)
int v1, v2;
- geom->getEdgeVertices(63, v1, v2);
- std::cout << "# " << v1 << ", " << v2 << std::endl;
- CPPUNIT_ASSERT_EQUAL(47, v1);
- CPPUNIT_ASSERT_EQUAL(59, v2);
+ geom->getEdgeVertices(23, v1, v2);
+ CPPUNIT_ASSERT_EQUAL(12, v1);
+ CPPUNIT_ASSERT_EQUAL(15, v2);
delete geom;
}
-void BrepGeometryTest::testGetFaceWires()
+void printVector(std::vector<int>& v)
+{
+ std::cout << "# ";
+ for (int i = 0; i < v.size(); i++)
+ std::cout << v[i] << ", ";
+ std::cout << std::endl;
+}
+
+void BrepGeometryTest::testGetFaceEdges()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
- CPPUNIT_ASSERT_EQUAL(2, geom->countFaceWires(13));
- CPPUNIT_ASSERT_EQUAL(1, geom->countFaceWires(29));
+ CPPUNIT_ASSERT_EQUAL(2, geom->countFaceWires(1)); // face 13
+ CPPUNIT_ASSERT_EQUAL(1, geom->countFaceWires(2)); // face 29
+
+ // wire 0 of face 1 (#13) => edge 4 (#15), 5 (#17), 0 (#5), 6 (#19)
+ std::vector<int> edges = geom->getFaceEdges(1, 0);
+ CPPUNIT_ASSERT_EQUAL(4, (int)edges.size());
+ int ids1[4] = { 4,5,0,6 };
+ for (int i = 0; i < 4; ++i)
+ CPPUNIT_ASSERT_EQUAL(ids1[i], edges[i]);
- std::vector<int> wires = geom->getFaceWires(13);
- CPPUNIT_ASSERT_EQUAL(2, (int)wires.size());
- CPPUNIT_ASSERT_EQUAL(2, wires[0]);
- CPPUNIT_ASSERT_EQUAL(11, wires[1]);
+ // wire 1 of face 13 => edge 7 (#21) ,8 (#24), 9 (#26), 10 (#28)
+ edges = geom->getFaceEdges(1, 1);
+ CPPUNIT_ASSERT_EQUAL(4, (int)edges.size());
+ int ids2[4] = { 7,8,9,10 };
+ for (int i = 0; i < 4; ++i)
+ CPPUNIT_ASSERT_EQUAL(ids2[i], edges[i]);
delete geom;
}
-void BrepGeometryTest::testSolidShells()
+void BrepGeometryTest::testSolidFaces()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Cut_2.brep");
- CPPUNIT_ASSERT_EQUAL(5, geom->countSolidShells(1));
+ CPPUNIT_ASSERT_EQUAL(5, geom->countSolidShells(0));
- std::vector<int> shells = geom->getSolidShells(1);
- CPPUNIT_ASSERT_EQUAL(5, (int)shells.size());
- int ids[5] = { 2, 35, 68, 76, 84 };
- for (int i = 0; i < 5; ++i)
- CPPUNIT_ASSERT_EQUAL(ids[i], shells[i]);
+ std::vector<int> faces = geom->getSolidFaces(0, 0);
+ CPPUNIT_ASSERT_EQUAL(6, (int)faces.size());
+ int ids[6] = { 0, 1, 2, 3, 4, 5 };
+ for (int i = 0; i < 6; ++i)
+ CPPUNIT_ASSERT_EQUAL(ids[i], faces[i]);
+
+ faces = geom->getSolidFaces(0, 1);
+ CPPUNIT_ASSERT_EQUAL(6, (int)faces.size());
+ int ids2[6] = { 6, 7, 8, 9, 10, 11 };
+ for (int i = 0; i < 6; ++i)
+ CPPUNIT_ASSERT_EQUAL(ids2[i], faces[i]);
delete geom;
}
readBrep(geom, "Box_2.brep");
double x, y, z;
- geom->getVertexXYZ(59, x, y, z);
+ geom->getVertexXYZ(15, x, y, z);
CPPUNIT_ASSERT_DOUBLES_EQUAL(60., x, 1e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(80., y, 1e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(60., z, 1e-6);
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
- CPPUNIT_ASSERT_DOUBLES_EQUAL(200., geom->getEdgeLength(5), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(80., geom->getEdgeLength(21), 0);
+ // edges 0 (#5), 7 (#21)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(200., geom->getEdgeLength(0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(80., geom->getEdgeLength(7), 0);
delete geom;
}
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
- CPPUNIT_ASSERT_DOUBLES_EQUAL(40000., geom->getFaceArea(3), 1e-9);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(33600., geom->getFaceArea(13), 1e-9);
+ // faces 0 (#3), 1 (#13)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(40000., geom->getFaceArea(0), 1e-9);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(33600., geom->getFaceArea(1), 1e-9);
delete geom;
}
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
- CPPUNIT_ASSERT_DOUBLES_EQUAL(7488000., geom->getSolidVolume(1), 1e-9);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(7488000., geom->getSolidVolume(0), 1e-9);
delete geom;
}
CPPUNIT_TEST(testGetIDs);
CPPUNIT_TEST(testGetReferences);
CPPUNIT_TEST(testGetEdgeVertices);
- CPPUNIT_TEST(testGetFaceWires);
- CPPUNIT_TEST(testSolidShells);
+ CPPUNIT_TEST(testGetFaceEdges);
+ CPPUNIT_TEST(testSolidFaces);
CPPUNIT_TEST(testGetVertex);
CPPUNIT_TEST(testGetEdgeLength);
CPPUNIT_TEST(testGetFaceArea);
void testGetIDs();
void testGetReferences();
void testGetEdgeVertices();
- void testGetFaceWires();
- void testSolidShells();
+ void testGetFaceEdges();
+ void testSolidFaces();
void testGetVertex();
void testGetEdgeLength();
step = f->addNewStep(1);
step = f->addNewStep(2);
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
+ CPPUNIT_ASSERT_THROW(f->addNewStep(2), SALOME_Exception); // step already exists
CPPUNIT_ASSERT_EQUAL(true, f->removeStep(step));
CPPUNIT_ASSERT_EQUAL(2, f->countSteps());
step = f->addStep(10);
CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, step->getType());
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
+ CPPUNIT_ASSERT_THROW(f->addStep(10), SALOME_Exception); // step already exists
}
+
void FieldTest::testIntegerField()
{
IntegerField* f = (IntegerField*)testField(XAO::INTEGER);
step = f->addStep(10);
CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, step->getType());
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
+ CPPUNIT_ASSERT_THROW(f->addStep(10), SALOME_Exception); // step already exists
}
void FieldTest::testDoubleField()
{
step = f->addStep(10);
CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, step->getType());
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
+ CPPUNIT_ASSERT_THROW(f->addStep(10), SALOME_Exception); // step already exists
}
void FieldTest::testStringField()
{
step = f->addStep(10);
CPPUNIT_ASSERT_EQUAL(XAO::STRING, step->getType());
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
+ CPPUNIT_ASSERT_THROW(f->addStep(10), SALOME_Exception); // step already exists
}
void FieldTest::testStep(XAO::Type type)