PartSet_WidgetSketchLabel.h
PartSet_Validators.h
PartSet_WidgetPoint2d.h
- PartSet_WidgetConstraintShapeSelector.h
PartSet_WidgetEditor.h
PartSet_WidgetPoint2dDistance.h
PartSet_WidgetShapeSelector.h
PartSet_Tools.cpp
PartSet_WidgetSketchLabel.cpp
PartSet_Validators.cpp
- PartSet_WidgetConstraintShapeSelector.cpp
PartSet_WidgetEditor.cpp
PartSet_WidgetPoint2d.cpp
PartSet_WidgetPoint2dDistance.cpp
#include <PartSet_WidgetPoint2d.h>
#include <PartSet_WidgetPoint2dDistance.h>
#include <PartSet_WidgetShapeSelector.h>
-#include <PartSet_WidgetConstraintShapeSelector.h>
#include <PartSet_WidgetEditor.h>
#include "PartSet_SketcherMgr.h"
#include "PartSet_MenuMgr.h"
new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
aWgt = aShapeSelectorWgt;
- } if (theType == "sketch_constraint_shape_selector") {
- PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
- new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
- aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
- aWgt = aConstraintShapeSelectorWgt;
} if (theType == WDG_DOUBLEVALUE_EDITOR) {
aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: PartSet_WidgetShapeSelector.cpp
-// Created: 27 Nov 2014
-// Author: Vitaly Smetannikov
-
-#include "PartSet_WidgetConstraintShapeSelector.h"
-
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Validator.h>
-
-#include <PartSet_Tools.h>
-#include <SketchPlugin_Feature.h>
-
-bool PartSet_WidgetConstraintShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
-{
- // initially the method is wrote to create an external object. Since the parent widget creates it,
- // the redefinition is not necessary anymore.
- // TODO: remove the widget and use the parent one insted of it
- return PartSet_WidgetShapeSelector::setObject(theSelectedObject, theShape);
- /*ObjectPtr aSelectedObject = theSelectedObject;
-
- FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject);
- if (aFeature) {
- std::shared_ptr<SketchPlugin_Feature> aSPFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
- if ((!aSPFeature) && (!theShape->isNull())) {
- createExternal(theSelectedObject, theShape);
-
- if (myExternalObject) {
- aSelectedObject = myExternalObject;
- } else
- return false;
- }
- }
- return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);*/
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: PartSet_WidgetShapeSelector.h
-// Created: 27 Nov 2014
-// Author: Vitaly Smetannikov
-
-
-#ifndef PartSet_WidgetConstraintShapeSelector_H
-#define PartSet_WidgetConstraintShapeSelector_H
-
-#include "PartSet.h"
-
-#include <PartSet_WidgetShapeSelector.h>
-
-#include <ModelAPI_CompositeFeature.h>
-
-
-/**
-* \ingroup Modules
-* Customosation of PartSet_WidgetShapeSelector in order to provide
-* working with constraints.
-*/
-class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public PartSet_WidgetShapeSelector
-{
-Q_OBJECT
- public:
- /// Constructor
- /// \param theParent the parent object
- /// \param theWorkshop instance of workshop interface
- /// \param theData the widget configuation. The attribute of the model widget is obtained from
- /// \param theParentId is Id of a parent of the current attribute
- PartSet_WidgetConstraintShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
- const Config_WidgetAPI* theData, const std::string& theParentId)
- : PartSet_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
-
- virtual ~PartSet_WidgetConstraintShapeSelector() {}
-
- /// Set sketcher
- /// \param theSketch a sketcher object
- //void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
-
- /// Retrurns installed sketcher
- //CompositeFeaturePtr sketch() const { return mySketch; }
-
-protected:
- /// Store the values to the model attribute of the widget. It casts this attribute to
- /// the specific type and set the given values
- /// \param theSelectedObject an object
- /// \param theShape a selected shape, which is used in the selection attribute
- virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-
-//private:
- /// Pointer to a sketch
- //CompositeFeaturePtr mySketch;
-};
-
-#endif
\ No newline at end of file
#include <ModelAPI_Validator.h>
#include <ModuleBase_Definitions.h>
+#include <Config_WidgetAPI.h>
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId)
-: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
+: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId), myUseExternal(true)
{
+ QString aIsExternal(theData->getProperty("use_external").c_str());
+ if (!aIsExternal.isEmpty()) {
+ QString aStr = aIsExternal.toUpper();
+ myUseExternal = (aStr == "TRUE") || (aStr == "YES");
+ }
}
bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
return false;
+ // Do check using of external feature
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
- if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) {
+
+ // Do check that we can use external feature
+ if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myUseExternal))
+ return false;
+
+ if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myUseExternal) {
aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
theSelectedObject, mySketch);
if (!aSelectedObject.get()) {
/// An external object
ObjectPtr myExternalObject;
+
+ bool myUseExternal;
};
#endif
\ No newline at end of file
<!-- SketchConstraintParallel -->
<feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
+ <sketch_shape_selector id="ConstraintEntityA"
label="First line" tooltip="Select a line" shape_types="edge">
<validator id="GeomValidators_Edge" parameters="line"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
- <sketch_constraint_shape_selector id="ConstraintEntityB" label="Second line" tooltip="Select a line"
+ <sketch_shape_selector id="ConstraintEntityB" label="Second line" tooltip="Select a line"
shape_types="edge">
<validator id="GeomValidators_Edge" parameters="line"/>
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
<validator id="PartSet_ParallelSelection"/>
</feature>
<feature id="SketchConstraintPerpendicular" title="Perpendicular"
tooltip="Create constraint defining two perpendicular lines"
icon=":icons/perpendicular.png">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
+ <sketch_shape_selector id="ConstraintEntityA"
label="First line" tooltip="Select an line"
shape_types="edge">
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
<validator id="GeomValidators_Edge" parameters="line"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
- <sketch_constraint_shape_selector id="ConstraintEntityB"
+ <sketch_shape_selector id="ConstraintEntityB"
label="Second line" tooltip="Select an line"
shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
<validator id="GeomValidators_Edge" parameters="line"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
<validator id="PartSet_PerpendicularSelection"/>
</feature>
<!-- SketchConstraintHorizontal -->
<feature id="SketchConstraintHorizontal" title="Horizontal" tooltip="Create constraint defining horizontal line" icon=":icons/horisontal.png">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
- label="Line" tooltip="Select a line" shape_types="edge">
+ <sketch_shape_selector id="ConstraintEntityA"
+ label="Line" tooltip="Select a line" shape_types="edge" use_external="false">
<validator id="GeomValidators_Edge" parameters="line"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
<validator id="PartSet_HVDirSelection"/>
</feature>
<!-- SketchConstraintVertical -->
<feature id="SketchConstraintVertical" title="Vertical" tooltip="Create constraint defining vertical line" icon=":icons/vertical.png">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
- label="Line" tooltip="Select a line" shape_types="edge">
+ <sketch_shape_selector id="ConstraintEntityA"
+ label="Line" tooltip="Select a line" shape_types="edge" use_external="false">
<validator id="GeomValidators_Edge" parameters="line"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
<validator id="PartSet_HVDirSelection"/>
</feature>
<feature id="SketchConstraintEqual" title="Equal"
tooltip="Create constraint defining equal lengths of two lines or line and arc or equal radii of two arcs or two circles or arc and circle"
icon=":icons/equal.png">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
+ <sketch_shape_selector id="ConstraintEntityA"
label="First object" tooltip="Select line, circle or arc" shape_types="edge">
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
- <sketch_constraint_shape_selector id="ConstraintEntityB"
+ <sketch_shape_selector id="ConstraintEntityB"
label="Second object" tooltip="Select line, circle or arc" shape_types="edge">
<validator id="SketchPlugin_EqualAttr" parameters="ConstraintEntityA"/>
<validator id="PartSet_DifferentObjects"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
</feature>
<!-- SketchConstraintTangent -->
<feature id="SketchConstraintTangent" title="Tangent" tooltip="Create constraint defining tangency of two objects" icon=":icons/tangent.png">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
+ <sketch_shape_selector id="ConstraintEntityA"
label="First object" tooltip="Select line or arc" shape_types="edge">
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
- <sketch_constraint_shape_selector id="ConstraintEntityB"
+ <sketch_shape_selector id="ConstraintEntityB"
label="Second object" tooltip="Select line or arc" shape_types="edge">
<validator id="SketchPlugin_TangentAttr" parameters="ConstraintEntityA"/>
<validator id="PartSet_DifferentObjects"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
<validator id="PartSet_TangentSelection"/>
</feature>
<group id="Edit">
<!-- SketchConstraintFillet -->
<feature id="SketchConstraintFillet" title="Fillet" tooltip="Create constraint defining fillet between two objects" icon=":icons/fillet.png">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
+ <sketch_shape_selector id="ConstraintEntityA"
label="First object" tooltip="Select line or arc" shape_types="edge">
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
- <sketch_constraint_shape_selector id="ConstraintEntityB"
+ <sketch_shape_selector id="ConstraintEntityB"
label="Second object" tooltip="Select line or arc" shape_types="edge">
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
<doublevalue_editor label="Value" tooltip="Fillet radius" id="ConstraintValue" min="0">
<validator id="GeomValidators_Positive"/>
id="SketchConstraintMirror"
title="Mirror" icon=":icons/mirror.png"
tooltip="Create constraint, mirroring group of objects">
- <sketch_constraint_shape_selector id="ConstraintEntityA"
+ <sketch_shape_selector id="ConstraintEntityA"
label="Mirror line" tooltip="Select mirror line" shape_types="edge">
<validator id="GeomValidators_Edge" parameters="line"/>
- </sketch_constraint_shape_selector>
+ </sketch_shape_selector>
<multi_selector id="ConstraintMirrorList"
label="List of objects"
tooltip="Select list of mirroring objects"
void SketchSolver_Constraint::update(ConstraintPtr theConstraint)
{
cleanErrorMsg();
- if (theConstraint && theConstraint != myBaseConstraint) {
- if (theConstraint->getKind() != myBaseConstraint->getKind())
+ bool needToRebuild = (theConstraint && theConstraint != myBaseConstraint);
+ if (!needToRebuild) {
+ // Check the attrbutes of constraint are changed
+ ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
+ std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
+ std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
+ for (; anAttrIter != anAttrList.end(); anAttrIter++) {
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+ if (aRefAttr) {
+ if (aRefAttr->isObject()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+ if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
+ needToRebuild = true;
+ break;
+ }
+ } else if (aRefAttr->attr() &&
+ myAttributeMap.find(aRefAttr->attr()) == myAttributeMap.end()) {
+ needToRebuild = true;
+ break;
+ }
+ }
+ AttributeRefListPtr aRefList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
+ if (aRefList) {
+ std::list<ObjectPtr> anItems = aRefList->list();
+ std::list<ObjectPtr>::iterator anIt = anItems.begin();
+ for (; anIt != anItems.end(); anIt++) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
+ needToRebuild = true;
+ break;
+ }
+ }
+ if (needToRebuild)
+ break;
+ }
+ }
+ }
+ if (needToRebuild) {
+ if (theConstraint && theConstraint->getKind() != myBaseConstraint->getKind())
return;
remove(myBaseConstraint);
- myBaseConstraint = theConstraint;
+ if (theConstraint)
+ myBaseConstraint = theConstraint;
process();
+ return;
}
// Update all attributes
std::map<FeaturePtr, Slvs_hEntity>::const_iterator aFIter = myFeatureMap.find(theFeature);
if (aFIter == myFeatureMap.end())
return SLVS_E_UNKNOWN;
- return aFIter->second;
+ // check the Feature is really in the storage
+ Slvs_Entity anEntity = myStorage->getEntity(aFIter->second);
+ if (anEntity.h == SLVS_E_UNKNOWN) {
+ // rebuild feature
+ int aType;
+ anEntity.h = const_cast<SketchSolver_Constraint*>(this)->changeEntity(aFIter->first, aType);
+ const_cast<SketchSolver_Constraint*>(this)->myFeatureMap[theFeature] = anEntity.h;
+ }
+ return anEntity.h;
}
Slvs_hEntity SketchSolver_Constraint::getId(AttributePtr theAttribute) const
setTemporary(aConstraint);
}
}
- // Fix base features for mirror
- if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
- AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
- theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_B()));
- fixFeaturesList(aRefList);
- }
+ //// Fix base features for mirror
+ //if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
+ // AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+ // theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_B()));
+ // fixFeaturesList(aRefList);
+ //}
if (!myFeatureStorage)
myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
bool aResult = true;
int aPos = Search(theEntityID, myEntities);
if (aPos >= 0 && aPos < (int)myEntities.size()) {
- // Firstly, check the entity is not used elsewhere
+ // Firstly, check the entity and its attributes is not used elsewhere
+ std::set<Slvs_hEntity> anEntAndSubs;
+ anEntAndSubs.insert(theEntityID);
+ for (int i = 0; i < 4; i++)
+ if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
+ anEntAndSubs.insert(myEntities[aPos].point[i]);
+
std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
for (; anEntIter != myEntities.end(); anEntIter++) {
for (int i = 0; i < 4; i++)
- if (anEntIter->point[i] == theEntityID)
+ if (anEntAndSubs.find(anEntIter->point[i]) != anEntAndSubs.end())
return false;
- if (anEntIter->distance == theEntityID)
+ if (anEntAndSubs.find(anEntIter->distance) != anEntAndSubs.end())
return false;
}
std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
aConstrIter->entityA, aConstrIter->entityB,
aConstrIter->entityC, aConstrIter->entityD};
for (int i = 0; i < 6; i++)
- if (anEntIDs[i] == theEntityID)
+ if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end())
return false;
}
// The entity is not used, remove it and its parameters
// Entity is not found, return empty object
static Slvs_Entity aDummy;
- aDummy.h = 0;
+ aDummy.h = SLVS_E_UNKNOWN;
return aDummy;
}
aResIndex--;
while (aResIndex < aVecSize && aResIndex >= 0 && theEntities[aResIndex].h < theEntityID)
aResIndex++;
- if (aResIndex == -1)
+ if (aResIndex == -1 || (aResIndex < aVecSize && theEntities[aResIndex].h != theEntityID))
aResIndex = aVecSize;
return aResIndex;
}