mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-02-05 16:44:17 +05:00
fix change in XAO API
This commit is contained in:
parent
61f8fff2a8
commit
56cbe27615
@ -42,6 +42,7 @@
|
||||
#include <Utils_ExceptHandlers.hxx>
|
||||
|
||||
#include "GEOM_Function.hxx"
|
||||
#include "GEOM_ISubShape.hxx"
|
||||
#include "GEOM_PythonDump.hxx"
|
||||
|
||||
#include "Xao.hxx"
|
||||
@ -61,6 +62,11 @@
|
||||
#include <TopAbs.hxx>
|
||||
#include <TopTools_IndexedMapOfShape.hxx>
|
||||
|
||||
#include <TopTools_Array1OfShape.hxx>
|
||||
#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
|
||||
#include <TopTools_ListIteratorOfListOfShape.hxx>
|
||||
#include <TopTools_MapOfShape.hxx>
|
||||
#include <TopTools_MapOfOrientedShape.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
#include <TColStd_HSequenceOfTransient.hxx>
|
||||
@ -121,6 +127,19 @@ TopAbs_ShapeEnum getGroupDimension(XAO::Group* group)
|
||||
return TopAbs_COMPOUND;
|
||||
}
|
||||
|
||||
XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape)
|
||||
{
|
||||
if (shape == TopAbs_VERTEX)
|
||||
return XAO::VERTEX;
|
||||
if (shape == TopAbs_EDGE)
|
||||
return XAO::EDGE;
|
||||
if (shape == TopAbs_FACE)
|
||||
return XAO::FACE;
|
||||
if (shape == TopAbs_SOLID)
|
||||
return XAO::SOLID;
|
||||
throw SALOME_Exception("Bad type"); // TODO
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
/*!
|
||||
* Export a shape to XAO format
|
||||
@ -212,51 +231,47 @@ bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape,
|
||||
{
|
||||
Handle(GEOM_Object) currGroup = (*groupIterator++);
|
||||
Handle(TColStd_HArray1OfInteger) groupIds = m_groupOperations->GetObjects(currGroup);
|
||||
XAO::Group* group = new XAO::Group();
|
||||
group->setName(currGroup->GetName());
|
||||
|
||||
|
||||
TopAbs_ShapeEnum shapeGroup = m_groupOperations->GetType(currGroup);
|
||||
XAO::Dimension dim = shapeEnumToDimension(shapeGroup);
|
||||
XAO::Group* group = xaoObject->addGroup(currGroup->GetName(), dim);
|
||||
|
||||
switch (shapeGroup)
|
||||
{
|
||||
case TopAbs_VERTEX:
|
||||
group->setDimension(XAO::VERTEX);
|
||||
for (int i = 1; i <= groupIds->Length(); i++)
|
||||
{
|
||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i));
|
||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
|
||||
const int index = geometry->getVertexIndexByReference(ref);
|
||||
group->addElement(index);
|
||||
}
|
||||
break;
|
||||
case TopAbs_EDGE:
|
||||
group->setDimension(XAO::EDGE);
|
||||
for (int i = 1; i <= groupIds->Length(); i++)
|
||||
{
|
||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i));
|
||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
|
||||
const int index = geometry->getEdgeIndexByReference(ref);
|
||||
group->addElement(index);
|
||||
}
|
||||
break;
|
||||
case TopAbs_FACE:
|
||||
group->setDimension(XAO::FACE);
|
||||
for (int i = 1; i <= groupIds->Length(); i++)
|
||||
{
|
||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i));
|
||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
|
||||
const int index = geometry->getFaceIndexByReference(ref);
|
||||
group->addElement(index);
|
||||
}
|
||||
break;
|
||||
case TopAbs_SOLID:
|
||||
group->setDimension(XAO::SOLID);
|
||||
for (int i = 1; i <= groupIds->Length(); i++)
|
||||
{
|
||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i));
|
||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
|
||||
const int index = geometry->getSolidIndexByReference(ref);
|
||||
group->addElement(index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
xaoObject->addGroup(group);
|
||||
}
|
||||
|
||||
// TODO: add the fields
|
||||
@ -299,6 +314,56 @@ bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GEOMImpl_IImportExportOperations::importSubShapes(XAO::Geometry* xaoGeometry,
|
||||
Handle(GEOM_Function) function, Handle(TColStd_HSequenceOfTransient)& fieldList,
|
||||
int shapeType, XAO::Dimension dim)
|
||||
{
|
||||
Handle(GEOM_Object) subShape;
|
||||
Handle(GEOM_Function) aFunction;
|
||||
Handle(TColStd_HArray1OfInteger) anArray;
|
||||
//for (int i = 0; i < xaoGeometry->countFaces(); i++)
|
||||
XAO::GeometricElementList::iterator elementIterator = xaoGeometry->begin(dim);
|
||||
for (; elementIterator != xaoGeometry->end(dim); elementIterator++)
|
||||
{
|
||||
// if (!xaoGeometry->hasFaceName(i))
|
||||
// continue;
|
||||
XAO::GeometricElement element = elementIterator->second;
|
||||
if (!element.hasName())
|
||||
continue;
|
||||
|
||||
//const char* name = xaoGeometry->getFaceName(i);
|
||||
//const char* ref = xaoGeometry->getFaceReference(i);
|
||||
std::string name = element.getName();
|
||||
std::string ref = element.getReference();
|
||||
int iref = atoi(ref.c_str());
|
||||
//std::cout << "face: " << name << " ref = " << ref << std::endl;
|
||||
|
||||
//TopoDS_Shape aValue = facesByIndex[iref];
|
||||
anArray = new TColStd_HArray1OfInteger(1, 1);
|
||||
anArray->SetValue(1, iref);
|
||||
|
||||
subShape = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
|
||||
Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
|
||||
if (aFunction.IsNull())
|
||||
return false;
|
||||
|
||||
subShape->SetName(name.c_str());
|
||||
subShape->SetType(shapeType);
|
||||
|
||||
GEOM_ISubShape aSSI(aFunction);
|
||||
aSSI.SetMainShape(function);
|
||||
aSSI.SetIndices(anArray);
|
||||
|
||||
// aFunction->SetValue(aValue);
|
||||
fieldList->Append(subShape);
|
||||
|
||||
// Put this subshape in the list of sub-shapes of theMainShape
|
||||
function->AddSubShapeReference(aFunction);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
/*!
|
||||
* Import a shape from XAO format
|
||||
@ -336,9 +401,36 @@ bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName,
|
||||
// set the geometry
|
||||
TopoDS_Shape geomShape = xaoGeometry->getShape();
|
||||
function->SetValue(geomShape);
|
||||
shape->SetName(xaoGeometry->getName());
|
||||
shape->SetName(xaoGeometry->getName().c_str());
|
||||
|
||||
// TODO: create sub shapes with names
|
||||
// create sub shapes with names
|
||||
|
||||
// get all the faces
|
||||
// TopTools_MapOfShape mapShape;
|
||||
// TopTools_ListOfShape listShape;
|
||||
// TopExp_Explorer exp(geomShape, TopAbs_ShapeEnum(TopAbs_FACE));
|
||||
// for (; exp.More(); exp.Next())
|
||||
// {
|
||||
// if (mapShape.Add(exp.Current()))
|
||||
// listShape.Append(exp.Current());
|
||||
// }
|
||||
// TopTools_IndexedMapOfShape indices;
|
||||
// TopExp::MapShapes(geomShape, indices);
|
||||
|
||||
// std::map<int, TopoDS_Shape> facesByIndex;
|
||||
// TopTools_ListIteratorOfListOfShape itSub(listShape);
|
||||
// for (int index = 1; itSub.More(); itSub.Next(), ++index)
|
||||
// {
|
||||
// TopoDS_Shape value = itSub.Value();
|
||||
// facesByIndex[indices.FindIndex(value)] = value;
|
||||
// }
|
||||
|
||||
std::cout << "==================" << std::endl;
|
||||
importSubShapes(xaoGeometry, function, fieldList, GEOM_POINT, XAO::VERTEX);
|
||||
importSubShapes(xaoGeometry, function, fieldList, GEOM_EDGE, XAO::EDGE);
|
||||
importSubShapes(xaoGeometry, function, fieldList, GEOM_FACE, XAO::FACE);
|
||||
importSubShapes(xaoGeometry, function, fieldList, GEOM_SOLID, XAO::SOLID);
|
||||
std::cout << "==================" << std::endl;
|
||||
|
||||
// create groups
|
||||
int nbGroups = xaoObject->countGroups();
|
||||
@ -352,14 +444,14 @@ bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName,
|
||||
for (int j = 0; j < nbElt; j++)
|
||||
{
|
||||
int index = xaoGroup->getElement(j);
|
||||
const char* ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
|
||||
array->SetValue(j + 1, atoi(ref));
|
||||
std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
|
||||
array->SetValue(j + 1, atoi(ref.c_str()));
|
||||
}
|
||||
|
||||
// create the group with the array of sub shapes indexes
|
||||
Handle(GEOM_Object) group = GetEngine()->AddSubShape(shape, array);
|
||||
group->SetType(GEOM_GROUP);
|
||||
group->SetName(xaoGroup->getName());
|
||||
group->SetName(xaoGroup->getName().c_str());
|
||||
|
||||
// Set a sub-shape type
|
||||
TDF_Label freeLabel = group->GetFreeLabel();
|
||||
|
@ -19,24 +19,20 @@
|
||||
#ifndef _GEOMImpl_IImportExportOperations_HXX_
|
||||
#define _GEOMImpl_IImportExportOperations_HXX_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include <Utils_SALOME_Exception.hxx>
|
||||
#include "GEOM_IOperations.hxx"
|
||||
#include "GEOM_Engine.hxx"
|
||||
#include "GEOM_Object.hxx"
|
||||
|
||||
#include <list>
|
||||
#include "Geometry.hxx"
|
||||
|
||||
class GEOMImpl_IShapesOperations;
|
||||
class GEOMImpl_IGroupOperations;
|
||||
|
||||
class GEOMImpl_IImportExportOperations: public GEOM_IOperations
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
GEOMImpl_IShapesOperations* m_shapesOperations;
|
||||
GEOMImpl_IGroupOperations* m_groupOperations;
|
||||
|
||||
public:
|
||||
Standard_EXPORT GEOMImpl_IImportExportOperations(GEOM_Engine* engine, int docID);
|
||||
Standard_EXPORT ~GEOMImpl_IImportExportOperations();
|
||||
@ -51,5 +47,14 @@ public:
|
||||
Handle(TColStd_HSequenceOfTransient)& groupList,
|
||||
Handle(TColStd_HSequenceOfTransient)& fieldList);
|
||||
/*@@ insert new functions before this line @@ do not remove this line @@*/
|
||||
|
||||
private:
|
||||
GEOMImpl_IShapesOperations* m_shapesOperations;
|
||||
GEOMImpl_IGroupOperations* m_groupOperations;
|
||||
|
||||
bool importSubShapes(XAO::Geometry* xaoGeometry,
|
||||
Handle(GEOM_Function) function,
|
||||
Handle(TColStd_HSequenceOfTransient)& fieldList, int shapeType, XAO::Dimension dim);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
@ -221,13 +221,22 @@ bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects)
|
||||
|
||||
if (!shape->_is_nil())
|
||||
{
|
||||
m_mainShape = shape;
|
||||
objects.push_back(shape._retn());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mainShape = NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < groups->length(); i++)
|
||||
{
|
||||
objects.push_back(GEOM::GEOM_Object::_duplicate(groups[i]));
|
||||
}
|
||||
for (int i = 0; i < fields->length(); i++)
|
||||
{
|
||||
objects.push_back(GEOM::GEOM_Object::_duplicate(fields[i]));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -235,10 +244,11 @@ bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects)
|
||||
GEOM::GEOM_Object_ptr ImportExportGUI_ImportXAODlg::getFather(GEOM::GEOM_Object_ptr object)
|
||||
{
|
||||
GEOM::GEOM_Object_var fatherObj;
|
||||
if (object->GetType() == GEOM_GROUP)
|
||||
if (object->GetType() != GEOM_IMPORT && m_mainShape != NULL)
|
||||
{
|
||||
GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId());
|
||||
fatherObj = groupOper->GetMainShape(object);
|
||||
//GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId());
|
||||
//fatherObj = groupOper->GetMainShape(object);
|
||||
fatherObj = m_mainShape;
|
||||
}
|
||||
return fatherObj._retn();
|
||||
}
|
||||
@ -249,3 +259,4 @@ QString ImportExportGUI_ImportXAODlg::getObjectName(GEOM::GEOM_Object_ptr object
|
||||
return QString::null;
|
||||
return object->GetName();
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ private:
|
||||
private:
|
||||
QLineEdit* ledFileName;
|
||||
QPushButton* btnFileSelect;
|
||||
GEOM::GEOM_Object_var m_mainShape;
|
||||
|
||||
private slots:
|
||||
void ClickOnOk();
|
||||
|
Loading…
Reference in New Issue
Block a user