]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
authorsbh <sergey.belash@opencascade.com>
Fri, 10 Apr 2015 15:46:04 +0000 (18:46 +0300)
committersbh <sergey.belash@opencascade.com>
Fri, 10 Apr 2015 15:46:04 +0000 (18:46 +0300)
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp [deleted file]
src/PartSet/PartSet_WidgetConstraintShapeSelector.h [deleted file]
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index 8b85b15c621600b877eeba50480d98dcdd6dc25c..76fc4c119760c0d1dd9c5995a916045024df3689 100644 (file)
@@ -12,7 +12,6 @@ SET(PROJECT_HEADERS
        PartSet_WidgetSketchLabel.h
        PartSet_Validators.h
        PartSet_WidgetPoint2d.h
-       PartSet_WidgetConstraintShapeSelector.h
     PartSet_WidgetEditor.h
        PartSet_WidgetPoint2dDistance.h
        PartSet_WidgetShapeSelector.h
@@ -27,7 +26,6 @@ SET(PROJECT_SOURCES
        PartSet_Tools.cpp
        PartSet_WidgetSketchLabel.cpp
        PartSet_Validators.cpp
-       PartSet_WidgetConstraintShapeSelector.cpp
     PartSet_WidgetEditor.cpp
        PartSet_WidgetPoint2d.cpp
        PartSet_WidgetPoint2dDistance.cpp
index b81a64bb3291fb07b2280883008df0594e201f99..60ab634a785d3722796b414c8cbc176039bd2249 100644 (file)
@@ -7,7 +7,6 @@
 #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"
@@ -472,11 +471,6 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
       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);
   } 
diff --git a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp
deleted file mode 100644 (file)
index f379935..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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);*/
-}
diff --git a/src/PartSet/PartSet_WidgetConstraintShapeSelector.h b/src/PartSet/PartSet_WidgetConstraintShapeSelector.h
deleted file mode 100644 (file)
index 9a69e43..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// 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
index cd659c04dc1aaac826683c67df61c3e6a167fe51..089bd98a6ccf1cc1794b3d8cd0da43b06a6d416b 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_Validator.h>
 
 #include <ModuleBase_Definitions.h>
+#include <Config_WidgetAPI.h>
 
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
@@ -23,8 +24,13 @@ PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
                                                          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)
@@ -35,9 +41,15 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
   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()) {
index fb32bff9cc7242135412d6e1fc82a7b421395003..b10c8a06fff2bf1e060e266e4e01d57faf4eceea 100644 (file)
@@ -63,6 +63,8 @@ protected:
 
   /// An external object
   ObjectPtr myExternalObject;
+
+  bool myUseExternal;
 };
 
 #endif
\ No newline at end of file
index 382bd3d612f7e8d9610be38cd0a515e4f26e2aaa..b42b4af66a0a9fa6d94983293f98cf3ec24c2c58 100644 (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"
index 2a2c85f383839a78c2844797a789d5f8edf6dd41..737809a985e0cf79be25c1cd1bd01eab79359f18 100644 (file)
@@ -116,12 +116,53 @@ void SketchSolver_Constraint::process()
 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
@@ -564,7 +605,15 @@ Slvs_hEntity SketchSolver_Constraint::getId(FeaturePtr theFeature) const
   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
index 9ccf3fa73d003b22f7743c08506a2cd0e11bd2d6..58d822786f807d1b4b92446b4e8be22be41dde35 100644 (file)
@@ -235,12 +235,12 @@ bool SketchSolver_Group::changeConstraint(
       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);
index eddd630c94aa4f9365e79673b170c13436306d5e..421696c175f8828c00fcf99c5f777c4b43162fcd 100644 (file)
@@ -142,13 +142,19 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID)
   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();
@@ -157,7 +163,7 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID)
           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
@@ -188,7 +194,7 @@ const Slvs_Entity& SketchSolver_Storage::getEntity(const Slvs_hEntity& theEntity
 
   // Entity is not found, return empty object
   static Slvs_Entity aDummy;
-  aDummy.h = 0;
+  aDummy.h = SLVS_E_UNKNOWN;
   return aDummy;
 }
 
@@ -639,7 +645,7 @@ int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities)
     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;
 }