Skip to content

Commit

Permalink
PartDesign: Transformed. Fix regression in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
davidosterberg authored and wwmayer committed Mar 13, 2021
1 parent 8453d41 commit 3131b97
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 53 deletions.
21 changes: 20 additions & 1 deletion src/Mod/PartDesign/App/FeatureTransformed.cpp
Expand Up @@ -296,7 +296,6 @@ App::DocumentObjectExecReturn *Transformed::execute(void)
bool overlapping = false;

std::vector<gp_Trsf>::const_iterator t = transformations.begin();
//++t; // Skip first transformation, which is always the identity transformation
bool first = true;
for (; t != transformations.end(); ++t) {
// Make an explicit copy of the shape because the "true" parameter to BRepBuilderAPI_Transform
Expand Down Expand Up @@ -372,6 +371,7 @@ App::DocumentObjectExecReturn *Transformed::execute(void)
}

this->Shape.setValue(getSolid(support)); // picking the first solid
rejected = getRemainingSolids(support);

#ifndef FC_DEBUG
Base::Console().Message("Transformed: Elapsed CPU time: %f s\n", (std::clock() - start0 ) / (double)(CLOCKS_PER_SEC));
Expand Down Expand Up @@ -454,4 +454,23 @@ void Transformed::divideTools(const std::vector<TopoDS_Shape> &toolsIn, std::vec
}
}

TopoDS_Shape Transformed::getRemainingSolids(const TopoDS_Shape& shape)
{
BRep_Builder builder;
TopoDS_Compound compShape;
builder.MakeCompound(compShape);

if (shape.IsNull())
Standard_Failure::Raise("Shape is null");
TopExp_Explorer xp;
xp.Init(shape,TopAbs_SOLID);
xp.Next(); // skip the first

for (; xp.More(); xp.Next()) {
builder.Add(compShape, xp.Current());
}

return compShape;
}

}
10 changes: 4 additions & 6 deletions src/Mod/PartDesign/App/FeatureTransformed.h
Expand Up @@ -83,20 +83,18 @@ class PartDesignExport Transformed : public PartDesign::Feature
short mustExecute() const;
//@}

/** returns a list of the transformations that where rejected during the last execute
/** returns the compound of the shapes that were rejected during the last execute
* because they did not overlap with the support
*/
typedef std::map<App::DocumentObject*, std::list<gp_Trsf> > rejectedMap;
const rejectedMap getRejectedTransformations(void) { return rejected; }
TopoDS_Shape rejected;

protected:
void Restore(Base::XMLReader &reader);
virtual void positionBySupport(void);
TopoDS_Shape refineShapeIfActive(const TopoDS_Shape&) const;
void divideTools(const std::vector<TopoDS_Shape> &toolsIn, std::vector<TopoDS_Shape> &individualsOut,
TopoDS_Compound &compoundOut) const;

rejectedMap rejected;
TopoDS_Compound &compoundOut) const;
static TopoDS_Shape getRemainingSolids(const TopoDS_Shape&);

private:
static const char* OverlapEnums[];
Expand Down
78 changes: 32 additions & 46 deletions src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp
Expand Up @@ -157,10 +157,15 @@ void ViewProviderTransformed::recomputeFeature(bool recompute)
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(getObject());
if(recompute || (pcTransformed->isError() || pcTransformed->mustExecute()))
pcTransformed->recomputeFeature(true);
const PartDesign::Transformed::rejectedMap &rejected_trsf = pcTransformed->getRejectedTransformations();

unsigned rejected = 0;
for (PartDesign::Transformed::rejectedMap::const_iterator r = rejected_trsf.begin(); r != rejected_trsf.end(); r++)
rejected += r->second.size();
TopoDS_Shape cShape = pcTransformed->rejected;
TopExp_Explorer xp;
xp.Init(cShape, TopAbs_SOLID);
for (; xp.More(); xp.Next()) {
rejected++;
}

QString msg = QString::fromLatin1("%1");
if (rejected > 0) {
msg = QString::fromLatin1("<font color='orange'>%1<br/></font>\r\n%2");
Expand Down Expand Up @@ -192,21 +197,9 @@ void ViewProviderTransformed::recomputeFeature(bool recompute)
pcRejectedRoot ->removeChild(7);
}

for (PartDesign::Transformed::rejectedMap::const_iterator o = rejected_trsf.begin(); o != rejected_trsf.end(); o++) {
if (o->second.empty()) continue;

Part::TopoShape fuseShape;
Part::TopoShape cutShape;
if ((o->first)->getTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) {
PartDesign::FeatureAddSub* feature = static_cast<PartDesign::FeatureAddSub*>(o->first);
feature->getAddSubShape(fuseShape, cutShape);
}

if (fuseShape.isNull()) continue;

// Display the rejected transformations in red
TopoDS_Shape cShape(fuseShape.getShape());
// Display the rejected transformations in red

if (rejected > 0) {
try {
// calculating the deflection value
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
Expand Down Expand Up @@ -333,41 +326,34 @@ void ViewProviderTransformed::recomputeFeature(bool recompute)
// counting up the per Face offsets
FaceNodeOffset += nbNodesInFace;
FaceTriaOffset += nbTriInFace;
}

// normalize all normals
for (int i=0; i < nbrNodes; i++)
norms[i].normalize();

// end the editing of the nodes
rejectedCoords ->point .finishEditing();
rejectedNorms ->vector .finishEditing();
rejectedFaceSet ->coordIndex .finishEditing();

// fill in the transformation matrices
SoMultipleCopy* rejectedTrfms = new SoMultipleCopy();
rejectedTrfms->matrix.setNum((o->second).size());
SbMatrix* mats = rejectedTrfms->matrix.startEditing();

std::list<gp_Trsf>::const_iterator trsf = (o->second).begin();
for (unsigned int i=0; i < (o->second).size(); i++,trsf++) {
Base::Matrix4D mat;
Part::TopoShape::convertToMatrix(*trsf,mat);
mats[i] = convert(mat);

// normalize all normals
for (int i=0; i < nbrNodes; i++)
norms[i].normalize();

// end the editing of the nodes
rejectedCoords ->point .finishEditing();
rejectedNorms ->vector .finishEditing();
rejectedFaceSet ->coordIndex .finishEditing();

// fill in the transformation matrices
SoMultipleCopy* rejectedTrfms = new SoMultipleCopy();


rejectedTrfms->matrix.finishEditing();
rejectedTrfms->addChild(rejectedFaceSet);
SoSeparator* sep = new SoSeparator();
sep->addChild(rejectedCoords);
sep->addChild(rejectedNorms);
sep->addChild(rejectedTrfms);
pcRejectedRoot->addChild(sep);
}
rejectedTrfms->matrix.finishEditing();
rejectedTrfms->addChild(rejectedFaceSet);
SoSeparator* sep = new SoSeparator();
sep->addChild(rejectedCoords);
sep->addChild(rejectedNorms);
sep->addChild(rejectedTrfms);
pcRejectedRoot->addChild(sep);
}
catch (...) {
Base::Console().Error("Cannot compute Inventor representation for the rejected transformations of shape of %s.\n",
pcTransformed->getNameInDocument());
pcTransformed->getNameInDocument());
}
}

}

0 comments on commit 3131b97

Please sign in to comment.