diff --git a/src/Mod/PartDesign/App/FeatureHole.cpp b/src/Mod/PartDesign/App/FeatureHole.cpp index fd0fa1fb2a..52f934f525 100644 --- a/src/Mod/PartDesign/App/FeatureHole.cpp +++ b/src/Mod/PartDesign/App/FeatureHole.cpp @@ -700,7 +700,7 @@ Hole::Hole() ADD_PROPERTY_TYPE(DrillForDepth, ((long)0), "Hole", App::Prop_None, "The size of the drill point will be taken into\n account for the depth of blind holes"); - ADD_PROPERTY_TYPE(Tapered, (false),"Hole", App::Prop_None, "Tapered"); + ADD_PROPERTY_TYPE(Tapered, (false), "Hole", App::Prop_None, "Tapered"); ADD_PROPERTY_TYPE(TaperedAngle, (90.0), "Hole", App::Prop_None, "Tapered angle"); TaperedAngle.setConstraints(&floatAngle); @@ -710,7 +710,7 @@ Hole::Hole() ADD_PROPERTY_TYPE(ThreadDepth, (23.5), "Hole", App::Prop_None, "Thread Length"); // default is assuming an M1 - ADD_PROPERTY_TYPE(UseCustomThreadClearance, (false), "Hole", App::Prop_None, "Use custom thread clearance"); + ADD_PROPERTY_TYPE(UseCustomThreadClearance, (false), "Hole", App::Prop_None, "Use custom thread clearance"); ADD_PROPERTY_TYPE(CustomThreadClearance, (0.0), "Hole", App::Prop_None, "Custom thread clearance (overrides ThreadClass)"); @@ -791,14 +791,14 @@ void Hole::updateHoleCutParams() } // cut definition - CutDimensionKey key { threadTypeStr, holeCutTypeStr }; + CutDimensionKey key{ threadTypeStr, holeCutTypeStr }; if (HoleCutTypeMap.count(key)) { - const CutDimensionSet &counter = find_cutDimensionSet(key); + const CutDimensionSet& counter = find_cutDimensionSet(key); if (counter.cut_type == CutDimensionSet::Counterbore) { // disable HoleCutCountersinkAngle and reset it to ISO's default HoleCutCountersinkAngle.setValue(90.0); HoleCutCountersinkAngle.setReadOnly(true); - const CounterBoreDimension &dimen = counter.get_bore(threadSizeStr); + const CounterBoreDimension& dimen = counter.get_bore(threadSizeStr); if (dimen.thread == "None") { // valid values for visual feedback HoleCutDiameter.setValue(Diameter.getValue() + 0.1); @@ -811,7 +811,8 @@ void Hole::updateHoleCutParams() HoleCutDiameter.setReadOnly(false); HoleCutDepth.setReadOnly(false); } - } else { + } + else { // set normed values if not overwritten or if previously there // were no normed values available and thus HoleCutCustomValues is checked and read-only if (!HoleCutCustomValues.getValue() @@ -829,8 +830,9 @@ void Hole::updateHoleCutParams() } HoleCutCustomValues.setReadOnly(false); } - } else if (counter.cut_type == CutDimensionSet::Countersink) { - const CounterSinkDimension &dimen = counter.get_sink(threadSizeStr); + } + else if (counter.cut_type == CutDimensionSet::Countersink) { + const CounterSinkDimension& dimen = counter.get_sink(threadSizeStr); if (dimen.thread == "None") { // valid values for visual feedback HoleCutDiameter.setValue(Diameter.getValue() + 0.1); @@ -847,7 +849,8 @@ void Hole::updateHoleCutParams() HoleCutDepth.setReadOnly(false); HoleCutCountersinkAngle.setReadOnly(false); } - } else { + } + else { // set normed values if not overwritten or if previously there // were no normed values available and thus HoleCutCustomValues is checked and read-only if (!HoleCutCustomValues.getValue() @@ -941,7 +944,7 @@ double Hole::getThreadClassClearance() // Calculate how much clearance to add based on Thread tolerance class and pitch if (ThreadClass.getValueAsString()[1] == 'G') { - for(unsigned int i=0; i Base::toRadians( 180.0 ) ) + if (TaperedAngleVal <= 0.0 || TaperedAngleVal > Base::toRadians(180.0)) return new App::DocumentObjectExecReturn("Hole error: Invalid taper angle"); - if ( isCountersink ) { - double countersinkAngle = Base::toRadians( HoleCutCountersinkAngle.getValue() / 2.0 ); + if (isCountersink) { + double countersinkAngle = Base::toRadians(HoleCutCountersinkAngle.getValue() / 2.0); - if ( countersinkAngle <= 0 || countersinkAngle > Base::toRadians( 180.0 ) ) + if (countersinkAngle <= 0 || countersinkAngle > Base::toRadians(180.0)) return new App::DocumentObjectExecReturn("Hole error: Invalid countersink angle"); if (holeCutRadius < radius) @@ -1731,23 +1735,23 @@ App::DocumentObjectExecReturn *Hole::execute(void) // Top point gp_Pnt newPoint = toPnt(holeCutRadius * xDir); - mkWire.Add( BRepBuilderAPI_MakeEdge(lastPoint, newPoint) ); + mkWire.Add(BRepBuilderAPI_MakeEdge(lastPoint, newPoint)); lastPoint = newPoint; computeIntersection(gp_Pnt( holeCutRadius, 0, 0 ), - gp_Pnt( holeCutRadius - sin( countersinkAngle ), -cos( countersinkAngle ), 0 ), - gp_Pnt( radius, 0, 0 ), - gp_Pnt( radiusBottom, -length, 0), xPosCounter, zPosCounter); + gp_Pnt(holeCutRadius - sin(countersinkAngle), -cos(countersinkAngle), 0), + gp_Pnt(radius, 0, 0), + gp_Pnt(radiusBottom, -length, 0), xPosCounter, zPosCounter); if (-length > zPosCounter) return new App::DocumentObjectExecReturn("Hole error: Invalid countersink"); lengthCounter = zPosCounter; newPoint = toPnt(xPosCounter * xDir + zPosCounter * zDir); - mkWire.Add( BRepBuilderAPI_MakeEdge( lastPoint, newPoint ) ); + mkWire.Add(BRepBuilderAPI_MakeEdge(lastPoint, newPoint)); lastPoint = newPoint; } - else if ( isCounterbore ) { + else if (isCounterbore) { double holeCutDepth = HoleCutDepth.getValue(); if (holeCutDepth <= 0.0) @@ -1770,10 +1774,10 @@ App::DocumentObjectExecReturn *Hole::execute(void) lastPoint = newPoint; // Compute intersection of tapered edge and line at bottom of counterbore hole - computeIntersection(gp_Pnt( 0, -holeCutDepth, 0 ), - gp_Pnt( holeCutRadius, -holeCutDepth, 0 ), - gp_Pnt( radius, 0, 0 ), - gp_Pnt( radiusBottom, length, 0 ), xPosCounter, zPosCounter); + computeIntersection(gp_Pnt(0, -holeCutDepth, 0), + gp_Pnt(holeCutRadius, -holeCutDepth, 0), + gp_Pnt(radius, 0, 0), + gp_Pnt(radiusBottom, length, 0), xPosCounter, zPosCounter); lengthCounter = zPosCounter; newPoint = toPnt(xPosCounter * xDir + zPosCounter * zDir); @@ -1796,16 +1800,16 @@ App::DocumentObjectExecReturn *Hole::execute(void) lastPoint = newPoint; newPoint = toPnt(-length * zDir); - mkWire.Add( BRepBuilderAPI_MakeEdge( lastPoint, newPoint ) ); + mkWire.Add(BRepBuilderAPI_MakeEdge(lastPoint, newPoint)); lastPoint = newPoint; } else if (drillPoint == "Angled") { - double drillPointAngle = Base::toRadians( ( 180.0 - DrillPointAngle.getValue() ) / 2.0 ); + double drillPointAngle = Base::toRadians((180.0 - DrillPointAngle.getValue()) / 2.0); gp_Pnt newPoint; bool isDrillForDepth = DrillForDepth.getValue(); // the angle is in any case > 0 and < 90 but nevertheless this safeguard: - if ( drillPointAngle <= 0.0 || drillPointAngle >= Base::toRadians( 180.0 ) ) + if (drillPointAngle <= 0.0 || drillPointAngle >= Base::toRadians(180.0)) return new App::DocumentObjectExecReturn("Hole error: Invalid drill point angle"); // if option to take drill point size into account @@ -1841,7 +1845,7 @@ App::DocumentObjectExecReturn *Hole::execute(void) } } - mkWire.Add( BRepBuilderAPI_MakeEdge(lastPoint, firstPoint) ); + mkWire.Add(BRepBuilderAPI_MakeEdge(lastPoint, firstPoint)); TopoDS_Wire wire = mkWire.Wire(); @@ -1863,7 +1867,7 @@ App::DocumentObjectExecReturn *Hole::execute(void) // Make thread if (Threaded.getValue() && ModelThread.getValue()) { - bool leftHanded = (bool) ThreadDirection.getValue(); + bool leftHanded = (bool)ThreadDirection.getValue(); // Nomenclature and formulae according to Figure 1 of ISO 68-1 // this is the same for all metric and UTS threads as stated here: @@ -2079,10 +2083,10 @@ App::DocumentObjectExecReturn *Hole::execute(void) void Hole::addCutType(const CutDimensionSet& dimensions) { const CutDimensionSet::ThreadType thread = dimensions.thread_type; - const std::string &name = dimensions.name; + const std::string& name = dimensions.name; - std::vector *list; - switch(thread) { + std::vector* list; + switch (thread) { case CutDimensionSet::Metric: HoleCutTypeMap.emplace(CutDimensionKey("ISOMetricProfile", name), dimensions); list = &HoleCutType_ISOmetric_Enums; @@ -2097,22 +2101,22 @@ void Hole::addCutType(const CutDimensionSet& dimensions) // add the collected lists of JSON definitions to the lists // if a name doesn't already exist in the list if (std::all_of(list->begin(), list->end(), - [name](const std::string &x){ return x != name; })) + [name](const std::string& x) { return x != name; })) list->push_back(name); } -bool Hole::isDynamicCounterbore(const std::string &thread, - const std::string &holeCutType) +bool Hole::isDynamicCounterbore(const std::string& thread, + const std::string& holeCutType) { - CutDimensionKey key { thread, holeCutType }; + CutDimensionKey key{ thread, holeCutType }; return HoleCutTypeMap.count(key) && HoleCutTypeMap.find(key)->second.cut_type == CutDimensionSet::Counterbore; } -bool Hole::isDynamicCountersink(const std::string &thread, - const std::string &holeCutType) +bool Hole::isDynamicCountersink(const std::string& thread, + const std::string& holeCutType) { - CutDimensionKey key { thread, holeCutType }; + CutDimensionKey key{ thread, holeCutType }; return HoleCutTypeMap.count(key) && HoleCutTypeMap.find(key)->second.cut_type == CutDimensionSet::Countersink; } @@ -2121,76 +2125,76 @@ bool Hole::isDynamicCountersink(const std::string &thread, * Counter Dimensions */ -const Hole::CounterBoreDimension Hole::CounterBoreDimension::nothing { "None", 0.0, 0.0 }; -const Hole::CounterSinkDimension Hole::CounterSinkDimension::nothing { "None", 0.0 }; +const Hole::CounterBoreDimension Hole::CounterBoreDimension::nothing{ "None", 0.0, 0.0 }; +const Hole::CounterSinkDimension Hole::CounterSinkDimension::nothing{ "None", 0.0 }; -Hole::CutDimensionKey::CutDimensionKey(const std::string &t, const std::string &c) : - thread_type { t }, cut_name { c } +Hole::CutDimensionKey::CutDimensionKey(const std::string& t, const std::string& c) : + thread_type{ t }, cut_name{ c } { } -bool Hole::CutDimensionKey::operator<(const CutDimensionKey &b) const +bool Hole::CutDimensionKey::operator<(const CutDimensionKey& b) const { return thread_type < b.thread_type || - (thread_type == b.thread_type && cut_name < b.cut_name); + (thread_type == b.thread_type && cut_name < b.cut_name); } -const Hole::CutDimensionSet& Hole::find_cutDimensionSet(const std::string &t, - const std::string &c) { +const Hole::CutDimensionSet& Hole::find_cutDimensionSet(const std::string& t, + const std::string& c) { return HoleCutTypeMap.find(CutDimensionKey(t, c))->second; } -const Hole::CutDimensionSet& Hole::find_cutDimensionSet(const CutDimensionKey &k) +const Hole::CutDimensionSet& Hole::find_cutDimensionSet(const CutDimensionKey& k) { return HoleCutTypeMap.find(k)->second; } -Hole::CutDimensionSet::CutDimensionSet(const std::string &nme, - std::vector &&d, CutType cut, ThreadType thread, double a) : - bore_data{ std::move(d) }, cut_type{ cut }, thread_type{thread}, name{nme}, angle{a} +Hole::CutDimensionSet::CutDimensionSet(const std::string& nme, + std::vector&& d, CutType cut, ThreadType thread, double a) : + bore_data{ std::move(d) }, cut_type{ cut }, thread_type{ thread }, name{ nme }, angle{ a } { } -Hole::CutDimensionSet::CutDimensionSet(const std::string &nme, - std::vector &&d, CutType cut, ThreadType thread, double a) : - sink_data{ std::move(d) }, cut_type{ cut }, thread_type{thread}, name{nme}, angle{a} +Hole::CutDimensionSet::CutDimensionSet(const std::string& nme, + std::vector&& d, CutType cut, ThreadType thread, double a) : + sink_data{ std::move(d) }, cut_type{ cut }, thread_type{ thread }, name{ nme }, angle{ a } { } -const Hole::CounterBoreDimension &Hole::CutDimensionSet::get_bore(const std::string &t) const +const Hole::CounterBoreDimension& Hole::CutDimensionSet::get_bore(const std::string& t) const { auto i = std::find_if(bore_data.begin(), bore_data.end(), - [t](const Hole::CounterBoreDimension &x) { return x.thread == t; } ); + [t](const Hole::CounterBoreDimension& x) { return x.thread == t; }); if (i == bore_data.end()) return CounterBoreDimension::nothing; else return *i; } -const Hole::CounterSinkDimension &Hole::CutDimensionSet::get_sink(const std::string &t) const +const Hole::CounterSinkDimension& Hole::CutDimensionSet::get_sink(const std::string& t) const { auto i = std::find_if(sink_data.begin(), sink_data.end(), - [t](const Hole::CounterSinkDimension &x) { return x.thread == t; } ); + [t](const Hole::CounterSinkDimension& x) { return x.thread == t; }); if (i == sink_data.end()) return CounterSinkDimension::nothing; else return *i; } -void from_json(const nlohmann::json &j, Hole::CounterBoreDimension &t) +void from_json(const nlohmann::json& j, Hole::CounterBoreDimension& t) { t.thread = j["thread"].get(); t.diameter = j["diameter"].get(); t.depth = j["depth"].get(); } -void from_json(const nlohmann::json &j, Hole::CounterSinkDimension &t) +void from_json(const nlohmann::json& j, Hole::CounterSinkDimension& t) { t.thread = j["thread"].get(); t.diameter = j["diameter"].get(); } -void from_json(const nlohmann::json &j, Hole::CutDimensionSet &t) +void from_json(const nlohmann::json& j, Hole::CutDimensionSet& t) { t.name = j["name"].get(); @@ -2207,7 +2211,8 @@ void from_json(const nlohmann::json &j, Hole::CutDimensionSet &t) t.cut_type = Hole::CutDimensionSet::Counterbore; t.bore_data = j["data"].get >(); t.angle = 0.0; - } else if (cut_type_string == "countersink") { + } + else if (cut_type_string == "countersink") { t.cut_type = Hole::CutDimensionSet::Countersink; t.sink_data = j["data"].get >(); t.angle = j["angle"].get(); @@ -2220,18 +2225,18 @@ void from_json(const nlohmann::json &j, Hole::CutDimensionSet &t) void Hole::readCutDefinitions() { - std::vector dirs { + std::vector dirs{ ::App::Application::getResourceDir() + "Mod/PartDesign/Resources/Hole", ::App::Application::getUserAppDataDir() + "PartDesign/Hole" }; std::clog << "Looking for thread definitions in: "; - for (auto &i : dirs) + for (auto& i : dirs) std::clog << i << " "; std::clog << "\n"; - for (auto &dir : dirs) { - std::vector<::Base::FileInfo> files { ::Base::FileInfo(dir).getDirectoryContent() }; - for (const auto &f : files) { + for (auto& dir : dirs) { + std::vector<::Base::FileInfo> files{ ::Base::FileInfo(dir).getDirectoryContent() }; + for (const auto& f : files) { if (f.extension() == "json") { try { std::ifstream input(f.filePath()); @@ -2240,8 +2245,8 @@ void Hole::readCutDefinitions() CutDimensionSet screwtype = j.get(); addCutType(screwtype); } - catch(std::exception &e) { - std::cerr << "Failed reading '" << f.filePath() << "' with: "<< e.what() << "\n"; + catch (std::exception& e) { + std::cerr << "Failed reading '" << f.filePath() << "' with: " << e.what() << "\n"; } } }