X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelHighAPI%2FModelHighAPI_Dumper.cpp;h=1031cf85498a1868ece8135255c77fa4a94591e7;hb=a13f87935d2a6f52f942790b6abc874f1016c9fc;hp=c8e37dc1c6598fbffb86604342bdce884a57119d;hpb=8038897b81335a9ec1ff08522ff652299cd2ff3f;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index c8e37dc1c..1031cf854 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -21,18 +21,25 @@ #include -#include +#include +#include +#include #include +#include +#include #include #include +#include #include #include #include #include +#include #include #include +#include #include #include #include @@ -308,7 +315,7 @@ void ModelHighAPI_Dumper::DumpStorage::write(const AttributeSelectionPtr& theAtt if (aShape.get()) { myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \"" - << theAttrSelect->namingName() << "\""; + << ModelAPI_Tools::toString(theAttrSelect->namingName()) << "\""; } myDumpBuffer << ")"; @@ -325,8 +332,18 @@ static int possibleSelectionsByPoint(const GeomPointPtr& thePoint, std::list aFeatures = aDoc1->allFeatures(); if (aDoc1 != aDoc2) { + // Find the position of the part, where its features should be inserted. + // It will avoid checking of appropriate elements in partSet after the current part. + std::list::iterator aFIt = aFeatures.begin(); + for (; aFIt != aFeatures.end(); ++aFIt) { + ResultPartPtr aPartRes = + std::dynamic_pointer_cast((*aFIt)->lastResult()); + if (aPartRes && aPartRes->partDoc() == aDoc2) + break; + } + std::list anAdditionalFeatures = aDoc2->allFeatures(); - aFeatures.insert(aFeatures.end(), anAdditionalFeatures.begin(), anAdditionalFeatures.end()); + aFeatures.insert(aFIt, anAdditionalFeatures.begin(), anAdditionalFeatures.end()); } CompositeFeaturePtr aLastCompositeFeature; @@ -367,8 +384,10 @@ static int possibleSelectionsByPoint(const GeomPointPtr& thePoint, std::list anApproproate; if (ModelGeomAlgo_Shape::findSubshapeByPoint(*aFIt, thePoint, theShape->shapeType(), anApproproate)) { + bool isContinue = true; + std::list > aCenters; std::list::iterator anApIt = anApproproate.begin(); - for (; anApIt != anApproproate.end(); ++anApIt) { + for (; anApIt != anApproproate.end() && isContinue; ++anApIt) { ++aNbPossibleSelections; // stop if the target shape and result are found @@ -376,9 +395,42 @@ static int possibleSelectionsByPoint(const GeomPointPtr& thePoint, if (!aCurShape) aCurShape = anApIt->myResult->shape(); - if (anApIt->myResult->isSame(theResult) && aCurShape->isSame(theShape)) - break; + if (anApIt->myResult->isSame(theResult)) { + if (anApIt->myCenterType == (int)ModelAPI_AttributeSelection::NOT_CENTER) + isContinue = !aCurShape->isSame(theShape); + else if (theShape->isVertex() && aCurShape->isEdge()) { + GeomEdgePtr aCurEdge = aCurShape->edge(); + GeomVertexPtr aVertex = theShape->vertex(); + GeomPointPtr aCenter; + switch (anApIt->myCenterType) { + case (int)ModelAPI_AttributeSelection::CIRCLE_CENTER: { + GeomCirclePtr aCirc = aCurEdge->circle(); + if (aCirc) + aCenter = aCirc->center(); + break; + } + case (int)ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS: { + GeomEllipsePtr anEllipse = aCurEdge->ellipse(); + if (anEllipse) + aCenter = anEllipse->firstFocus(); + break; + } + case (int)ModelAPI_AttributeSelection::ELLIPSE_SECOND_FOCUS: { + GeomEllipsePtr anEllipse = aCurEdge->ellipse(); + if (anEllipse) + aCenter = anEllipse->secondFocus(); + break; + } + } + if (aCenter && aCenter->distance(aVertex->point()) < 1.e-7) + aCenters.push_back(std::pair(aCurShape, aNbPossibleSelections)); + } + } } + // passed till the appropriate shape, check the center of circle + // or a focus of ellipse is selected + if (isContinue && !aCenters.empty()) + aNbPossibleSelections = aCenters.front().second; } } return aNbPossibleSelections; @@ -444,7 +496,8 @@ void ModelHighAPI_Dumper::DumpStorageWeak::write(const AttributeSelectionPtr& th int anIndex = aNExplode.index(aShape); if (anIndex != 0) { // found a week-naming index, so, export it myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr() << "\", \"" - << theAttrSelect->contextName(aContext) << "\", " << anIndex << ")"; + << ModelAPI_Tools::toString(theAttrSelect->contextName(aContext)) + << "\", " << anIndex << ")"; aStandardDump = false; } } @@ -517,25 +570,30 @@ static int toInt(const std::string& theString) const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, bool theSaveNotDumped, - bool theUseEntityName) -{ - EntityNameMap::const_iterator aFound = myNames.find(theEntity); - if (aFound != myNames.end()) + bool theUseEntityName, + bool theSetIsDumped) +{ + EntityNameMap::iterator aFound = myNames.find(theEntity); + if (aFound != myNames.end()) { + // Set dumped flag for postponed constraints which are without names + if (!aFound->second.myIsDumped) + aFound->second.myIsDumped = theSetIsDumped; return aFound->second.myCurrentName; - + } // entity is not found, store it - std::string aName, aKind; + std::string aName; + std::string aKind; bool isDefaultName = false; bool isSaveNotDumped = theSaveNotDumped; std::ostringstream aDefaultName; FeaturePtr aFeature = std::dynamic_pointer_cast(theEntity); if (aFeature) { - aName = aFeature->name(); + aName = ModelAPI_Tools::toString(aFeature->name()); aKind = aFeature->getKind(); } else { FolderPtr aFolder = std::dynamic_pointer_cast(theEntity); if (aFolder) { - aName = aFolder->data()->name(); + aName = ModelAPI_Tools::toString(aFolder->data()->name()); aKind = ModelAPI_Folder::ID(); isSaveNotDumped = false; } @@ -598,6 +656,8 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, if (aFeature) saveResultNames(aFeature); + myNames[theEntity].myIsDumped = theSetIsDumped; + return myNames[theEntity].myCurrentName; } @@ -626,9 +686,9 @@ void ModelHighAPI_Dumper::saveResultNames(const FeaturePtr& theFeature) std::list allRes; ModelAPI_Tools::allResults(theFeature, allRes); for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { - std::pair aName = ModelAPI_Tools::getDefaultName(*aRes); - std::string aDefaultName = aName.first; - std::string aResName = (*aRes)->data()->name(); + std::pair aName = ModelAPI_Tools::getDefaultName(*aRes); + std::string aDefaultName = ModelAPI_Tools::toString(aName.first); + std::string aResName = ModelAPI_Tools::toString((*aRes)->data()->name()); bool isUserDefined = !(isFeatureDefaultName && aDefaultName == aResName); myNames[*aRes] = EntityName(aResName, (isUserDefined ? aResName : std::string()), !isUserDefined); @@ -645,7 +705,6 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr& theD // dump subfeatures and store result to file bool isOk = process(theDoc) && myDumpStorage->exportTo(theFileName, myModules); - clearCustomStorage(); return isOk; } @@ -663,8 +722,12 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr& theD // dump all other features for (anObjIt = anObjects.begin(); anObjIt != anObjects.end(); ++anObjIt) { CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast(*anObjIt); - if (aCompFeat) // iteratively process composite features - isOk = process(aCompFeat) && isOk; + if (aCompFeat) { + // iteratively process composite features, + // if the composite feature is the last in the document, no need to dump "model.do()" action + std::list::const_iterator aNext = anObjIt; + isOk = process(aCompFeat, false, ++aNext != anObjects.end()) && isOk; + } else if (!isDumped(EntityPtr(*anObjIt))) { // dump folder FolderPtr aFolder = std::dynamic_pointer_cast(*anObjIt); @@ -683,7 +746,7 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr& theD } bool ModelHighAPI_Dumper::process(const std::shared_ptr& theComposite, - bool isForce) + bool isForce, bool isDumpModelDo) { // increase composite features stack ++gCompositeStackDepth; @@ -716,7 +779,9 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptrname(), false); + myNames[theSubFeature] = + EntityName(theSubFeatureGet, ModelAPI_Tools::toString(theSubFeature->name()), false); // store results if they have user-defined names or colors std::list aResultsWithNameOrColor; const std::list& aResults = theSubFeature->results(); std::list::const_iterator aResIt = aResults.begin(); for (; aResIt != aResults.end(); ++aResIt) { - std::string aResName = (*aResIt)->data()->name(); + std::string aResName = ModelAPI_Tools::toString((*aResIt)->data()->name()); myNames[*aResIt] = EntityName(aResName, aResName, false); aResultsWithNameOrColor.push_back(*aResIt); } @@ -997,6 +1063,16 @@ bool ModelHighAPI_Dumper::isDefaultTransparency(const ResultPtr& theResult) cons return fabs(anAttribute->value()) < 1.e-12; } +bool ModelHighAPI_Dumper::dumpCommentBeforeFeature(const FeaturePtr& theFeature) const +{ + // currently, the comment should not be dumped only before the filters + FiltersFeaturePtr aFilters = std::dynamic_pointer_cast(theFeature); + if (aFilters) + return false; + // all other features should be commented before the dump + return true; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar) { *myDumpStorage << theChar; @@ -1015,6 +1091,12 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::string& theStrin return *this; } +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::wstring& theString) +{ + *myDumpStorage << ModelAPI_Tools::toString(theString); + return *this; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const bool theValue) { *myDumpStorage << (theValue ? "True" : "False"); @@ -1076,6 +1158,43 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( return *this; } +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( + const std::shared_ptr& thePointArray) +{ + static const int aThreshold = 4; + static bool aDumpAsIs = false; + static std::string aSeparator = ""; + // if number of elements in the list if greater than a threshold, + // dump it in a separate line with specific name + int aSize = thePointArray->size(); + if (aDumpAsIs || aSize <= aThreshold) { + *myDumpStorage << "["; + GeomPnt2dPtr aPoint = thePointArray->pnt(0); + *myDumpStorage << "(" << aPoint->x() << ", " << aPoint->y() << ")"; + for (int anIndex = 1; anIndex < aSize; ++anIndex) { + aPoint = thePointArray->pnt(anIndex); + *myDumpStorage << "," << aSeparator << " (" << aPoint->x() << ", " << aPoint->y() << ")"; + } + *myDumpStorage << aSeparator << "]"; + } + else { + // name of list + FeaturePtr anOwner = ModelAPI_Feature::feature(thePointArray->owner()); + std::string aListName = name(anOwner) + "_" + thePointArray->id(); + // reserve dumped buffer and store list "as is" + myDumpStorage->reserveBuffer(); + aDumpAsIs = true; + aSeparator = std::string("\n") + std::string(aListName.size() + 3, ' '); + *this << aListName << " = " << thePointArray << "\n"; + aDumpAsIs = false; + aSeparator = ""; + // append reserved data to the end of the current buffer + myDumpStorage->restoreReservedBuffer(); + *myDumpStorage << aListName; + } + return *this; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& theAttrBool) { @@ -1094,6 +1213,20 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( return *this; } +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( + const std::shared_ptr& theArray) +{ + *myDumpStorage << "["; + int aSize = theArray->size(); + if (aSize > 0) { + *myDumpStorage << theArray->value(0); + for (int anIndex = 1; anIndex < aSize; ++anIndex) + *myDumpStorage << ", " << theArray->value(anIndex); + } + *myDumpStorage << "]"; + return *this; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& theAttrReal) { @@ -1105,6 +1238,20 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( return *this; } +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( + const std::shared_ptr& theArray) +{ + *myDumpStorage << "["; + int aSize = theArray->size(); + if (aSize > 0) { + *myDumpStorage << theArray->value(0); + for (int anIndex = 1; anIndex < aSize; ++anIndex) + *myDumpStorage << ", " << theArray->value(anIndex); + } + *myDumpStorage << "]"; + return *this; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& theAttrStr) { @@ -1227,7 +1374,8 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const AttributePtr& theAttr // Check the attribute belongs to copied (in multi-translation or multi-rotation) feature. // In this case we need to cast explicitly feature to appropriate type. AttributeBooleanPtr isCopy = anOwner->boolean("Copy"); - if (isCopy.get() && isCopy->value()) { + AttributeReferencePtr hasParent = anOwner->reference("ParentFeature"); + if ((isCopy.get() && isCopy->value()) || (hasParent && hasParent->value())) { aWrapperPrefix = featureWrapper(anOwner) + "("; aWrapperSuffix = ")"; importModule("SketchAPI"); @@ -1324,10 +1472,10 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& theAttrSelList) { static const int aThreshold = 2; - static bool aDumpAsIs = false; + static int aNbSpaces = 0; // if number of elements in the list if greater than a threshold, // dump it in a separate line with specific name - if (aDumpAsIs || theAttrSelList->size() <= aThreshold) { + if (aNbSpaces > 0 || theAttrSelList->size() <= aThreshold) { *myDumpStorage << "["; GeomShapePtr aShape; @@ -1350,6 +1498,11 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( if(isAdded) { *myDumpStorage << ", "; + // print each attribute on separate line with the appropriate shift + if (aNbSpaces > 0) { + std::string aSpaces(aNbSpaces + 1, ' '); + *myDumpStorage << "\n" << aSpaces; + } } else { isAdded = true; } @@ -1383,9 +1536,9 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( } // reserve dumped buffer and store list "as is" myDumpStorage->reserveBuffer(); - aDumpAsIs = true; + aNbSpaces = (int)aListName.size() + 3; *this << aListName << " = " << theAttrSelList << "\n"; - aDumpAsIs = false; + aNbSpaces = 0; // append reserved data to the end of the current buffer myDumpStorage->restoreReservedBuffer(); *myDumpStorage << aListName; @@ -1410,6 +1563,11 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( return *this; } +void ModelHighAPI_Dumper::newline() +{ + *this << std::endl; +} + /// Dump std::endl ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper, std::basic_ostream& (*theEndl)(std::basic_ostream&)) @@ -1439,6 +1597,7 @@ ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper, // store all not-dumped entities first std::set aNotDumped = theDumper.myNotDumpedEntities; + theDumper.clearNotDumped(); theDumper.myDumpStorage->reserveBuffer(); std::set::const_iterator anIt = aNotDumped.begin(); for (; anIt != aNotDumped.end(); ++anIt) { @@ -1476,3 +1635,33 @@ ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper, return theDumper; } + + +void ModelHighAPI_Dumper::exportVariables() const +{ + DocumentPtr aRoot = ModelAPI_Session::get()->moduleDocument(); + EntityNameMap::const_iterator aNameIter = myNames.cbegin(); + for(; aNameIter != myNames.end(); aNameIter++) { + FeaturePtr aFeature = std::dynamic_pointer_cast(aNameIter->first); + if (aFeature.get() && aFeature->document() != aRoot) { + FeaturePtr aPartFeat = ModelAPI_Tools::findPartFeature(aRoot, aFeature->document()); + if (aPartFeat.get()) { + int aFeatureId = aFeature->data()->featureId(); + int aPartId = aPartFeat->data()->featureId(); + std::ostringstream anEntryStr; + anEntryStr<second.myCurrentName); + size_t aSize = aFeature->results().size(); + if (aSize > 1) { // additional entries for features with more than one result + for(int a = 1; a < aSize; a++) { + std::ostringstream aResEntryStr; + aResEntryStr<second.myCurrentName); + } + } + } + } + } +}