Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sketcher: Viewprovider B-Spline pole representation factor
========================================================== Previously for Weights, ViewProviderSketch used getScaleFactor. This caused that upon zoom change the Weights would not increase progresively, rather the would grow on the next redraw. Additionally, upon substantial zoom out, the poles would grow several times bigger than the B-Spline. This commit uses a new geometry extension intended only for ViewProviderSketch, to store a geometry specific representation scale factor. This is calculated as a function of the B-Spline length. The extension does not serialise to disk. It is just intended for runtime. Dragging from the edge when the radius is constrained gives a wrong cosmetic result, because the representation circle and the real value of the weight are different (by a scale factor). This commit prevents dragging on the edge in the most representative cases where the radius is constrained.
- Loading branch information
1 parent
95c1a26
commit 2197db0
Showing
6 changed files
with
249 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtension.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2019 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> * | ||
* * | ||
* 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 <Base/Writer.h> | ||
#include <Base/Reader.h> | ||
#include <Base/Exception.h> | ||
|
||
#include "ViewProviderSketchGeometryExtension.h" | ||
|
||
using namespace SketcherGui; | ||
|
||
//---------- Geometry Extension | ||
TYPESYSTEM_SOURCE(SketcherGui::ViewProviderSketchGeometryExtension,Part::GeometryExtension) | ||
|
||
|
||
ViewProviderSketchGeometryExtension::ViewProviderSketchGeometryExtension():RepresentationFactor(1.0) | ||
{ | ||
|
||
} | ||
|
||
|
||
// Persistence implementer | ||
unsigned int ViewProviderSketchGeometryExtension::getMemSize (void) const | ||
{ | ||
return sizeof(double); | ||
} | ||
|
||
void ViewProviderSketchGeometryExtension::Save(Base::Writer &writer) const | ||
{ | ||
(void) writer; | ||
// So far only intended for runtime | ||
} | ||
|
||
void ViewProviderSketchGeometryExtension::Restore(Base::XMLReader &reader) | ||
{ | ||
(void) reader; | ||
// So far only intended for runtime | ||
} | ||
|
||
std::unique_ptr<Part::GeometryExtension> ViewProviderSketchGeometryExtension::copy(void) const | ||
{ | ||
auto cpy = std::make_unique<ViewProviderSketchGeometryExtension>(); | ||
|
||
cpy->RepresentationFactor = this->RepresentationFactor; | ||
|
||
cpy->setName(this->getName()); // Base Class | ||
|
||
#if defined (__GNUC__) && (__GNUC__ <=4) | ||
return std::move(cpy); | ||
#else | ||
return cpy; | ||
#endif | ||
} | ||
|
||
PyObject * ViewProviderSketchGeometryExtension::getPyObject(void) | ||
{ | ||
THROWM(Base::NotImplementedError, "ViewProviderSketchGeometryExtension does not have a Python counterpart"); | ||
} |
68 changes: 68 additions & 0 deletions
68
src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtension.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2020 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> * | ||
* * | ||
* 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 SKETCHER_VIEWPROVIDERSKETCHGEOMETRYEXTENSION_H | ||
#define SKETCHER_VIEWPROVIDERSKETCHGEOMETRYEXTENSION_H | ||
|
||
#include <Mod/Part/App/Geometry.h> | ||
|
||
namespace SketcherGui { | ||
|
||
class SketcherGuiExport ViewProviderSketchGeometryExtension : public Part::GeometryExtension | ||
{ | ||
TYPESYSTEM_HEADER_WITH_OVERRIDE(); | ||
public: | ||
|
||
ViewProviderSketchGeometryExtension(); | ||
virtual ~ViewProviderSketchGeometryExtension() override = default; | ||
|
||
// Persistence implementer --------------------- | ||
virtual unsigned int getMemSize(void) const override; | ||
virtual void Save(Base::Writer &/*writer*/) const override; | ||
virtual void Restore(Base::XMLReader &/*reader*/) override; | ||
|
||
virtual std::unique_ptr<Part::GeometryExtension> copy(void) const override; | ||
|
||
virtual PyObject *getPyObject(void) override; | ||
|
||
// Data Members | ||
|
||
// Representation factor | ||
// Provides a mechanism to store a factor associated with the representation of a geometry | ||
// This is only useful when a geometry must be scaled only for representation, while keeping its value | ||
// Applicability: General abstract concepts embodied in a geometry, in practice B-Spline poles. | ||
// Why not in SketchGeometryExtension? Because it is merely representation related. It has no place in | ||
// a console application. | ||
virtual double getRepresentationFactor() const {return RepresentationFactor;} | ||
virtual void setRepresentationFactor(double representationFactor) {RepresentationFactor = representationFactor;} | ||
|
||
private: | ||
ViewProviderSketchGeometryExtension(const ViewProviderSketchGeometryExtension&) = default; | ||
|
||
private: | ||
double RepresentationFactor; | ||
}; | ||
|
||
} //namespace SketcherGui | ||
|
||
|
||
#endif // SKETCHER_VIEWPROVIDERSKETCHGEOMETRYEXTENSION_H |