| 115 | } |
| 116 | |
| 117 | bool GcodeToolsLibrary::drawCreateToolDialog() |
| 118 | { |
| 119 | if ( !createToolDialogIsOpen_ ) |
| 120 | return false; |
| 121 | |
| 122 | const auto menuWidth = 220.f * UI::scale(); |
| 123 | if ( !ImGui::BeginCustomStatePlugin( _tr( "Create Tool" ), &createToolDialogIsOpen_, { |
| 124 | .width = menuWidth, |
| 125 | } ) ) |
| 126 | return false; |
| 127 | |
| 128 | bool result = false; |
| 129 | |
| 130 | const auto itemWidth = 160.f * UI::scale(); |
| 131 | |
| 132 | UI::inputTextCentered( _tr( "Name" ), createToolName_, itemWidth ); |
| 133 | |
| 134 | const std::vector<std::string> cToolTypeNames { |
| 135 | _tr( "Flat End Mill" ), |
| 136 | _tr( "Ball End Mill" ), |
| 137 | _tr( "Bull Nose End Mill" ), |
| 138 | _tr( "Chamfer End Mill" ), |
| 139 | }; |
| 140 | assert( cToolTypeNames.size() == (int)EndMillCutter::Type::Count ); |
| 141 | ImGui::SetNextItemWidth( itemWidth ); |
| 142 | UI::combo( _tr( "Type" ), &createToolType_, cToolTypeNames ); |
| 143 | |
| 144 | UI::separator( _tr( "Specifications" ) ); |
| 145 | |
| 146 | ImGui::PushItemWidth( 115.f * UI::scale() ); |
| 147 | UI::drag<LengthUnit>( _tr( "Length" ), createToolLength_, 1e-3f, 1e-3f, 1e+3f ); |
| 148 | UI::drag<LengthUnit>( _tr( "Diameter" ), createToolDiameter_, 1e-3f, 1e-3f, 1e+3f ); |
| 149 | if ( createToolType_ == (int)EndMillCutter::Type::Ball ) |
| 150 | { |
| 151 | auto radius = createToolDiameter_ / 2.f; |
| 152 | if ( UI::drag<LengthUnit>( _tr( "Cutter Radius" ), radius, 1e-3f, 1e-3f, 1e+3f ) ) |
| 153 | createToolDiameter_ = radius * 2.f; |
| 154 | } |
| 155 | if ( createToolType_ == (int)EndMillCutter::Type::BullNose ) |
| 156 | { |
| 157 | UI::drag<LengthUnit>( _tr( "Cutter Radius" ), createToolCornerRadius_, 1e-3f, 0.f, createToolDiameter_ / 2.f ); |
| 158 | } |
| 159 | if ( createToolType_ == (int)EndMillCutter::Type::Chamfer ) |
| 160 | { |
| 161 | UI::drag<AngleUnit>( _tr( "Cutting Angle" ), createToolCuttingAngle_, 1.f, 0.f, 180.f, { .sourceUnit = AngleUnit::degrees } ); |
| 162 | UI::drag<LengthUnit>( _tr( "End Diameter" ), createToolEndDiameter_, 1e-3f, 0.f, createToolDiameter_ ); |
| 163 | } |
| 164 | ImGui::PopItemWidth(); |
| 165 | |
| 166 | // TODO: visualize tool |
| 167 | |
| 168 | const auto isValid = !createToolName_.empty() && createToolLength_ > 0.f && createToolDiameter_ > 0.f; |
| 169 | if ( UI::button( _tr( "Create" ), isValid, { -1.f, 0.f } ) ) |
| 170 | { |
| 171 | addNewTool_( createToolName_, { |
| 172 | .length = createToolLength_, |
| 173 | .diameter = createToolDiameter_, |
| 174 | .cutter = EndMillCutter { |
nothing calls this directly
no test coverage detected