/// <summary> /// Executes the command. /// Deletes the selected Items. /// If none is selected, it requests a selection. /// </summary> /// <param name="services">CommandServices object to interact with the system</param> public override void Run(Canguro.Controller.CommandServices services) { Canguro.Model.Model model = services.Model; if (model.LoadCases.Count > 1) { Canguro.Model.Load.LoadCase oldCase = model.ActiveLoadCase; // Remove associated AnalysisCase // Find the corresponding AbstractCase Canguro.Model.Load.AnalysisCase aCase = null; foreach (Canguro.Model.Load.AbstractCase ac in services.Model.AbstractCases) { if (ac is Canguro.Model.Load.AnalysisCase && ac.Name.Equals(oldCase.Name)) { aCase = (Canguro.Model.Load.AnalysisCase)ac; break; } } bool deleteLCase = true; // Now remove the AnalysisCase if (aCase != null) { deleteLCase = services.Model.AbstractCases.Remove(aCase); } if (deleteLCase) { services.Model.LoadCases.Remove(oldCase.Name); services.Model.ChangeModel(); } } }
/// <summary> /// Adds all the selected Items to the provided selection list. /// </summary> /// <param name="model">The current Model object</param> /// <param name="selection">The list to add all the selected Items.</param> /// <returns>true if selection contains Items. false otherwise</returns> private bool getSelection(Canguro.Model.Model model, List <Canguro.Model.Item> selection) { foreach (Canguro.Model.Item item in model.JointList) { if (item != null && item.IsSelected) { selection.Add(item); } } foreach (Canguro.Model.Item item in model.LineList) { if (item != null && item.IsSelected) { selection.Add(item); } } foreach (Canguro.Model.Item item in model.AreaList) { if (item != null && item.IsSelected) { selection.Add(item); } } return(selection.Count > 0); }
public void Start(Canguro.Controller.CommandServices services) { if (services == null) { this.services = null; Reset(); return; } Canguro.Model.Model m = Canguro.Model.Model.Instance; // If it's a new command asking for its first selection, throw current (past) selection away if (this.services != services) { m.UnSelectAll(); } this.services = services; Reset(); // Start selection command Canguro.Controller.Controller.Instance.Execute("select"); // If starting a Get Point Selection, start Snap if (services.SelectionFilter == Canguro.Controller.WaitingFor.Point) { Controller.Controller.Instance.TrackingController.SnapController.IsActive = true; } }
public LoadCombinationsDialog(Canguro.Model.Model model, LoadCombination combo) { this.currentCombo = combo; this.model = model; InitializeComponent(); wizardControl.HideTabs = true; oneCombo = (combo != null); }
private static void TestModel(Canguro.Model.Model model) { model.JointList.Add(new Canguro.Model.Joint(-2, 5, 0)); model.JointList.Add(new Canguro.Model.Joint(0, 0, 0)); model.JointList.Add(new Canguro.Model.Joint(2, 5, 0)); model.JointList.Add(new Canguro.Model.Joint(0, 1, 0)); Model.AreaProps props = new Model.AreaProps(); Model.AreaElement area = new Canguro.Model.AreaElement(props, model.JointList[1], model.JointList[2], model.JointList[3], model.JointList[4]); model.AreaList.Add(area); Canguro.Model.Load.Load l = null; area.Loads.Add(l); }
public ReportOptionsDialog(Canguro.Model.Model model) { this.model = model; InitializeComponent(); allReports = new Dictionary <string, ReportOptions>(); allReports.Add(Culture.Get(typeof(JointWrapper).ToString().Replace(".", "")), ReportOptions.Joints); allReports.Add(Culture.Get(typeof(LineWrapper).ToString().Replace(".", "")), ReportOptions.Lines); allReports.Add(Culture.Get(typeof(LoadCaseWrapper).ToString().Replace(".", "")), ReportOptions.LoadCases); allReports.Add(Culture.Get(typeof(JointForcesWrapper).ToString().Replace(".", "")), ReportOptions.JointForces); allReports.Add(Culture.Get(typeof(GroundDisplacementWrapper).ToString().Replace(".", "")), ReportOptions.GroundDisplacements); allReports.Add(Culture.Get(typeof(LineConcentratedForcesWrapper).ToString().Replace(".", "")), ReportOptions.LineConcentratedForces); allReports.Add(Culture.Get(typeof(LineDistributedForcesWrapper).ToString().Replace(".", "")), ReportOptions.LineDistributedLoads); allReports.Add(Culture.Get(typeof(ConstraintWrapper).ToString().Replace(".", "")), ReportOptions.Constraints); allReports.Add(Culture.Get(typeof(MaterialWrapper).ToString().Replace(".", "")), ReportOptions.Materials); allReports.Add(Culture.Get(typeof(MaterialAmountWrapper).ToString().Replace(".", "")), ReportOptions.MaterialAmounts); allReports.Add(Culture.Get(typeof(SectionWrapper).ToString().Replace(".", "")), ReportOptions.Sections); allReports.Add(Culture.Get(typeof(JointDisplacementsWrapper).ToString().Replace(".", "")), ReportOptions.JointDisplacements); allReports.Add(Culture.Get(typeof(BaseReactionsWrapper).ToString().Replace(".", "")), ReportOptions.BaseReactions); allReports.Add(Culture.Get(typeof(ElementJointForcesWrapper).ToString().Replace(".", "")), ReportOptions.ElementJointForces); allReports.Add(Culture.Get(typeof(AssembledJointMassesWrapper).ToString().Replace(".", "")), ReportOptions.AssembledJointMasses); //Begin Modal Tables allReports.Add(Culture.Get(typeof(ModalLPRWrapper).ToString().Replace(".", "")), ReportOptions.ModalLoadParticipationRatios); allReports.Add(Culture.Get(typeof(ModalPMRWrapper).ToString().Replace(".", "")), ReportOptions.ModalParticipatingMassRatios); allReports.Add(Culture.Get(typeof(ModalPFWrapper).ToString().Replace(".", "")), ReportOptions.ModalParticipationFactors); allReports.Add(Culture.Get(typeof(ModalPeriodsWrapper).ToString().Replace(".", "")), ReportOptions.ModalPeriodsAndFrequencies); //End Modal Tables allReports.Add(Culture.Get(typeof(ResponseSpectrumMIWrapper).ToString().Replace(".", "")), ReportOptions.ResponseSpectrumInfo); allReports.Add(Culture.Get(typeof(JointReactionsWrapper).ToString().Replace(".", "")), ReportOptions.JointReactions); allReports.Add(Culture.Get(typeof(JointAccelerationsWrapper).ToString().Replace(".", "")), ReportOptions.JointAccelerations); allReports.Add(Culture.Get(typeof(JointVelocitiesWrapper).ToString().Replace(".", "")), ReportOptions.JointVelocities); //Begin Design Tables allReports.Add(Culture.Get(typeof(DesignOptionsWrapper).ToString().Replace(".", "")), ReportOptions.DesignOptions); allReports.Add(Culture.Get(typeof(SteelDesignWrapper).ToString().Replace(".", "")), ReportOptions.SteelDesign); allReports.Add(Culture.Get(typeof(SteelDesignPMMWrapper).ToString().Replace(".", "")), ReportOptions.SteelDesignPMM); allReports.Add(Culture.Get(typeof(SteelDesignShearWrapper).ToString().Replace(".", "")), ReportOptions.SteelDesignShear); allReports.Add(Culture.Get(typeof(ConcreteColumnDesignWrapper).ToString().Replace(".", "")), ReportOptions.ConcreteColumnDesign); allReports.Add(Culture.Get(typeof(ConcreteBeamDesignWrapper).ToString().Replace(".", "")), ReportOptions.ConcreteBeamDesign); //End Design Tables enableOptions(); }
public ReportOptionsDialog(Canguro.Model.Model model) { this.model = model; InitializeComponent(); allReports = new Dictionary<string, ReportOptions>(); allReports.Add(Culture.Get(typeof(JointWrapper).ToString().Replace(".", "")), ReportOptions.Joints); allReports.Add(Culture.Get(typeof(LineWrapper).ToString().Replace(".", "")), ReportOptions.Lines); allReports.Add(Culture.Get(typeof(LoadCaseWrapper).ToString().Replace(".", "")), ReportOptions.LoadCases); allReports.Add(Culture.Get(typeof(JointForcesWrapper).ToString().Replace(".", "")), ReportOptions.JointForces); allReports.Add(Culture.Get(typeof(GroundDisplacementWrapper).ToString().Replace(".", "")), ReportOptions.GroundDisplacements); allReports.Add(Culture.Get(typeof(LineConcentratedForcesWrapper).ToString().Replace(".", "")), ReportOptions.LineConcentratedForces); allReports.Add(Culture.Get(typeof(LineDistributedForcesWrapper).ToString().Replace(".", "")), ReportOptions.LineDistributedLoads); allReports.Add(Culture.Get(typeof(ConstraintWrapper).ToString().Replace(".", "")), ReportOptions.Constraints); allReports.Add(Culture.Get(typeof(MaterialWrapper).ToString().Replace(".", "")), ReportOptions.Materials); allReports.Add(Culture.Get(typeof(MaterialAmountWrapper).ToString().Replace(".", "")), ReportOptions.MaterialAmounts); allReports.Add(Culture.Get(typeof(SectionWrapper).ToString().Replace(".", "")), ReportOptions.Sections); allReports.Add(Culture.Get(typeof(JointDisplacementsWrapper).ToString().Replace(".", "")), ReportOptions.JointDisplacements); allReports.Add(Culture.Get(typeof(BaseReactionsWrapper).ToString().Replace(".", "")), ReportOptions.BaseReactions); allReports.Add(Culture.Get(typeof(ElementJointForcesWrapper).ToString().Replace(".", "")), ReportOptions.ElementJointForces); allReports.Add(Culture.Get(typeof(AssembledJointMassesWrapper).ToString().Replace(".", "")), ReportOptions.AssembledJointMasses); //Begin Modal Tables allReports.Add(Culture.Get(typeof(ModalLPRWrapper).ToString().Replace(".", "")), ReportOptions.ModalLoadParticipationRatios); allReports.Add(Culture.Get(typeof(ModalPMRWrapper).ToString().Replace(".", "")), ReportOptions.ModalParticipatingMassRatios); allReports.Add(Culture.Get(typeof(ModalPFWrapper).ToString().Replace(".", "")), ReportOptions.ModalParticipationFactors); allReports.Add(Culture.Get(typeof(ModalPeriodsWrapper).ToString().Replace(".", "")), ReportOptions.ModalPeriodsAndFrequencies); //End Modal Tables allReports.Add(Culture.Get(typeof(ResponseSpectrumMIWrapper).ToString().Replace(".", "")), ReportOptions.ResponseSpectrumInfo); allReports.Add(Culture.Get(typeof(JointReactionsWrapper).ToString().Replace(".", "")), ReportOptions.JointReactions); allReports.Add(Culture.Get(typeof(JointAccelerationsWrapper).ToString().Replace(".", "")), ReportOptions.JointAccelerations); allReports.Add(Culture.Get(typeof(JointVelocitiesWrapper).ToString().Replace(".", "")), ReportOptions.JointVelocities); //Begin Design Tables allReports.Add(Culture.Get(typeof(DesignOptionsWrapper).ToString().Replace(".", "")), ReportOptions.DesignOptions); allReports.Add(Culture.Get(typeof(SteelDesignWrapper).ToString().Replace(".", "")), ReportOptions.SteelDesign); allReports.Add(Culture.Get(typeof(SteelDesignPMMWrapper).ToString().Replace(".", "")), ReportOptions.SteelDesignPMM); allReports.Add(Culture.Get(typeof(SteelDesignShearWrapper).ToString().Replace(".", "")), ReportOptions.SteelDesignShear); allReports.Add(Culture.Get(typeof(ConcreteColumnDesignWrapper).ToString().Replace(".", "")), ReportOptions.ConcreteColumnDesign); allReports.Add(Culture.Get(typeof(ConcreteBeamDesignWrapper).ToString().Replace(".", "")), ReportOptions.ConcreteBeamDesign); //End Design Tables enableOptions(); }
public void Init() { try { updatingDialog = true; Canguro.Model.Model model = services.Model; int responseSpectrumCases = 0; foreach (AbstractCase aCase in model.AbstractCases) { if (aCase is AnalysisCase && ((AnalysisCase)aCase).Properties is ModalCaseProps) { modalCase = (AnalysisCase)aCase; modalAnalysisCheckBox.Checked = aCase.IsActive; } else if (aCase is AnalysisCase && ((AnalysisCase)aCase).Properties is PDeltaCaseProps) { pDeltaCase = (AnalysisCase)aCase; pDeltaCheckBox.Checked = aCase.IsActive; } else if (aCase is AnalysisCase && ((AnalysisCase)aCase).Properties is ResponseSpectrumCaseProps) { responseCases.Add((AnalysisCase)aCase); if (aCase.IsActive) { responseSpectrumCases++; } switch (responseSpectrumCases) { case 1: case 2: responseSpectrumCheckBox.CheckState = CheckState.Indeterminate; break; case 3: responseSpectrumCheckBox.CheckState = CheckState.Checked; break; default: responseSpectrumCheckBox.CheckState = CheckState.Unchecked; break; } } } responseSpectrumFunctionsComboBox.Items.Clear(); foreach (ResponseSpectrum rs in model.ResponseSpectra) { responseSpectrumFunctionsComboBox.Items.Add(rs); } steelDesignComboBox.Items.Add(NoDesign.Instance); concreteDesignComboBox.Items.Add(NoDesign.Instance); foreach (DesignOptions option in model.DesignOptions) { if (option is SteelDesignOptions) { steelDesignComboBox.Items.Add(option); } else if (option is ConcreteDesignOptions) { concreteDesignComboBox.Items.Add(option); } } steelDesignComboBox.SelectedItem = model.SteelDesignOptions; concreteDesignComboBox.SelectedItem = model.ConcreteDesignOptions; bool steelActive = false; bool concreteActive = false; foreach (Canguro.Model.LineElement e in model.LineList) { if (e != null && e.Properties is Canguro.Model.StraightFrameProps && ((Canguro.Model.StraightFrameProps)e.Properties).Section.Material.DesignProperties is Canguro.Model.Material.SteelDesignProps) { steelActive = true; } else if (e != null && e.Properties is Canguro.Model.StraightFrameProps && ((Canguro.Model.StraightFrameProps)e.Properties).Section.Material.DesignProperties is Canguro.Model.Material.ConcreteDesignProps) { concreteActive = true; } } steelDesignComboBox.Enabled = steelActive; concreteDesignComboBox.Enabled = concreteActive; } finally { updatingDialog = false; } this.Width = NormalWidth; }
public void UpdateDialog() { try { updatingDialog = true; int responseSpectrumCases = 0; Canguro.Model.Model model = services.Model; analysisCasesCheckedListBox.Items.Clear(); foreach (AbstractCase aCase in model.AbstractCases) { if (!(aCase is AnalysisCase) || (!(((AnalysisCase)aCase).Properties is ModalCaseProps) && (!(((AnalysisCase)aCase).Properties is ResponseSpectrumCaseProps)) && (!(((AnalysisCase)aCase).Properties is PDeltaCaseProps)))) { analysisCasesCheckedListBox.Items.Add(aCase); } if (aCase is AnalysisCase && ((AnalysisCase)aCase).Properties is ResponseSpectrumCaseProps) { if (aCase.IsActive) { responseSpectrumCases++; } switch (responseSpectrumCases) { case 0: responseSpectrumCheckBox.CheckState = CheckState.Unchecked; break; case 1: case 2: responseSpectrumCheckBox.CheckState = CheckState.Indeterminate; break; default: responseSpectrumCheckBox.CheckState = CheckState.Checked; responseSpectrumFactorUpDown.Value = Convert.ToDecimal(((ResponseSpectrumCaseProps)((AnalysisCase)aCase).Properties).ScaleFactor); dampingFactorUpDown.Value = Convert.ToDecimal(((ResponseSpectrumCaseProps)((AnalysisCase)aCase).Properties).ModalDamping); break; } } if (aCase is AnalysisCase && ((AnalysisCase)aCase).Properties is ModalCaseProps) { modalAnalysisCheckBox.Checked = aCase.IsActive; } if (aCase is AnalysisCase && ((AnalysisCase)aCase).Properties is PDeltaCaseProps) { pDeltaCheckBox.Checked = aCase.IsActive; } } for (int i = 0; i < analysisCasesCheckedListBox.Items.Count; i++) { analysisCasesCheckedListBox.SetItemChecked(i, ((AbstractCase)analysisCasesCheckedListBox.Items[i]).IsActive); } if (modalCase != null) { modesNumericUpDown.Value = ((ModalCaseProps)modalCase.Properties).MaxModes; } if (responseCases.Count > 0 && responseCases[0].IsActive) { ResponseSpectrumCaseProps rsProps = (ResponseSpectrumCaseProps)responseCases[0].Properties; //responseSpectrumFunctionsComboBox.SelectedText = rsProps.ResponseSpectrumFunction.ToString(); if (responseSpectrumFunctionsComboBox.SelectedValue == null || !responseSpectrumFunctionsComboBox.SelectedValue.ToString().Equals(rsProps.ResponseSpectrumFunction.ToString())) { foreach (object obj in responseSpectrumFunctionsComboBox.Items) { if (rsProps != null && obj.ToString().Equals(rsProps.ResponseSpectrumFunction.ToString())) { responseSpectrumFunctionsComboBox.SelectedItem = obj; } } } viewSpectrumLink.Enabled = true; } else { viewSpectrumLink.Enabled = false; } modesNumericUpDown.Enabled = modalAnalysisCheckBox.Checked; //responseSpectrumCheckBox.Enabled = modalAnalysisCheckBox.Checked; responseSpectrumFunctionsComboBox.Enabled = responseSpectrumCheckBox.Checked; responseSpectrumFactorUpDown.Enabled = responseSpectrumCheckBox.Checked; dampingFactorLabel.Enabled = responseSpectrumCheckBox.Checked; dampingFactorUpDown.Enabled = responseSpectrumCheckBox.Checked; editSteelDesignLinkLabel.Enabled = steelDesignComboBox.Enabled && model.SteelDesignOptions is SteelDesignOptions; steelCombosLinkLabel.Enabled = editSteelDesignLinkLabel.Enabled; editConcreteDesignLinkLabel.Enabled = concreteDesignComboBox.Enabled && model.ConcreteDesignOptions is ConcreteDesignOptions; concreteCombosLinkLabel.Enabled = editConcreteDesignLinkLabel.Enabled; if (model.SteelDesignOptions is SteelDesignOptions && model.SteelDesignOptions.DesignCombinations.Count == 0) { currentDesignOptions = model.SteelDesignOptions; } else if (model.ConcreteDesignOptions is ConcreteDesignOptions && model.ConcreteDesignOptions.DesignCombinations.Count == 0) { currentDesignOptions = model.ConcreteDesignOptions; } else { currentDesignOptions = null; } AnalyzeButton.Text = (currentDesignOptions == null) ? Culture.Get("analyze") : Culture.Get("next"); AcceptButton = AnalyzeButton; } finally { updatingDialog = false; } Update(); }
//private List<ResultsCase> resultCases; public ResultsSerializer(Canguro.Model.Model model) { results = model.Results; }
public LoadCombinationsDialog(Canguro.Model.Model model) : this(model, null) { }
public ResultsDeserializer(Canguro.Model.Model model) { this.model = model; results = null; }
/* * private object pick(Canguro.View.GraphicView activeView, int x, int y, Controller.WaitingFor wf) * { * // Calculate ray and tolerance * Vector3 rayP = new Vector3(x, y, 0.5f); * Vector3 rayP2 = new Vector3(x, y, 1); * Vector3 rayT1 = new Vector3(x + PickHalfWidthPixels, y, 0.5f); * Vector3 rayT2 = new Vector3(x + PickHalfWidthPixels, y, 1); * activeView.Unproject(ref rayP); * activeView.Unproject(ref rayP2); * activeView.Unproject(ref rayT1); * activeView.Unproject(ref rayT2); * * Vector3 ray = rayP2 - rayP; * ray.Normalize(); * * Vector3 rayTolerance = (rayT2 - rayT1); * rayTolerance.Normalize(); * * float toleranceBiasSq = (rayT1 - rayP).Length(); * float toleranceSlopeSq = (rayT2 - rayP2).Length() - toleranceBiasSq; * float tolerance2xBiasxSlope = 2.0f * toleranceBiasSq * toleranceSlopeSq; * toleranceBiasSq *= toleranceBiasSq; * toleranceSlopeSq *= toleranceSlopeSq; * * // If mouse has moved, generate empty List to store candidates and throw last list away * if ((Math.Abs(lastPickX - fx) > 1 || Math.Abs(lastPickY - fy) > 1) || candidatesPickList == null) * { * candidatesPickList = new List<SelectedItem>(100); * lastCandidatePicked = -1; * lastPickX = fx; * lastPickY = fy; * * // Calculate for Joints * // _ _ _ _ _ _ _ _ * // dSq = (r - p)^2 - ((r-p).u0)^2, point = r, line = p + tq * double dSq, dDist; * Vector3 vTmp; * if ((wf == Canguro.Controller.WaitingFor.Joint || wf == Canguro.Controller.WaitingFor.Any || wf == Canguro.Controller.WaitingFor.Many) * && Canguro.Model.Model.Instance.JointList != null) * { * foreach (Canguro.Model.Joint j in Canguro.Model.Model.Instance.JointList) * { * if (j != null) * { * // Calculate distance * vTmp = j.Position - rayP; * dDist = Vector3.Dot(vTmp, ray); * dSq = Vector3.Dot(vTmp, vTmp) - dDist * dDist; * * // d^2 < (toleranceBias + dDist*toleranceSlope)^2 * if (dSq < (toleranceBiasSq + dDist * dDist * toleranceSlopeSq + dDist * tolerance2xBiasxSlope)) * { * // Add candidate for selection * candidatesPickList.Add(new SelectedItem(dDist, j)); * } * } * } * } * * // Calculate for Lines * // _ _ _ _ _ _ _ _ _ * // dist = (q - p) . n0, g: x = p + ru h: x = q + sv * double dist; * Vector3 u, n0; * if ((wf == Canguro.Controller.WaitingFor.Line || wf == Canguro.Controller.WaitingFor.Any || wf == Canguro.Controller.WaitingFor.Many) * && Canguro.Model.Model.Instance.LineList != null) * { * foreach (Canguro.Model.LineElement l in Canguro.Model.Model.Instance.LineList) * { * if (l != null) * { * // Obtain LineElement parametric form * u = l.J.Position - l.I.Position; * u.Normalize(); * * n0 = Vector3.Cross(u, ray); * n0.Normalize(); * * dist = Vector3.Dot((rayP - l.I.Position), n0); * * // Falta encontrar altura a la que la dist fue calculada * * } * } * } * * candidatesPickList.Sort(new SelectedItemComparer()); * } * * // Return next pick (if the list has recently been created, the first element will be returned) * int unselectIndex = lastCandidatePicked; * lastCandidatePicked++; * if (lastCandidatePicked >= candidatesPickList.Count) * lastCandidatePicked = 0; * * int count; * if ((count = candidatesPickList.Count) > 0) * { * // Unselect previously selected Item * if (unselectIndex >= 0 && count > 1) * candidatesPickList[unselectIndex].item.IsSelected = false; * return candidatesPickList[lastCandidatePicked].item; * } * else * return null; * } */ #endregion /// <summary> /// Método para determinar lo objetos que se encuentren dentro de la ventana. /// Para ello se obtienen primero los parámetros (normal n y punto en el plano s) /// de 4 planos correspondientes a las 4 aristas de la ventana. Estos pueden ser /// ortogonales o piramidales (perspectiva) según el tipo de proyección activo. /// /// Las esquinas se nombran como sigue: /// A----------B (fx1,fy1)-----------(fx2,fy1) /// | World | | Screen space | /// | Space | | | /// D----------C (fx1,fy2)-----------(fx2,fy2) /// /// Tomando las siguientes ecuaciones vectoriales: /// X = P + rQ (Ec. Recta) /// 0 = (X - S) . N (Ec. Plano) /// /// Se puede conocer la distancia entre un punto P y un plano si se crea una /// recta con base en P y dirección N y se interseca con el plano. /// /// La intersección de una recta y un plano es como sigue: /// /// 0 = (P + rQ - S) . N, /// /// y si la dirección de la recta es perpendicular al plano, tenemos que: /// /// Q = N /// /// lo que nos lleva a: /// /// r = (P - S) . N/|N| = (P.(N/|N|)) - (S.(N/|N|)) /// /// Si N es un vector unitario, entonces: /// /// N = N / |N| /// /// Por lo tanto: /// /// r = P.N - S.N /// /// y la distancia entre P y el plano es igual a r. /// /// P.N es la distancia desde el punto al origen, perpendicular al plano /// posX es P.N con N = la normal al plano BC /// posY es P.N con N = la normal al plano AB /// deltaX es la distancia entre los planos BC y DA /// deltaY es la distancia entre los planos AB y CD /// /// Si N apunta hacia afuera en los 4 planos mencionados arriba, entonces una r /// positiva corresponde a estar en la parte interna del plano (con respecto a la /// caja formada por los 4). Por lo tanto un punto con las 4 r's positivas será un /// punto dentro de dicha caja. /// </summary> /// <param name="activeView">La vista (ventana) activa</param> internal void SelectWindow(Canguro.View.GraphicView activeView, int fx1, int fy1, int fx2, int fy2, List <Canguro.Model.Item> selectedItems, Controller.SelectionFilter selectionFilter) { int idJ1, idJ2, idJ3, idJ4; Canguro.Model.Model model = Canguro.Model.Model.Instance; #region Get the selection Box Params Vector3 nAB, sAB, nBC, sBC, nCD, sCD, nDA, sDA; Vector3[] corners1, corners2; corners1 = new Vector3[4]; corners2 = new Vector3[4]; // Checar si el cuadro está vacío if (fx1 == fx2 && fy1 == fy2) { return; } // Obtener parámetros de los 4 planos getPlanes(activeView, fx1, fy1, fx2, fy2, out nAB, out sAB, out nBC, out sBC, out nCD, out sCD, out nDA, out sDA, ref corners1, ref corners2); // Calcular los parámetros que dependen únicamente de los planos // (Como sólo nos interesa el signo de r y no su magnitud real, // no es necesario calcular N.N) float snAB, snBC, snCD, snDA; // nnAB, nnBC, nnCD, nnDA; snAB = Vector3.Dot(sAB, nAB); snBC = Vector3.Dot(sBC, nBC); snCD = Vector3.Dot(sCD, nCD); snDA = Vector3.Dot(sDA, nDA); #endregion #region Displacements and Deformation factors float[,] displacements = null; float deformedScaleFactor = 0f; if (model.HasResults && model.Results.JointDisplacements != null) { displacements = model.Results.JointDisplacements; if (activeView.ModelRenderer.RenderOptions.ShowDeformed) { deformedScaleFactor = model.Results.PaintScaleFactorTranslation; if (activeView.ModelRenderer.RenderOptions.ShowAnimated) { deformedScaleFactor *= activeView.ModelRenderer.RenderOptions.DeformationScale; } } } #endregion #region Joints select window/crossing (Cohen-Sutherland classification) Vector3 jPos; float posY, posX; float distY, distX; distY = (float)-(snCD + snAB); distX = (float)-(snBC + snDA); #region Array memory management // Array to qualify all the joints as in the Cohen Sutherland Algorithm // See http://www.cs.helsinki.fi/group/goa/viewing/leikkaus/lineClip.html for more info int jointCount = model.JointList.Count; int newBufferLength = jointPos.Length; if (newBufferLength != jointCount) { while (jointCount > newBufferLength) { newBufferLength *= 2; } jointPos = new byte[newBufferLength]; jointPosY = new float[newBufferLength]; jointPosX = new float[newBufferLength]; } #endregion // Determinar los Joints que se encuentren dentro de la caja, si es lo que se pide foreach (Canguro.Model.Joint j in model.JointList) { if (j != null) { idJ1 = (int)j.Id; jPos = getJointPos(j, displacements, deformedScaleFactor); jointPosY[idJ1] = posY = Vector3.Dot(jPos, nAB); jointPosX[idJ1] = posX = Vector3.Dot(jPos, nBC); #region Cohen Sutherland classification // Se divide la pantalla de la siguiente forma: // 1001 | 1000 | 1010 // 0001 | 0000 | 0010 // 0101 | 0100 | 0110 // // Si el puntoA OR puntoB == 0 está dentro // Si el puntoA AND puntoB != 0 está fuera // Si no se cumple ninguna de las anteriores, hay que checar la intersección para ver si está dentro if (snAB <= posY) { if (snBC <= posX) { if (snCD <= (-posY)) // posCD { if (snDA <= (-posX)) // posDA { // Está dentro --> seleccionar if (j.IsVisible && ((selectionFilter & Canguro.Controller.SelectionFilter.Joints) > 0)) { if (selectedItems == null) { j.IsSelected = true; newlySelected = true; } else { selectedItems.Add(j); } } jointPos[idJ1] = 0x0; } else { jointPos[idJ1] = 0x8; } } else { if (snDA <= (-posX)) // posDA { jointPos[idJ1] = 0x2; } else { jointPos[idJ1] = 0xA; } } } else { if (snCD <= (-posY)) // posCD { jointPos[idJ1] = 0x4; } else { jointPos[idJ1] = 0x6; } } } else { if (snDA >= (-posX)) // posDA { jointPos[idJ1] = 0x9; } else if (snBC <= posX) { jointPos[idJ1] = 0x1; } else { jointPos[idJ1] = 0x5; } } #endregion } } #endregion if (crossingSelectionOn || selectedItems != null) { #region Crossing Selection #region Lines crossing selection if ((selectionFilter & Canguro.Controller.SelectionFilter.Lines) > 0) { // Selección de LineElements tipo Select Crossing foreach (Canguro.Model.LineElement l in model.LineList) { if (l != null && l.IsVisible) { idJ1 = (int)l.I.Id; idJ2 = (int)l.J.Id; if ((jointPos[idJ1] & jointPos[idJ2]) == 0) { if (jointPos[idJ1] == 0 || jointPos[idJ2] == 0 || (jointPos[idJ1] == 0x1 && jointPos[idJ2] == 0x2) || (jointPos[idJ1] == 0x2 && jointPos[idJ2] == 0x1) || (jointPos[idJ1] == 0x8 && jointPos[idJ2] == 0x4) || (jointPos[idJ1] == 0x4 && jointPos[idJ2] == 0x8)) { if (selectedItems == null) { l.IsSelected = true; newlySelected = true; } else { selectedItems.Add(l); } } else { // Check if line is inside float yL, yR; yL = (jointPosY[idJ1] - snAB) + ((snBC - jointPosX[idJ1]) / (jointPosX[idJ2] - jointPosX[idJ1])) * (jointPosY[idJ2] - jointPosY[idJ1]); yR = (jointPosY[idJ1] - snAB) + ((snDA + jointPosX[idJ1]) / (jointPosX[idJ1] - jointPosX[idJ2])) * (jointPosY[idJ2] - jointPosY[idJ1]); if ((yL >= 0 && yR <= distY) || (yL <= distY && yR >= 0)) { if (selectedItems == null) { l.IsSelected = true; newlySelected = true; } else { selectedItems.Add(l); } } } } } } } #endregion #region Areas crossing selection if ((selectionFilter & Canguro.Controller.SelectionFilter.Areas) > 0) { Vector3 cornersDir = Vector3.Normalize(corners2[0] - corners1[0]); // Selección de AreaElements tipo Select Crossing foreach (Canguro.Model.AreaElement a in model.AreaList) { if (a != null && a.IsVisible) { idJ1 = (int)a.J1.Id; idJ2 = (int)a.J2.Id; idJ3 = (int)a.J3.Id; idJ4 = (int)a.J4.Id; if ((jointPos[idJ1] & jointPos[idJ2] & jointPos[idJ3] & jointPos[idJ4]) == 0) { if (jointPos[idJ1] == 0 || jointPos[idJ2] == 0 || jointPos[idJ3] == 0 || jointPos[idJ4] == 0 || ((jointPos[idJ1] | jointPos[idJ2]) == 0x3) || ((jointPos[idJ1] | jointPos[idJ3]) == 0x3) || ((jointPos[idJ1] | jointPos[idJ4]) == 0x3) || ((jointPos[idJ2] | jointPos[idJ3]) == 0x3) || ((jointPos[idJ2] | jointPos[idJ4]) == 0x3) || ((jointPos[idJ3] | jointPos[idJ4]) == 0x3) || ((jointPos[idJ1] | jointPos[idJ2]) == 0xC) || ((jointPos[idJ1] | jointPos[idJ3]) == 0xC) || ((jointPos[idJ1] | jointPos[idJ4]) == 0xC) || ((jointPos[idJ2] | jointPos[idJ3]) == 0xC) || ((jointPos[idJ2] | jointPos[idJ4]) == 0xC) || ((jointPos[idJ3] | jointPos[idJ4]) == 0xC)) { if (selectedItems == null) { a.IsSelected = true; newlySelected = true; } else { selectedItems.Add(a); } } else { // Check if area intersect selection box Vector3 p, u, v, w, rst; p = a.J1.Position; u = a.J2.Position - p; v = a.J3.Position - p; w = Vector3.Scale(cornersDir, -1f); bool cornerInside = isCornerInsideTriangle(ref p, ref u, ref v, ref w, ref corners1); if (!cornerInside && a.J4 != null) { u = a.J4.Position - p; cornerInside = isCornerInsideTriangle(ref p, ref u, ref v, ref w, ref corners1); } if (cornerInside) { if (selectedItems == null) { a.IsSelected = true; newlySelected = true; } else { selectedItems.Add(a); } } } } } } } #endregion #endregion } else { #region Window Selection // Line select window if ((selectionFilter & Canguro.Controller.SelectionFilter.Lines) > 0) { // Selección de LineElements tipo Select Window foreach (Canguro.Model.LineElement l in model.LineList) { if (l != null && l.IsVisible) { if (jointPos[(int)l.I.Id] + jointPos[(int)l.J.Id] == 0) { if (selectedItems == null) { l.IsSelected = true; newlySelected = true; } else { selectedItems.Add(l); } } } } } // Areas select window if ((selectionFilter & Canguro.Controller.SelectionFilter.Areas) > 0) { // Selección de LineElements tipo Select Window foreach (Canguro.Model.AreaElement a in model.AreaList) { if (a != null && a.IsVisible) { int sumJPos = jointPos[(int)a.J1.Id] + jointPos[(int)a.J2.Id] + jointPos[(int)a.J3.Id] + ((a.J4 != null) ? jointPos[(int)a.J4.Id] : (byte)0); if (sumJPos == 0) { if (selectedItems == null) { a.IsSelected = true; newlySelected = true; } else { selectedItems.Add(a); } } } } } #endregion } }
/// <summary> /// Responds to MouseDown event. Performs picking or selection (start and end of /// window selection) according to the current SelectionFilter. It also sends a /// signal to CommandServices when selection is over so as to unlock waiting commands. /// </summary> /// <param name="activeView">The active View</param> /// <param name="e">MouseDown event arguments</param> public override void ButtonDown(Canguro.View.GraphicView activeView, System.Windows.Forms.MouseEventArgs e) { fx = e.X; fy = e.Y; object pickedObj = null; Canguro.Model.Model m = Canguro.Model.Model.Instance; Canguro.Controller.WaitingFor wf; if (services == null) { wf = Canguro.Controller.WaitingFor.Many; } else { wf = services.SelectionFilter; } if (e.Button == System.Windows.Forms.MouseButtons.Left) { switch (wf) { case Canguro.Controller.WaitingFor.None: case Canguro.Controller.WaitingFor.SimpleValue: case Canguro.Controller.WaitingFor.Text: return; case Canguro.Controller.WaitingFor.Point: pickedObj = pickPoint(activeView); break; case Canguro.Controller.WaitingFor.Joint: case Canguro.Controller.WaitingFor.Line: case Canguro.Controller.WaitingFor.Area: case Canguro.Controller.WaitingFor.Any: pickedObj = pick(fx, fy, wf); break; case Canguro.Controller.WaitingFor.Many: if (windowSelectionOn) { endWindowSelection(true, activeView, wf); pickedObj = null; } else { // TODO: Try to get Anything by Picking and assign it to pickedObj pickedObj = pick(fx, fy, wf); // If nothing was picked turn to window selection mode if (pickedObj == null) { startWindowSelection(e.Location); } } break; default: throw new NotImplementedException("Selection.ButtonDown: " + wf.ToString()); } // If something was picked if (pickedObj != null) { // If an Item was picked, select it if (wf == Canguro.Controller.WaitingFor.Many) { if (pickedObj is Canguro.Model.Item) { ((Canguro.Model.Item)pickedObj).IsSelected = !((Canguro.Model.Item)pickedObj).IsSelected; Canguro.Model.Model.Instance.ChangeSelection((Canguro.Model.Item)pickedObj); } } else { //// Send signal (and item) to CommandServices if selection is over //// (SelectionFilter != WaitingFor.Many) //if (wf != Canguro.Controller.WaitingFor.Many) endCycle(pickedObj); } } } }