PD: Add offset / overall length modes for LinearPattern
This commit adds support for two separate modes of defining distance between elements in PD's Linear Pattern. 1. Overall Length - which works exactly like it works before, 2. Spacing - which allows user to explicitly define distance (offset) between features.
This commit is contained in:
@@ -51,25 +51,42 @@ PROPERTY_SOURCE(PartDesign::LinearPattern, PartDesign::Transformed)
|
||||
|
||||
const App::PropertyIntegerConstraint::Constraints LinearPattern::intOccurrences = { 1, INT_MAX, 1 };
|
||||
|
||||
const char* LinearPattern::ModeEnums[] = { "length", "offset", nullptr };
|
||||
|
||||
LinearPattern::LinearPattern()
|
||||
{
|
||||
auto initialMode = LinearPatternMode::length;
|
||||
|
||||
ADD_PROPERTY_TYPE(Direction,(nullptr),"LinearPattern",(App::PropertyType)(App::Prop_None),"Direction");
|
||||
ADD_PROPERTY(Reversed,(0));
|
||||
ADD_PROPERTY(Mode, (long(initialMode)));
|
||||
ADD_PROPERTY(Length,(100.0));
|
||||
ADD_PROPERTY(Offset,(10.0));
|
||||
ADD_PROPERTY(Occurrences,(3));
|
||||
Occurrences.setConstraints(&intOccurrences);
|
||||
Mode.setEnums(ModeEnums);
|
||||
setReadWriteStatusForMode(initialMode);
|
||||
}
|
||||
|
||||
short LinearPattern::mustExecute() const
|
||||
{
|
||||
if (Direction.isTouched() ||
|
||||
Reversed.isTouched() ||
|
||||
Length.isTouched() ||
|
||||
Mode.isTouched() ||
|
||||
// Length and Offset are mutually exclusive, only one could be updated at once
|
||||
Length.isTouched() ||
|
||||
Offset.isTouched() ||
|
||||
Occurrences.isTouched())
|
||||
return 1;
|
||||
return Transformed::mustExecute();
|
||||
}
|
||||
|
||||
void LinearPattern::setReadWriteStatusForMode(LinearPatternMode mode)
|
||||
{
|
||||
Length.setReadOnly(mode != LinearPatternMode::length);
|
||||
Offset.setReadOnly(mode != LinearPatternMode::offset);
|
||||
}
|
||||
|
||||
const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App::DocumentObject*>)
|
||||
{
|
||||
int occurrences = Occurrences.getValue();
|
||||
@@ -173,7 +190,20 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
|
||||
dir.Transform(invObjLoc.Transformation());
|
||||
|
||||
gp_Vec offset(dir.X(), dir.Y(), dir.Z());
|
||||
offset *= distance / (occurrences - 1);
|
||||
|
||||
switch (static_cast<LinearPatternMode>(Mode.getValue())) {
|
||||
case LinearPatternMode::length:
|
||||
offset *= distance / (occurrences - 1);
|
||||
break;
|
||||
|
||||
case LinearPatternMode::offset:
|
||||
offset *= Offset.getValue();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw Base::ValueError("Invalid mode");
|
||||
}
|
||||
|
||||
if (reversed)
|
||||
offset.Reverse();
|
||||
|
||||
@@ -206,4 +236,14 @@ void LinearPattern::handleChangedPropertyType(Base::XMLReader& reader, const cha
|
||||
}
|
||||
}
|
||||
|
||||
void LinearPattern::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (prop == &Mode) {
|
||||
auto mode = static_cast<LinearPatternMode>(Mode.getValue());
|
||||
setReadWriteStatusForMode(mode);
|
||||
}
|
||||
|
||||
Transformed::onChanged(prop);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user