+bool BuildPlugin_Vertex::buildVertices(FeaturePtr theFeature,
+ bool isIntersect,
+ int& theResultIndex)
+{
+ if (theFeature->getKind() != "Sketch") return false;
+
+ // Sub-features
+ CompositeFeaturePtr aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
+ if (!aComposite) return false;
+ int nbSubs = aComposite->numberOfSubs();
+ if (nbSubs < 1) return false;
+
+ // The whole sketch shape
+ ResultPtr aContext = theFeature->firstResult();
+ GeomShapePtr theShape = aContext->shape();
+
+ GeomAPI_DataMapOfShapeShape alreadyProcessed;
+
+ // 1. Explode on Vertices
+ for (GeomAPI_ShapeExplorer anExp (theShape, GeomAPI_Shape::VERTEX); anExp.more(); anExp.next()) {
+ GeomShapePtr aSubShape = anExp.current();
+
+ if (alreadyProcessed.bind(aSubShape, aSubShape)) {
+ // Store result.
+ ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
+ aResultBody->storeModified(theShape, aSubShape);
+ setResult(aResultBody, theResultIndex);
+ ++theResultIndex;
+ }
+ }
+
+ // 2. If need intersection points, perform Partition
+ if (isIntersect) {
+ // Partition
+ ListOfShape anObjList, aTools;
+ anObjList.push_back(theShape);
+ std::shared_ptr<GeomAlgoAPI_Partition> aPartitionAlgo (new GeomAlgoAPI_Partition(anObjList, aTools));
+
+ std::string anError;
+ if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPartitionAlgo, getKind(), anError)) {
+ setError(anError);
+ return false;
+ }
+ GeomShapePtr aSplittedSketch = aPartitionAlgo->shape();
+
+ // Explode on Vertices, skip vertices of initial sketch
+ for (GeomAPI_ShapeExplorer anExp (aSplittedSketch, GeomAPI_Shape::VERTEX); anExp.more(); anExp.next()) {
+ GeomShapePtr aSubShape = anExp.current();
+
+ //if (!theShape->isSubShape(aSubShape)) { // skip vertices of initial sketch
+ if (alreadyProcessed.bind(aSubShape, aSubShape)) {
+ // Store result.
+ ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
+ aResultBody->storeGenerated(anObjList, aSubShape, aPartitionAlgo);
+ setResult(aResultBody, theResultIndex);
+ ++theResultIndex;
+ }
+ }
+ }
+
+ // 3. Add construction points (centers of circles, etc.)
+ for (int i = 0; i < nbSubs; i++) {
+ FeaturePtr aSubFeature = aComposite->subFeature(i);
+ const std::list<ResultPtr>& aSubResults = aSubFeature->results();
+ std::list<ResultPtr>::const_iterator anItRes = aSubResults.cbegin();
+ // Iterate on all sub-results
+ for (; anItRes != aSubResults.cend(); anItRes++) {
+ ResultPtr aRes = *anItRes;
+ if (aRes.get()) {
+ // Sub-result i
+ GeomShapePtr aSubResShape = aRes->shape();
+
+ for (GeomAPI_ShapeExplorer anExp (aSubResShape, GeomAPI_Shape::VERTEX); anExp.more(); anExp.next()) {
+ GeomShapePtr aSubShape = anExp.current();
+
+ if (alreadyProcessed.bind(aSubShape, aSubShape)) {
+ // Store result.
+ ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
+ aResultBody->storeModified(theShape, aSubShape);
+ setResult(aResultBody, theResultIndex);
+ ++theResultIndex;
+ }
+ }
+ }
+ }
+ }
+
+ return true;
+}
+