Part: Offset feature: split off into separate file

withdrew code from PartFeatures.h/.cpp and created FeatureOffset.h/.cpp
This commit is contained in:
DeepSOIC 2016-09-02 00:39:59 +03:00 committed by wmayer
parent 7f6872817a
commit 1f6174e3f2
8 changed files with 165 additions and 95 deletions

View File

@ -49,6 +49,7 @@
#include "FeatureFillet.h"
#include "FeatureMirroring.h"
#include "FeatureRevolution.h"
#include "FeatureOffset.h"
#include "PartFeatures.h"
#include "BodyBase.h"
#include "PrimitiveFeature.h"

View File

@ -124,6 +124,8 @@ SET(Features_SRCS
FeatureMirroring.h
FeatureRevolution.cpp
FeatureRevolution.h
FeatureOffset.cpp
FeatureOffset.h
PartFeatures.cpp
PartFeatures.h
PartFeature.cpp

View File

@ -0,0 +1,95 @@
/***************************************************************************
* Copyright (c) 2016 Victor Titov (DeepSOIC) <vv.titov@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"
#ifndef _PreComp_
# include <Precision.hxx>
#endif
#include "FeatureOffset.h"
using namespace Part;
const char* Part::Offset::ModeEnums[]= {"Skin","Pipe", "RectoVerso",NULL};
const char* Part::Offset::JoinEnums[]= {"Arc","Tangent", "Intersection",NULL};
PROPERTY_SOURCE(Part::Offset, Part::Feature)
Offset::Offset()
{
ADD_PROPERTY_TYPE(Source,(0),"Offset",App::Prop_None,"Source shape");
ADD_PROPERTY_TYPE(Value,(1.0),"Offset",App::Prop_None,"Offset value");
ADD_PROPERTY_TYPE(Mode,(long(0)),"Offset",App::Prop_None,"Mode");
Mode.setEnums(ModeEnums);
ADD_PROPERTY_TYPE(Join,(long(0)),"Offset",App::Prop_None,"Join type");
Join.setEnums(JoinEnums);
ADD_PROPERTY_TYPE(Intersection,(false),"Offset",App::Prop_None,"Intersection");
ADD_PROPERTY_TYPE(SelfIntersection,(false),"Offset",App::Prop_None,"Self Intersection");
ADD_PROPERTY_TYPE(Fill,(false),"Offset",App::Prop_None,"Fill offset");
}
Offset::~Offset()
{
}
short Offset::mustExecute() const
{
if (Source.isTouched())
return 1;
if (Value.isTouched())
return 1;
if (Mode.isTouched())
return 1;
if (Join.isTouched())
return 1;
if (Intersection.isTouched())
return 1;
if (SelfIntersection.isTouched())
return 1;
if (Fill.isTouched())
return 1;
return 0;
}
App::DocumentObjectExecReturn *Offset::execute(void)
{
App::DocumentObject* source = Source.getValue();
if (!(source && source->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
return new App::DocumentObjectExecReturn("No source shape linked.");
double offset = Value.getValue();
double tol = Precision::Confusion();
bool inter = Intersection.getValue();
bool self = SelfIntersection.getValue();
short mode = (short)Mode.getValue();
short join = (short)Join.getValue();
bool fill = Fill.getValue();
const TopoShape& shape = static_cast<Part::Feature*>(source)->Shape.getShape();
if (fabs(offset) > 2*tol)
this->Shape.setValue(shape.makeOffsetShape(offset, tol, inter, self, mode, join, fill));
else
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}

View File

@ -0,0 +1,65 @@
/***************************************************************************
* Copyright (c) 2016 Victor Titov (DeepSOIC) <vv.titov@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 PART_FEATUREOFFSET_H
#define PART_FEATUREOFFSET_H
#include <App/PropertyStandard.h>
#include <App/PropertyUnits.h>
#include <Mod/Part/App/PartFeature.h>
namespace Part
{
class PartExport Offset : public Part::Feature
{
PROPERTY_HEADER(Part::Offset);
public:
Offset();
~Offset();
App::PropertyLink Source;
App::PropertyFloat Value;
App::PropertyEnumeration Mode;
App::PropertyEnumeration Join;
App::PropertyBool Intersection;
App::PropertyBool SelfIntersection;
App::PropertyBool Fill;
/** @name methods override feature */
//@{
/// recalculate the feature
virtual App::DocumentObjectExecReturn *execute(void) override;
virtual short mustExecute() const override;
virtual const char* getViewProviderName(void) const override {
return "PartGui::ViewProviderOffset";
}
//@}
private:
static const char* ModeEnums[];
static const char* JoinEnums[];
};
}
#endif // PART_FEATUREOFFSET_H

View File

@ -476,69 +476,6 @@ App::DocumentObjectExecReturn *Sweep::execute(void)
// ----------------------------------------------------------------------------
const char* Part::Offset::ModeEnums[]= {"Skin","Pipe", "RectoVerso",NULL};
const char* Part::Offset::JoinEnums[]= {"Arc","Tangent", "Intersection",NULL};
PROPERTY_SOURCE(Part::Offset, Part::Feature)
Offset::Offset()
{
ADD_PROPERTY_TYPE(Source,(0),"Offset",App::Prop_None,"Source shape");
ADD_PROPERTY_TYPE(Value,(1.0),"Offset",App::Prop_None,"Offset value");
ADD_PROPERTY_TYPE(Mode,(long(0)),"Offset",App::Prop_None,"Mode");
Mode.setEnums(ModeEnums);
ADD_PROPERTY_TYPE(Join,(long(0)),"Offset",App::Prop_None,"Join type");
Join.setEnums(JoinEnums);
ADD_PROPERTY_TYPE(Intersection,(false),"Offset",App::Prop_None,"Intersection");
ADD_PROPERTY_TYPE(SelfIntersection,(false),"Offset",App::Prop_None,"Self Intersection");
ADD_PROPERTY_TYPE(Fill,(false),"Offset",App::Prop_None,"Fill offset");
}
Offset::~Offset()
{
}
short Offset::mustExecute() const
{
if (Source.isTouched())
return 1;
if (Value.isTouched())
return 1;
if (Mode.isTouched())
return 1;
if (Join.isTouched())
return 1;
if (Intersection.isTouched())
return 1;
if (SelfIntersection.isTouched())
return 1;
if (Fill.isTouched())
return 1;
return 0;
}
App::DocumentObjectExecReturn *Offset::execute(void)
{
App::DocumentObject* source = Source.getValue();
if (!(source && source->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
return new App::DocumentObjectExecReturn("No source shape linked.");
double offset = Value.getValue();
double tol = Precision::Confusion();
bool inter = Intersection.getValue();
bool self = SelfIntersection.getValue();
short mode = (short)Mode.getValue();
short join = (short)Join.getValue();
bool fill = Fill.getValue();
const TopoShape& shape = static_cast<Part::Feature*>(source)->Shape.getShape();
if (fabs(offset) > 2*tol)
this->Shape.setValue(shape.makeOffsetShape(offset, tol, inter, self, mode, join, fill));
else
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}
// ----------------------------------------------------------------------------
const char* Part::Thickness::ModeEnums[]= {"Skin","Pipe", "RectoVerso",NULL};
const char* Part::Thickness::JoinEnums[]= {"Arc","Tangent", "Intersection",NULL};

View File

@ -115,37 +115,6 @@ private:
static const char* TransitionEnums[];
};
class Offset : public Part::Feature
{
PROPERTY_HEADER(Part::Offset);
public:
Offset();
~Offset();
App::PropertyLink Source;
App::PropertyFloat Value;
App::PropertyEnumeration Mode;
App::PropertyEnumeration Join;
App::PropertyBool Intersection;
App::PropertyBool SelfIntersection;
App::PropertyBool Fill;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
const char* getViewProviderName(void) const {
return "PartGui::ViewProviderOffset";
}
//@}
private:
static const char* ModeEnums[];
static const char* JoinEnums[];
};
class Thickness : public Part::Feature
{
PROPERTY_HEADER(Part::Thickness);

View File

@ -45,7 +45,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Mod/Part/App/PartFeatures.h>
#include <Mod/Part/App/FeatureOffset.h>
using namespace PartGui;

View File

@ -45,6 +45,7 @@
#include <Mod/Part/App/FeatureFillet.h>
#include <Mod/Part/App/FeatureChamfer.h>
#include <Mod/Part/App/FeatureRevolution.h>
#include <Mod/Part/App/FeatureOffset.h>
#include <Mod/Part/App/PartFeatures.h>
#include <Gui/Application.h>
#include <Gui/Control.h>