Moving B-spline or its extremity points.
setSize(anOther->size());
myArray->ChangeArray(anOther->myArray->Array(), false);
+ owner()->data()->sendAttributeUpdated(this);
+
+ return true;
}
int GeomData_Point2DArray::size()
return aProcessed;
}
const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
- AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
- mySketchMgr->activeSketch());
- if (anAttribute.get()) {
+ std::pair<AttributePtr, int> anAttribute =
+ PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape, mySketchMgr->activeSketch());
+ if (anAttribute.first.get()) {
ModuleBase_WidgetFactory aFactory(theXmlRepr.toStdString(), workshop());
- const std::string anAttributeId = anAttribute->id();
+ const std::string anAttributeId = anAttribute.first->id();
aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
theWidgets = aFactory.getModelWidgets();
if (aGeomShape.get()) {
TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
- return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
- mySketchMgr->activeSketch());
+ std::pair<AttributePtr, int> anAttrAndIndex =
+ PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, mySketchMgr->activeSketch());
+ return anAttrAndIndex.first;
}
return anAttribute;
}
#include <ModuleBase_ViewerFilters.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point2DArray.h>
#include <GeomAPI_Shape.h>
void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
const FeaturePtr& theFeature, const FeaturePtr& theSketch,
const ResultPtr& theResult,
- std::set<AttributePtr>& theSelectedAttributes,
+ std::map<AttributePtr, int>& theSelectedAttributes,
std::set<ResultPtr>& theSelectedResults,
TopTools_MapOfShape& theShapes)
{
theShapes.Add(aShape);
TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
if (aShapeType == TopAbs_VERTEX) {
- AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
- aShape, theSketch);
- if (aPntAttr.get() != NULL)
- theSelectedAttributes.insert(aPntAttr);
+ std::pair<AttributePtr, int> aPntAttrIndex =
+ PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
+ if (aPntAttrIndex.first.get() != NULL)
+ theSelectedAttributes[aPntAttrIndex.first] = aPntAttrIndex.second;
}
else if (aShapeType == TopAbs_EDGE &&
theSelectedResults.find(theResult) == theSelectedResults.end()) {
for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = anIt.key();
- std::set<AttributePtr> anAttributes = anIt.value().myAttributes;
+ std::map<AttributePtr, int> anAttributes = anIt.value().myAttributes;
// Process selection by attribute: the priority to the attribute
if (!anAttributes.empty()) {
- std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
+ std::map<AttributePtr, int>::const_iterator anAttIt = anAttributes.begin(),
anAttLast = anAttributes.end();
for (; anAttIt != anAttLast; anAttIt++) {
- AttributePtr anAttr = *anAttIt;
+ AttributePtr anAttr = anAttIt->first;
if (anAttr.get() == NULL)
continue;
std::string aAttrId = anAttr->id();
DataPtr aData = aFeature->data();
if (aData->isValid()) {
- std::shared_ptr<GeomDataAPI_Point2D> aPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
- if (aPoint.get() != NULL) {
+ AttributePtr aPoint = aData->attribute(aAttrId);
+ if (aPoint->attributeType() == GeomDataAPI_Point2D::typeId() ||
+ aPoint->attributeType() == GeomDataAPI_Point2DArray::typeId()) {
bool isImmutable = aPoint->setImmutable(true);
std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
<ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
- aMessage->setMovedAttribute(aPoint);
+ aMessage->setMovedAttribute(aPoint, anAttIt->second);
aMessage->setOriginalPosition(anOriginalPosition);
aMessage->setCurrentPosition(aCurrentPosition);
Events_Loop::loop()->send(aMessage);
FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
SelectionInfo anInfo = anIt.value();
- std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
+ std::map<AttributePtr, int> aSelectedAttributes = anInfo.myAttributes;
std::set<ResultPtr> aSelectedResults = anInfo.myResults;
ModuleBase_IViewer* aViewer = theWorkshop->viewer();
const TopoDS_Shape& aShape = anOwner->Shape();
TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
if (aShapeType == TopAbs_VERTEX) {
- AttributePtr aPntAttr =
+ std::pair<AttributePtr, int> aPntAttrIndex =
PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
- if (aPntAttr.get() != NULL &&
- aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
+ if (aPntAttrIndex.first.get() != NULL &&
+ aSelectedAttributes.find(aPntAttrIndex.first) != aSelectedAttributes.end())
theOwnersToSelect.Add(anOwner);
else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
theOwnersToSelect.Add(anOwner);
/// Struct to define selection model information to store/restore selection
struct SelectionInfo
{
- std::set<AttributePtr> myAttributes; /// the selected attributes
+ /// the selected attributes and indices of points if array
+ std::map<AttributePtr, int> myAttributes;
std::set<ResultPtr> myResults; /// the selected results
TopoDS_Shape myFirstResultShape; /// the first shape of feature result
TopTools_MapOfShape myLocalSelectedShapes; /// shapes of local selection
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point2DArray.h>
#include <GeomAPI_Pln.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Pnt.h>
// attribute, returns the shape
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(theWorkshop->module());
PartSet_SketcherMgr* aSketchMgr = aModule->sketchMgr();
- AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature,
- aBRepShape, aSketchMgr->activeSketch());
- if (aPntAttr.get() != NULL && aPntAttr == theAttribute) {
+ std::pair<AttributePtr, int> aPntAttrIndex = PartSet_Tools::findAttributeBy2dPoint(
+ anAttributeFeature, aBRepShape, aSketchMgr->activeSketch());
+ if (aPntAttrIndex.first.get() != NULL && aPntAttrIndex.first == theAttribute) {
aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
aShape->setImpl(new TopoDS_Shape(aBRepShape));
break;
return aPnt;
}
-AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj,
- const TopoDS_Shape theShape,
- FeaturePtr theSketch)
+class PointWrapper
+{
+public:
+ PointWrapper(AttributePtr theAttribute)
+ : myPoint(std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute)),
+ myArray(std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute))
+ {}
+
+ int size() const { return myPoint.get() ? 1 : (myArray.get() ? myArray->size() : 0); }
+
+ GeomPointPtr point(int theIndex, FeaturePtr theSketch)
+ {
+ GeomPnt2dPtr aP2d;
+ if (myPoint.get())
+ aP2d = myPoint->pnt();
+ else if (myArray.get())
+ aP2d = myArray->pnt(theIndex);
+
+ GeomPointPtr aP3d;
+ if (aP2d.get())
+ aP3d = PartSet_Tools::convertTo3D(aP2d->x(), aP2d->y(), theSketch);
+ return aP3d;
+ }
+
+ bool isArray() const { return myArray.get(); }
+
+private:
+ AttributePoint2DPtr myPoint;
+ AttributePoint2DArrayPtr myArray;
+};
+
+std::pair<AttributePtr, int> PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj,
+ const TopoDS_Shape theShape,
+ FeaturePtr theSketch)
{
AttributePtr anAttribute;
+ int aPointIndex = -1;
FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
if (aFeature) {
if (theShape.ShapeType() == TopAbs_VERTEX) {
// find the given point in the feature attributes
std::list<AttributePtr> anAttiributes =
aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr> anArrays =
+ aFeature->data()->attributes(GeomDataAPI_Point2DArray::typeId());
+ anAttiributes.insert(anAttiributes.end(), anArrays.begin(), anArrays.end());
+
std::list<AttributePtr>::const_iterator anIt = anAttiributes.begin(),
aLast = anAttiributes.end();
double aMinDistance = 1.e-6; // searching for point with minimal distance and < 1.e-6
for (; anIt != aLast && !anAttribute; anIt++) {
- std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
- if (!aCurPoint->isInitialized())
- continue;
-
- std::shared_ptr<GeomAPI_Pnt> aPnt =
- convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch);
- if (aPnt) {
- double aDistance = aPnt->distance(aValue);
- if (aDistance < aMinDistance) {
- anAttribute = aCurPoint;
- aMinDistance = aPnt->distance(aValue);
+ PointWrapper aWrapper(*anIt);
+ for (int anIndex = 0, aSize = aWrapper.size(); anIndex < aSize; ++anIndex) {
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aWrapper.point(anIndex, theSketch);
+ if (aPnt) {
+ double aDistance = aPnt->distance(aValue);
+ if (aDistance < aMinDistance) {
+ anAttribute = *anIt;
+ if (aWrapper.isArray())
+ aPointIndex = anIndex;
+ aMinDistance = aPnt->distance(aValue);
+ }
}
}
}
}
}
}
- return anAttribute;
+ return std::pair<AttributePtr, int>(anAttribute, aPointIndex);
}
void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
* \param theObj - an object
* \param theShape - a Shape
* \param theSketch - a Sketch to get a plane of converting to 2d
+ * \return Found attribute and index of point if the attribute is an array
*/
- static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
- FeaturePtr theSketch);
+ static std::pair<AttributePtr, int> findAttributeBy2dPoint(ObjectPtr theObj,
+ const TopoDS_Shape theShape,
+ FeaturePtr theSketch);
/**
* Finds an attribute value in attribute reference attribute value
aParameters.push_back(anEllArc->endAngle);
break;
}
+ case ENTITY_BSPLINE: {
+ std::shared_ptr<GCS::BSpline> aBSpline =
+ std::dynamic_pointer_cast<GCS::BSpline>(anEntity->entity());
+ for (GCS::VEC_P::iterator anIt = aBSpline->poles.begin();
+ anIt != aBSpline->poles.end(); ++anIt) {
+ aParameters.push_back(anIt->x);
+ aParameters.push_back(anIt->y);
+ }
+ break;
+ }
default:
break;
}