public double this[int index] { get { return(conversion.Convert(list[index])); } set { throw new NotSupportedException(); } }
private void buttonYield_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { PosDialogWindow window = IngredientAmountControl.CreateInDefaultWindow(Types.Strings.IngredientEditorEditRecipeYield); IngredientAmountControl control = window.DockedControl as IngredientAmountControl; PosDialogWindow parent = Window.GetWindow(this) as PosDialogWindow; control.MeasurementUnit = MeasurementUnit; control.Amount = (ExtendedIngredientYield.HasValue ? ExtendedIngredientYield.Value : 0); window.ShowDialog(parent); if (!window.ClosedByUser) { double amount = 0; if (control.Amount > 0) { amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit, MeasurementUnit); _extendedIngredientYield = amount; } else { _extendedIngredientYield = null; } buttonYield.Text = amount.ToString(CultureInfo.InvariantCulture); labelUnits.Content = MeasurementUnit.ToString() + (Math.Abs(amount - 1) > double.Epsilon ? Types.Strings.S : ""); if (YieldAmountChanged != null) { YieldAmountChanged.Invoke(this, new EventArgs()); } DoValueChangedEvent(); } e.Handled = true; }
private void AdjustInventory(string windowTitle, int factor) { PosDialogWindow window = IngredientAmountControl.CreateInDefaultWindow(windowTitle); IngredientAmountControl control = window.DockedControl as IngredientAmountControl; PosDialogWindow parent = Window.GetWindow(this) as PosDialogWindow; control.Amount = 0; control.MeasurementUnit = ActiveIngredient.MeasurementUnit; window.ShowDialog(parent); if (!window.ClosedByUser) { if (control.Amount > 0) { double amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit, ActiveIngredient.MeasurementUnit) * factor; IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id, ActiveIngredient.InventoryAmount, ActiveIngredient.InventoryAmount + amount, ActiveIngredient.MeasurementUnit); ActiveIngredient.SetInventoryAmount(ActiveIngredient.InventoryAmount + amount); ActiveIngredient.Update(); } } }
private void buttonSet_Click(object sender, RoutedEventArgs e) { PosDialogWindow window = IngredientAmountControl.CreateInDefaultWindow(Strings.InventorySetAmount); IngredientAmountControl control = window.DockedControl as IngredientAmountControl; PosDialogWindow parent = Window.GetWindow(this) as PosDialogWindow; control.Amount = 0; control.MeasurementUnit = ActiveIngredient.MeasurementUnit; window.ShowDialog(parent); if (!window.ClosedByUser) { if (control.Amount > 0) { double amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit, ActiveIngredient.MeasurementUnit); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id, ActiveIngredient.InventoryAmount, amount, ActiveIngredient.MeasurementUnit); ActiveIngredient.SetInventoryAmount(amount); ActiveIngredient.Update(); } UpdateListBoxItem(); } }
/// <summary> /// Sets the host. /// </summary> /// <param name="host">The main document to which this instance belongs.</param> public void SetHost(OSMDocument host) { this._host = host; this.RenderTransform = this._host.RenderTransformation; this._host._createNewSpatialDataField.Items.Add(this.visualization_Menu); this._strok_thickness = UnitConversion.Convert(0.1d, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType); }
public void Update(int itemId) { // Added Ingredients foreach (ItemIngredient itemIngredient in _itemIngredientsAdded) { itemIngredient.SetItemId(itemId); itemIngredient.Update(); ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, itemId, itemIngredient.IngredientId, null, itemIngredient.Amount, itemIngredient.MeasurementUnit); } // Changed Ingredients foreach (ItemIngredient itemIngredient in _itemIngredientsNeedingUpdate) { ItemIngredient original = ItemIngredient.Get(itemIngredient.Id); double oldAmount = UnitConversion.Convert(original.Amount, original.MeasurementUnit, itemIngredient.MeasurementUnit); itemIngredient.Update(); ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, itemId, itemIngredient.IngredientId, oldAmount, itemIngredient.Amount, itemIngredient.MeasurementUnit); } // Removed Ingredients foreach (ItemIngredient itemIngredient in _itemIngredientsRemoved) { ItemIngredient.Delete(itemIngredient.Id); ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, itemId, itemIngredient.IngredientId, itemIngredient.Amount, null, itemIngredient.MeasurementUnit); } _itemIngredientsAdded.Clear(); _itemIngredientsNeedingUpdate.Clear(); _itemIngredientsRemoved.Clear(); }
/// <summary> /// Sets the host. /// </summary> /// <param name="host">The main document to which this control belongs.</param> public void SetHost(OSMDocument host) { this._host = host; this._stroke_thickness = UnitConversion.Convert(0.1, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType); this.RenderTransform = this._host.RenderTransformation; this._host._activities.Items.Insert(0, this._editeActivity_Menu); this._host._activities.Items.Insert(0, this.visualization_Menu); }
//zoom private void MainWindow_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { double factor = UnitConversion.Convert(0.1, Length_Unit_Types.FEET, _host.BIM_To_OSM.UnitType); var direction = this.camera.LookDirection; direction.Normalize(); this.camera.Position = Vector3D.Add(direction * factor * e.Delta, this.camera.Position); }
private WriteableBitmap getImage() { var cellToValue = this.loadData(); double min = double.PositiveInfinity, max = double.NegativeInfinity; foreach (var item in cellToValue.Values) { min = Math.Min(min, item); max = Math.Max(max, item); } UV diagonal = this._host.cellularFloor.TopRight - this._host.cellularFloor.Origin; /*Seting the size of the image*/ double size_ = 1600 * this.textureDPI / UnitConversion.Convert(1000, this._host.BIM_To_OSM.UnitType, Length_Unit_Types.FEET, 5); //assuming diagonal.U <= diagonal.V double height_ = size_; double width_ = size_ * diagonal.U / diagonal.V; if (diagonal.U > diagonal.V) { width_ = size_; height_ = size_ * diagonal.V / diagonal.U; } //image scale to real world scale double scale = width_ / diagonal.U; //set the image size int h = (int)height_; int w = (int)width_; WriteableBitmap bmp = BitmapFactory.New(w, h); using (bmp.GetBitmapContext()) { bmp.Clear(); foreach (KeyValuePair <Cell, double> item in cellToValue) { Point p1_ = this._materialTransformation.Transform(new Point(item.Key.U, item.Key.V)); Point p2_ = this._materialTransformation.Transform(new Point(item.Key.U + this._host.cellularFloor.CellSize, item.Key.V + this._host.cellularFloor.CellSize)); var color = this._host.ColorCode.GetColor((item.Value - min) / (max - min)); color.A = (byte)(255 * this._dataOpacity); bmp.FillRectangle((int)(p1_.X * scale), (int)(p1_.Y * scale), (int)(p2_.X * scale), (int)(p2_.Y * scale), color); } } return(bmp); /* * //apply Gaussian Smoothing * int[,] kernel = new int[5, 5] * { * {1,4,7,4,1 }, * {4,16,26,16,4 }, * {7,26,41,26,7 }, * {4,16,26,16,4 }, * {1,4,7,4,1 } * }; * return bmp.Convolute(kernel); */ }
internal bool UpdateItem() { string fullName = EditorDetails.FullName; string shortName = EditorDetails.ShortName; double inventoryAmount = EditorDetails.InventoryAmount; MeasurementUnit unit = EditorDetails.MeasurementUnit; double costPerUnit = EditorDetails.CostPerUnit; double? parQuantity = EditorDetails.ParQuantity; // Is there an ActiveItem? if (ActiveIngredient == null) { ActiveIngredient = Ingredient.Add(fullName, shortName, inventoryAmount, unit, costPerUnit, parQuantity); EditorPreparation.Update(ActiveIngredient.Id); ActiveIngredient = Ingredient.Get(ActiveIngredient.Id); } else { if (Math.Abs(ActiveIngredient.InventoryAmount - inventoryAmount) > double.Epsilon) { double originalAmount = UnitConversion.Convert(ActiveIngredient.InventoryAmount, ActiveIngredient.MeasurementUnit, unit); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id, originalAmount, inventoryAmount, unit); } if (ActiveIngredient.MeasurementUnit != unit) { IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id, -1, -1, ActiveIngredient.MeasurementUnit, (int)unit); } if (EditorDetails.IsAdjustedByRecipe) { ProcessInventoryChangesForPrepIngredients( ActiveIngredient.InventoryAmount, inventoryAmount); } // Update the category values for the ActiveItem ActiveIngredient.SetFullName(fullName); ActiveIngredient.SetShortName(shortName); ActiveIngredient.SetInventoryAmount(inventoryAmount); ActiveIngredient.SetMeasurementUnit(unit); ActiveIngredient.SetCostPerUnit(costPerUnit); ActiveIngredient.SetParQuantity(parQuantity); // Update the database ActiveIngredient.Update(); EditorPreparation.Update(ActiveIngredient.Id); ActiveIngredient = Ingredient.Get(ActiveIngredient.Id); } return(true); }
/// <summary> /// Gets the item's ingredient cost (for a single item) /// </summary> /// <returns></returns> public double GetCostOfIngredients() { double result = 0; foreach (ItemIngredient itemIngredient in ItemIngredient.GetAll(Id)) { Ingredient ingredient = Ingredient.Get(itemIngredient.IngredientId); double amountInInventoryUnits = UnitConversion.Convert(itemIngredient.Amount, itemIngredient.MeasurementUnit, ingredient.MeasurementUnit); result += (amountInInventoryUnits * ingredient.GetActualCostPerUnit()); } return(result); }
public void SetMeasurementUnit(MeasurementUnit unit, bool update) { if (update && (MeasurementUnit != unit) && ExtendedIngredientYield.HasValue && (ExtendedIngredientYield.Value > 0) && (unit != MeasurementUnit.Unit) && (unit != MeasurementUnit.None) && ((unit.IsVolume() && MeasurementUnit.IsVolume()) || (unit.IsWeight() && MeasurementUnit.IsWeight()))) { ExtendedIngredientYield = UnitConversion.Convert(ExtendedIngredientYield.Value, MeasurementUnit, unit); buttonYield.Text = (ExtendedIngredientYield.Value.ToString(CultureInfo.InvariantCulture)); } MeasurementUnit = unit; labelUnits.Content = MeasurementUnit.ToString() + Types.Strings.S; }
public void Update(int activeIngredientId) { Ingredient ingredient = Ingredient.Get(activeIngredientId); // Yield if (ingredient.ExtendedIngredientYield != ExtendedIngredientYield) { IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredient.Id, ingredient.ExtendedIngredientYield, ExtendedIngredientYield, MeasurementUnit.None, -1); ingredient.UpdateExtendedIngredientYield(ExtendedIngredientYield); } // Added Ingredients foreach (IngredientSet ingredientSet in _ingredientSetsAdded) { ingredientSet.SetExtendedIngredientId(activeIngredientId); ingredientSet.Update(); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredientSet.IngredientId, null, ingredientSet.Amount, ingredientSet.MeasurementUnit, activeIngredientId); } // Changed Ingredients foreach (IngredientSet ingredientSet in _ingredientSetsNeedingUpdate) { IngredientSet original = IngredientSet.Get(ingredientSet.Id); double oldAmount = UnitConversion.Convert(original.Amount, original.MeasurementUnit, ingredientSet.MeasurementUnit); ingredientSet.Update(); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredientSet.IngredientId, oldAmount, ingredientSet.Amount, ingredientSet.MeasurementUnit, activeIngredientId); } // Removed Ingredients foreach (IngredientSet ingredientSet in _ingredientSetsRemoved) { IngredientSet original = IngredientSet.Get(ingredientSet.Id); IngredientSet.Delete(ingredientSet.Id); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredientSet.IngredientId, original.Amount, null, original.MeasurementUnit, activeIngredientId); } _ingredientSetsAdded.Clear(); _ingredientSetsNeedingUpdate.Clear(); _ingredientSetsRemoved.Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="IsovistClippedGaussian"/> class. /// </summary> /// <param name="cellularFloor">The cellular floor.</param> /// <param name="range">The range of interpolation.</param> /// <param name="tolerance">The tolerance.</param> public IsovistClippedGaussian(CellularFloor cellularFloor, int range, double tolerance = OSMDocument.AbsoluteTolerance) { this.Range = range; this._cellularFloor = cellularFloor; this.Tolerance = tolerance; double x = (this.Range + 1) * this._cellularFloor.CellSize; this._rangeLengthSquared = x * x; double lowerBound = UnitConversion.Convert(0.001d, Length_Unit_Types.FEET, this._cellularFloor.UnitType); double upperBound = UnitConversion.Convert(5.0d, Length_Unit_Types.FEET, this._cellularFloor.UnitType); this._sigma = MathNet.Numerics.RootFinding.RobustNewtonRaphson.FindRoot(this.gaussianPDF, differentialOfGaussianPDF, lowerBound, upperBound); //MessageBox.Show("Sigma: " + this.Sigma.ToString() + "\nValue: " + this.gaussianPDF(this.Sigma).ToString()); this.Filter = IsovistClippedGaussian.GaussianFilter(this.Range + 1, this._cellularFloor.CellSize, this.Sigma); this.RayIndices = IsovistClippedGaussian.LoadRayIndices(this.Range, this._cellularFloor, this.Tolerance); }
/// <summary> /// Sets the main document to which this control belongs. /// </summary> /// <param name="host">The host.</param> public void SetHost(OSMDocument host) { this._host = host; this.RenderTransform = this._host.RenderTransformation; this._stroke_thickness = UnitConversion.Convert(0.1d, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType); this._host.Menues.Items.Insert(5, this._eventMenu); this._host._createNewSpatialDataField.Items.Add(this._generateData); var bindConvector = new ValueToBoolConverter(); Binding bind = new Binding("VisualEventSettings"); bind.Source = this._host; bind.Converter = bindConvector; bind.Mode = BindingMode.OneWay; this._reportVisibilityDetails.SetBinding(MenuItem.IsEnabledProperty, bind); }
/// <summary> /// Will either use the cost of its ingredients, if this is /// a prepared ingredient, else returns this.CostPerUnit /// </summary> /// <returns></returns> public double GetActualCostPerUnit() { if (!IngredientSet.HasEntries(Id)) { return(CostPerUnit); } double result = 0; foreach (IngredientSet ingredientSet in IngredientSet.GetAll(Id)) { Ingredient ingredient = Ingredient.Get(ingredientSet.IngredientId); double amountInInventoryUnits = UnitConversion.Convert(ingredientSet.Amount, ingredientSet.MeasurementUnit, ingredient.MeasurementUnit); result += (amountInInventoryUnits * ingredient.GetActualCostPerUnit()); } return(result); }
void updateTextBoxUnits(Length_Unit_Types original, Length_Unit_Types expected) { double number = 0.0; if (double.TryParse(ObstacleSetting.Text, out number)) { ObstacleSetting.Text = UnitConversion.Convert(number, original, expected).ToString("0.000000"); } if (double.TryParse(CurveApproximationLength_.Text, out number)) { CurveApproximationLength_.Text = UnitConversion.Convert(number, original, expected).ToString("0.000000"); } if (double.TryParse(MinimumCurveLength_.Text, out number)) { MinimumCurveLength_.Text = UnitConversion.Convert(number, original, expected).ToString("0.000000"); } }
/// <summary> /// Checks to see if there is enough Ingredients to make this Item /// </summary> /// <param name="quantity">The quantity of this item to be made</param> /// <returns></returns> public bool HaveIngredientsToMake(int quantity) { if (quantity <= 0) { throw new ArgumentOutOfRangeException("Quantity must be a positive non-zero integer"); } foreach (ItemIngredient itemIngredient in ItemIngredient.GetAll(Id)) { Ingredient ingredient = Ingredient.Get(itemIngredient.IngredientId); double amountInInventoryUnits = UnitConversion.Convert(itemIngredient.Amount, itemIngredient.MeasurementUnit, ingredient.MeasurementUnit); if (ingredient.InventoryAmount < (amountInInventoryUnits * quantity)) { return(false); } } return(true); }
// camera update when panning private void panUpdate(object sender, MouseEventArgs e) { var p = Mouse.GetPosition(this.Scene); this.navigationVectorVisual.X2 = p.X; this.navigationVectorVisual.Y2 = p.Y; if (!this.Scene.Children.Contains(this.navigationVectorVisual)) { this.Scene.Children.Add(this.navigationVectorVisual); } // displacement on the scene Vector3D translationOn2DScene = new Vector3D(p.X - this.navigationVectorStart.X, p.Y - this.navigationVectorStart.Y, 0); Vector3D direction = this.navigationMat.Transform(translationOn2DScene); direction = direction - Vector3D.DotProduct(this.camera.LookDirection, direction) * this.camera.LookDirection; direction = UnitConversion.Convert(0.1, Length_Unit_Types.FEET, _host.BIM_To_OSM.UnitType) * direction; this.camera.Position = Point3D.Add(this.initialCameraPosition, direction); }
public static void LoadDefaultParameters(Length_Unit_Types unitTypeOrigin, Length_Unit_Types unitTypeExpected) { UnitConversion cntr = new UnitConversion(unitTypeOrigin, unitTypeExpected); DefaultParameters = new Dictionary <AgentParameters, Parameter> { //{FreeNavigationAgentParameters.OPT_IsovistInternalDepth.ToString(), // Parameter.CreateReadOnly(FreeNavigationAgentParameters.OPT_IsovistInternalDepth.ToString(), 5.0d, 1.0d,5.0d)}, { AgentParameters.OPT_IsovistExternalDepth, Parameter.CreateReadOnly(AgentParameters.OPT_IsovistExternalDepth.ToString(), cntr.Convert(20.0d, 6), cntr.Convert(5.0d, 6), cntr.Convert(25.0d, 6)) }, { AgentParameters.OPT_NumberOfDestinations, Parameter.CreateReadOnly(AgentParameters.OPT_NumberOfDestinations.ToString(), 100.0d, 20.0d, 200.0d) }, { AgentParameters.OPT_AngleDistributionLambdaFactor, Parameter.CreateReadOnly(AgentParameters.OPT_AngleDistributionLambdaFactor.ToString(), 2.5d, 0.001d, 3.0d) }, { AgentParameters.OPT_DesirabilityDistributionLambdaFactor, Parameter.CreateReadOnly(AgentParameters.OPT_DesirabilityDistributionLambdaFactor.ToString(), 1.5d, 0.001d, 3.0d) }, { AgentParameters.OPT_DecisionMakingPeriodLambdaFactor, Parameter.CreateReadOnly(AgentParameters.OPT_DecisionMakingPeriodLambdaFactor.ToString(), 0.88d, 0.05d, 2.0d) }, { AgentParameters.GEN_VelocityMagnitude, Parameter.CreateReadOnly(AgentParameters.GEN_VelocityMagnitude.ToString(), cntr.Convert(3.8, 6), cntr.Convert(2.0d, 6), cntr.Convert(5.0d, 6)) }, { AgentParameters.GEN_AngularVelocity, Parameter.CreateReadOnly(AgentParameters.GEN_AngularVelocity.ToString(), Math.PI, 0.1d, 6.283185d) }, { AgentParameters.GEN_BodySize, Parameter.CreateReadOnly(AgentParameters.GEN_BodySize.ToString(), cntr.Convert(1.80d, 6), cntr.Convert(1.0d, 6), cntr.Convert(2.2d, 6)) }, { AgentParameters.GEN_VisibilityAngle, Parameter.CreateReadOnly(AgentParameters.GEN_VisibilityAngle.ToString(), 160.0d, 0.0d, 180.0d) }, { AgentParameters.GEN_BarrierRepulsionRange, Parameter.CreateReadOnly(AgentParameters.GEN_BarrierRepulsionRange.ToString(), cntr.Convert(1.4d, 6), cntr.Convert(1.0d, 6), cntr.Convert(5.0d, 6)) }, { AgentParameters.GEN_MaximumRepulsion, Parameter.CreateReadOnly(AgentParameters.GEN_MaximumRepulsion.ToString(), cntr.Convert(15.0d, 6), cntr.Convert(1.0d, 6), cntr.Convert(20.0d, 6)) }, { AgentParameters.GEN_AccelerationMagnitude, Parameter.CreateReadOnly(AgentParameters.GEN_AccelerationMagnitude.ToString(), cntr.Convert(15.0d, 6), cntr.Convert(5.0d, 6), cntr.Convert(20.0d, 6)) }, { AgentParameters.GEN_BarrierFriction, Parameter.CreateReadOnly(AgentParameters.GEN_BarrierFriction.ToString(), 0.1d, 0.0d, 1.0d) }, { AgentParameters.GEN_AgentBodyElasticity, Parameter.CreateReadOnly(AgentParameters.GEN_AgentBodyElasticity.ToString(), 0.2d, 0.0d, 1.0d) }, { AgentParameters.MAN_AngularDeviationCost, Parameter.CreateReadOnly(AgentParameters.MAN_AngularDeviationCost.ToString(), 3.0d, 1.0d, 7.0d) }, { AgentParameters.MAN_DistanceCost, Parameter.CreateReadOnly(AgentParameters.MAN_DistanceCost.ToString(), cntr.Convert(1.0d, 6), cntr.Convert(0.05d, 6), cntr.Convert(2.0d, 6)) }, //{AgentParameters.MAN_GAUSSIANNEIGHBORHOODSIZE, // Parameter.CreateReadOnly(AgentParameters.MAN_AngularDeviationCost.ToString(),7,2,20)}, }; }
private void ProcessInventoryChangesForPrepIngredients(double originalAmount, double newAmount) { if ((Math.Abs(originalAmount - newAmount) < double.Epsilon) || !ActiveIngredient.ExtendedIngredientYield.HasValue) { return; } foreach (IngredientSet ingredientSet in IngredientSet.GetAll(ActiveIngredient.Id)) { Ingredient prepIngredient = Ingredient.Get(ingredientSet.IngredientId); double difference = newAmount - originalAmount; double amount = UnitConversion.Convert(ingredientSet.Amount, ingredientSet.MeasurementUnit, prepIngredient.MeasurementUnit) * difference / ActiveIngredient.ExtendedIngredientYield.Value; prepIngredient.SetInventoryAmount(prepIngredient.InventoryAmount - amount); prepIngredient.Update(); if (ModifiedIngredient != null) { ModifiedIngredient.Invoke(prepIngredient, new EventArgs()); } } }
void animation_Menu_Click(object sender, RoutedEventArgs e) { if (!this._host.AgentMandatoryScenario.IsReadyForPerformance()) { MessageBox.Show(this._host.AgentMandatoryScenario.Message, "Scenario Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } this._settings = new RealTimeMandatoryNavigationControler(); //set the agent thickness { double t_ = double.Parse(this._settings._strokeThicknessMax.Text); this._settings._strokeThicknessMax.Text = UnitConversion.Convert(t_, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType).ToString("0.0000"); this._settings._strokeThickness.Value *= UnitConversion.Convert(1.0, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType); } //set events this._settings._addAgent.Click += _addAgent_Click; this._settings.Closing += _settings_Closing; //show the dialog this._settings.Owner = this._host; this._settings.ShowDialog(); }
private void AdjustInventory(string windowTitle, int factor) { PosDialogWindow window = IngredientAmountControl.CreateInDefaultWindow(windowTitle); IngredientAmountControl control = window.DockedControl as IngredientAmountControl; PosDialogWindow parent = Window.GetWindow(this) as PosDialogWindow; control.Amount = 0; control.MeasurementUnit = MeasurementUnit; window.ShowDialog(parent); if (!window.ClosedByUser) { if (control.Amount > 0) { double amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit, ActiveIngredient.MeasurementUnit) * factor; InventoryAmount += amount; textBoxInventoryAmount.Text = FormatDoubleToString(InventoryAmount); DoValueChangedEvent(); } } }
//orbit camera private void orbitUpdate(object sender, MouseEventArgs e) { var p = Mouse.GetPosition(this.Scene); this.navigationVectorVisual.X2 = p.X; this.navigationVectorVisual.Y2 = p.Y; if (!this.Scene.Children.Contains(this.navigationVectorVisual)) { this.Scene.Children.Add(this.navigationVectorVisual); } // displacement on the scene Vector3D translationOn2DScene = new Vector3D(p.X - this.navigationVectorStart.X, p.Y - this.navigationVectorStart.Y, 0); Vector3D direction = this.navigationMat.Transform(translationOn2DScene); direction = direction - Vector3D.DotProduct(this.initialCameraLookDirection, direction) * this.initialCameraLookDirection; direction *= UnitConversion.Convert(1.0d, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType); if (direction.Length != 0) { Point3D pn1 = Vector3D.Add(direction, this.initialCameraPosition); Vector3D fromTargetToCamera = Point3D.Subtract(pn1, this.targetPoint); Vector3D translation = fromTargetToCamera * (this.distanceToTargetPoint / fromTargetToCamera.Length); //getting new camera position Point3D newCamPos = Point3D.Add(targetPoint, translation); //getting new camera look direction var newCamDir = -1 * fromTargetToCamera; newCamDir.Normalize(); //getting new camera up direction Vector3D helper = Vector3D.CrossProduct(newCamDir, this.initialCameraUpDirection); Vector3D newUp = Vector3D.CrossProduct(helper, newCamDir); if (newUp.LengthSquared != 0) { newUp.Normalize(); } this.camera.UpDirection = newUp; this.camera.Position = newCamPos; this.camera.LookDirection = newCamDir; } }
private void comboBoxMeasuringUnits_SelectedIndexChanged(object sender, EventArgs e) { MeasurementUnit origUnit = _measurementUnit; if (_measurementUnit.IsWeight()) { switch (comboBoxMeasuringUnits.SelectedIndex) { case 0: _measurementUnit = MeasurementUnit.Pound; break; case 1: _measurementUnit = MeasurementUnit.Ounce; break; case 2: _measurementUnit = MeasurementUnit.Gram; break; case 3: _measurementUnit = MeasurementUnit.Milligram; break; case 4: _measurementUnit = MeasurementUnit.Kilogram; break; } } else if (_measurementUnit.IsVolume()) { switch (comboBoxMeasuringUnits.SelectedIndex) { case 0: _measurementUnit = MeasurementUnit.Gallon; break; case 1: _measurementUnit = MeasurementUnit.Quart; break; case 2: _measurementUnit = MeasurementUnit.Pint; break; case 3: _measurementUnit = MeasurementUnit.Cup; break; case 4: _measurementUnit = MeasurementUnit.Tablespoon; break; case 5: _measurementUnit = MeasurementUnit.Teaspoon; break; case 6: _measurementUnit = MeasurementUnit.Liter; break; case 7: _measurementUnit = MeasurementUnit.FluidOunce; break; case 8: _measurementUnit = MeasurementUnit.Milliliter; break; case 9: _measurementUnit = MeasurementUnit.Kiloliter; break; } } Amount = UnitConversion.Convert(Amount, origUnit, _measurementUnit); }
private void settingCompleted() { if (!double.TryParse(this.ObstacleSetting.Text, out this.MinimumHeight)) { MessageBox.Show("Enter a valid number for the 'Minimum Height of Visual Obstacles'!\n(Larger than zero)"); return; } else if (this.MinimumHeight < 0) { MessageBox.Show("Enter a valid number for the 'Minimum Height of Visual Obstacles'!\n(Larger than zero)"); return; } if (!double.TryParse(this.CurveApproximationLength_.Text, out this.CurveApproximationLength)) { MessageBox.Show("Enter a valid number for 'Curve Approximation Length'!"); return; } if (!double.TryParse(this.MinimumCurveLength_.Text, out this.MinimumCurveLength)) { MessageBox.Show("Enter a valid number for 'Minimum Curve Approximation Length'!\n(This length should be smaller than curve approximation length and larger than zero)"); return; } else if (this.MinimumCurveLength >= this.CurveApproximationLength || this.MinimumCurveLength <= 0f) { MessageBox.Show("Enter a valid number for 'Minimum Curve Approximation Length'!\n(This length should be smaller than curve approximation length and larger than zero)"); return; } if (this.FloorPlan == null) { MessageBox.Show("Select a floor plan to continue!"); return; } using (Transaction t = new Transaction(this.uidoc.Document, "Update View Range")) { t.Start(); try { PlanViewRange viewRange = this.FloorPlan.GetViewRange(); ElementId topClipPlane = viewRange.GetLevelId(PlanViewPlane.TopClipPlane); double revitMinimumHeight = UnitConversion.Convert(this.MinimumHeight, this.unitType, Length_Unit_Types.FEET); if (viewRange.GetOffset(PlanViewPlane.TopClipPlane) < revitMinimumHeight) { viewRange.SetOffset(PlanViewPlane.CutPlane, revitMinimumHeight); viewRange.SetOffset(PlanViewPlane.TopClipPlane, revitMinimumHeight); } else { viewRange.SetOffset(PlanViewPlane.CutPlane, revitMinimumHeight); } this.FloorPlan.SetViewRange(viewRange); } catch (Exception ex) { t.Commit(); MessageBox.Show(ex.Report()); } t.Commit(); } uidoc.ActiveView = this.FloorPlan; this.floorPlanNames = null; this.DialogResult = true; this.Close(); }
private void comboBoxMeasuringUnits_SelectedIndexChanged(object sender, EventArgs e) { MeasurementUnit oldUnit = MeasurementUnit; string text = comboBoxMeasuringUnits.SelectedItem; if (text == null) { MeasurementUnit = MeasurementUnit.None; } else { switch (comboBoxMeasuringUnits.SelectedIndex) { case 0: MeasurementUnit = MeasurementUnit.Unit; break; case 1: MeasurementUnit = MeasurementUnit.Pound; break; case 2: MeasurementUnit = MeasurementUnit.Ounce; break; case 3: MeasurementUnit = MeasurementUnit.Gram; break; case 4: MeasurementUnit = MeasurementUnit.Kilogram; break; case 5: MeasurementUnit = MeasurementUnit.Milligram; break; case 6: MeasurementUnit = MeasurementUnit.Gallon; break; case 7: MeasurementUnit = MeasurementUnit.Quart; break; case 8: MeasurementUnit = MeasurementUnit.Pint; break; case 9: MeasurementUnit = MeasurementUnit.Cup; break; case 10: MeasurementUnit = MeasurementUnit.Tablespoon; break; case 11: MeasurementUnit = MeasurementUnit.Teaspoon; break; case 12: MeasurementUnit = MeasurementUnit.Liter; break; case 13: MeasurementUnit = MeasurementUnit.FluidOunce; break; case 14: MeasurementUnit = MeasurementUnit.Milliliter; break; case 15: MeasurementUnit = MeasurementUnit.Kiloliter; break; } } if ((oldUnit != MeasurementUnit) && (MeasurementUnit != MeasurementUnit.Unit) && (MeasurementUnit != MeasurementUnit.None) && ((oldUnit.IsVolume() && MeasurementUnit.IsVolume()) || (oldUnit.IsWeight() && MeasurementUnit.IsWeight())) && PosDialogWindow.ShowDialog( Types.Strings.IngredientEditorConvert1 + (IngredientSet.HasEntries(ActiveIngredient.Id) ? Types.Strings.IngredientEditorConvert2 : "") + Types.Strings.IngredientEditorConvert3, Types.Strings.IngredientEditorUpdateInventory, DialogButtons.YesNo) == DialogButton.Yes) { InventoryAmount = UnitConversion.Convert(InventoryAmount, oldUnit, MeasurementUnit); textBoxInventoryAmount.Text = FormatDoubleToString(InventoryAmount); if (UnitsChanged != null) { UnitsChanged.Invoke(MeasurementUnit, new EventArgs()); } } else { if (UnitsChanged != null) { UnitsChanged.Invoke(MeasurementUnit, null); } } // Events DoValueChangedEvent(); }
/// <summary> /// Initializes a new instance of the <see cref="VisualizerHost3D"/> class. /// </summary> /// <param name="host">The main document to which this window belongs.</param> public VisualizerHost3D(OSMDocument host) { InitializeComponent(); this._host = host; this._materialBound = new Rect(0, 0, this._host.cellularFloor.TopRight.U - this._host.cellularFloor.Origin.U, this._host.cellularFloor.TopRight.V - this._host.cellularFloor.Origin.V); Matrix matrix = Matrix.Identity; matrix.Translate(-this._host.cellularFloor.Origin.U, -this._host.cellularFloor.Origin.V); matrix.Scale(1, -1); matrix.Translate(0, this._host.cellularFloor.TopRight.V - this._host.cellularFloor.Origin.V); this._materialTransformation = new MatrixTransform(matrix); this._contourCount = 10; this._clrMode = ColorMode.Solid; this._geomType = GeometryType.None; this.geomBrush = Brushes.Black.Clone(); this.geomThickness = UnitConversion.Convert(0.1, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType, 5); this.surfaceBrush = Brushes.Tomato.Clone(); this.geometryBrush = Brushes.AliceBlue.Clone(); this.geometryBrush.Opacity = .4; this.geometryMaterial = new DiffuseMaterial(this.geometryBrush); this.textureDPI = UnitConversion.Convert(1000, this._host.BIM_To_OSM.UnitType, Length_Unit_Types.FEET, 5); this._dataOpacity = 1.0d; #region load ground double defaultHeight = -.1; this.leftBottom = new Point3D(this._host.cellularFloor.Territory_Min.U, this._host.cellularFloor.Territory_Min.V, defaultHeight); this.leftTop = new Point3D(this._host.cellularFloor.Territory_Min.U, this._host.cellularFloor.Territory_Max.V, defaultHeight); this.rightBottom = new Point3D(this._host.cellularFloor.Territory_Max.U, this._host.cellularFloor.Territory_Min.V, defaultHeight); this.rightTop = new Point3D(this._host.cellularFloor.Territory_Max.U, this._host.cellularFloor.Territory_Max.V, defaultHeight); Point3DCollection collection2 = new Point3DCollection() { this.leftBottom, this.leftTop, this.rightBottom, this.rightTop }; Int32Collection indices2 = new Int32Collection() { 0, 2, 1, 1, 2, 3, }; this.groundMesh.Positions = collection2; this.groundMesh.TriangleIndices = indices2; #endregion #region set Camera UV center = this._host.cellularFloor.Origin + this._host.cellularFloor.TopRight; center /= 2; this.objectCenter = new Point3D(center.U, center.V, 0); double x = this._host.cellularFloor.Origin.DistanceTo(this._host.cellularFloor.TopRight); x *= -1; var look = new Vector3D(-1, 1, -1); this.camera.LookDirection = look; this.camera.Position = Point3D.Add(this.objectCenter, x * look); var z = new Vector3D(0, 0, 1); var helper = Vector3D.CrossProduct(z, look); var up = Vector3D.CrossProduct(look, helper); up.Normalize(); this.camera.UpDirection = up; #endregion //for zooming this.PreviewMouseWheel += new MouseWheelEventHandler(MainWindow_PreviewMouseWheel); //this.previousCameraPos = this.camera.Position; this.MouseRightButtonDown += new MouseButtonEventHandler(navigationTrigger); this._translateTransform3D = new TranslateTransform3D(new Vector3D(0.0d, 0.0d, UnitConversion.Convert(0.005d, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType))); }
private void importModel_Click(object sender, RoutedEventArgs e) { string name = (string)this.importModel.Header; if (name == "Import Model Geometry") { try { this.AllModels.Children.Remove(this.groundModel); GetNumber getNumber = new GetNumber("Field Offset Value", "Enter a number to expand the territory of the walkable field to include more model geometries", UnitConversion.Convert(1, Length_Unit_Types.FEET, this._host.BIM_To_OSM.UnitType, 6)); getNumber.Owner = this; getNumber.ShowDialog(); double offset = getNumber.NumberValue; getNumber = null; this.modelGeometries = new List <GeometryModel3D>(); foreach (GeometryModel3D item in this._host.BIM_To_OSM.GetSlicedMeshGeometries(this._host.cellularFloor.Territory_Min, this._host.cellularFloor.Territory_Max, offset)) { this.modelGeometries.Add(item); } foreach (var item in this.modelGeometries) { this.AllModels.Children.Add(item); } this.importModel.Header = "Clear Model Geometry"; this.setModelGeometryBrush.IsEnabled = true; } catch (Exception error) { MessageBox.Show(error.Message); } } else { try { this.AllModels.Children.Add(this.groundModel); if (this.modelGeometries != null) { foreach (GeometryModel3D item in this.modelGeometries) { this.AllModels.Children.Remove(item); } } this.modelGeometries.Clear(); this.modelGeometries = null; this.importModel.Header = "Import Model Geometry"; this.setModelGeometryBrush.IsEnabled = false; } catch (Exception error) { MessageBox.Show(error.Message); } } }