Changes
1 changed files (+259/-166)
-
-
@@ -46,65 +46,55 @@ init : Parameters -> Modelinit params = let fields = Dict.fromList [ ( Key.toString LugWidth, String.fromFloat (toMM params.lugWidth) ) , ( Key.toString SurfaceThickness, String.fromFloat (toMM params.thickness) ) , ( Key.toString LiningThickness, String.fromFloat (toMM params.lining) ) , ( Key.toString BuckleHoleOffset, String.fromFloat (toMM params.longPiece.buckleHole.offset) ) , ( Key.toString BuckleHoleCount, String.fromInt params.longPiece.buckleHole.count ) , ( Key.toString BuckleHoleInterval, String.fromFloat (toMM params.longPiece.buckleHole.interval) ) , ( Key.toString BuckleHoleDiameter, String.fromFloat (toMM params.longPiece.buckleHole.diameter) ) , ( Key.toString LongPieceLength, String.fromFloat (toMM params.longPiece.length) ) , ( Key.toString LoopThickness, String.fromFloat (toMM params.shortPiece.loops.thickness) ) , ( Key.toString LoopStyle, loopStyleToString params.shortPiece.loops.style ) , ( Key.toString HasFixedLoop , if params.shortPiece.loops.fixed == Nothing then "false" else "true" ) , ( Key.toString FixedLoopWidth , params.shortPiece.loops.fixed |> Maybe.withDefault defaultFixedLoop |> .width |> toMM |> String.fromFloat ) , ( Key.toString FixedLoopPlay , params.shortPiece.loops.fixed |> Maybe.withDefault defaultFixedLoop |> .play |> toMM |> String.fromFloat ) , ( Key.toString HasFreeLoop , if params.shortPiece.loops.free == Nothing then "false" else "true" ) , ( Key.toString FreeLoopWidth , params.shortPiece.loops.free |> Maybe.withDefault defaultFreeLoop |> .width |> toMM |> String.fromFloat ) , ( Key.toString FreeLoopPlay , params.shortPiece.loops.free |> Maybe.withDefault defaultFreeLoop |> .play |> toMM |> String.fromFloat ) , ( Key.toString FreeLoopOverlap , params.shortPiece.loops.free |> Maybe.withDefault defaultFreeLoop |> .overlap |> toMM |> String.fromFloat ) , ( Key.toString BuckleSpringBarDiameter, String.fromFloat (toMM params.shortPiece.buckle.springBarDiameter) ) , ( Key.toString HasBuckleTongue , if params.shortPiece.buckle.tongue == Nothing then "false" else "true" ) , ( Key.toString BuckleTongueThickness , params.shortPiece.buckle.tongue |> Maybe.withDefault defaultBuckleTongue |> .thickness |> toMM |> String.fromFloat ) , ( Key.toString BuckleTongueWidth , params.shortPiece.buckle.tongue |> Maybe.withDefault defaultBuckleTongue |> .width |> toMM |> String.fromFloat ) , ( Key.toString ShortPieceLength, String.fromFloat (toMM params.shortPiece.length) ) , ( Key.toString CanvasMargin, String.fromFloat (toMM params.rendering.margin) ) , ( Key.toString LineWidth, String.fromFloat (toMM params.rendering.lineWidth) ) , ( Key.toString ColorSchema, colorSchemaToString params.rendering.colorSchema ) ] [ Just ( Key.toString LugWidth, String.fromFloat (toMM params.lugWidth) ) , Just ( Key.toString SurfaceThickness, String.fromFloat (toMM params.thickness) ) , Just ( Key.toString LiningThickness, String.fromFloat (toMM params.lining) ) , Just ( Key.toString BuckleHoleOffset, String.fromFloat (toMM params.longPiece.buckleHole.offset) ) , Just ( Key.toString BuckleHoleCount, String.fromInt params.longPiece.buckleHole.count ) , Just ( Key.toString BuckleHoleInterval, String.fromFloat (toMM params.longPiece.buckleHole.interval) ) , Just ( Key.toString BuckleHoleDiameter, String.fromFloat (toMM params.longPiece.buckleHole.diameter) ) , Just ( Key.toString LongPieceLength, String.fromFloat (toMM params.longPiece.length) ) , Just ( Key.toString LoopThickness, String.fromFloat (toMM params.shortPiece.loops.thickness) ) , Just ( Key.toString LoopStyle, loopStyleToString params.shortPiece.loops.style ) , params.shortPiece.loops.fixed |> Maybe.map (\_ -> ( Key.toString HasFixedLoop, "" )) , Just ( Key.toString FixedLoopWidth , params.shortPiece.loops.fixed |> Maybe.withDefault defaultFixedLoop |> .width |> toMM |> String.fromFloat ) , Just ( Key.toString FixedLoopPlay , params.shortPiece.loops.fixed |> Maybe.withDefault defaultFixedLoop |> .play |> toMM |> String.fromFloat ) , params.shortPiece.loops.free |> Maybe.map (\_ -> ( Key.toString HasFreeLoop, "" )) , Just ( Key.toString FreeLoopWidth , params.shortPiece.loops.free |> Maybe.withDefault defaultFreeLoop |> .width |> toMM |> String.fromFloat ) , Just ( Key.toString FreeLoopPlay , params.shortPiece.loops.free |> Maybe.withDefault defaultFreeLoop |> .play |> toMM |> String.fromFloat ) , Just ( Key.toString FreeLoopOverlap , params.shortPiece.loops.free |> Maybe.withDefault defaultFreeLoop |> .overlap |> toMM |> String.fromFloat ) , Just ( Key.toString BuckleSpringBarDiameter, String.fromFloat (toMM params.shortPiece.buckle.springBarDiameter) ) , params.shortPiece.buckle.tongue |> Maybe.map (\_ -> ( Key.toString HasBuckleTongue, "" )) , Just ( Key.toString BuckleTongueThickness , params.shortPiece.buckle.tongue |> Maybe.withDefault defaultBuckleTongue |> .thickness |> toMM |> String.fromFloat ) , Just ( Key.toString BuckleTongueWidth , params.shortPiece.buckle.tongue |> Maybe.withDefault defaultBuckleTongue |> .width |> toMM |> String.fromFloat ) , Just ( Key.toString ShortPieceLength, String.fromFloat (toMM params.shortPiece.length) ) , Just ( Key.toString CanvasMargin, String.fromFloat (toMM params.rendering.margin) ) , Just ( Key.toString LineWidth, String.fromFloat (toMM params.rendering.lineWidth) ) , Just ( Key.toString ColorSchema, colorSchemaToString params.rendering.colorSchema ) ] |> List.filterMap identity |> Dict.fromList in { fields = fields , errors =
-
@@ -125,6 +115,7 @@type Msg = FieldChanged Key String | FieldUnset Key | ColorSchemaChanged ColorSchema | Highlight Key | Unhighlight Key
-
@@ -152,60 +143,63 @@ Just e_ -> Nothing hasField : Key -> Fields -> Bool hasField key fields = not (Dict.get (Key.toString key) fields == Nothing) parseFixedLoop : Fields -> Result Errors (Maybe Parameters.FixedLoop) parseFixedLoop fields = case parseField HasFixedLoop parseBool fields of Ok True -> case ( parseField FixedLoopWidth (parseLength constraints.shortPiece.loops.fixed.width) fields , parseField FixedLoopPlay (parseLength constraints.shortPiece.loops.fixed.play) fields ) of ( Ok width, Ok play ) -> let base = Parameters.defaultFixedLoop in Ok (Just { base | width = width, play = play }) if hasField HasFixedLoop fields then case ( parseField FixedLoopWidth (parseLength constraints.shortPiece.loops.fixed.width) fields , parseField FixedLoopPlay (parseLength constraints.shortPiece.loops.fixed.play) fields ) of ( Ok width, Ok play ) -> let base = Parameters.defaultFixedLoop in Ok (Just { base | width = width, play = play }) ( width, play ) -> Err (mkErrors [ ( FixedLoopWidth, getError width ) , ( FixedLoopPlay, getError play ) ] ) ( width, play ) -> Err (mkErrors [ ( FixedLoopWidth, getError width ) , ( FixedLoopPlay, getError play ) ] ) _ -> Ok Nothing else Ok Nothing parseFreeLoop : Fields -> Result Errors (Maybe Parameters.FreeLoop) parseFreeLoop fields = case parseField HasFreeLoop parseBool fields of Ok True -> case ( parseField FreeLoopWidth (parseLength constraints.shortPiece.loops.free.width) fields , parseField FreeLoopPlay (parseLength constraints.shortPiece.loops.free.play) fields , parseField FreeLoopOverlap (parseLength constraints.shortPiece.loops.free.overlap) fields ) of ( Ok width, Ok play, Ok overlap ) -> Ok (Just { width = width, play = play, overlap = overlap }) if hasField HasFreeLoop fields then case ( parseField FreeLoopWidth (parseLength constraints.shortPiece.loops.free.width) fields , parseField FreeLoopPlay (parseLength constraints.shortPiece.loops.free.play) fields , parseField FreeLoopOverlap (parseLength constraints.shortPiece.loops.free.overlap) fields ) of ( Ok width, Ok play, Ok overlap ) -> Ok (Just { width = width, play = play, overlap = overlap }) ( width, play, overlap ) -> Err (mkErrors [ ( FreeLoopWidth, getError width ) , ( FreeLoopPlay, getError play ) , ( FreeLoopOverlap, getError overlap ) ] ) ( width, play, overlap ) -> Err (mkErrors [ ( FreeLoopWidth, getError width ) , ( FreeLoopPlay, getError play ) , ( FreeLoopOverlap, getError overlap ) ] ) _ -> Ok Nothing else Ok Nothing parseLoops : Fields -> Result Errors Parameters.Loops
-
@@ -233,26 +227,25 @@parseBuckleTongue : Fields -> Result Errors (Maybe Parameters.BuckleTongue) parseBuckleTongue fields = case parseField HasBuckleTongue parseBool fields of Ok True -> case ( parseField BuckleTongueWidth (parseLength constraints.shortPiece.buckle.tongue.width) fields , parseField BuckleTongueThickness (parseLength constraints.shortPiece.buckle.tongue.thickness) fields ) of ( Ok width, Ok thickness ) -> Ok (Just { width = width, thickness = thickness }) if hasField HasBuckleTongue fields then case ( parseField BuckleTongueWidth (parseLength constraints.shortPiece.buckle.tongue.width) fields , parseField BuckleTongueThickness (parseLength constraints.shortPiece.buckle.tongue.thickness) fields ) of ( Ok width, Ok thickness ) -> Ok (Just { width = width, thickness = thickness }) ( width, thickness ) -> Err (mkErrors [ ( BuckleTongueWidth, getError width ) , ( BuckleTongueThickness, getError thickness ) ] ) ( width, thickness ) -> Err (mkErrors [ ( BuckleTongueWidth, getError width ) , ( BuckleTongueThickness, getError thickness ) ] ) _ -> Ok Nothing else Ok Nothing parseBuckle : Fields -> Result Errors Parameters.Buckle
-
@@ -418,6 +411,24 @@ FieldChanged key value ->let fields = Dict.insert (Key.toString key) value model.fields in case parse fields of Ok newParams -> ( { model | fields = fields , errors = Dict.empty , parameters = newParams } , Cmd.none ) Err errors -> ( { model | fields = fields, errors = errors }, Cmd.none ) FieldUnset key -> let fields = Dict.remove (Key.toString key) model.fields in case parse fields of Ok newParams ->
-
@@ -679,6 +690,94 @@ choices) type alias BoolFieldProps msg = { key : Key , title : List (Html.Html msg) , description : List (Html.Html msg) , attrs : List (Html.Attribute msg) , disabled : Bool , true : { label : List (Html.Html msg), description : List (Html.Html msg) } , false : { label : List (Html.Html msg), description : List (Html.Html msg) } } boolField : Model -> BoolFieldProps Msg -> Html.Html Msg boolField model { key, title, disabled, description, attrs, true, false } = let isTrue = not (Dict.get (Key.toString key) model.fields == Nothing) id : Bool -> String id v = Key.toString key ++ "_" ++ (if v then "true" else "false" ) choiceDescriptionId : Bool -> String choiceDescriptionId v = id v ++ "_description" in node "x-field" [ if disabled then attribute "disabled" "" else class "" ] [ span [ slot "title" ] title , p [ slot "description" ] description , node "x-radio-box" [ if isTrue then attribute "checked" "" else class "" ] [ Html.label [ for (id True), slot "label" ] true.label , Html.p [ Html.Attributes.id (choiceDescriptionId True), slot "description" ] true.description , input (type_ "radio" :: Html.Attributes.id (id True) :: Html.Attributes.name (Key.toString key) :: Html.Attributes.value "true" :: Html.Attributes.checked isTrue :: Html.Attributes.disabled disabled :: Html.Events.onCheck (\_ -> FieldChanged key "") :: ariaDescribedBy [ choiceDescriptionId True ] :: attrs ) [] ] , node "x-radio-box" [ if not isTrue then attribute "checked" "" else class "" ] [ Html.label [ for (id False), slot "label" ] false.label , Html.p [ Html.Attributes.id (choiceDescriptionId False), slot "description" ] false.description , input (type_ "radio" :: Html.Attributes.id (id False) :: Html.Attributes.name (Key.toString key) :: Html.Attributes.value "false" :: Html.Attributes.checked (not isTrue) :: Html.Attributes.disabled disabled :: Html.Events.onCheck (\_ -> FieldUnset key) :: ariaDescribedBy [ choiceDescriptionId False ] :: attrs ) [] ] ] type alias GroupProps msg = { title : List (Html.Html msg) , description : Maybe (List (Html.Html msg))
-
@@ -800,25 +899,23 @@ , disabled = False, attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.buckle.springBarDiameter } , choiceField model , boolField model { key = HasBuckleTongue , title = [ text "Buckle Tongue Cutout" ] , description = [ text "Whether to draw cutout for buckle tongue." ] , attrs = [] , disabled = False , choices = [ { label = [ text "Enabled" ] , description = [ text "Draw cutout at where buckle tongue sits on." ] , value = "true" } , { label = [ text "Disabled" ] , description = [ text "Do not draw cutout for buckle tongue. " , text "Select this if you're planning to use a deployant buckle." ] , value = "false" } ] , true = { label = [ text "Enabled" ] , description = [ text "Draw cutout at where buckle tongue sits on." ] } , false = { label = [ text "Disabled" ] , description = [ text "Do not draw cutout for buckle tongue. " , text "Select this if you're planning to use a deployant buckle." ] } } , numberField model { key = BuckleTongueWidth
-
@@ -826,7 +923,7 @@ , title = [ text "Buckle Tongue Width" ], description = [ text "Width of the buckle tongue / pin." ] , unit = Just "mm" , disabled = not (Dict.get (Key.toString HasBuckleTongue) model.fields == Just "true") , disabled = not (hasField HasBuckleTongue model.fields) , attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.buckle.tongue.width }
-
@@ -836,7 +933,7 @@ , title = [ text "Buckle Tongue Thickness" ], description = [ text "Thickness of the buckle tongue / pin, to add to the cutout depth." ] , unit = Just "mm" , disabled = not (Dict.get (Key.toString HasBuckleTongue) model.fields == Just "true") , disabled = not (hasField HasBuckleTongue model.fields) , attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.buckle.tongue.thickness }
-
@@ -849,8 +946,8 @@ { key = LoopStyle, title = [ text "Loop Style" ] , description = [ text "Style of the fixed loop and the free loop." ] , disabled = not (Dict.get (Key.toString HasFixedLoop) model.fields == Just "true") && not (Dict.get (Key.toString HasFreeLoop) model.fields == Just "true") not (hasField HasFixedLoop model.fields) && not (hasField HasFreeLoop model.fields) , attrs = [] , choices = [ { label = [ text "Simple" ]
-
@@ -869,34 +966,32 @@ , title = [ text "Loop Leather Thickness" ], description = [ text "Thickness of the leather to use for loops. Final thickness will be doubled if you choose \"Folded\" style." ] , unit = Just "mm" , disabled = not (Dict.get (Key.toString HasFixedLoop) model.fields == Just "true") && not (Dict.get (Key.toString HasFreeLoop) model.fields == Just "true") not (hasField HasFixedLoop model.fields) && not (hasField HasFreeLoop model.fields) , attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.loops.thickness } , choiceField model , boolField model { key = HasFixedLoop , title = [ text "Fixed Loop" ] , description = [ text "Whether to draw fixed loop. Certain kind of deployant buckles don't require a fixed loop." ] , attrs = [] , disabled = False , choices = [ { label = [ text "Enabled" ] , description = [ text "Output fixed loop." ] , value = "true" } , { label = [ text "Disabled" ] , description = [ text "Do not output fixed loop." ] , value = "false" } ] , true = { label = [ text "Enabled" ] , description = [ text "Output fixed loop." ] } , false = { label = [ text "Disabled" ] , description = [ text "Do not output fixed loop." ] } } , numberField model { key = FixedLoopWidth , title = [ text "Fixed Loop Width" ] , description = [ text "Width of the fixed loop." ] , unit = Just "mm" , disabled = not (Dict.get (Key.toString HasFixedLoop) model.fields == Just "true") , disabled = not (hasField HasFixedLoop model.fields) , attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.loops.fixed.width }
-
@@ -905,33 +1000,31 @@ { key = FixedLoopPlay, title = [ text "Fixed Loop Play" ] , description = [ text "Extra length to add to the fixed loop, for adjusting tightness." ] , unit = Just "mm" , disabled = not (Dict.get (Key.toString HasFixedLoop) model.fields == Just "true") , disabled = not (hasField HasFixedLoop model.fields) , attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.loops.fixed.play } , choiceField model , boolField model { key = HasFreeLoop , title = [ text "Free Loop" ] , description = [ text "Whether to draw free loop. Certain kind of deployant buckles don't require a free loop." ] , attrs = [] , disabled = False , choices = [ { label = [ text "Enabled" ] , description = [ text "Output free loop." ] , value = "true" } , { label = [ text "Disabled" ] , description = [ text "Do not output free loop." ] , value = "false" } ] , true = { label = [ text "Enabled" ] , description = [ text "Output free loop." ] } , false = { label = [ text "Disabled" ] , description = [ text "Do not output free loop." ] } } , numberField model { key = FreeLoopWidth , title = [ text "Free Loop Width" ] , description = [ text "Width of the free loop." ] , unit = Just "mm" , disabled = not (Dict.get (Key.toString HasFreeLoop) model.fields == Just "true") , disabled = not (hasField HasFreeLoop model.fields) , attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.loops.free.width }
-
@@ -940,7 +1033,7 @@ { key = FreeLoopPlay, title = [ text "Free Loop Play" ] , description = [ text "Extra length to add to the free loop, for adjusting tightness." ] , unit = Just "mm" , disabled = not (Dict.get (Key.toString HasFreeLoop) model.fields == Just "true") , disabled = not (hasField HasFreeLoop model.fields) , attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.loops.free.play }
-
@@ -949,7 +1042,7 @@ { key = FreeLoopOverlap, title = [ text "Free Loop Overlap" ] , description = [ text "Length of overlapping section of the free loop for gluing and/or stitching." ] , unit = Just "mm" , disabled = not (Dict.get (Key.toString HasFreeLoop) model.fields == Just "true") , disabled = not (hasField HasFreeLoop model.fields) , attrs = step "0.1" :: lengthFieldAttrs constraints.shortPiece.loops.free.overlap }
-