diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 31920dbafa..a1827a2ff5 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -1604,13 +1604,16 @@ PyObject *PropertyStringList::getPyObject(void) void PropertyStringList::setPyObject(PyObject *value) { - if (PyList_Check(value)) { - Py_ssize_t nSize = PyList_Size(value); + if (PyString_Check(value)) { + setValue(PyString_AsString(value)); + } + else if (PySequence_Check(value)) { + Py_ssize_t nSize = PySequence_Size(value); std::vector values; values.resize(nSize); for (Py_ssize_t i=0; iob_type->tp_name; diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index 8c832cf969..1d82e3690b 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -73,6 +73,7 @@ # include # include # include +# include # include # include # include @@ -244,6 +245,7 @@ ViewProviderPartExt::ViewProviderPartExt() ADD_PROPERTY(PointMaterial,(mat)); ADD_PROPERTY(LineColor,(mat.diffuseColor)); ADD_PROPERTY(PointColor,(mat.diffuseColor)); + ADD_PROPERTY(PointColorArray, (PointColor.getValue())); ADD_PROPERTY(DiffuseColor,(ShapeColor.getValue())); ADD_PROPERTY(LineColorArray,(LineColor.getValue())); ADD_PROPERTY(LineWidth,(lwidth)); @@ -273,8 +275,8 @@ ViewProviderPartExt::ViewProviderPartExt() nodeset = new SoBrepPointSet(); nodeset->ref(); - pcShapeBind = new SoMaterialBinding(); - pcShapeBind->ref(); + pcFaceBind = new SoMaterialBinding(); + pcFaceBind->ref(); pcLineBind = new SoMaterialBinding(); pcLineBind->ref(); @@ -282,6 +284,8 @@ ViewProviderPartExt::ViewProviderPartExt() pcLineMaterial->ref(); LineMaterial.touch(); + pcPointBind = new SoMaterialBinding(); + pcPointBind->ref(); pcPointMaterial = new SoMaterial; pcPointMaterial->ref(); PointMaterial.touch(); @@ -308,8 +312,9 @@ ViewProviderPartExt::ViewProviderPartExt() ViewProviderPartExt::~ViewProviderPartExt() { - pcShapeBind->unref(); + pcFaceBind->unref(); pcLineBind->unref(); + pcPointBind->unref(); pcLineMaterial->unref(); pcPointMaterial->unref(); pcLineStyle->unref(); @@ -391,7 +396,7 @@ void ViewProviderPartExt::onChanged(const App::Property* prop) setHighlightedFaces(DiffuseColor.getValues()); } else if (prop == &ShapeMaterial || prop == &ShapeColor) { - pcShapeBind->value = SoMaterialBinding::OVERALL; + pcFaceBind->value = SoMaterialBinding::OVERALL; ViewProviderGeometryObject::onChanged(prop); DiffuseColor.setValue(ShapeColor.getValue()); } @@ -400,7 +405,7 @@ void ViewProviderPartExt::onChanged(const App::Property* prop) long value = (long)(100*Mat.transparency); if (value != Transparency.getValue()) { float trans = Transparency.getValue()/100.0f; - if (pcShapeBind->value.getValue() == SoMaterialBinding::PER_PART) { + if (pcFaceBind->value.getValue() == SoMaterialBinding::PER_PART) { int cnt = pcShapeMaterial->diffuseColor.getNum(); pcShapeMaterial->transparency.setNum(cnt); float *t = pcShapeMaterial->transparency.startEditing(); @@ -480,7 +485,7 @@ void ViewProviderPartExt::attach(App::DocumentObject *pcFeat) // just faces with no edges or points pcFlatRoot->addChild(pShapeHints); - pcFlatRoot->addChild(pcShapeBind); + pcFlatRoot->addChild(pcFaceBind); pcFlatRoot->addChild(pcShapeMaterial); SoDrawStyle* pcFaceStyle = new SoDrawStyle(); pcFaceStyle->style = SoDrawStyle::FILLED; @@ -494,6 +499,7 @@ void ViewProviderPartExt::attach(App::DocumentObject *pcFeat) pcWireframeRoot->addChild(pcPointsRoot); // normal viewing with edges and points + pcPointsRoot->addChild(pcPointBind); pcPointsRoot->addChild(pcPointMaterial); pcPointsRoot->addChild(pcPointStyle); pcPointsRoot->addChild(nodeset); @@ -643,7 +649,7 @@ void ViewProviderPartExt::setHighlightedFaces(const std::vector& col { int size = static_cast(colors.size()); if (size > 1 && size == this->faceset->partIndex.getNum()) { - pcShapeBind->value = SoMaterialBinding::PER_PART; + pcFaceBind->value = SoMaterialBinding::PER_PART; pcShapeMaterial->diffuseColor.setNum(size); pcShapeMaterial->transparency.setNum(size); SbColor* ca = pcShapeMaterial->diffuseColor.startEditing(); @@ -656,7 +662,7 @@ void ViewProviderPartExt::setHighlightedFaces(const std::vector& col pcShapeMaterial->transparency.finishEditing(); } else if (colors.size() == 1) { - pcShapeBind->value = SoMaterialBinding::OVERALL; + pcFaceBind->value = SoMaterialBinding::OVERALL; pcShapeMaterial->diffuseColor.setValue(colors[0].r, colors[0].g, colors[0].b); //pcShapeMaterial->transparency = colors[0].a; do not get transparency from DiffuseColor in this case } @@ -666,7 +672,7 @@ void ViewProviderPartExt::setHighlightedFaces(const std::vector& { int size = static_cast(colors.size()); if (size > 1 && size == this->faceset->partIndex.getNum()) { - pcShapeBind->value = SoMaterialBinding::PER_PART; + pcFaceBind->value = SoMaterialBinding::PER_PART; pcShapeMaterial->diffuseColor.setNum(size); pcShapeMaterial->ambientColor.setNum(size); @@ -691,7 +697,7 @@ void ViewProviderPartExt::setHighlightedFaces(const std::vector& pcShapeMaterial->emissiveColor.finishEditing(); } else if (colors.size() == 1) { - pcShapeBind->value = SoMaterialBinding::OVERALL; + pcFaceBind->value = SoMaterialBinding::OVERALL; pcShapeMaterial->diffuseColor.setValue(colors[0].diffuseColor.r, colors[0].diffuseColor.g, colors[0].diffuseColor.b); pcShapeMaterial->ambientColor.setValue(colors[0].ambientColor.r, colors[0].ambientColor.g, colors[0].ambientColor.b); pcShapeMaterial->specularColor.setValue(colors[0].specularColor.r, colors[0].specularColor.g, colors[0].specularColor.b); @@ -701,7 +707,7 @@ void ViewProviderPartExt::setHighlightedFaces(const std::vector& void ViewProviderPartExt::unsetHighlightedFaces() { - ShapeMaterial.touch(); + DiffuseColor.touch(); Transparency.touch(); } @@ -744,8 +750,14 @@ void ViewProviderPartExt::setHighlightedPoints(const std::vector& co { int size = static_cast(colors.size()); if (size > 1) { - // FIXME: Check for size mismatch between number of points and number of colors - pcShapeBind->value = SoMaterialBinding::PER_VERTEX; +#ifdef FC_DEBUG + int numPoints = coords->point.getNum() - nodeset->startIndex.getValue(); + if (numPoints != size) { + SoDebugError::postWarning("ViewProviderPartExt::setHighlightedPoints", + "The number of points (%d) doesn't match with the number of colors (%d).", numPoints, size); + } +#endif + pcPointBind->value = SoMaterialBinding::PER_VERTEX; pcPointMaterial->diffuseColor.setNum(size); SbColor* ca = pcPointMaterial->diffuseColor.startEditing(); for (int i = 0; i < size; ++i) @@ -753,14 +765,14 @@ void ViewProviderPartExt::setHighlightedPoints(const std::vector& co pcPointMaterial->diffuseColor.finishEditing(); } else if (size == 1) { - pcShapeBind->value = SoMaterialBinding::OVERALL; + pcPointBind->value = SoMaterialBinding::OVERALL; pcPointMaterial->diffuseColor.setValue(colors[0].r, colors[0].g, colors[0].b); } } void ViewProviderPartExt::unsetHighlightedPoints() { - PointMaterial.touch(); + PointColorArray.touch(); } bool ViewProviderPartExt::loadParameter() @@ -818,7 +830,7 @@ void ViewProviderPartExt::updateData(const App::Property* prop) if (!VisualTouched) { if (this->faceset->partIndex.getNum() > this->pcShapeMaterial->diffuseColor.getNum()) { - this->pcShapeBind->value = SoMaterialBinding::OVERALL; + this->pcFaceBind->value = SoMaterialBinding::OVERALL; } } } diff --git a/src/Mod/Part/Gui/ViewProviderExt.h b/src/Mod/Part/Gui/ViewProviderExt.h index 36f2130dfa..33accd97a0 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.h +++ b/src/Mod/Part/Gui/ViewProviderExt.h @@ -145,8 +145,9 @@ protected: TColgp_Array1OfDir& theNormals); // nodes for the data representation - SoMaterialBinding * pcShapeBind; + SoMaterialBinding * pcFaceBind; SoMaterialBinding * pcLineBind; + SoMaterialBinding * pcPointBind; SoMaterial * pcLineMaterial; SoMaterial * pcPointMaterial; SoDrawStyle * pcLineStyle; diff --git a/src/Mod/Surface/App/FeatureFilling.cpp b/src/Mod/Surface/App/FeatureFilling.cpp index 172e01f6f9..b7a7abd1ca 100644 --- a/src/Mod/Surface/App/FeatureFilling.cpp +++ b/src/Mod/Surface/App/FeatureFilling.cpp @@ -46,42 +46,52 @@ PROPERTY_SOURCE(Surface::Filling, Part::Spline) Filling::Filling() { - ADD_PROPERTY_TYPE(Border,(0,""), "Filling", App::Prop_None, "Border Edges (C0 is required for edges without a corresponding face)"); - ADD_PROPERTY_TYPE(BorderFaces,(0,""), "Filling", App::Prop_None, "Border Faces"); - ADD_PROPERTY_TYPE(OrderBorderFaces,(-1), "Filling", App::Prop_None, "Order of constraint on border faces (C0, G1 and G2 are possible)"); + ADD_PROPERTY_TYPE(BoundaryEdges,(0,""), "Filling", App::Prop_None, "Boundary Edges (C0 is required for edges without a corresponding face)"); + ADD_PROPERTY_TYPE(BoundaryFaces,(""), "Filling", App::Prop_None, "Boundary Faces"); + ADD_PROPERTY_TYPE(BoundaryOrder,(-1), "Filling", App::Prop_None, "Order of constraint on boundary faces (C0, G1 and G2 are possible)"); - ADD_PROPERTY_TYPE(Curves,(0,""), "Filling", App::Prop_None, "Other Constraint Curves (C0 is required for edges without a corresponding face)"); - ADD_PROPERTY_TYPE(CurveFaces,(0,""), "Filling", App::Prop_None, "Curve Faces"); - ADD_PROPERTY_TYPE(OrderCurveFaces,(-1), "Filling", App::Prop_None, "Order of constraint on curve faces (C0, G1 and G2 are possible)"); + ADD_PROPERTY_TYPE(UnboundEdges,(0,""), "Filling", App::Prop_None, "Unbound constraint edges (C0 is required for edges without a corresponding face)"); + ADD_PROPERTY_TYPE(UnboundFaces,(""), "Filling", App::Prop_None, "Unbound constraint faces"); + ADD_PROPERTY_TYPE(UnboundOrder,(-1), "Filling", App::Prop_None, "Order of constraint on curve faces (C0, G1 and G2 are possible)"); ADD_PROPERTY_TYPE(FreeFaces,(0,""), "Filling", App::Prop_None, "Free constraint on a face"); - ADD_PROPERTY_TYPE(OrderFreeFaces,(0), "Filling", App::Prop_None, "Order of constraint on free faces"); + ADD_PROPERTY_TYPE(FreeOrder,(0), "Filling", App::Prop_None, "Order of constraint on free faces"); ADD_PROPERTY_TYPE(Points,(0,""), "Filling", App::Prop_None, "Constraint Points (on Surface)"); ADD_PROPERTY_TYPE(InitialFace,(0), "Filling", App::Prop_None, "Initial surface to use"); ADD_PROPERTY_TYPE(Degree,(3), "Filling", App::Prop_None, "Starting degree"); - ADD_PROPERTY_TYPE(PointsOnCurve,(3), "Filling", App::Prop_None, "Number of points on an edge for constraint"); + ADD_PROPERTY_TYPE(PointsOnCurve,(15), "Filling", App::Prop_None, "Number of points on an edge for constraint"); ADD_PROPERTY_TYPE(Iterations,(2), "Filling", App::Prop_None, "Number of iterations"); ADD_PROPERTY_TYPE(Anisotropy,(false), "Filling", App::Prop_None, "Anisotropy"); ADD_PROPERTY_TYPE(Tolerance2d,(0.00001), "Filling", App::Prop_None, "2D Tolerance"); ADD_PROPERTY_TYPE(Tolerance3d,(0.0001), "Filling", App::Prop_None, "3D Tolerance"); - ADD_PROPERTY_TYPE(TolAngular,(0.001), "Filling", App::Prop_None, "G1 tolerance"); - ADD_PROPERTY_TYPE(TolCurvature,(0.01), "Filling", App::Prop_None, "G2 tolerance"); + ADD_PROPERTY_TYPE(TolAngular,(0.01), "Filling", App::Prop_None, "G1 tolerance"); + ADD_PROPERTY_TYPE(TolCurvature,(0.1), "Filling", App::Prop_None, "G2 tolerance"); ADD_PROPERTY_TYPE(MaximumDegree,(8), "Filling", App::Prop_None, "Maximum curve degree"); - ADD_PROPERTY_TYPE(MaximumSegments,(10000), "Filling", App::Prop_None, "Maximum number of segments"); + ADD_PROPERTY_TYPE(MaximumSegments,(9), "Filling", App::Prop_None, "Maximum number of segments"); + + BoundaryEdges.setSize(0); + BoundaryFaces.setSize(0); + BoundaryOrder.setSize(0); + UnboundEdges.setSize(0); + UnboundFaces.setSize(0); + UnboundOrder.setSize(0); + FreeFaces.setSize(0); + FreeOrder.setSize(0); + Points.setSize(0); } short Filling::mustExecute() const { - if (Border.isTouched() || - BorderFaces.isTouched() || - OrderBorderFaces.isTouched() || - Curves.isTouched() || - CurveFaces.isTouched() || - OrderCurveFaces.isTouched() || + if (BoundaryEdges.isTouched() || + BoundaryFaces.isTouched() || + BoundaryOrder.isTouched() || + UnboundEdges.isTouched() || + UnboundFaces.isTouched() || + UnboundOrder.isTouched() || FreeFaces.isTouched() || - OrderFreeFaces.isTouched() || + FreeOrder.isTouched() || Points.isTouched() || InitialFace.isTouched() || Degree.isTouched() || @@ -100,39 +110,61 @@ short Filling::mustExecute() const void Filling::addConstraints(BRepFill_Filling& builder, const App::PropertyLinkSubList& edges, - const App::PropertyLinkSubList& faces, + const App::PropertyStringList& faces, const App::PropertyIntegerList& orders, Standard_Boolean bnd) { auto edge_obj = edges.getValues(); auto edge_sub = edges.getSubValues(); - auto face_obj = faces.getValues(); - auto face_sub = faces.getSubValues(); + auto face_sub = faces.getValues(); auto contvals = orders.getValues(); - // tmp. workaround - if (edge_obj.size() != contvals.size()) { - contvals.resize(edge_obj.size()); + // if the number of continuities doesn't match then fall back to C0 + if (edge_sub.size() != contvals.size()) { + contvals.resize(edge_sub.size()); std::fill(contvals.begin(), contvals.end(), static_cast(GeomAbs_C0)); } - if (edge_obj.size() == edge_sub.size() && - edge_obj.size() == contvals.size()) { + // if the number of faces doesn't match then fall back to empty strings + // an empty face string indicates that there is no face associated to an edge + if (face_sub.size() != edge_sub.size()) { + face_sub.resize(edge_obj.size()); + std::fill(face_sub.begin(), face_sub.end(), std::string()); + } + + if (edge_obj.size() == edge_sub.size()) { for (std::size_t index = 0; index < edge_obj.size(); index++) { + // get the part object App::DocumentObject* obj = edge_obj[index]; const std::string& sub = edge_sub[index]; + if (obj && obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + // get the sub-edge of the part's shape const Part::TopoShape& shape = static_cast(obj)->Shape.getShape(); TopoDS_Shape edge = shape.getSubShape(sub.c_str()); if (!edge.IsNull() && edge.ShapeType() == TopAbs_EDGE) { GeomAbs_Shape cont = static_cast(contvals[index]); - if (cont == GeomAbs_C0) { + + // check for an adjacent face of the edge + std::string subFace = face_sub[index]; + + // edge doesn't have set an adjacent face + if (subFace.empty()) { builder.Add(TopoDS::Edge(edge), cont, bnd); } else { - builder.Add(TopoDS::Edge(edge), cont, bnd); + TopoDS_Shape face = shape.getSubShape(subFace.c_str()); + if (!face.IsNull() && face.ShapeType() == TopAbs_FACE) { + builder.Add(TopoDS::Edge(edge), TopoDS::Face(face), cont, bnd); + } + else { + Standard_Failure::Raise("Sub-shape is not a face"); + } } } + else { + Standard_Failure::Raise("Sub-shape is not an edge"); + } } } } @@ -141,6 +173,7 @@ void Filling::addConstraints(BRepFill_Filling& builder, } } +// Add free support faces with their continuities void Filling::addConstraints(BRepFill_Filling& builder, const App::PropertyLinkSubList& faces, const App::PropertyIntegerList& orders) @@ -161,6 +194,9 @@ void Filling::addConstraints(BRepFill_Filling& builder, GeomAbs_Shape cont = static_cast(contvals[index]); builder.Add(TopoDS::Face(face), cont); } + else { + Standard_Failure::Raise("Sub-shape is not a face"); + } } } } @@ -207,7 +243,7 @@ App::DocumentObjectExecReturn *Filling::execute(void) BRepFill_Filling builder(degree, ptsoncurve, numIter, anisotropy, tol2d, tol3d, tolG1, tolG2, maxdeg, maxseg); - if ((Border.getSize()) < 1) { + if ((BoundaryEdges.getSize()) < 1) { return new App::DocumentObjectExecReturn("Border must have at least one curve defined."); } @@ -226,16 +262,16 @@ App::DocumentObjectExecReturn *Filling::execute(void) } // Add the constraints of border curves/faces (bound) - addConstraints(builder, Border, BorderFaces, OrderBorderFaces, Standard_True); + addConstraints(builder, BoundaryEdges, BoundaryFaces, BoundaryOrder, Standard_True); - // Add additional curves constraints if available (unbound) - if (Curves.getSize() > 0) { - addConstraints(builder, Curves, CurveFaces, OrderCurveFaces, Standard_False); + // Add additional edge constraints if available (unbound) + if (UnboundEdges.getSize() > 0) { + addConstraints(builder, UnboundEdges, UnboundFaces, UnboundOrder, Standard_False); } // Add additional constraint on free faces if (FreeFaces.getSize() > 0) { - addConstraints(builder, FreeFaces, OrderFreeFaces); + addConstraints(builder, FreeFaces, FreeOrder); } // App point constraints diff --git a/src/Mod/Surface/App/FeatureFilling.h b/src/Mod/Surface/App/FeatureFilling.h index bdc1ba535d..9e1f1f6b8c 100644 --- a/src/Mod/Surface/App/FeatureFilling.h +++ b/src/Mod/Surface/App/FeatureFilling.h @@ -41,14 +41,14 @@ public: Filling(); //Properties of Curves - App::PropertyLinkSubList Border; // Border Edges (C0 is required for edges without a corresponding face) - App::PropertyLinkSubList BorderFaces; // Border Faces (C0, G1 and G2 are possible) - App::PropertyIntegerList OrderBorderFaces; // Order of constraint on border faces - App::PropertyLinkSubList Curves; // Other Constraint Curves (C0 is required for edges without a corresponding face) - App::PropertyLinkSubList CurveFaces; // Curve Faces (C0, G1 and G2 are possible) - App::PropertyIntegerList OrderCurveFaces; // Order of constraint on curve faces - App::PropertyLinkSubList FreeFaces; // Free constraint on a face - App::PropertyIntegerList OrderFreeFaces; // Order of constraint on free faces + App::PropertyLinkSubList BoundaryEdges; // Boundary Edges (C0 is required for edges without a corresponding face) + App::PropertyStringList BoundaryFaces; // Boundary Faces (C0, G1 and G2 are possible) + App::PropertyIntegerList BoundaryOrder; // Order of constraint on border faces + App::PropertyLinkSubList UnboundEdges; // Unbound constraint edges (C0 is required for edges without a corresponding face) + App::PropertyStringList UnboundFaces; // Unbound constraint faces (C0, G1 and G2 are possible) + App::PropertyIntegerList UnboundOrder; // Order of constraint on curve faces + App::PropertyLinkSubList FreeFaces; // Free constraint faces + App::PropertyIntegerList FreeOrder; // Order of constraint on free faces App::PropertyLinkSubList Points; // Constraint Points (on Surface) App::PropertyLinkSub InitialFace; // Initial Face to use @@ -75,7 +75,7 @@ public: private: void addConstraints(BRepFill_Filling& builder, const App::PropertyLinkSubList& edges, - const App::PropertyLinkSubList& faces, + const App::PropertyStringList& faces, const App::PropertyIntegerList& orders, Standard_Boolean bnd); void addConstraints(BRepFill_Filling& builder, diff --git a/src/Mod/Surface/Gui/CMakeLists.txt b/src/Mod/Surface/Gui/CMakeLists.txt index 9421d69d6b..36bb016d40 100644 --- a/src/Mod/Surface/Gui/CMakeLists.txt +++ b/src/Mod/Surface/Gui/CMakeLists.txt @@ -10,7 +10,7 @@ include_directories( ${CMAKE_BINARY_DIR}/src ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIRS} - ${COIN3D_INCLUDE_DIR} + ${COIN3D_INCLUDE_DIRS} ${OCC_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS} ${XercesC_INCLUDE_DIRS} @@ -25,6 +25,7 @@ set(SurfaceGui_LIBS set(SurfaceGui_MOC_HDRS TaskFilling.h + TaskFillingVertex.h TaskGeomFillSurface.h ) fc_wrap_cpp(SurfaceGui_MOC_SRCS ${SurfaceGui_MOC_HDRS}) @@ -38,6 +39,7 @@ endif() SET(SurfaceGui_UIC_SRCS TaskFilling.ui + TaskFillingVertex.ui TaskGeomFillSurface.ui ) @@ -52,6 +54,8 @@ SET(SurfaceGui_SRCS ${SurfaceGui_UIC_HDRS} TaskFilling.cpp TaskFilling.h + TaskFillingVertex.cpp + TaskFillingVertex.h TaskGeomFillSurface.cpp TaskGeomFillSurface.h AppSurfaceGui.cpp diff --git a/src/Mod/Surface/Gui/TaskFilling.cpp b/src/Mod/Surface/Gui/TaskFilling.cpp index 2436461335..7f7b82b26c 100644 --- a/src/Mod/Surface/Gui/TaskFilling.cpp +++ b/src/Mod/Surface/Gui/TaskFilling.cpp @@ -1,6 +1,5 @@ /*************************************************************************** - * Copyright (c) 2015 Balázs Bámer * - * Werner Mayer * + * Copyright (c) 2017 Werner Mayer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -26,8 +25,11 @@ #include #include #include +#include #include #include +#include +#include #include #include @@ -40,6 +42,7 @@ #include #include "TaskFilling.h" +#include "TaskFillingVertex.h" #include "ui_TaskFilling.h" @@ -101,32 +104,78 @@ QIcon ViewProviderFilling::getIcon(void) const return Gui::BitmapFactory().pixmap("BSplineSurf"); } -void ViewProviderFilling::highlightReferences(bool on) +void ViewProviderFilling::highlightReferences(ShapeType type, const References& refs, bool on) { - Surface::Filling* surface = static_cast(getObject()); - auto bounds = surface->Border.getSubListValues(); - for (auto it : bounds) { + for (auto it : refs) { Part::Feature* base = dynamic_cast(it.first); if (base) { PartGui::ViewProviderPartExt* svp = dynamic_cast( Gui::Application::Instance->getViewProvider(base)); if (svp) { - if (on) { - std::vector colors; - TopTools_IndexedMapOfShape eMap; - TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, eMap); - colors.resize(eMap.Extent(), svp->LineColor.getValue()); + switch (type) { + case ViewProviderFilling::Vertex: + if (on) { + std::vector colors; + TopTools_IndexedMapOfShape vMap; + TopExp::MapShapes(base->Shape.getValue(), TopAbs_VERTEX, vMap); + colors.resize(vMap.Extent(), svp->PointColor.getValue()); - for (auto jt : it.second) { - std::size_t idx = static_cast(std::stoi(jt.substr(4)) - 1); - assert (idx < colors.size()); - colors[idx] = App::Color(1.0,0.0,1.0); // magenta + for (auto jt : it.second) { + // check again that the index is in range because it's possible that the + // sub-names are invalid + std::size_t idx = static_cast(std::stoi(jt.substr(6)) - 1); + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta + } + + svp->setHighlightedPoints(colors); } + else { + svp->unsetHighlightedPoints(); + } + break; + case ViewProviderFilling::Edge: + if (on) { + std::vector colors; + TopTools_IndexedMapOfShape eMap; + TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, eMap); + colors.resize(eMap.Extent(), svp->LineColor.getValue()); - svp->setHighlightedEdges(colors); - } - else { - svp->unsetHighlightedEdges(); + for (auto jt : it.second) { + std::size_t idx = static_cast(std::stoi(jt.substr(4)) - 1); + // check again that the index is in range because it's possible that the + // sub-names are invalid + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta + } + + svp->setHighlightedEdges(colors); + } + else { + svp->unsetHighlightedEdges(); + } + break; + case ViewProviderFilling::Face: + if (on) { + std::vector colors; + TopTools_IndexedMapOfShape fMap; + TopExp::MapShapes(base->Shape.getValue(), TopAbs_FACE, fMap); + colors.resize(fMap.Extent(), svp->ShapeColor.getValue()); + + for (auto jt : it.second) { + std::size_t idx = static_cast(std::stoi(jt.substr(4)) - 1); + // check again that the index is in range because it's possible that the + // sub-names are invalid + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta + } + + svp->setHighlightedFaces(colors); + } + else { + svp->unsetHighlightedFaces(); + } + break; } } } @@ -138,12 +187,16 @@ void ViewProviderFilling::highlightReferences(bool on) class FillingPanel::ShapeSelection : public Gui::SelectionFilterGate { public: - ShapeSelection(FillingPanel::SelectionMode mode, Surface::Filling* editedObject) + ShapeSelection(FillingPanel::SelectionMode& mode, Surface::Filling* editedObject) : Gui::SelectionFilterGate(static_cast(nullptr)) , mode(mode) , editedObject(editedObject) { } + ~ShapeSelection() + { + mode = FillingPanel::None; + } /** * Allow the user to pick only edges. */ @@ -171,7 +224,7 @@ public: } private: - bool allowFace(App::DocumentObject* pObj, const char* sSubName) + bool allowFace(App::DocumentObject*, const char* sSubName) { std::string element(sSubName); if (element.substr(0,4) != "Face") @@ -184,7 +237,7 @@ private: if (element.substr(0,4) != "Edge") return false; - auto links = editedObject->Border.getSubListValues(); + auto links = editedObject->BoundaryEdges.getSubListValues(); for (auto it : links) { if (it.first == pObj) { for (auto jt : it.second) { @@ -198,7 +251,7 @@ private: } private: - FillingPanel::SelectionMode mode; + FillingPanel::SelectionMode& mode; Surface::Filling* editedObject; }; @@ -208,6 +261,8 @@ FillingPanel::FillingPanel(ViewProviderFilling* vp, Surface::Filling* obj) { ui = new Ui_TaskFilling(); ui->setupUi(this); + ui->statusLabel->clear(); + selectionMode = None; this->vp = vp; checkCommand = true; @@ -216,9 +271,9 @@ FillingPanel::FillingPanel(ViewProviderFilling* vp, Surface::Filling* obj) // Create context menu QAction* action = new QAction(tr("Remove"), this); action->setShortcut(QString::fromLatin1("Del")); - ui->listWidget->addAction(action); + ui->listBoundary->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(onDeleteEdge())); - ui->listWidget->setContextMenuPolicy(Qt::ActionsContextMenu); + ui->listBoundary->setContextMenuPolicy(Qt::ActionsContextMenu); } /* @@ -235,6 +290,7 @@ void FillingPanel::setEditedObject(Surface::Filling* obj) { editedObject = obj; + // get the link to the initial surface if set App::DocumentObject* initFace = editedObject->InitialFace.getValue(); const std::vector& subList = editedObject->InitialFace.getSubValues(); if (initFace && subList.size() == 1) { @@ -244,27 +300,56 @@ void FillingPanel::setEditedObject(Surface::Filling* obj) ui->lineInitFaceName->setText(text); } - auto objects = editedObject->Border.getValues(); - auto element = editedObject->Border.getSubValues(); - auto it = objects.begin(); - auto jt = element.begin(); + // get the boundary edges, if set their adjacent faces and continuities + auto objects = editedObject->BoundaryEdges.getValues(); + auto edges = editedObject->BoundaryEdges.getSubValues(); + auto count = objects.size(); + + // fill up faces if wrong size + auto faces = editedObject->BoundaryFaces.getValues(); + if (faces.size() != edges.size()) { + faces.resize(edges.size()); + std::fill(faces.begin(), faces.end(), std::string()); + } + + // fill up continuities if wrong size + auto conts = editedObject->BoundaryOrder.getValues(); + if (edges.size() != conts.size()) { + conts.resize(edges.size()); + std::fill(conts.begin(), conts.end(), static_cast(GeomAbs_C0)); + } App::Document* doc = editedObject->getDocument(); - for (; it != objects.end() && jt != element.end(); ++it, ++jt) { - QListWidgetItem* item = new QListWidgetItem(ui->listWidget); - ui->listWidget->addItem(item); + for (std::size_t i=0; ilistBoundary); + ui->listBoundary->addItem(item); QString text = QString::fromLatin1("%1.%2") - .arg(QString::fromUtf8((*it)->Label.getValue())) - .arg(QString::fromStdString(*jt)); + .arg(QString::fromUtf8(obj->Label.getValue())) + .arg(QString::fromStdString(edge)); item->setText(text); + // The user data field of a list widget item + // is a list of five elementa: + // 1. document name + // 2. object name + // 3. sub-element name of the edge + // 4. sub-element of an adjacent face or empty string + // 5. the continuity as int QList data; data << QByteArray(doc->getName()); - data << QByteArray((*it)->getNameInDocument()); - data << QByteArray(jt->c_str()); + data << QByteArray(obj->getNameInDocument()); + data << QByteArray(edge.c_str()); + data << QByteArray(face.c_str()); + data << static_cast(conts[i]); item->setData(Qt::UserRole, data); } + + // attach this document observer attachDocument(Gui::Application::Instance->getDocument(doc)); } @@ -281,7 +366,17 @@ void FillingPanel::changeEvent(QEvent *e) void FillingPanel::open() { checkOpenCommand(); - this->vp->highlightReferences(true); + + // highlight the boundary edges + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), true); + + // highlight the referenced face + std::vector links; + links.push_back(std::make_pair(editedObject->InitialFace.getValue(), + editedObject->InitialFace.getSubValues())); + this->vp->highlightReferences(ViewProviderFilling::Face, links, true); + Gui::Selection().clearSelection(); } @@ -310,6 +405,22 @@ void FillingPanel::slotRedoDocument(const Gui::Document&) checkCommand = true; } +void FillingPanel::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) +{ + // If this view provider is being deleted then reset the colors of + // referenced part objects. The dialog will be deleted later. + if (this->vp == &Obj) { + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), false); + + // unhighlight the referenced face + std::vector links; + links.push_back(std::make_pair(editedObject->InitialFace.getValue(), + editedObject->InitialFace.getSubValues())); + this->vp->highlightReferences(ViewProviderFilling::Face, links, false); + } +} + bool FillingPanel::accept() { selectionMode = None; @@ -323,23 +434,32 @@ bool FillingPanel::accept() return false; } - this->vp->highlightReferences(false); + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), false); + + // unhighlight the referenced face + std::vector links; + links.push_back(std::make_pair(editedObject->InitialFace.getValue(), + editedObject->InitialFace.getSubValues())); + this->vp->highlightReferences(ViewProviderFilling::Face, links, false); - Gui::Command::commitCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); - Gui::Command::updateActive(); return true; } bool FillingPanel::reject() { - this->vp->highlightReferences(false); + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), false); + + // unhighlight the referenced face + std::vector links; + links.push_back(std::make_pair(editedObject->InitialFace.getValue(), + editedObject->InitialFace.getSubValues())); + this->vp->highlightReferences(ViewProviderFilling::Face, links, false); + selectionMode = None; Gui::Selection().rmvSelectionGate(); - Gui::Command::abortCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); - Gui::Command::updateActive(); return true; } @@ -347,6 +467,13 @@ void FillingPanel::on_lineInitFaceName_textChanged(const QString& text) { if (text.isEmpty()) { checkOpenCommand(); + + // unhighlight the referenced face + std::vector links; + links.push_back(std::make_pair(editedObject->InitialFace.getValue(), + editedObject->InitialFace.getSubValues())); + this->vp->highlightReferences(ViewProviderFilling::Face, links, false); + editedObject->InitialFace.setValue(nullptr); editedObject->recomputeFeature(); } @@ -354,20 +481,89 @@ void FillingPanel::on_lineInitFaceName_textChanged(const QString& text) void FillingPanel::on_buttonInitFace_clicked() { - selectionMode = InitFace; + // 'selectionMode' is passed by reference and changed when the filter is deleted Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject)); + selectionMode = InitFace; } void FillingPanel::on_buttonEdgeAdd_clicked() { - selectionMode = AppendEdge; + // 'selectionMode' is passed by reference and changed when the filter is deleted Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject)); + selectionMode = AppendEdge; } void FillingPanel::on_buttonEdgeRemove_clicked() { - selectionMode = RemoveEdge; + // 'selectionMode' is passed by reference and changed when the filter is deleted Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject)); + selectionMode = RemoveEdge; +} + +void FillingPanel::on_listBoundary_itemDoubleClicked(QListWidgetItem* item) +{ + Gui::Selection().clearSelection(); + Gui::Selection().rmvSelectionGate(); + selectionMode = None; + + ui->comboBoxFaces->clear(); + ui->comboBoxCont->clear(); + + if (item) { + QList data; + data = item->data(Qt::UserRole).toList(); + + try { + App::Document* doc = App::GetApplication().getDocument(data[0].toByteArray()); + App::DocumentObject* obj = doc ? doc->getObject(data[1].toByteArray()) : nullptr; + if (obj && obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + const Part::TopoShape& shape = static_cast(obj)->Shape.getShape(); + TopoDS_Shape edge = shape.getSubShape(data[2].toByteArray()); + + // build up map edge->face + TopTools_IndexedMapOfShape faces; + TopExp::MapShapes(shape.getShape(), TopAbs_FACE, faces); + TopTools_IndexedDataMapOfShapeListOfShape edge2Face; + TopExp::MapShapesAndAncestors(shape.getShape(), TopAbs_EDGE, TopAbs_FACE, edge2Face); + const TopTools_ListOfShape& adj_faces = edge2Face.FindFromKey(edge); + if (adj_faces.Extent() > 0) { + int n = adj_faces.Extent(); + ui->statusLabel->setText(tr("Edge has %n adjacent face(s)", 0, n)); + + // fill up the combo boxes + modifyBoundary(true); + ui->comboBoxFaces->addItem(tr("None"), QByteArray("")); + ui->comboBoxCont->addItem(QString::fromLatin1("C0"), static_cast(GeomAbs_C0)); + ui->comboBoxCont->addItem(QString::fromLatin1("G1"), static_cast(GeomAbs_G1)); + ui->comboBoxCont->addItem(QString::fromLatin1("G2"), static_cast(GeomAbs_G2)); + TopTools_ListIteratorOfListOfShape it(adj_faces); + for (; it.More(); it.Next()) { + const TopoDS_Shape& F = it.Value(); + int index = faces.FindIndex(F); + QString text = QString::fromLatin1("Face%1").arg(index); + ui->comboBoxFaces->addItem(text, text.toLatin1()); + } + + // activste face and continuity + if (data.size() == 5) { + int index = ui->comboBoxFaces->findData(data[3]); + ui->comboBoxFaces->setCurrentIndex(index); + index = ui->comboBoxCont->findData(data[4]); + ui->comboBoxCont->setCurrentIndex(index); + } + } + else { + ui->statusLabel->setText(tr("Edge has no adjacent faces")); + } + } + + Gui::Selection().addSelection(data[0].toByteArray(), + data[1].toByteArray(), + data[2].toByteArray()); + } + catch (...) { + } + } } void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg) @@ -387,14 +583,18 @@ void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg) std::vector subList; subList.push_back(msg.pSubName); editedObject->InitialFace.setValue(sel.getObject(), subList); - //this->vp->highlightReferences(true); + + // highlight the referenced face + std::vector links; + links.push_back(std::make_pair(sel.getObject(), subList)); + this->vp->highlightReferences(ViewProviderFilling::Face, links, true); Gui::Selection().rmvSelectionGate(); selectionMode = None; } else if (selectionMode == AppendEdge) { - QListWidgetItem* item = new QListWidgetItem(ui->listWidget); - ui->listWidget->addItem(item); + QListWidgetItem* item = new QListWidgetItem(ui->listBoundary); + ui->listBoundary->addItem(item); Gui::SelectionObject sel(msg); QString text = QString::fromLatin1("%1.%2") @@ -406,14 +606,31 @@ void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg) data << QByteArray(msg.pDocName); data << QByteArray(msg.pObjectName); data << QByteArray(msg.pSubName); + data << QByteArray(""); + data << static_cast(GeomAbs_C0); item->setData(Qt::UserRole, data); - auto objects = editedObject->Border.getValues(); + auto objects = editedObject->BoundaryEdges.getValues(); + std::size_t count = objects.size(); objects.push_back(sel.getObject()); - auto element = editedObject->Border.getSubValues(); + auto element = editedObject->BoundaryEdges.getSubValues(); element.push_back(msg.pSubName); - editedObject->Border.setValues(objects, element); - this->vp->highlightReferences(true); + editedObject->BoundaryEdges.setValues(objects, element); + + // extend faces and continuities lists if needed + auto faces = editedObject->BoundaryFaces.getValues(); + if (count == faces.size()) { + faces.push_back(std::string()); + editedObject->BoundaryFaces.setValues(faces); + } + auto conts = editedObject->BoundaryOrder.getValues(); + if (count == conts.size()) { + conts.push_back(static_cast(GeomAbs_C0)); + editedObject->BoundaryOrder.setValues(conts); + } + + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), true); } else if (selectionMode == RemoveEdge) { Gui::SelectionObject sel(msg); @@ -421,30 +638,53 @@ void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg) data << QByteArray(msg.pDocName); data << QByteArray(msg.pObjectName); data << QByteArray(msg.pSubName); - for (int i=0; ilistWidget->count(); i++) { - QListWidgetItem* item = ui->listWidget->item(i); - if (item && item->data(Qt::UserRole) == data) { - ui->listWidget->takeItem(i); - delete item; - } - } - this->vp->highlightReferences(false); - App::DocumentObject* obj = sel.getObject(); - std::string sub = msg.pSubName; - auto objects = editedObject->Border.getValues(); - auto element = editedObject->Border.getSubValues(); - auto it = objects.begin(); - auto jt = element.begin(); - for (; it != objects.end() && jt != element.end(); ++it, ++jt) { - if (*it == obj && *jt == sub) { - objects.erase(it); - element.erase(jt); - editedObject->Border.setValues(objects, element); + // only the three first elements must match + for (int i=0; ilistBoundary->count(); i++) { + QListWidgetItem* item = ui->listBoundary->item(i); + QList userdata = item->data(Qt::UserRole).toList(); + if (userdata.mid(0,3) == data) { + ui->listBoundary->takeItem(i); + delete item; break; } } - this->vp->highlightReferences(true); + + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), false); + App::DocumentObject* obj = sel.getObject(); + std::string sub = msg.pSubName; + auto objects = editedObject->BoundaryEdges.getValues(); + auto element = editedObject->BoundaryEdges.getSubValues(); + auto it = objects.begin(); + auto jt = element.begin(); + + for (; it != objects.end() && jt != element.end(); ++it, ++jt) { + if (*it == obj && *jt == sub) { + std::size_t index = std::distance(objects.begin(), it); + + objects.erase(it); + element.erase(jt); + editedObject->BoundaryEdges.setValues(objects, element); + + // try to remove the item also from the faces + auto faces = editedObject->BoundaryFaces.getValues(); + if (index < faces.size()) { + faces.erase(faces.begin() + index); + editedObject->BoundaryFaces.setValues(faces); + } + + // try to remove the item also from the orders + auto order = editedObject->BoundaryOrder.getValues(); + if (index < order.size()) { + order.erase(order.begin() + index); + editedObject->BoundaryOrder.setValues(order); + } + break; + } + } + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), true); } editedObject->recomputeFeature(); @@ -454,46 +694,141 @@ void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg) void FillingPanel::onDeleteEdge() { - int row = ui->listWidget->currentRow(); - QListWidgetItem* item = ui->listWidget->item(row); + int row = ui->listBoundary->currentRow(); + QListWidgetItem* item = ui->listBoundary->item(row); if (item) { checkOpenCommand(); QList data; data = item->data(Qt::UserRole).toList(); - ui->listWidget->takeItem(row); + ui->listBoundary->takeItem(row); delete item; App::Document* doc = App::GetApplication().getDocument(data[0].toByteArray()); App::DocumentObject* obj = doc ? doc->getObject(data[1].toByteArray()) : nullptr; std::string sub = data[2].toByteArray().constData(); - auto objects = editedObject->Border.getValues(); - auto element = editedObject->Border.getSubValues(); + auto objects = editedObject->BoundaryEdges.getValues(); + auto element = editedObject->BoundaryEdges.getSubValues(); auto it = objects.begin(); auto jt = element.begin(); - this->vp->highlightReferences(false); + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), false); for (; it != objects.end() && jt != element.end(); ++it, ++jt) { if (*it == obj && *jt == sub) { + std::size_t index = std::distance(objects.begin(), it); + objects.erase(it); element.erase(jt); - editedObject->Border.setValues(objects, element); + editedObject->BoundaryEdges.setValues(objects, element); + + // try to remove the item also from the faces + auto faces = editedObject->BoundaryFaces.getValues(); + if (index < faces.size()) { + faces.erase(faces.begin() + index); + editedObject->BoundaryFaces.setValues(faces); + } + + // try to remove the item also from the orders + auto order = editedObject->BoundaryOrder.getValues(); + if (index < order.size()) { + order.erase(order.begin() + index); + editedObject->BoundaryOrder.setValues(order); + } break; } } - this->vp->highlightReferences(true); + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), true); + + editedObject->recomputeFeature(); } } +void FillingPanel::on_buttonAccept_clicked() +{ + QListWidgetItem* item = ui->listBoundary->currentItem(); + if (item) { + QList data; + data = item->data(Qt::UserRole).toList(); + + QVariant face = ui->comboBoxFaces->itemData(ui->comboBoxFaces->currentIndex()); + QVariant cont = ui->comboBoxCont->itemData(ui->comboBoxCont->currentIndex()); + if (data.size() == 5) { + data[3] = face; + data[4] = cont; + } + else { + data << face; + data << cont; + } + + item->setData(Qt::UserRole, data); + + std::size_t index = ui->listBoundary->row(item); + + // try to set the item of the faces + auto faces = editedObject->BoundaryFaces.getValues(); + if (index < faces.size()) { + faces[index] = face.toByteArray().data(); + editedObject->BoundaryFaces.setValues(faces); + } + + // try to set the item of the orders + auto order = editedObject->BoundaryOrder.getValues(); + if (index < order.size()) { + order[index] = cont.toInt(); + editedObject->BoundaryOrder.setValues(order); + } + } + + modifyBoundary(false); + ui->comboBoxFaces->clear(); + ui->comboBoxCont->clear(); + ui->statusLabel->clear(); + + editedObject->recomputeFeature(); +} + +void FillingPanel::on_buttonIgnore_clicked() +{ + modifyBoundary(false); + ui->comboBoxFaces->clear(); + ui->comboBoxCont->clear(); + ui->statusLabel->clear(); +} + +void FillingPanel::modifyBoundary(bool on) +{ + ui->buttonInitFace->setDisabled(on); + ui->lineInitFaceName->setDisabled(on); + ui->buttonEdgeAdd->setDisabled(on); + ui->buttonEdgeRemove->setDisabled(on); + ui->listBoundary->setDisabled(on); + + ui->comboBoxFaces->setEnabled(on); + ui->comboBoxCont->setEnabled(on); + ui->buttonAccept->setEnabled(on); + ui->buttonIgnore->setEnabled(on); +} + // ---------------------------------------------------------------------------- TaskFilling::TaskFilling(ViewProviderFilling* vp, Surface::Filling* obj) { - widget = new FillingPanel(vp, obj); - widget->setWindowTitle(QObject::tr("Surface")); - taskbox = new Gui::TaskView::TaskBox( + // first task box + widget1 = new FillingPanel(vp, obj); + Gui::TaskView::TaskBox* taskbox1 = new Gui::TaskView::TaskBox( Gui::BitmapFactory().pixmap("BezSurf"), - widget->windowTitle(), true, 0); - taskbox->groupLayout()->addWidget(widget); - Content.push_back(taskbox); + widget1->windowTitle(), true, 0); + taskbox1->groupLayout()->addWidget(widget1); + Content.push_back(taskbox1); + + // second task box + widget2 = new FillingVertexPanel(vp, obj); + Gui::TaskView::TaskBox* taskbox2 = new Gui::TaskView::TaskBox( + QPixmap(), widget2->windowTitle(), true, 0); + taskbox2->groupLayout()->addWidget(widget2); + Content.push_back(taskbox2); + taskbox2->hideGroupBox(); } TaskFilling::~TaskFilling() @@ -503,22 +838,39 @@ TaskFilling::~TaskFilling() void TaskFilling::setEditedObject(Surface::Filling* obj) { - widget->setEditedObject(obj); + widget1->setEditedObject(obj); } void TaskFilling::open() { - widget->open(); + widget1->open(); + widget2->open(); } bool TaskFilling::accept() { - return widget->accept(); + bool ok = widget1->accept(); + if (ok) { + widget2->reject(); + Gui::Command::commitCommand(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + Gui::Command::updateActive(); + } + + return ok; } bool TaskFilling::reject() { - return widget->reject(); + bool ok = widget1->reject(); + if (ok) { + widget2->reject(); + Gui::Command::abortCommand(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + Gui::Command::updateActive(); + } + + return ok; } } diff --git a/src/Mod/Surface/Gui/TaskFilling.h b/src/Mod/Surface/Gui/TaskFilling.h index ce56c7b3b8..157c2172c5 100644 --- a/src/Mod/Surface/Gui/TaskFilling.h +++ b/src/Mod/Surface/Gui/TaskFilling.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2015 Balázs Bámer * + * Copyright (c) 2017 Werner Mayer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -31,20 +31,26 @@ #include #include +class QListWidgetItem; + namespace SurfaceGui { +class FillingVertexPanel; class Ui_TaskFilling; class ViewProviderFilling : public PartGui::ViewProviderSpline { PROPERTY_HEADER(SurfaceGui::ViewProviderFilling); + typedef std::vector References; + public: + enum ShapeType {Vertex, Edge, Face}; virtual void setupContextMenu(QMenu*, QObject*, const char*); virtual bool setEdit(int ModNum); virtual void unsetEdit(int ModNum); QIcon getIcon(void) const; - void highlightReferences(bool on); + void highlightReferences(ShapeType type, const References& refs, bool on); }; class FillingPanel : public QWidget, @@ -81,12 +87,18 @@ protected: virtual void slotUndoDocument(const Gui::Document& Doc); /** Notifies on redo */ virtual void slotRedoDocument(const Gui::Document& Doc); + /** Notifies when the object is about to be removed. */ + virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj); + void modifyBoundary(bool); private Q_SLOTS: void on_buttonInitFace_clicked(); void on_buttonEdgeAdd_clicked(); void on_buttonEdgeRemove_clicked(); void on_lineInitFaceName_textChanged(const QString&); + void on_listBoundary_itemDoubleClicked(QListWidgetItem*); + void on_buttonAccept_clicked(); + void on_buttonIgnore_clicked(); void onDeleteEdge(void); void clearSelection(); }; @@ -109,8 +121,8 @@ public: { return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; } private: - FillingPanel* widget; - Gui::TaskView::TaskBox* taskbox; + FillingPanel* widget1; + FillingVertexPanel* widget2; }; } //namespace SurfaceGui diff --git a/src/Mod/Surface/Gui/TaskFilling.ui b/src/Mod/Surface/Gui/TaskFilling.ui index 733779d10f..42c41f8e1e 100644 --- a/src/Mod/Surface/Gui/TaskFilling.ui +++ b/src/Mod/Surface/Gui/TaskFilling.ui @@ -19,7 +19,7 @@ Filling - + @@ -39,43 +39,135 @@ - - - - - true - - - - 0 - 0 - - - - Add Edge - - - false - - - - - - - - 0 - 0 - - - - Remove Edge - - - - - - - + + + Boundary + + + + + + + + + + 0 + 0 + + + + Faces: + + + + + + + false + + + + + + + + 0 + 0 + + + + Continuity: + + + + + + + false + + + + + + + Qt::Horizontal + + + QSizePolicy::Maximum + + + + 74 + 20 + + + + + + + + false + + + Accept + + + + + + + false + + + Ignore + + + + + + + + + true + + + + 0 + 0 + + + + Add Edge + + + false + + + + + + + + 0 + 0 + + + + Remove Edge + + + + + + + + + Status messages + + + + + diff --git a/src/Mod/Surface/Gui/TaskFillingVertex.cpp b/src/Mod/Surface/Gui/TaskFillingVertex.cpp new file mode 100644 index 0000000000..b39d0fd334 --- /dev/null +++ b/src/Mod/Surface/Gui/TaskFillingVertex.cpp @@ -0,0 +1,355 @@ +/*************************************************************************** + * Copyright (c) 2017 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "TaskFillingVertex.h" +#include "ui_TaskFillingVertex.h" +#include "TaskFilling.h" + + +using namespace SurfaceGui; + +namespace SurfaceGui { + +class FillingVertexPanel::VertexSelection : public Gui::SelectionFilterGate +{ +public: + VertexSelection(FillingVertexPanel::SelectionMode& mode, Surface::Filling* editedObject) + : Gui::SelectionFilterGate(static_cast(nullptr)) + , mode(mode) + , editedObject(editedObject) + { + } + ~VertexSelection() + { + mode = FillingVertexPanel::None; + } + /** + * Allow the user to pick only edges. + */ + bool allow(App::Document*, App::DocumentObject* pObj, const char* sSubName) + { + // don't allow references to itself + if (pObj == editedObject) + return false; + if (!pObj->isDerivedFrom(Part::Feature::getClassTypeId())) + return false; + + if (!sSubName || sSubName[0] == '\0') + return false; + + switch (mode) { + case FillingVertexPanel::AppendVertex: + return allowVertex(true, pObj, sSubName); + case FillingVertexPanel::RemoveVertex: + return allowVertex(false, pObj, sSubName); + default: + return false; + } + } + +private: + bool allowVertex(bool appendVertex, App::DocumentObject* pObj, const char* sSubName) + { + std::string element(sSubName); + if (element.substr(0,6) != "Vertex") + return false; + + auto links = editedObject->Points.getSubListValues(); + for (auto it : links) { + if (it.first == pObj) { + for (auto jt : it.second) { + if (jt == sSubName) + return !appendVertex; + } + } + } + + return appendVertex; + } + +private: + FillingVertexPanel::SelectionMode& mode; + Surface::Filling* editedObject; +}; + +// ---------------------------------------------------------------------------- + +FillingVertexPanel::FillingVertexPanel(ViewProviderFilling* vp, Surface::Filling* obj) +{ + ui = new Ui_TaskFillingVertex(); + ui->setupUi(this); + + selectionMode = None; + this->vp = vp; + checkCommand = true; + setEditedObject(obj); + + // Create context menu + QAction* action = new QAction(tr("Remove"), this); + action->setShortcut(QString::fromLatin1("Del")); + ui->listFreeVertex->addAction(action); + connect(action, SIGNAL(triggered()), this, SLOT(onDeleteVertex())); + ui->listFreeVertex->setContextMenuPolicy(Qt::ActionsContextMenu); +} + +/* + * Destroys the object and frees any allocated resources + */ +FillingVertexPanel::~FillingVertexPanel() +{ + // no need to delete child widgets, Qt does it all for us + delete ui; + Gui::Selection().rmvSelectionGate(); +} + +// stores object pointer, its old fill type and adjusts radio buttons according to it. +void FillingVertexPanel::setEditedObject(Surface::Filling* obj) +{ + editedObject = obj; + + auto objects = editedObject->Points.getValues(); + auto element = editedObject->Points.getSubValues(); + auto it = objects.begin(); + auto jt = element.begin(); + + App::Document* doc = editedObject->getDocument(); + for (; it != objects.end() && jt != element.end(); ++it, ++jt) { + QListWidgetItem* item = new QListWidgetItem(ui->listFreeVertex); + ui->listFreeVertex->addItem(item); + + QString text = QString::fromLatin1("%1.%2") + .arg(QString::fromUtf8((*it)->Label.getValue())) + .arg(QString::fromStdString(*jt)); + item->setText(text); + + QList data; + data << QByteArray(doc->getName()); + data << QByteArray((*it)->getNameInDocument()); + data << QByteArray(jt->c_str()); + item->setData(Qt::UserRole, data); + } + attachDocument(Gui::Application::Instance->getDocument(doc)); +} + +void FillingVertexPanel::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } + else { + QWidget::changeEvent(e); + } +} + +void FillingVertexPanel::open() +{ + checkOpenCommand(); + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), true); + Gui::Selection().clearSelection(); +} + +void FillingVertexPanel::reject() +{ + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), false); +} + +void FillingVertexPanel::clearSelection() +{ + Gui::Selection().clearSelection(); +} + +void FillingVertexPanel::checkOpenCommand() +{ + if (checkCommand && !Gui::Command::hasPendingCommand()) { + std::string Msg("Edit "); + Msg += editedObject->Label.getValue(); + Gui::Command::openCommand(Msg.c_str()); + checkCommand = false; + } +} + +void FillingVertexPanel::slotUndoDocument(const Gui::Document&) +{ + checkCommand = true; +} + +void FillingVertexPanel::slotRedoDocument(const Gui::Document&) +{ + checkCommand = true; +} + +void FillingVertexPanel::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) +{ + // If this view provider is being deleted then reset the colors of + // referenced part objects. The dialog will be deleted later. + if (this->vp == &Obj) { + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), false); + } +} + +void FillingVertexPanel::on_buttonVertexAdd_clicked() +{ + // 'selectionMode' is passed by reference and changed when the filter is deleted + Gui::Selection().addSelectionGate(new VertexSelection(selectionMode, editedObject)); + selectionMode = AppendVertex; +} + +void FillingVertexPanel::on_buttonVertexRemove_clicked() +{ + // 'selectionMode' is passed by reference and changed when the filter is deleted + Gui::Selection().addSelectionGate(new VertexSelection(selectionMode, editedObject)); + selectionMode = RemoveVertex; +} + +void FillingVertexPanel::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if (selectionMode == None) + return; + + if (msg.Type == Gui::SelectionChanges::AddSelection) { + checkOpenCommand(); + if (selectionMode == AppendVertex) { + QListWidgetItem* item = new QListWidgetItem(ui->listFreeVertex); + ui->listFreeVertex->addItem(item); + + Gui::SelectionObject sel(msg); + QString text = QString::fromLatin1("%1.%2") + .arg(QString::fromUtf8(sel.getObject()->Label.getValue())) + .arg(QString::fromLatin1(msg.pSubName)); + item->setText(text); + + QList data; + data << QByteArray(msg.pDocName); + data << QByteArray(msg.pObjectName); + data << QByteArray(msg.pSubName); + item->setData(Qt::UserRole, data); + + auto objects = editedObject->Points.getValues(); + objects.push_back(sel.getObject()); + auto element = editedObject->Points.getSubValues(); + element.push_back(msg.pSubName); + editedObject->Points.setValues(objects, element); + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), true); + } + else if (selectionMode == RemoveVertex) { + Gui::SelectionObject sel(msg); + QList data; + data << QByteArray(msg.pDocName); + data << QByteArray(msg.pObjectName); + data << QByteArray(msg.pSubName); + for (int i=0; ilistFreeVertex->count(); i++) { + QListWidgetItem* item = ui->listFreeVertex->item(i); + if (item && item->data(Qt::UserRole) == data) { + ui->listFreeVertex->takeItem(i); + delete item; + } + } + + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), false); + App::DocumentObject* obj = sel.getObject(); + std::string sub = msg.pSubName; + auto objects = editedObject->Points.getValues(); + auto element = editedObject->Points.getSubValues(); + auto it = objects.begin(); + auto jt = element.begin(); + for (; it != objects.end() && jt != element.end(); ++it, ++jt) { + if (*it == obj && *jt == sub) { + objects.erase(it); + element.erase(jt); + editedObject->Points.setValues(objects, element); + break; + } + } + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), true); + } + + editedObject->recomputeFeature(); + QTimer::singleShot(50, this, SLOT(clearSelection())); + } +} + +void FillingVertexPanel::onDeleteVertex() +{ + int row = ui->listFreeVertex->currentRow(); + QListWidgetItem* item = ui->listFreeVertex->item(row); + if (item) { + checkOpenCommand(); + QList data; + data = item->data(Qt::UserRole).toList(); + ui->listFreeVertex->takeItem(row); + delete item; + + App::Document* doc = App::GetApplication().getDocument(data[0].toByteArray()); + App::DocumentObject* obj = doc ? doc->getObject(data[1].toByteArray()) : nullptr; + std::string sub = data[2].toByteArray().constData(); + auto objects = editedObject->Points.getValues(); + auto element = editedObject->Points.getSubValues(); + auto it = objects.begin(); + auto jt = element.begin(); + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), false); + + for (; it != objects.end() && jt != element.end(); ++it, ++jt) { + if (*it == obj && *jt == sub) { + objects.erase(it); + element.erase(jt); + editedObject->Points.setValues(objects, element); + editedObject->recomputeFeature(); + break; + } + } + + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), true); + } +} + +} + +#include "moc_TaskFillingVertex.cpp" diff --git a/src/Mod/Surface/Gui/TaskFillingVertex.h b/src/Mod/Surface/Gui/TaskFillingVertex.h new file mode 100644 index 0000000000..7b67493425 --- /dev/null +++ b/src/Mod/Surface/Gui/TaskFillingVertex.h @@ -0,0 +1,87 @@ +/*************************************************************************** + * Copyright (c) 2017 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef SURFACEGUI_TASKFILLINGVERTEX_H +#define SURFACEGUI_TASKFILLINGVERTEX_H + +#include +#include +#include +#include +#include +#include +#include + +class QListWidgetItem; + +namespace SurfaceGui +{ + +class ViewProviderFilling; +class Ui_TaskFillingVertex; + +class FillingVertexPanel : public QWidget, + public Gui::SelectionObserver, + public Gui::DocumentObserver +{ + Q_OBJECT + +protected: + class VertexSelection; + enum SelectionMode { None, AppendVertex, RemoveVertex }; + SelectionMode selectionMode; + Surface::Filling* editedObject; + bool checkCommand; + +private: + Ui_TaskFillingVertex* ui; + ViewProviderFilling* vp; + +public: + FillingVertexPanel(ViewProviderFilling* vp, Surface::Filling* obj); + ~FillingVertexPanel(); + + void open(); + void reject(); + void checkOpenCommand(); + void setEditedObject(Surface::Filling* obj); + +protected: + void changeEvent(QEvent *e); + virtual void onSelectionChanged(const Gui::SelectionChanges& msg); + /** Notifies on undo */ + virtual void slotUndoDocument(const Gui::Document& Doc); + /** Notifies on redo */ + virtual void slotRedoDocument(const Gui::Document& Doc); + /** Notifies when the object is about to be removed. */ + virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj); + +private Q_SLOTS: + void on_buttonVertexAdd_clicked(); + void on_buttonVertexRemove_clicked(); + void onDeleteVertex(void); + void clearSelection(); +}; + +} //namespace SurfaceGui + +#endif // SURFACEGUI_TASKFILLINGVERTEX_H diff --git a/src/Mod/Surface/Gui/TaskFillingVertex.ui b/src/Mod/Surface/Gui/TaskFillingVertex.ui new file mode 100644 index 0000000000..7e939ad7e8 --- /dev/null +++ b/src/Mod/Surface/Gui/TaskFillingVertex.ui @@ -0,0 +1,69 @@ + + + SurfaceGui::TaskFillingVertex + + + + 0 + 0 + 273 + 329 + + + + Vertexes + + + + + + Unbound vertexes + + + + + + + + true + + + + 0 + 0 + + + + Add Vertex + + + false + + + + + + + + 0 + 0 + + + + Remove Vertex + + + + + + + + + + + + + + + + diff --git a/src/Mod/Surface/Gui/TaskGeomFillSurface.cpp b/src/Mod/Surface/Gui/TaskGeomFillSurface.cpp index 19ddc7037c..ae9ec5eb36 100644 --- a/src/Mod/Surface/Gui/TaskGeomFillSurface.cpp +++ b/src/Mod/Surface/Gui/TaskGeomFillSurface.cpp @@ -297,9 +297,17 @@ void GeomFillSurface::slotRedoDocument(const Gui::Document&) checkCommand = true; } +void GeomFillSurface::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) +{ + // If this view provider is being deleted then reset the colors of + // referenced part objects. The dialog will be deleted later. + if (this->vp == &Obj) { + this->vp->highlightReferences(false); + } +} + bool GeomFillSurface::accept() { - this->vp->highlightReferences(false); selectionMode = None; Gui::Selection().rmvSelectionGate(); @@ -325,6 +333,8 @@ bool GeomFillSurface::accept() return false; } + this->vp->highlightReferences(false); + Gui::Command::commitCommand(); Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); Gui::Command::updateActive(); diff --git a/src/Mod/Surface/Gui/TaskGeomFillSurface.h b/src/Mod/Surface/Gui/TaskGeomFillSurface.h index 8ba76034ec..1ed15fa287 100644 --- a/src/Mod/Surface/Gui/TaskGeomFillSurface.h +++ b/src/Mod/Surface/Gui/TaskGeomFillSurface.h @@ -82,6 +82,8 @@ protected: virtual void slotUndoDocument(const Gui::Document& Doc); /** Notifies on redo */ virtual void slotRedoDocument(const Gui::Document& Doc); + /** Notifies when the object is about to be removed. */ + virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj); void changeFillType(GeomFill_FillingStyle); private Q_SLOTS: