Part: refactor onFlipXclicked, onFlipYclicked and onFlipZclicked of SectionCut
This commit is contained in:
@@ -1663,49 +1663,21 @@ void SectionCut::onFlipXclicked()
|
||||
{
|
||||
FlipClickedHelper(BoxXName);
|
||||
|
||||
auto CutObject = doc->getObject(CutXName);
|
||||
// there should be a cut, but maybe the user deleted it meanwhile
|
||||
if (!CutObject) {
|
||||
Base::Console().Warning((std::string("SectionCut warning: there is no ")
|
||||
+ std::string(CutXName) + std::string(", trying to recreate it\n")).c_str());
|
||||
// recreate the box
|
||||
startCutting();
|
||||
return;
|
||||
}
|
||||
|
||||
// if there is another cut, we must recalculate it too
|
||||
// the hierarchy is always Z->Y->X
|
||||
if (hasBoxY && !hasBoxZ) { // only Y
|
||||
auto CutFeatureY = doc->getObject(CutYName);
|
||||
if (!CutFeatureY) {
|
||||
Base::Console().Warning((std::string("SectionCut warning: the expected ")
|
||||
+ std::string(CutYName)
|
||||
+ std::string(" is missing, trying to recreate it\n"))
|
||||
.c_str());
|
||||
// recreate the box
|
||||
startCutting();
|
||||
return;
|
||||
if (auto CutObject = flipCutObject(CutXName)) {
|
||||
// if there is another cut, we must recalculate it too
|
||||
// the hierarchy is always Z->Y->X
|
||||
if (hasBoxY && !hasBoxZ) {
|
||||
// only Y
|
||||
CutObject = flipCutObject(CutYName);
|
||||
}
|
||||
|
||||
CutFeatureY->recomputeFeature(true);
|
||||
}
|
||||
else if ((!hasBoxY && hasBoxZ) || (hasBoxY && hasBoxZ)) { // at least Z
|
||||
// the main cut is Z, no matter if there is a cut in Y
|
||||
auto CutFeatureZ = doc->getObject(CutZName);
|
||||
if (!CutFeatureZ) {
|
||||
Base::Console().Warning((std::string("SectionCut warning: the expected ")
|
||||
+ std::string(CutZName)
|
||||
+ std::string(" is missing, trying to recreate it\n"))
|
||||
.c_str());
|
||||
// recreate the box
|
||||
startCutting();
|
||||
return;
|
||||
else if ((!hasBoxY && hasBoxZ) || (hasBoxY && hasBoxZ)) {
|
||||
// at least Z
|
||||
CutObject = flipCutObject(CutZName);
|
||||
}
|
||||
if (auto cut = dynamic_cast<Part::Cut*>(CutObject)) {
|
||||
// only do this when there is no other box to save recomputes
|
||||
cut->recomputeFeature(true);
|
||||
}
|
||||
|
||||
CutFeatureZ->recomputeFeature(true);
|
||||
}
|
||||
else { // only do this when there is no other box to save recomputes
|
||||
CutObject->recomputeFeature(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1713,24 +1685,15 @@ void SectionCut::onFlipYclicked()
|
||||
{
|
||||
FlipClickedHelper(BoxYName);
|
||||
|
||||
auto CutObject = doc->getObject(CutYName);
|
||||
// there should be a cut, but maybe the user deleted it meanwhile
|
||||
if (!CutObject) {
|
||||
Base::Console().Warning((std::string("SectionCut warning: there is no ")
|
||||
+ std::string(CutYName) + std::string(", trying to recreate it\n")).c_str());
|
||||
// recreate the box
|
||||
startCutting();
|
||||
return;
|
||||
}
|
||||
|
||||
// if there is another cut, we must recalculate it too
|
||||
// we only need to check for Z since the hierarchy is always Z->Y->X
|
||||
if (hasBoxZ) {
|
||||
auto CutFeatureZ = doc->getObject(CutZName);
|
||||
CutFeatureZ->recomputeFeature(true);
|
||||
}
|
||||
else {
|
||||
CutObject->recomputeFeature(true);
|
||||
if (auto CutObject = flipCutObject(CutYName)) {
|
||||
// if there is another cut, we must recalculate it too
|
||||
// we only need to check for Z since the hierarchy is always Z->Y->X
|
||||
if (hasBoxZ) {
|
||||
CutObject = findObject(CutZName);
|
||||
}
|
||||
if (auto cut = dynamic_cast<Part::Cut*>(CutObject)) {
|
||||
cut->recomputeFeature(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1738,17 +1701,28 @@ void SectionCut::onFlipZclicked()
|
||||
{
|
||||
FlipClickedHelper(BoxZName);
|
||||
|
||||
auto CutObject = doc->getObject(CutZName);
|
||||
if (auto CutObject = flipCutObject(CutZName)) {
|
||||
CutObject->recomputeFeature(true);
|
||||
}
|
||||
}
|
||||
|
||||
App::DocumentObject* SectionCut::findObject(const char* objName) const
|
||||
{
|
||||
return doc ? doc->getObject(objName) : nullptr;
|
||||
}
|
||||
|
||||
App::DocumentObject* SectionCut::flipCutObject(const char* cutName)
|
||||
{
|
||||
auto CutObject = findObject(cutName);
|
||||
// there should be a cut, but maybe the user deleted it meanwhile
|
||||
if (!CutObject) {
|
||||
Base::Console().Warning((std::string("SectionCut warning: there is no ")
|
||||
+ std::string(CutZName) + std::string(", trying to recreate it\n")).c_str());
|
||||
+ std::string(cutName) + std::string(", trying to recreate it\n")).c_str());
|
||||
// recreate the box
|
||||
startCutting();
|
||||
return;
|
||||
}
|
||||
|
||||
CutObject->recomputeFeature(true);
|
||||
return CutObject;
|
||||
}
|
||||
|
||||
// changes the cutface color
|
||||
|
||||
@@ -72,13 +72,6 @@ public:
|
||||
void reject() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_SectionCut> ui;
|
||||
std::vector<App::DocumentObjectT> ObjectsListVisible;
|
||||
App::Document* doc = nullptr; // pointer to active document
|
||||
bool hasBoxX = false;
|
||||
bool hasBoxY = false;
|
||||
bool hasBoxZ = false;
|
||||
bool hasBoxCustom = false;
|
||||
void noDocumentActions();
|
||||
void startCutting(bool isInitial = false);
|
||||
static SbBox3f getViewBoundingBox();
|
||||
@@ -86,6 +79,20 @@ private:
|
||||
bool forXRange = true, bool forYRange = true, bool forZRange = true);
|
||||
void CutValueHelper(double val, QDoubleSpinBox* SpinBox, QSlider* Slider);
|
||||
void FlipClickedHelper(const char* BoxName);
|
||||
void changeCutBoxColors();
|
||||
App::DocumentObject* CreateBooleanFragments(App::Document* doc);
|
||||
void setBooleanFragmentsColor();
|
||||
App::DocumentObject* findObject(const char* objName) const;
|
||||
App::DocumentObject* flipCutObject(const char* cutName);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_SectionCut> ui;
|
||||
std::vector<App::DocumentObjectT> ObjectsListVisible;
|
||||
App::Document* doc = nullptr; // pointer to active document
|
||||
bool hasBoxX = false;
|
||||
bool hasBoxY = false;
|
||||
bool hasBoxZ = false;
|
||||
bool hasBoxCustom = false;
|
||||
const char* CompoundName = "SectionCutCompound";
|
||||
const char* BoxXName = "SectionCutBoxX";
|
||||
const char* BoxYName = "SectionCutBoxY";
|
||||
@@ -93,9 +100,6 @@ private:
|
||||
const char* CutXName = "SectionCutX";
|
||||
const char* CutYName = "SectionCutY";
|
||||
const char* CutZName = "SectionCutZ";
|
||||
void changeCutBoxColors();
|
||||
App::DocumentObject* CreateBooleanFragments(App::Document* doc);
|
||||
void setBooleanFragmentsColor();
|
||||
};
|
||||
|
||||
} // namespace PartGui
|
||||
|
||||
Reference in New Issue
Block a user