icon=":icons/sketch.png"
tooltip="Select a face for extrusion"
activate="true"
- shape_types="face"
+ shape_types="face wire"
+ use_subshapes="true"
/>
<doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="0" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
<validator id="GeomValidators_Positive"/>
GeomAPI_Pln.h
GeomAPI_Shape.h
GeomAPI_Edge.h
+ GeomAPI_Wire.h
GeomAPI_AISObject.h
GeomAPI_IPresentable.h
GeomAPI_Curve.h
GeomAPI_Pln.cpp
GeomAPI_Shape.cpp
GeomAPI_Edge.cpp
+ GeomAPI_Wire.cpp
GeomAPI_AISObject.cpp
GeomAPI_Curve.cpp
)
--- /dev/null
+// File: GeomAPI_Wire.cpp
+// Created: 06 Oct 2014
+// Author: Sergey BELASH
+
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_Wire.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepTools_WireExplorer.hxx>
+
+#include <list>
+
+GeomAPI_Wire::GeomAPI_Wire() : GeomAPI_Shape()
+{
+ TopoDS_Compound aBigWireImpl;
+ BRep_Builder aBuilder;
+ aBuilder.MakeCompound(aBigWireImpl);
+ this->setImpl(new TopoDS_Shape(aBigWireImpl));
+}
+
+void GeomAPI_Wire::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
+{
+ const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
+ if (anEdge.ShapeType() != TopAbs_EDGE)
+ return;
+ TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+ BRep_Builder aBuilder;
+ aBuilder.Add(aWire, anEdge);
+}
+
+std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_Wire::getEdges()
+{
+ TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+ BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
+ for (; aWireExp.More(); aWireExp.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
+ anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
+ aResult.push_back(anEdge);
+ }
+ return aResult;
+}
--- /dev/null
+// File: GeomAPI_Wire.hxx
+// Created: 24 Jul 2014
+// Author: Artem ZHIDKOV
+
+#ifndef GEOMAPI_WIRE_H_
+#define GEOMAPI_WIRE_H_
+
+#include <GeomAPI.h>
+#include <GeomAPI_Edge.h>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
+
+/**\class GeomAPI_Wire
+ * \ingroup DataModel
+ * \brief Interface to the edge object
+ */
+
+class GEOMAPI_EXPORT GeomAPI_Wire : public GeomAPI_Shape
+{
+ public:
+ /// Creation of empty (null) shape
+ GeomAPI_Wire();
+
+ virtual bool isVertex() const
+ {
+ return false;
+ }
+
+ /// Returns whether the shape is an edge
+ virtual bool isEdge() const
+ {
+ return false;
+ }
+
+ void addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge);
+ std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
+
+};
+
+#endif
+
// Author: Artem ZHIDKOV
#include <GeomAlgoAPI_SketchBuilder.h>
+#include <GeomAPI_Wire.h>
#include <set>
fixIntersections(theResultFaces);
}
+void GeomAlgoAPI_SketchBuilder::createFaces(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+ const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+ const boost::shared_ptr<GeomAPI_Shape>& theWire,
+ std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces)
+{
+ boost::shared_ptr<GeomAPI_Wire> aWire = boost::dynamic_pointer_cast<GeomAPI_Wire>(theWire);
+ if(!aWire)
+ return;
+ // Filter wires, return only faces.
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aFilteredWires;
+ createFaces(theOrigin, theDirX, theDirY, theNorm,
+ aWire->getEdges(), theResultFaces, aFilteredWires);
+}
+
+
void GeomAlgoAPI_SketchBuilder::fixIntersections(
std::list<boost::shared_ptr<GeomAPI_Shape> >& theFaces)
{
std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces,
std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultWires);
+ /** \brief Creates list of faces and unclosed wires on basis of the features of the sketch
+ * \param[in] theOrigin origin point of the sketch
+ * \param[in] theDirX x-direction of the sketch
+ * \param[in] theDirY y-direction of the sketch
+ * \param[in] theNorm normal of the sketch
+ * \param[in] theWire a wire which contains all edges
+ * \param[out] theResultFaces faces based on closed wires
+ *
+ * The algorithm searches all loops of edges surrounding lesser squares.
+ * It finds the vertex with minimal coordinates along X axis (theDirX) and then
+ * goes through the edges passing the surrounding area on the left.
+ */
+ static void createFaces(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+ const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+ const boost::shared_ptr<GeomAPI_Shape>& theWire,
+ std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces);
+
/** \brief Searches intersections between the faces in the list
* and make holes in the faces to avoid intersections
* \param[in,out] theFaces list of faces to proccess
typedef QList<double> QDoubleList; //!< list of double values
typedef QList<FeaturePtr> QFeatureList; //!< List of features
typedef QList<ResultPtr> QResultList; //!< List of results
-
#endif
#define ModuleBase_IWorkshop_H
#include "ModuleBase.h"
+#include "ModuleBase_Definitions.h"
#include <ModelAPI_Object.h>
virtual ModuleBase_ISelection* selection() const = 0;
+ /// Activate sub-shapes selection (opens local context)
+ /// Types has to be dined according to TopAbs_ShapeEnum
+ virtual void activateSubShapesSelection(const QIntList& theTypes) = 0;
+
+ /// Deactivate sub-shapes selection (closes local context)
+ virtual void deactivateSubShapesSelection() = 0;
+
//! Returns instance of loaded module
virtual ModuleBase_IModule* module() const = 0;
disconnect(myPropertyPanel, 0, this, 0);
stopOperation();
-
ModelAPI_Session::get()->finishOperation();
+
emit stopped();
afterCommitOperation();
const Config_WidgetAPI* theData,
const std::string& theParentId)
: ModuleBase_ModelWidget(theParent, theData, theParentId),
- myWorkshop(theWorkshop), myIsActive(false)
+ myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
{
myContainer = new QWidget(theParent);
QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
std::string aTypes = theData->getProperty("shape_types");
myShapeTypes = QString(aTypes.c_str()).split(' ');
+
+ std::string aUseSubShapes = theData->getProperty("use_subshapes");
+ if (aUseSubShapes.length() > 0) {
+ QString aVal(aUseSubShapes.c_str());
+ myUseSubShapes = (aVal.toUpper() == "TRUE");
+ }
}
//********************************************************************
myTextLine->setPalette(myInactivePalet);
updateSelectionName();
- if (myIsActive)
+ if (myIsActive) {
connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- else
+ if (myUseSubShapes) {
+ QIntList aList;
+ foreach (QString aType, myShapeTypes)
+ aList.append(shapeType(aType));
+ myWorkshop->activateSubShapesSelection(aList);
+ }
+ } else {
disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ if (myUseSubShapes)
+ myWorkshop->deactivateSubShapesSelection();
+ }
}
//********************************************************************
ObjectPtr mySelectedObject;
QStringList myShapeTypes;
+ /// If true then local selector has to be activated in context
+ bool myUseSubShapes;
+
QPalette myBasePalet;
QPalette myInactivePalet;
aDisplayer->deactivateObjectsOutOfContext();
} else {
Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext();
+ //TODO (VSV): We have to open Local context because at neutral point filters don't work (bug 25340)
aAIS->AddFilter(myDocumentShapeFilter);
}
}
PartSet_OperationSketchBase::stopOperation();
emit featureConstructed(feature(), FM_Hide);
emit closeLocalContext();
+}
+void PartSet_OperationSketch::afterCommitOperation()
+{
FeaturePtr aFeature = feature();
std::list<ResultPtr> aResults = aFeature->results();
std::list<ResultPtr>::const_iterator aIt;
/// Default impl calls corresponding slot and commits immediately.
virtual void startOperation();
+ /// Virtual method called after operation committed (see commit() method for more description)
+ virtual void afterCommitOperation();
+
private:
std::list<ModuleBase_ViewerPrs> myFeatures; ///< the features to apply the edit operation
};
// Created: 27 Mar 2014
// Author: Mikhail PONIKAROV
-#include "SketchPlugin_Sketch.h"
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeRefList.h>
+#include <Config_PropManager.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+
#include <GeomAPI_AISObject.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Wire.h>
#include <GeomAPI_XYZ.h>
+
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point.h>
-#include <GeomAlgoAPI_FaceBuilder.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
-#include <GeomAlgoAPI_SketchBuilder.h>
+
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
#include <ModelAPI_ResultConstruction.h>
-#include <Config_PropManager.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <vector>
using namespace std;
if (aFeaturesPreview.empty())
return;
- std::list<boost::shared_ptr<GeomAPI_Shape> > aLoops;
- std::list<boost::shared_ptr<GeomAPI_Shape> > aWires;
- GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
- aFeaturesPreview, aLoops, aWires);
- aLoops.insert(aLoops.end(), aWires.begin(), aWires.end());
- boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops);
+ // Collect all edges as one big wire
+ boost::shared_ptr<GeomAPI_Wire> aBigWire(new GeomAPI_Wire);
+ std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator aShapeIt = aFeaturesPreview.begin();
+ for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
+ aBigWire->addEdge(*aShapeIt);
+ }
+// GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
+// aFeaturesPreview, aLoops, aWires);
boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
- aConstr->setShape(aCompound);
+ aConstr->setShape(aBigWire);
setResult(aConstr);
}
myEntities.clear();
myEntOfConstr.clear();
myConstraints.clear();
-
myTempConstraints.clear();
- myTempPointWhereDragged.clear();
- myTempPointWDrgdID = 0;
// Initialize workplane
myWorkplane.h = SLVS_E_UNKNOWN;
myConstraints.clear();
myConstraintMap.clear();
myTempConstraints.clear();
- myTempPointWhereDragged.clear();
// If the group with maximal identifier is deleted, decrease the indexer
if (myID == myGroupIndexer)
}
/// \todo Other types of entities
+ Slvs_hEntity aResult = SLVS_E_UNKNOWN; // Unsupported or wrong entity type
+
if (isEntExists) {
if (!myEntOfConstr[aEntPos]) // the entity is not used by constraints, no need to resolve them
myNeedToSolve = isNeedToSolve;
else
myNeedToSolve = myNeedToSolve || isNeedToSolve;
- return aEntIter->second;
- }
-
- if (aNewEntity.h != SLVS_E_UNKNOWN) {
+ aResult = aEntIter->second;
+ } else if (aNewEntity.h != SLVS_E_UNKNOWN) {
myEntities.push_back(aNewEntity);
myEntOfConstr.push_back(false);
myEntityAttrMap[theEntity] = aNewEntity.h;
- return aNewEntity.h;
+ aResult = aNewEntity.h;
}
- // Unsupported or wrong entity type
- return SLVS_E_UNKNOWN;
+ // If the attribute was changed by the user, we need to fix it before solving
+ if (myNeedToSolve && theEntity->isImmutable())
+ addTemporaryConstraintWhereDragged(theEntity);
+
+ return aResult;
}
// ============================================================================
myConstrSolver.setParameters(myParams);
myConstrSolver.setEntities(myEntities);
myConstrSolver.setConstraints(myConstraints);
- myConstrSolver.setDraggedParameters(myTempPointWhereDragged);
int aResult = myConstrSolver.solve();
if (aResult == SLVS_RESULT_OKAY) { // solution succeeded, store results into correspondent attributes
myTempConstraints.push_back(aFind->second);
}
- if (myTempPointWhereDragged.empty())
- myTempPointWhereDragged = theGroup.myTempPointWhereDragged;
- else if (!theGroup.myTempPointWhereDragged.empty()) { // Need to create additional transient constraint
- std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator aFeatureIter =
- theGroup.myEntityAttrMap.begin();
- for (; aFeatureIter != theGroup.myEntityAttrMap.end(); aFeatureIter++)
- if (aFeatureIter->second == myTempPointWDrgdID) {
- addTemporaryConstraintWhereDragged(aFeatureIter->first);
- break;
- }
- }
-
myNeedToSolve = myNeedToSolve || theGroup.myNeedToSolve;
}
if (anEntIter == myEntityAttrMap.end())
return;
- // If this is a first dragged point, its parameters should be placed
- // into Slvs_System::dragged field to avoid system inconsistense
- if (myTempPointWhereDragged.empty()) {
- int anEntPos = Search(anEntIter->second, myEntities);
- Slvs_hParam* aDraggedParam = myEntities[anEntPos].param;
- for (int i = 0; i < 4; i++, aDraggedParam++)
- if (*aDraggedParam != 0)
- myTempPointWhereDragged.push_back(*aDraggedParam);
- myTempPointWDrgdID = myEntities[anEntPos].h;
- return;
- }
-
// Get identifiers of all dragged points
std::set<Slvs_hEntity> aDraggedPntID;
- aDraggedPntID.insert(myTempPointWDrgdID);
std::list<Slvs_hConstraint>::iterator aTmpCoIter = myTempConstraints.begin();
for (; aTmpCoIter != myTempConstraints.end(); aTmpCoIter++) {
unsigned int aConstrPos = Search(*aTmpCoIter, myConstraints);
myConstrMaxID--;
}
myTempConstraints.clear();
-
- // Clear basic dragged point
- myTempPointWhereDragged.clear();
}
// ============================================================================
SketchSolver_Solver myConstrSolver; ///< Solver for set of equations obtained by constraints
- std::vector<Slvs_hParam> myTempPointWhereDragged; ///< Parameters of one of the points which is moved by user
- Slvs_hEntity myTempPointWDrgdID; ///< Identifier of such point
std::list<Slvs_hConstraint> myTempConstraints; ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user
// SketchPlugin entities
{
return myWorkshop->operationMgr()->currentOperation();
}
+
+
+void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
+{
+ Handle(AIS_InteractiveContext) aAIS = myWorkshop->viewer()->AISContext();
+ if (!aAIS->HasOpenedContext())
+ aAIS->OpenLocalContext();
+ foreach(int aType, theTypes)
+ aAIS->ActivateStandardMode((TopAbs_ShapeEnum)aType);
+}
+
+void XGUI_ModuleConnector::deactivateSubShapesSelection()
+{
+ Handle(AIS_InteractiveContext) aAIS = myWorkshop->viewer()->AISContext();
+ aAIS->CloseAllContexts();
+}
//! Returns list of currently selected data objects
virtual ModuleBase_ISelection* selection() const;
+ /// Activate sub-shapes selection (opens local context if it was not opened)
+ /// Types has to be dined according to TopAbs_ShapeEnum
+ virtual void activateSubShapesSelection(const QIntList& theTypes);
+
+ /// Deactivate sub-shapes selection (closes local context)
+ virtual void deactivateSubShapesSelection();
+
//! Returns instance of loaded module
virtual ModuleBase_IModule* module() const;
IMPLEMENT_STANDARD_RTTIEXT(XGUI_ShapeDocumentFilter, SelectMgr_Filter);
-//TODO (VSV): Check bug in OCCT: Filter result is ignored
+//TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
Standard_Boolean XGUI_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
{
if (theOwner->HasSelectable()) {