Code cleanup and debug of features movement.
}
}
-#ifndef SUPPORT_NEW_MOVE
void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj)
{
//blockUpdateViewer(true);
qDebug("ModuleBase_ModelWidget::moveObject");
#endif
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
Events_Loop::loop()->flush(anEvent);
//blockUpdateViewer(false);
}
-#endif
bool ModuleBase_ModelWidget::processEnter()
{
/// \param theObj is updating object
void updateObject(ObjectPtr theObj);
-#ifndef SUPPORT_NEW_MOVE
/// Sends Move event for the given object
/// \param theObj is object for moving
static void moveObject(ObjectPtr theObj);
-#endif
/// Translate passed string with widget context()
virtual QString translate(const std::string& theStr) const;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
Point aMousePnt;
get2dPoint(theWnd, theEvent, aMousePnt);
-#ifndef SUPPORT_NEW_MOVE
- double dX = aMousePnt.myCurX - myCurrentPoint.myCurX;
- double dY = aMousePnt.myCurY - myCurrentPoint.myCurY;
-#else
+
std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
-#endif
+
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
if (aPoint.get() != NULL) {
bool isImmutable = aPoint->setImmutable(true);
-#ifndef SUPPORT_NEW_MOVE
- aPoint->move(dX, dY);
- ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
-#else
+
std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
<ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
aMessage->setMovedAttribute(aPoint);
aMessage->setOriginalPosition(anOriginalPosition);
aMessage->setCurrentPosition(aCurrentPosition);
Events_Loop::loop()->send(aMessage);
-#endif
+
isModified = true;
aPoint->setImmutable(isImmutable);
}
std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if (aSketchFeature) {
-#ifndef SUPPORT_NEW_MOVE
- aSketchFeature->move(dX, dY);
- ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
-#else
std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
<ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
aMessage->setMovedObject(aFeature);
aMessage->setOriginalPosition(anOriginalPosition);
aMessage->setCurrentPosition(aCurrentPosition);
Events_Loop::loop()->send(aMessage);
-#endif
isModified = true;
}
}
// myYSpin->hasVariable() ? myYSpin->text().toStdString() : "");
//aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(),
// !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y());
- aPoint->setValue(myXSpin->value(), myYSpin->value());
-
- // after movement the solver will call the update event: optimization
-#ifndef SUPPORT_NEW_MOVE
- moveObject(myFeature);
-#else
- updateObject(myFeature);
-#endif
+
+ if (myFeature->isMacro()) {
+ // Moving points of macro-features has been processed directly (without solver)
+ aPoint->setValue(myXSpin->value(), myYSpin->value());
+ moveObject(myFeature);
+ } else {
+ if (!aPoint->isInitialized())
+ aPoint->setValue(0., 0.);
+
+ std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage(
+ new ModelAPI_ObjectMovedMessage(this));
+ aMessage->setMovedAttribute(aPoint);
+ aMessage->setOriginalPosition(aPoint->pnt());
+ aMessage->setCurrentPosition(myXSpin->value(), myYSpin->value());
+ Events_Loop::loop()->send(aMessage);
+ }
+
aPoint->setImmutable(isImmutable);
that->blockSignals(isBlocked);
std::map<AttributePtr, EntityWrapperPtr>::const_iterator anIt = myAttributeMap.begin();
for (; anIt != myAttributeMap.end(); ++anIt) {
+ if (!anIt->first->isInitialized())
+ continue;
+
// the external feature always should keep the up to date values, so,
// refresh from the solver is never needed
if (isExternalAttribute(anIt->first))
return SolverConstraintPtr(new SketchSolver_Constraint(theConstraint));
}
-#ifdef SUPPORT_NEW_MOVE
std::shared_ptr<SketchSolver_ConstraintMovement> PlaneGCSSolver_Tools::createMovementConstraint(
FeaturePtr theMovedFeature)
{
return std::shared_ptr<SketchSolver_ConstraintMovement>(
new SketchSolver_ConstraintMovement(theMovedAttribute));
}
-#else
-std::shared_ptr<SketchSolver_ConstraintFixed> PlaneGCSSolver_Tools::createMovementConstraint(
- FeaturePtr theMovedFeature)
-{
- return std::shared_ptr<SketchSolver_ConstraintFixed>(
- new SketchSolver_ConstraintFixed(theMovedFeature));
-}
-#endif
/// or returns empty pointer if not all attributes are correct
SolverConstraintPtr createConstraint(ConstraintPtr theConstraint);
-#ifdef SUPPORT_NEW_MOVE
/// \brief Creates temporary constraint to fix the feature after movement
std::shared_ptr<SketchSolver_ConstraintMovement>
createMovementConstraint(FeaturePtr theMovedFeature);
/// \brief Creates temporary constraint to fix the attribute after movement
std::shared_ptr<SketchSolver_ConstraintMovement>
createMovementConstraint(AttributePtr theMovedAttribute);
-#else
- /// \brief Creates temporary constraint to fix the feature after movement
- std::shared_ptr<SketchSolver_ConstraintFixed>
- createMovementConstraint(FeaturePtr theMovedFeature);
-#endif
/// \brief Creates new constraint using given parameters
/// \param theConstraint [in] original constraint
myType = CONSTRAINT_FIXED;
}
-#ifndef SUPPORT_NEW_MOVE
-SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature)
- : SketchSolver_Constraint(),
- myBaseFeature(theFeature)
-{
- myType = CONSTRAINT_FIXED;
-}
-#endif
-
void SketchSolver_ConstraintFixed::blockEvents(bool isBlocked)
{
-#ifndef SUPPORT_NEW_MOVE
- if (myBaseFeature)
- myBaseFeature->data()->blockSendAttributeUpdated(isBlocked);
- if (myBaseConstraint)
-#endif
SketchSolver_Constraint::blockEvents(isBlocked);
}
void SketchSolver_ConstraintFixed::process()
{
cleanErrorMsg();
-#ifdef SUPPORT_NEW_MOVE
if (!myBaseConstraint || !myStorage) {
-#else
- if ((!myBaseConstraint && !myBaseFeature) || !myStorage) {
-#endif
// Not enough parameters are assigned
return;
}
-#ifdef SUPPORT_NEW_MOVE
EntityWrapperPtr aBaseEntity = entityToFix();
if (!aBaseEntity)
myErrorMsg = SketchSolver_Error::ALREADY_FIXED();
-#else
- EntityWrapperPtr aBaseEntity;
- getAttributes(aBaseEntity, myFixedEntity);
- if (!aBaseEntity) {
- moveFeature(); // remove myFixed entity
- myErrorMsg = SketchSolver_Error::ALREADY_FIXED();
- }
-#endif
if (!myErrorMsg.empty())
return;
-#ifdef SUPPORT_NEW_MOVE
ConstraintWrapperPtr aConstraint = fixFeature(aBaseEntity);
myStorage->addConstraint(myBaseConstraint, aConstraint);
-#else
- myConstraint = fixFeature(aBaseEntity);
- if (myBaseConstraint)
- myStorage->addConstraint(myBaseConstraint, myConstraint);
- else
- myStorage->addMovementConstraint(myConstraint);
-#endif
}
ConstraintWrapperPtr SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature)
new PlaneGCSSolver_ConstraintWrapper(aConstraints, getType()));
}
-#ifdef SUPPORT_NEW_MOVE
EntityWrapperPtr SketchSolver_ConstraintFixed::entityToFix()
{
// Constraint Fixed is added by user.
return *anIt;
return EntityWrapperPtr();
}
-#else
-void SketchSolver_ConstraintFixed::getAttributes(EntityWrapperPtr& theBaseEntity,
- EntityWrapperPtr& theFixedEntity)
-{
- if (myBaseFeature) {
- // if the feature is copy, do not move it
- std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(myBaseFeature);
- if (aSketchFeature && aSketchFeature->isCopy()) {
- myStorage->setNeedToResolve(true);
- return;
- }
-
- // The feature is fixed.
- PlaneGCSSolver_FeatureBuilder aBuilder;
- std::list<AttributePtr> aBaseAttr = myBaseFeature->data()->attributes(std::string());
- std::list<AttributePtr>::const_iterator anIt = aBaseAttr.begin();
- for (; anIt != aBaseAttr.end(); ++anIt)
- aBuilder.createAttribute(*anIt);
- theFixedEntity = aBuilder.createFeature(myBaseFeature);
-
- theBaseEntity = myStorage->entity(myBaseFeature);
- if (isEqual(theBaseEntity, theFixedEntity))
- theBaseEntity = EntityWrapperPtr(); // do not want to fix already fixed entity
-
- } else if (myBaseConstraint) {
- // Constraint Fixed is added by user.
- // Get the attribute of constraint (it should be alone in the list of constraints).
- EntityWrapperPtr aValue;
- std::vector<EntityWrapperPtr> anAttributes;
- SketchSolver_Constraint::getAttributes(aValue, anAttributes);
- std::vector<EntityWrapperPtr>::const_iterator anIt = anAttributes.begin();
- for (; anIt != anAttributes.end(); ++anIt)
- if (*anIt)
- theBaseEntity = *anIt;
- } else
- myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
-}
-
-void SketchSolver_ConstraintFixed::moveFeature()
-{
- if (!myFixedEntity)
- return;
-
- GCS::VEC_pD aFixedParams = toParameters(myFixedEntity);
- for (int i = 0; i < aFixedParams.size() && i < myFixedValues.size(); ++i)
- myFixedValues[i] = *(aFixedParams[i]);
-
- // Remove fixed entity due to its parameters already copied into the constraint
- PlaneGCSSolver_EntityDestroyer aDestroyer;
- aDestroyer.remove(myFixedEntity);
- std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(myStorage)->removeParameters(
- aDestroyer.parametersToRemove());
-
- myFixedEntity = EntityWrapperPtr();
-}
-#endif
GCS::VEC_pD SketchSolver_ConstraintFixed::toParameters(const EntityWrapperPtr& theEntity)
{
std::dynamic_pointer_cast<GCS::Circle>(anEntity->entity());
aParameters.push_back(aCircle->center.x);
aParameters.push_back(aCircle->center.y);
-#ifndef SUPPORT_NEW_MOVE
- aParameters.push_back(aCircle->rad);
-#endif
break;
}
case ENTITY_ARC: {
std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(anEntity->entity());
aParameters.push_back(anArc->center.x);
aParameters.push_back(anArc->center.y);
-#ifndef SUPPORT_NEW_MOVE
- aParameters.push_back(anArc->rad);
- aParameters.push_back(anArc->startAngle);
- aParameters.push_back(anArc->endAngle);
-#endif
break;
}
default:
return aParameters;
}
-
-#ifndef SUPPORT_NEW_MOVE
-// ==================== Auxiliary functions ===============================
-bool isEqual(const EntityWrapperPtr& theEntity1, const EntityWrapperPtr& theEntity2)
-{
- GCS::VEC_pD aParamList1 = SketchSolver_ConstraintFixed::toParameters(theEntity1);
- GCS::VEC_pD aParamList2 = SketchSolver_ConstraintFixed::toParameters(theEntity2);
-
- GCS::VEC_pD::const_iterator anIt1 = aParamList1.begin();
- GCS::VEC_pD::const_iterator anIt2 = aParamList2.begin();
- for (; anIt1 != aParamList1.end() && anIt2 != aParamList2.end(); ++anIt1, ++anIt2)
- if (fabs((**anIt1) - (**anIt2)) > tolerance)
- return false;
-
- return anIt1 == aParamList1.end() && anIt2 == aParamList2.end();
-}
-#endif
public:
/// Creates constraint to manage the given constraint from plugin
SketchSolver_ConstraintFixed(ConstraintPtr theConstraint);
-#ifndef SUPPORT_NEW_MOVE
- /// Creates temporary constraint based on feature (useful while the feature is being moved)
- SketchSolver_ConstraintFixed(FeaturePtr theFeature);
-#endif
/// \brief Block or unblock events from this constraint
virtual void blockEvents(bool isBlocked);
-#ifndef SUPPORT_NEW_MOVE
- /// \brief Set coordinates of fixed feature to the values where it has been dragged.
- /// Useful when the feature is being moved.
- void moveFeature();
-#endif
-
protected:
/// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
virtual void process();
virtual void getAttributes(EntityWrapperPtr& , std::vector<EntityWrapperPtr>& )
{}
-#ifdef SUPPORT_NEW_MOVE
/// \brief Obtain entity to be fixed
virtual EntityWrapperPtr entityToFix();
-#else
- /// \brief Generate list of attributes of constraint in order useful for constraints
- /// \param[out] theBaseEntity the entity which coordinates should be fixed
- /// \param[out] theFixedEntity the entity containing fixed values
- virtual void getAttributes(EntityWrapperPtr& theBaseEntity,
- EntityWrapperPtr& theFixedEntity);
-#endif
/// \brief Create Fixed constraint for the feature basing on its type
/// \param theFeature [in] feature, converted to solver specific format
/// \return Fixed constraint
virtual ConstraintWrapperPtr fixFeature(EntityWrapperPtr theFeature);
-#ifndef SUPPORT_NEW_MOVE
-public:
-#endif
/// \brief Get list of parameters of current entity
static GCS::VEC_pD toParameters(const EntityWrapperPtr& theEntity);
-#ifdef SUPPORT_NEW_MOVE
protected:
-#else
-private:
- FeaturePtr myBaseFeature; ///< fixed feature (when it is set, myBaseConstraint should be NULL)
-
- ConstraintWrapperPtr myConstraint;
- EntityWrapperPtr myFixedEntity;
-#endif
std::vector<double> myFixedValues;
};
return;
}
- ConstraintWrapperPtr aConstraint = fixFeature(aMovedEntity);
- myStorage->addMovementConstraint(aConstraint);
+ mySolverConstraint = fixFeature(aMovedEntity);
+ myStorage->addMovementConstraint(mySolverConstraint);
}
return EntityWrapperPtr();
}
- return myStorage->entity(myMovedFeature);
+ EntityWrapperPtr anEntity =
+ myDraggedPoint ? myStorage->entity(myDraggedPoint) : myStorage->entity(myMovedFeature);
+ if (!anEntity) {
+ myStorage->update(myMovedFeature, true);
+ anEntity = myStorage->entity(myMovedFeature);
+ }
+ return anEntity;
}
void SketchSolver_ConstraintMovement::moveTo(
const std::shared_ptr<GeomAPI_Pnt2d>& theDestinationPoint)
{
-#ifdef SUPPORT_NEW_MOVE
- EntityWrapperPtr aMovedEntity = myStorage->entity(myMovedFeature);
+ EntityWrapperPtr aMovedEntity =
+ myDraggedPoint ? myStorage->entity(myDraggedPoint) : myStorage->entity(myMovedFeature);
if (!aMovedEntity)
return;
for (int i = 0; i < aFixedParams.size() && i < myFixedValues.size(); ++i)
myFixedValues[i] = *(aFixedParams[i]) + aDelta[i % 2];
-#endif
+ // no persistent constraints in the storage, thus store values directly to the feature
+ if (myStorage->isEmpty()) {
+ for (int i = 0; i < aFixedParams.size() && i < myFixedValues.size(); ++i)
+ *(aFixedParams[i]) = myFixedValues[i];
+ myStorage->setNeedToResolve(true);
+ }
}
return myStorage->update(theFeature);
}
-#ifdef SUPPORT_NEW_MOVE
template <class Type>
static SolverConstraintPtr move(StoragePtr theStorage,
SolverPtr theSketchSolver,
setTemporary(aConstraint);
return true;
}
-#else
-bool SketchSolver_Group::moveFeature(FeaturePtr theFeature)
-{
- bool isFeatureExists = (myStorage->entity(theFeature).get() != 0);
- if (myDOF == 0 && isFeatureExists) {
- // avoid moving elements of fully constrained sketch
- myStorage->refresh();
- return true;
- }
-
- // Create temporary Fixed constraint
- std::shared_ptr<SketchSolver_ConstraintFixed> aConstraint =
- PlaneGCSSolver_Tools::createMovementConstraint(theFeature);
- if (!aConstraint)
- return false;
- SolverConstraintPtr(aConstraint)->process(myStorage, myIsEventsBlocked);
- if (aConstraint->error().empty()) {
- setTemporary(aConstraint);
- if (!myStorage->isEmpty())
- myStorage->setNeedToResolve(true);
-
- mySketchSolver->initialize();
- aConstraint->moveFeature();
- } else
- myStorage->notify(theFeature);
-
- return true;
-}
-#endif
// ============================================================================
// Function: resolveConstraints
*/
bool updateFeature(FeaturePtr theFeature);
-#ifdef SUPPORT_NEW_MOVE
/** \brief Updates the data corresponding the specified feature moved in GUI.
* Special kind of Fixed constraints is created.
* \param[in] theFeature the feature to be updated
bool movePoint(AttributePtr thePoint,
const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
-#else
- /** \brief Updates the data corresponding the specified feature moved in GUI.
- * Additional Fixed constraints are created.
- * \param[in] theFeature the feature to be updated
- * \return \c true, if the feature is moved
- */
- bool moveFeature(FeaturePtr theFeature);
-#endif
/// Returns the current workplane
inline const CompositeFeaturePtr& getWorkplane() const
return;
myIsComputed = true;
-#ifdef SUPPORT_NEW_MOVE
if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)
|| theMessage->eventID() == anUpdateEvent) {
-#else
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)
- || theMessage->eventID() == anUpdateEvent
- || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) {
-#endif
std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
std::set<ObjectPtr> aFeatures = anUpdateMsg->objects();
isUpdateFlushed = stopSendUpdate();
-#ifndef SUPPORT_NEW_MOVE
- isMovedEvt = theMessage->eventID()
- == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED);
-
- // Shows that the message has at least one feature applicable for solver
- bool hasProperFeature = false;
-#endif
-
// update sketch features only
std::set<ObjectPtr>::iterator aFeatIter;
for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
if (!aFeature || aFeature->isMacro())
continue;
-#ifdef SUPPORT_NEW_MOVE
updateFeature(aFeature);
-#else
- hasProperFeature = updateFeature(aFeature, isMovedEvt) || hasProperFeature;
-#endif
}
-#ifndef SUPPORT_NEW_MOVE
- if (isMovedEvt && hasProperFeature)
- needToResolve = true;
-
-#else
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) {
std::shared_ptr<ModelAPI_ObjectMovedMessage> aMoveMsg =
std::dynamic_pointer_cast<ModelAPI_ObjectMovedMessage>(theMessage);
} else if (aMovedPoint)
needToResolve = moveAttribute(aMovedPoint, aFrom, aTo);
-#endif
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleteMsg =
std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
// Function: updateFeature
// Purpose: create/update constraint or feature in appropriate group
// ============================================================================
-#ifdef SUPPORT_NEW_MOVE
bool SketchSolver_Manager::updateFeature(const std::shared_ptr<SketchPlugin_Feature>& theFeature)
-#else
-bool SketchSolver_Manager::updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature,
- bool theMoved)
-#endif
{
// Check feature validity and find a group to place it.
// If the feature is not valid, the returned group will be empty.
bool isOk = false;
if (aConstraint)
isOk = aGroup->changeConstraint(aConstraint);
-#ifndef SUPPORT_NEW_MOVE
- else if (theMoved)
- isOk = aGroup->moveFeature(theFeature);
-#endif
else
isOk = aGroup->updateFeature(theFeature);
return isOk;
}
-#ifdef SUPPORT_NEW_MOVE
// ============================================================================
// Function: moveFeature
// Purpose: move given feature in appropriate group
SketchGroupPtr aGroup;
if (aSketchFeature)
aGroup = findGroup(aSketchFeature);
- if (!aGroup)
+ if (!aGroup) {
+ theMovedAttribute->setValue(theTo);
return false;
+ }
aGroup->blockEvents(true);
return aGroup->movePoint(theMovedAttribute, theFrom, theTo);
}
-#endif
// ============================================================================
// Function: findGroup
SketchSolver_Manager();
~SketchSolver_Manager();
-#ifdef SUPPORT_NEW_MOVE
/** \brief Adds or updates a constraint or an entity in the suitable group
* \param[in] theFeature sketch feature to be changed
* \return \c true if the feature changed successfully
bool moveAttribute(const std::shared_ptr<GeomDataAPI_Point2D>& theMovedAttribute,
const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
-#else
- /** \brief Adds or updates a constraint or an entity in the suitable group
- * \param[in] theFeature sketch feature to be changed
- * \param[in] theMoved \c true if the feature has been moved in the viewer
- * \return \c true if the feature changed successfully
- */
- bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature, bool theMoved = false);
-#endif
/** \brief Removes a constraint from the manager
* \param[in] theConstraint constraint to be removed