/// <summary> /// Loads data from current SdkBoard /// </summary> private void LoadCurrentBoard() { bool isNew = false; if (this.currentSdkBoard == null) { // Create new construction with default name this.currentSdkBoard = new SdkBoard(); this.currentSdkBoard.Name = string.Format( "{0} {1}", Properties.Resources.HEADER_BOARD, (this.currentConstruction.SdkBoards.Count + 1).ToString() ); isNew = true; } // Set enum ComboBoxes this.cbx_Impregnation.SelectedItem = SdkImpregnationEnumTranslator.GetTranslatedEnumName(this.currentSdkBoard.Impregnation); this.cbx_LeftEnd.SelectedItem = SdkConstructionEndEnumTranslator.GetTranslatedEnumName(this.currentSdkBoard.LeftEnd); this.cbx_RightEnd.SelectedItem = SdkConstructionEndEnumTranslator.GetTranslatedEnumName(this.currentSdkBoard.RightEnd); // Load other settings this.tbx_LeftHeigth.Text = isNew ? string.Empty : this.currentSdkBoard.LeftHeight.ToString(); this.tbx_RigthHeight.Text = isNew ? string.Empty : this.currentSdkBoard.RightHeight.ToString(); this.tbx_Length.Text = isNew ? string.Empty : this.currentSdkBoard.Length.ToString(); this.tbx_BoardName.Text = this.currentSdkBoard.Name; // Set datagird source RefreshDatagrid(dg_Losts, this.DoorsAndWindows); }
/// <summary> /// Load selected SdkBoard /// </summary> /// <param name="sender">Sender</param> /// <param name="e">EventArgs</param> private void OnBoardSelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.dg_Boards.SelectedItem != null && this.dg_Boards.SelectedItem is SdkBoard) { //Load selected SDK board this.currentSdkBoard = (SdkBoard)this.dg_Boards.SelectedItem; // Load its settings LoadCurrentBoard(); // Go to tab to update construction SwitchTabs(this.CurrentTab, this.tab_Step3); } }
/// <summary> /// Checks dimesions, normalizes dimenzions to fit canvas, /// calculates points of construction and draws them to canvas /// </summary> /// <param name="canvas">Canvas to draw in</param> /// <param name="polygon">Polygon to draw in</param> /// <param name="board">SdkBoard to draw</param> /// <param name="leftHeigth">Left height of construction</param> /// <param name="rigthHeight">Right height of construction</param> /// <param name="length">Length of construction</param> /// <param name="padding">Padding of canvas polygon is in</param> /// <param name="drawLoses">True to draw doors and windows</param> /// <returns>Returns true if polygon was drawn, false otherwise </returns> private bool DrawPolygon( Canvas canvas, Polygon polygon, SdkBoard board, int leftHeigth, int rigthHeight, int length, double padding, bool drawLoses) { try { double ratio; Point leftBottomPoint; double canvasHeight = canvas.ActualHeight; double canvasWidth = canvas.ActualWidth; // Nothing to draw to if (canvas == null || canvasHeight == 0 || canvasWidth == 0 || board == null) return false; NormalizeDimensions( Math.Min( (int)(canvasHeight - 2 * padding), (int)(canvasWidth - 2 * padding) ), ref leftHeigth, ref rigthHeight, ref length, out ratio ); canvas.Children.Clear(); // Count points and draw them DrawPointsInPolygon( polygon, CountConstructionPoints( leftHeigth, rigthHeight, length, (int)canvasHeight, (int)canvasWidth, out leftBottomPoint ) ); canvas.Children.Add(polygon); // Draw loses if specified if (drawLoses) DrawDoorsAndWindows(canvas, ratio, leftBottomPoint, board.DoorsAndWindows); return true; } catch (Exception ex) { Karafa.Errors.KarafaLogger.LogError(ex); return false; } }
/// <summary> /// Creates new SdkBoard and jumps to next step /// </summary> /// <param name="nextStep">TabItem to jump after creation new construction</param> private void CreateNewBoard(TabItem nextStep) { // Create new SDK Construction this.currentSdkBoard = null; // Load its settings LoadCurrentBoard(); // Draw default SDk shapes this.IsResultValid = DrawDefaultShapes(); // Go to step 1 to edit new construction SwitchTabs(CurrentTab, nextStep); }
/// <summary> /// Draws new Result shape of SDK construction based on given dimensions (step 2) /// </summary> /// <param name="board">SdkBoard to draw</param> /// <param name="leftHeigth">Left height of SDK construction</param> /// <param name="rigthHeight">Right height of SDK construction</param> /// <param name="length">Length of SDK construction</param> /// <returns>Returns true if polygon was drawn, false otherwise </returns> private bool ResizeResultShapePolygon(SdkBoard board, int leftHeigth, int rigthHeight, int length) { return DrawPolygon(this.can_Result, this.pgn_ResultShape, board, leftHeigth, rigthHeight, length, 5, true); }
/// <summary> /// Draws new General shape of SDK construction based on given dimensions (step 2) /// </summary> /// <param name="board">SdkBoard to draw</param> /// <param name="leftHeigth">Left height of SDK construction</param> /// <param name="rigthHeight">Right height of SDK construction</param> /// <param name="length">Length of SDK construction</param> /// <returns>Returns true if polygon was drawn, false otherwise </returns> private bool ResizeGeneralShapePolygon(SdkBoard board, int leftHeigth, int rigthHeight, int length) { return DrawPolygon(this.can_General, this.pgn_GeneralShape, board, leftHeigth, rigthHeight, length, 10, false); }
/// <summary> /// Sets material usage based on parameters /// </summary> /// <param name="material">Material to update</param> /// <param name="board">Sdk contstruction board</param> /// <param name="dimension">Specify the part of SDK construction material belongs to</param> /// <param name="usage">Usage for material quantity</param> private void SetSdkMaterialUsage(MaterialItem material, SdkBoard board, string dimension, decimal usage) { // Switch needs constants expressions in case, that is why can not be used decimal quantity = 0; // Quantity is based on dimension (type of construction) ... if (dimension.Equals(Properties.Resources.HTK_SDK_SURFACE_NO_IMPREGNATION)) { quantity = 2 * board.SdkSurface_NoImpregnation + board.SdkSurface_OneSideImpregnation; quantity /= 10000; //cm2 -> m2 } else if (dimension.Equals(Properties.Resources.HTK_SDK_SURFACE_WITH_IMPREGNATION)) { quantity = board.SdkSurface_OneSideImpregnation + 2 * board.SdkSurface_BothSideImpregnation; quantity /= 10000; //cm2 -> m2 } else if (dimension.Equals(Properties.Resources.HTK_SDK_BASE_FLOOR)) { quantity = board.BaseAtFloor; quantity /= 100; //cm -> m } else if (dimension.Equals(Properties.Resources.HTK_SDK_VERTICAL_TRANSOM)) { quantity = (decimal)board.VerticalTransomCount; } else if (dimension.Equals(Properties.Resources.HTK_SDK_BASE_DOOR)) { quantity = (decimal)board.DoorsWidth; quantity /= 10; //cm -> m } else if (dimension.Equals(Properties.Resources.HTK_SDK_END_ROOF)) { quantity = board.EndingAtRoof; quantity /= 10; //cm -> m } else if (dimension.Equals(Properties.Resources.HTK_SDK_END_CORNER)) { quantity = (decimal)board.EndingAtCorner; quantity /= 10; //cm -> m } else if (dimension.Equals(Properties.Resources.HTK_SDK_END_WALL)) { quantity = (decimal)board.EndingAtWall; quantity /= 10; //cm -> m } else if (dimension.Equals(Properties.Resources.HTK_SDK_OVERLAY)) { quantity = (decimal)(board.DoorsOverlay + board.WindowsOverlay); quantity /= 10; //cm -> m } else if (dimension.Equals(Properties.Resources.HTK_SDK_VERTICAL_EDGES)) { quantity = (decimal)(board.WindowsEdgesToBeBought + board.DoorsEdgesToBeBought); } else { quantity = 0; } // Save quantity material.Usage = quantity * usage; }