public void OnActionExecuting(ActionExecutingContext filterContext) { if (!FeatureUtilities.IsEnabled(_featureToggle)) { filterContext.Result = new HttpNotFoundResult(); } }
protected void TreeView_NodeMouseClickPart(object sender, TreeNodeMouseClickEventArgs e) { try { if (e.Button == MouseButtons.Right) { if (!TreeView.IsNodeSelected(e.Node)) { TreeView.ClearSelection(); TreeView.SetSelected(e.Node, true, false); } SelectInventorFeatures(); if (e.Node.Tag is PartFeature) { if (FeatureUtilities.IsAssociativitySupported(e.Node.Tag as PartFeature)) { _ctxMenuTree.Show(TreeView, e.Location); } } } else { SelectInventorFeatures(); } } catch { //Exception here means that the browser //is out-ot-sync with the features state. RefreshControl(AdnInventorUtilities.InvApplication.ActiveDocument); } }
public void PopulateFlags_ConfigurationResults_ListOfFlags() { // arrange var test1Name = "Test1"; var test2Name = "Test2"; var oneSectionMock = new Mock <IConfigurationSection>(); oneSectionMock.Setup(s => s.Value).Returns(test1Name); var twoSectionMock = new Mock <IConfigurationSection>(); twoSectionMock.Setup(s => s.Value).Returns(test2Name); var section = new List <IConfigurationSection> { oneSectionMock.Object, twoSectionMock.Object }; // act FeatureUtilities.PopulateFlags(section); // assert Assert.AreEqual(2, FeatureUtilities.Flags.Count(), "Flags do not contain 2 elements, actual count: " + FeatureUtilities.Flags.Count()); Assert.IsNotNull(FeatureUtilities.Flags.FirstOrDefault(x => x.Id == test1Name), $"There is no flag named {test1Name}"); Assert.IsNotNull(FeatureUtilities.Flags.FirstOrDefault(x => x.Id == test2Name), $"There is no flag named {test2Name}"); }
public void OctaneMyItemsViewModelTests_MyItems_NotSupported_Feature_Success() { var epic = EpicUtilities.CreateEpic(); try { ValidateType(FeatureUtilities.CreateFeature(epic), 0); } finally { EntityService.DeleteById <Epic>(WorkspaceContext, epic.Id); } }
public ActionResult Index() { string message = "Beta feature is off"; if (FeatureUtilities.IsEnabled(FeatureToggles.Beta)) { message = "Beta feature is on"; } ViewBag.Message = message; return(View()); }
public void IsEnabled_MissingFlag_FeatureDisabled() { // arrange var result = true; FeatureUtilities.Flags = new List <FeatureFlag>(); // act result = FeatureUtilities.IsEnabled(FeatureToggles.Test); // assert Assert.IsFalse(result); }
/// <summary> /// Sends indexing configs. /// </summary> /// <param name="userConnection"><see cref="UserConnection"/> instance.</param> /// <param name="parameters">Execution parameters.</param> public void Execute(UserConnection userConnection, IDictionary <string, object> parameters) { _log.Info("Global search config job started"); var isEnabled = FeatureUtilities.GetIsFeatureEnabled(userConnection, "GlobalSearch_V2"); _log.InfoFormat("GlobalSearch_V2 feature is {0}", isEnabled); if (isEnabled) { var indexginConfigSender = GetIndexingConfigSender(userConnection); indexginConfigSender.Send(); return; } }
protected void RefreshTreeViewAsm(AssemblyDocument document) { InitializeAsm(); _AssemblyDocument = document; TreeNode root = TreeView.Nodes.Add("AsmRoot", _AssemblyDocument.DisplayName, 24); foreach (PartFeature Feature in _AssemblyDocument.ComponentDefinition.Features) { FeatureUtilities.AddAsmFeatureNode(TreeView, root, Feature); } root.Expand(); }
protected void RefreshTreeViewPart(PartDocument document) { InitializePart(); _PartDocument = document; TreeNode root = TreeView.Nodes.Add("PartRoot", _PartDocument.DisplayName, 25); foreach (PartFeature Feature in _PartDocument.ComponentDefinition.Features) { FeatureUtilities.AddPartFeatureNode(TreeView, root, Feature); } root.Expand(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void UpdateFeaturesFromAsm(object sender, EventArgs e) { List <PartFeature> Features = new List <PartFeature>(); foreach (TreeNode node in TreeView.SelectedNodes) { if (node.Tag is PartFeature) { Features.Add(node.Tag as PartFeature); } } FeatureUtilities.UpdateFeaturesFromAsm(_PartDocument, Features); RefreshControl(_PartDocument as Document); }
public void SetSuppressedState(TreeNode node, bool Suppressed) { PartFeature Feature = node.Tag as PartFeature; if (Suppressed) { node.ForeColor = SystemColors.GrayText; node.ImageIndex = FeatureUtilities.GetFeatureImageIndex(Feature) + 1; node.SelectedImageIndex = node.ImageIndex; return; } node.ForeColor = this.ForeColor; node.ImageIndex = FeatureUtilities.GetFeatureImageIndex(Feature); node.SelectedImageIndex = node.ImageIndex; }
public void ToolWindowHelperTests_ConstructContextMenu_Feature_Success() { var epic = EpicUtilities.CreateEpic(); try { ValidateContextMenuItems(FeatureUtilities.CreateFeature(epic), new List <MenuItemEnum> { MenuItemEnum.OpenInBrowser, }, false); } finally { EntityService.DeleteById <Epic>(WorkspaceContext, epic.Id); } }
/// <summary>The application_ begin request.</summary> protected void Application_BeginRequest() { _configuration = new ConfigurationBuilder() .AddAzureAppConfiguration(options => { options.Connect(Environment.GetEnvironmentVariable("AppConfigConnectionString")) .UseFeatureFlags() .ConfigureRefresh(refresh => { refresh.Register("FeatureManagement") .SetCacheExpiration(TimeSpan.FromSeconds(10)); }); _refresher = options.GetRefresher(); }).Build(); var results = _configuration.GetSection("FeatureManagement").GetChildren(); FeatureUtilities.PopulateFlags(results); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public FeatureReport SendToParts(AssemblyDocument ParentDocument, List <ComponentOccurrence> Participants, PartFeature AsmFeature) { ExtrudeFeature extrudeFeature = AsmFeature as ExtrudeFeature; FeatureReport result = new FeatureReport(AsmFeature); if (FeatureUtilities.CreateBackupFile) { FeatureUtilities.BackupFile(Participants); } PlanarSketch asmSketch = extrudeFeature.Profile.Parent as PlanarSketch; foreach (ComponentOccurrence occurrence in Participants) { if (!FeatureUtilities.IsValidOccurrence(occurrence)) { continue; } Matrix invTransfo = occurrence.Transformation; invTransfo.Invert(); PartComponentDefinition partCompDef = occurrence.Definition as PartComponentDefinition; PartFeature newFeature = CopyFeature(partCompDef, AsmFeature, invTransfo); //Place Feature Tag: associativity handling FeatureAttributeManager.CreatePartFeatureTag(ParentDocument, AsmFeature, newFeature, occurrence); ReportData reportData = new ReportData(partCompDef.Document as PartDocument, newFeature); result.addReportData(reportData); } return(result); }
public void IsNotEnabled_MatchingParameter_YesTheFeatureIsNotEnabled() { // arrange var result = true; FeatureUtilities.Flags = new List <FeatureFlag>() { new FeatureFlag { Id = "Test", Enabled = false } }; // act result = FeatureUtilities.IsEnabled(FeatureToggles.Test); // assert Assert.IsFalse(result); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public bool IsPartFeatureUpToDate(PartFeature AsmFeature, PartFeature PartFeature, Matrix invTransfo) { ExtrudeFeature asmFeature = AsmFeature as ExtrudeFeature; ExtrudeFeature partFeature = PartFeature as ExtrudeFeature; try { PlanarSketch asmSketch = asmFeature.Profile.Parent as PlanarSketch; PlanarSketch partSketch = partFeature.Profile.Parent as PlanarSketch; if (!FeatureUtilities.CompareSketches(asmSketch, partSketch, invTransfo)) { return(false); } if (!FeatureUtilities.CompareProfiles(asmFeature.Profile, partFeature.Profile)) { return(false); } if (!FeatureUtilities.IsEqual(asmFeature.TaperAngle.Value, partFeature.TaperAngle.Value)) { return(false); } if (!FeatureUtilities.CompareFeatureExtents(asmFeature.Extent, partFeature.Extent, invTransfo)) { return(false); } return(true); } catch { //Something went wrong return(false); } }
public void IsEnabled_MatchingParameter_YesTheFeatureIsEnabled() { // arrange FeatureUtilities.Flags = new List <FeatureFlag>() { new FeatureFlag { Id = "Test", Enabled = true }, new FeatureFlag { Id = "Beta", Enabled = true } }; // act var result = FeatureUtilities.IsEnabled(FeatureToggles.Test); // assert Assert.IsTrue(result); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void LoadReport(int index) { FeatureReport report = _Reports[index]; switch (report.ReportStatus) { case ReportStatusEnum.kFailed: lbFeatureStatus.Text = " Send to Parts Failed"; lbFeatureStatus.ForeColor = System.Drawing.Color.Red; break; case ReportStatusEnum.kPartial: lbFeatureStatus.Text = " Send to Parts Partially Succeeded"; lbFeatureStatus.ForeColor = System.Drawing.Color.Orange; break; case ReportStatusEnum.kSuccess: lbFeatureStatus.Text = " Send to Parts Succeeded"; lbFeatureStatus.ForeColor = System.Drawing.Color.Green; break; } switch (report.FinalizeAction) { case FinalizeActionEnum.kSuppress: cbAction.SelectedIndex = 0; break; case FinalizeActionEnum.kDeleteAll: case FinalizeActionEnum.kDeleteRetainConsumedSketches: case FinalizeActionEnum.kDeleteRetainSketchesFeatAndWorkFeat: cbAction.SelectedIndex = 1; break; case FinalizeActionEnum.kNone: cbAction.SelectedIndex = 2; break; default: break; } cbStyles.Text = report.Style; lvNewFeatures.Items.Clear(); foreach (ReportData data in report.ReportDataList) { ListViewItem item = null; if (data.PartFeature == null) { item = lvNewFeatures.Items.Add(" --- "); item.UseItemStyleForSubItems = false; item.Tag = data; ListViewItem.ListViewSubItem subItemName = item.SubItems.Add(" --- "); ListViewItem.ListViewSubItem subItemHealth = item.SubItems.Add("Copy Failure"); subItemHealth.ForeColor = System.Drawing.Color.Red; ListViewItem.ListViewSubItem subItemPath = item.SubItems.Add(data.Document.FullFileName); } else { switch (data.FinalizeAction) { case FinalizeActionEnum.kDeleteAll: case FinalizeActionEnum.kDeleteRetainConsumedSketches: case FinalizeActionEnum.kDeleteRetainSketchesFeatAndWorkFeat: item = lvNewFeatures.Items.Add("Delete"); break; case FinalizeActionEnum.kSuppress: item = lvNewFeatures.Items.Add("Suppress"); break; case FinalizeActionEnum.kNone: default: item = lvNewFeatures.Items.Add("None"); break; } item.UseItemStyleForSubItems = false; item.Tag = data; ListViewItem.ListViewSubItem subItemName = item.SubItems.Add(data.FeatureName); ListViewItem.ListViewSubItem subItemHealth = item.SubItems.Add(FeatureUtilities.GetHealthStatusString(data.PartFeature.HealthStatus)); if (data.PartFeature.HealthStatus != HealthStatusEnum.kUpToDateHealth) { subItemHealth.ForeColor = System.Drawing.Color.Red; } ListViewItem.ListViewSubItem subItemPath = item.SubItems.Add(data.Document.FullFileName); } } lvUnrefDocs.Items.Clear(); foreach (string doc in report.UnreferencedDocuments) { ListViewItem item = lvUnrefDocs.Items.Add(doc); item.Checked = report.GetUnrefDocAction(doc); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static RectangularPatternFeature[] CopyRectangularPatternFeature(PartComponentDefinition partCompDef, RectangularPatternFeature AsmFeature, Matrix invTransfo, int elementIdx, ComponentOccurrence occurrence, out ReportData[] reports) { List <RectangularPatternFeature> newFeatures = new List <RectangularPatternFeature>(); ObjectCollection ParentFeatures = FeatureUtilities.CopyParentFeatures(partCompDef, AsmFeature.Parent.Document as Document, AsmFeature.ParentFeatures, invTransfo, occurrence, out reports); if (ParentFeatures.Count == 0) { return(null); } Sketch3D sketch3D = partCompDef.Sketches3D.Add(); List <RectangularPatternFeatureData> FeaturesDataList = new List <RectangularPatternFeatureData>(); //Only along X Axis if (AsmFeature.XDirectionEntity != null && AsmFeature.YDirectionEntity == null) { UnitVector xDirection = FeatureUtilities.GetDirection(AsmFeature.XDirectionEntity); xDirection.TransformBy(invTransfo); Point xDirStartPoint = null; WorkAxis xDirAxis = null; SketchPoint3D xDirStartPoint3D = null; try { xDirStartPoint = FeatureUtilities.GetPoint(AsmFeature.XDirectionStartPoint); xDirStartPoint.TransformBy(invTransfo); xDirAxis = partCompDef.WorkAxes.AddFixed(xDirStartPoint, xDirection, FeatureUtilities.ConstructionWorkAxis); xDirStartPoint3D = sketch3D.SketchPoints3D.Add(xDirStartPoint, false); } catch { xDirAxis = partCompDef.WorkAxes.AddFixed(partCompDef.WorkPoints[1].Point, xDirection, FeatureUtilities.ConstructionWorkAxis); } double count1 = (double)(AsmFeature.XCount.Value) - elementIdx + 1; //Check it's not the last pattern element if (count1 != 0 && elementIdx != (double)(AsmFeature.XCount.Value)) { RectangularPatternFeatureData featureData = newRectangularPatternFeatureData(); featureData.xCount = count1; featureData.xSpacing = AsmFeature.XSpacing.Value; featureData.naturalXDirection = AsmFeature.NaturalXDirection; featureData.xDirectionSpacingType = AsmFeature.XDirectionSpacingType; featureData.xDirAxis = xDirAxis; featureData.xDirStartPoint3D = xDirStartPoint3D; FeaturesDataList.Add(featureData); } double count2 = elementIdx; //Check it's not the first pattern element if (count2 != 0 && elementIdx != 1) { RectangularPatternFeatureData featureData = newRectangularPatternFeatureData(); featureData.xCount = count2; featureData.xSpacing = AsmFeature.XSpacing.Value; featureData.naturalXDirection = !AsmFeature.NaturalXDirection; featureData.xDirectionSpacingType = AsmFeature.XDirectionSpacingType; featureData.xDirAxis = xDirAxis; featureData.xDirStartPoint3D = xDirStartPoint3D; FeaturesDataList.Add(featureData); } } //Only along Y Axis if (AsmFeature.YDirectionEntity != null && AsmFeature.XDirectionEntity == null) { } //Only along both Axes if (AsmFeature.XDirectionEntity != null && AsmFeature.YDirectionEntity != null) { } foreach (RectangularPatternFeatureData featureData in FeaturesDataList) { RectangularPatternFeature newFeature = partCompDef.Features.RectangularPatternFeatures.Add(ParentFeatures, featureData.xDirAxis, featureData.naturalXDirection, featureData.xCount, featureData.xSpacing, featureData.xDirectionSpacingType, featureData.xDirStartPoint3D, featureData.yDirAxis, featureData.naturalYDirection, featureData.yCount, featureData.ySpacing, featureData.yDirectionSpacingType, featureData.yDirStartPoint3D, AsmFeature.ComputeType, AsmFeature.OrientationMethod); foreach (FeaturePatternElement element in newFeature.PatternElements) { if (newFeature.HealthStatus == HealthStatusEnum.kUpToDateHealth) { break; } if (element.Faces.Count == 0 && element.Index != 1) { element.Suppressed = true; } } if (newFeature != null) { newFeatures.Add(newFeature); } } return(newFeatures.ToArray()); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static FeatureReport SendToPartsAsPattern(AssemblyDocument ParentDocument, List <ComponentOccurrence> Participants, RectangularPatternFeature AsmFeature) { FeatureReport result = new FeatureReport(AsmFeature as PartFeature); if (FeatureUtilities.CreateBackupFile) { FeatureUtilities.BackupFile(Participants); } foreach (ComponentOccurrence occurrence in Participants) { if (!FeatureUtilities.IsValidOccurrence(occurrence)) { continue; } bool loop = true; int elementIdx = 1; Matrix patternElemTransfo = FeatureUtilities.Application.TransientGeometry.CreateMatrix(); //Find first pattern element that affect this occurrence foreach (FeaturePatternElement element in AsmFeature.PatternElements) { foreach (FaceProxy faceProxy in element.Faces) { if (faceProxy.ContainingOccurrence == occurrence) { patternElemTransfo = element.Transform; patternElemTransfo.Invert(); elementIdx = element.Index; loop = false; break; } } if (!loop) { break; } } Matrix invTransfo = occurrence.Transformation; invTransfo.TransformBy(patternElemTransfo); invTransfo.Invert(); PartComponentDefinition partCompDef = occurrence.Definition as PartComponentDefinition; ReportData[] reports = null; RectangularPatternFeature[] newFeatures = CopyRectangularPatternFeature(partCompDef, AsmFeature, invTransfo, elementIdx, occurrence, out reports); foreach (ReportData reportData in reports) { result.addReportData(reportData); } foreach (RectangularPatternFeature newFeature in newFeatures) { result.addReportData(new ReportData(partCompDef.Document as PartDocument, newFeature as PartFeature)); } } return(result); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static FeatureReport SendToPartsAsCollection(AssemblyDocument ParentDocument, List <ComponentOccurrence> Participants, RectangularPatternFeature AsmFeature) { FeatureReport result = new FeatureReport(AsmFeature as PartFeature); if (FeatureUtilities.CreateBackupFile) { FeatureUtilities.BackupFile(Participants); } foreach (ComponentOccurrence occurrence in Participants) { if (!FeatureUtilities.IsValidOccurrence(occurrence)) { continue; } //Find if a pattern element affects this occurrence foreach (FeaturePatternElement element in AsmFeature.PatternElements) { bool affected = false; foreach (FaceProxy faceProxy in element.Faces) { if (faceProxy.ContainingOccurrence == occurrence) { affected = true; break; } } //first occurrence won't be migrated to parts. //Need to migrate parent feature for that if (!affected) { continue; } Matrix invTransfo = occurrence.Transformation; Matrix patternElemTransfo = element.Transform; patternElemTransfo.Invert(); invTransfo.TransformBy(patternElemTransfo); invTransfo.Invert(); PartComponentDefinition partCompDef = occurrence.Definition as PartComponentDefinition; ReportData[] reports = null; ObjectCollection ParentFeatures = FeatureUtilities.CopyParentFeatures(partCompDef, ParentDocument as Document, AsmFeature.ParentFeatures, invTransfo, occurrence, out reports); foreach (ReportData reportData in reports) { //Place Feature Tag: associativity handling //Not supported yet /*FeatureAttributeManager.CreatePartFeatureTag(ParentDocument, * AsmFeature as PartFeature, * reportData.PartFeature, * occurrence);*/ result.addReportData(reportData); } } } return(result); }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { // This method is called by Inventor when it loads the addin. // The AddInSiteObject provides access to the Inventor Application object. // The FirstTime flag indicates if the addin is loaded for the first time. // Initialize AddIn members. m_inventorApplication = addInSiteObject.Application; //Prevent user from unloading the add-in (except at Inventor shutdown). //This workarounds an issue concerning unloading/reloading an addin that //creates controls in a native Inventor Panel. //addInSiteObject.Parent.UserUnloadable = false; Type addinType = this.GetType(); AdnInventorUtilities.Initialize(m_inventorApplication, addinType); //Initialize the FeatureUtilities library FeatureUtilities.Initialize(m_inventorApplication); //Initialize FeatureMigratorss for each type of feature we support FeatureUtilities.SetFeatureMigrator(ObjectTypeEnum.kExtrudeFeatureObject, new FeatureMigratorLib.ExtrudeFeatureMigrator()); FeatureUtilities.SetFeatureMigrator(ObjectTypeEnum.kHoleFeatureObject, new FeatureMigratorLib.HoleFeatureMigrator()); FeatureUtilities.SetFeatureMigrator(ObjectTypeEnum.kCircularPatternFeatureObject, new FeatureMigratorLib.CircularPatternFeatureMigrator()); FeatureUtilities.SetFeatureMigrator(ObjectTypeEnum.kRectangularPatternFeatureObject, new FeatureMigratorLib.RectangularPatternFeatureMigrator()); AdnCommand.AddCommand( new FeatureMigratorAsmCtrlCmd( m_inventorApplication, addInSiteObject, _dockableWindow)); AdnCommand.AddCommand( new FeatureMigratorPartCtrlCmd( m_inventorApplication, addInSiteObject, _dockableWindow)); AdnCommand.AddCommand( new FeatureMigratorSettingsCtrlCmd( m_inventorApplication)); AdnCommand.AddCommand( new FeatureMigratorHelpCtrlCmd( m_inventorApplication)); AdnCommand.AddCommand( new FeatureMigratorAboutCtrlCmd( m_inventorApplication)); // Only after all commands have been added, // load Ribbon UI from customized xml file. // Make sure "InternalName" of above commands is matching // "internalName" tag described in xml of corresponding command. AdnRibbonBuilder.CreateRibbon( m_inventorApplication, addinType, "FeatureMigratorAddin.resources.ribbons.xml"); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static CircularPatternFeature[] CopyCircularPatternFeature(PartComponentDefinition partCompDef, CircularPatternFeature Feature, Matrix invTransfo, int elementIdx, ComponentOccurrence occurrence, out ReportData[] reports) { List <CircularPatternFeature> newFeatures = new List <CircularPatternFeature>(); ObjectCollection ParentFeatures = FeatureUtilities.CopyParentFeatures(partCompDef, Feature.Parent.Document as Document, Feature.ParentFeatures, invTransfo, occurrence, out reports); if (ParentFeatures.Count == 0) { return(null); } List <CircularPatternFeatureData> FeaturesDataList = new List <CircularPatternFeatureData>(); WorkAxis axis = FeatureUtilities.GetAxis(partCompDef, Feature.AxisEntity, invTransfo); double step = (double)Feature.Angle.Value / (double)Feature.Count.Value; double count1 = (double)Feature.Count.Value - elementIdx + 1; //Check it's not the last pattern element if (elementIdx != (double)(Feature.Count.Value)) { CircularPatternFeatureData featureData = new CircularPatternFeatureData(); featureData.axis = axis; featureData.naturalAxisDirection = Feature.NaturalAxisDirection; featureData.count = count1; featureData.angle = step * (count1 - 1); featureData.fitWithinAngle = Feature.FitWithinAngle; FeaturesDataList.Add(featureData); } double count2 = elementIdx; //Check it's not the first pattern element if (elementIdx != 1) { CircularPatternFeatureData featureData = new CircularPatternFeatureData(); featureData.axis = axis; featureData.naturalAxisDirection = !Feature.NaturalAxisDirection; featureData.count = count2; featureData.angle = step * (count2 - (elementIdx == (double)(Feature.Count.Value) ? 0 : 1)); featureData.fitWithinAngle = Feature.FitWithinAngle; FeaturesDataList.Add(featureData); } foreach (CircularPatternFeatureData featureData in FeaturesDataList) { CircularPatternFeature newFeature = partCompDef.Features.CircularPatternFeatures.Add(ParentFeatures, featureData.axis, featureData.naturalAxisDirection, featureData.count, featureData.angle, featureData.fitWithinAngle, Feature.ComputeType); if (newFeature != null) { newFeatures.Add(newFeature); } } return(newFeatures.ToArray()); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static FeatureReport SendToPartsAsPattern(AssemblyDocument ParentDocument, List <ComponentOccurrence> Participants, CircularPatternFeature AsmFeature) { FeatureReport result = new FeatureReport(AsmFeature as PartFeature); if (FeatureUtilities.CreateBackupFile) { FeatureUtilities.BackupFile(Participants); } foreach (ComponentOccurrence occurrence in Participants) { if (!FeatureUtilities.IsValidOccurrence(occurrence)) { continue; } bool loop = true; int elementIdx = 1; Matrix patternElemTransfo = FeatureUtilities.Application.TransientGeometry.CreateMatrix(); //Find first pattern element that affect this occurrence foreach (FeaturePatternElement element in AsmFeature.PatternElements) { foreach (FaceProxy faceProxy in element.Faces) { if (faceProxy.ContainingOccurrence == occurrence) { patternElemTransfo = element.Transform; patternElemTransfo.Invert(); elementIdx = element.Index; loop = false; break; } } if (!loop) { break; } } Matrix invTransfo = occurrence.Transformation; invTransfo.TransformBy(patternElemTransfo); invTransfo.Invert(); PartComponentDefinition partCompDef = occurrence.Definition as PartComponentDefinition; ReportData[] reports = null; CircularPatternFeature[] newFeatures = CopyCircularPatternFeature(partCompDef, AsmFeature, invTransfo, elementIdx, occurrence, out reports); foreach (ReportData reportData in reports) { result.addReportData(reportData); } foreach (CircularPatternFeature newFeature in newFeatures) { double count = (double)(newFeature.Count.Value); if (newFeature.HealthStatus != HealthStatusEnum.kUpToDateHealth) { foreach (FeaturePatternElement element in newFeature.PatternElements) { if (element.Faces.Count == 0 && element.Index != 1) { element.Suppressed = true; --count; } } } //Single pattern occurrence -> delete the pattern feature if (count == 1) { newFeature.Delete(false, false, false); continue; } result.addReportData(new ReportData(partCompDef.Document as PartDocument, newFeature as PartFeature)); } } return(result); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public bool UpdateFeatureFromAsm(PartFeature AsmFeature, PartFeature PartFeature, Matrix invTransfo) { ExtrudeFeature asmFeature = AsmFeature as ExtrudeFeature; ExtrudeFeature partFeature = PartFeature as ExtrudeFeature; try { PartComponentDefinition partCompDef = partFeature.Parent as PartComponentDefinition; PlanarSketch partSketch = partFeature.Profile.Parent as PlanarSketch; UnitVector xAxis = null; UnitVector yAxis = null; FeatureUtilities.UpdateSketch(asmFeature.Profile.Parent as PlanarSketch, partSketch, invTransfo, out xAxis, out yAxis); Document asmDocument = asmFeature.Parent.Document as Document; bool suppressed = partFeature.Suppressed; //Feature needs to be suppressed if we change the Profile partFeature.Suppressed = true; Profile newPartProfile = FeatureUtilities.UpdateProfile(asmDocument, partCompDef.Document as Document, asmFeature.Profile, partFeature.Profile, true); if (newPartProfile != null) { partFeature.Profile = newPartProfile; } partFeature.Suppressed = suppressed; partFeature.TaperAngle.Value = asmFeature.TaperAngle.Value; if (FeatureUtilities.UpdateFeatureExtent(asmFeature.Extent, partFeature.Extent, invTransfo)) { return(true); } switch (asmFeature.ExtentType) { case PartFeatureExtentEnum.kThroughAllExtent: { ThroughAllExtent asmThroughAllExtent = asmFeature.Extent as ThroughAllExtent; partFeature.SetThroughAllExtent(asmThroughAllExtent.Direction); break; } case PartFeatureExtentEnum.kDistanceExtent: { DistanceExtent asmDistanceExtent = asmFeature.Extent as DistanceExtent; partFeature.SetDistanceExtent(asmDistanceExtent.Distance.Value, asmDistanceExtent.Direction); break; } case PartFeatureExtentEnum.kToExtent: { ToExtent asmToExtent = asmFeature.Extent as ToExtent; object ToEntity = FeatureUtilities.CopyFromToEntity(asmToExtent.ToEntity, partCompDef, invTransfo); partFeature.SetToExtent(ToEntity, false); break; } case PartFeatureExtentEnum.kFromToExtent: { FromToExtent asmFromToExtent = asmFeature.Extent as FromToExtent; object FromEntity = FeatureUtilities.CopyFromToEntity(asmFromToExtent.FromFace, partCompDef, invTransfo); object ToEntity = FeatureUtilities.CopyFromToEntity(asmFromToExtent.ToFace, partCompDef, invTransfo); partFeature.SetFromToExtent(FromEntity, false, ToEntity, false); break; } default: return(false); } return(true); } catch { //Something went wrong return(false); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void SendToParts(object sender, EventArgs e) { //Check assembly state before the features migration switch (FeatureUtilities.CheckAssemblyState(_AssemblyDocument)) { case FeatureUtilities.AssemblyStateEnum.kAssemblyNotSaved: { string msg = "Assembly and its sub-components need to be saved on the disk" + System.Environment.NewLine + "for the features migration." + System.Environment.NewLine + "Please save each file first and run the command again..."; System.Windows.Forms.MessageBox.Show(msg, "Feature Migrator", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } case FeatureUtilities.AssemblyStateEnum.kException: return; default: break; } Transaction Tx = null; try { Tx = FeatureUtilities.Application.TransactionManager.StartTransaction( _AssemblyDocument as _Document, "Send Features"); List <FeatureReport> results = new List <FeatureReport>(); foreach (TreeNode node in TreeView.SelectedNodesBottomUp) { if (!(node.Tag is PartFeature)) { continue; } PartFeature Feature = node.Tag as PartFeature; if (Feature.Suppressed) { //Do not migrate a suppressed feature continue; } List <ComponentOccurrence> Participants = new List <ComponentOccurrence>(); foreach (TreeNode occNode in node.Nodes) { //Check if node is enabled if (occNode.Tag != null && occNode.Tag is ComponentOccurrence) { Participants.Add(occNode.Tag as ComponentOccurrence); } } if (Participants.Count != 0) { FeatureReport result = FeatureUtilities.SendToParts(_AssemblyDocument, Feature, Participants); if (result != null) { results.Add(result); } } } if (results.Count != 0) { if (FeatureUtilities.SingleFeatureOptions) { ActionPreFinalize(results); DetailReportControl detailReportControl = new DetailReportControl(_AssemblyDocument, results); detailReportControl.ShowAsChildModal(); } else { ActionPreFinalize(results); ActionFinalize(results); } System.IO.FileInfo fi = new System.IO.FileInfo(_AssemblyDocument.FullFileName); string logfile = fi.DirectoryName + "\\" + fi.Name.Substring(0, fi.Name.Length - 4) + ".log"; FeatureReport.LogReport(results, logfile); } Tx.End(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "Exception occurred!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Tx.Abort(); } finally { RefreshControl(_AssemblyDocument as Document); _AssemblyDocument.Update2(true); this.Parent.Refresh(); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public PartFeature CopyFeature(PartComponentDefinition partCompDef, PartFeature AsmFeature, Matrix invTransfo) { try { ExtrudeFeature extrudeFeature = AsmFeature as ExtrudeFeature; ExtrudeFeature newFeature = null; UnitVector xAxis = null; UnitVector yAxis = null; PlanarSketch asmSketch = extrudeFeature.Profile.Parent as PlanarSketch; PlanarSketch partSketch = FeatureUtilities.CopySketch(partCompDef, asmSketch, invTransfo, out xAxis, out yAxis); ObjectCollection pathSegments = FeatureUtilities.GetPathSegments(extrudeFeature.Profile, partSketch); Profile partProfile = partSketch.Profiles.AddForSolid(true, pathSegments, null); FeatureUtilities.CopyProfile(extrudeFeature.Profile, partProfile); switch (extrudeFeature.ExtentType) { case PartFeatureExtentEnum.kThroughAllExtent: { ThroughAllExtent ThroughAllExtent = extrudeFeature.Extent as ThroughAllExtent; newFeature = partCompDef.Features.ExtrudeFeatures.AddByThroughAllExtent(partProfile, ThroughAllExtent.Direction, extrudeFeature.Operation, extrudeFeature.TaperAngle.Value); break; } case PartFeatureExtentEnum.kDistanceExtent: { DistanceExtent DistanceExtent = extrudeFeature.Extent as DistanceExtent; newFeature = partCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(partProfile, DistanceExtent.Distance.Value, DistanceExtent.Direction, extrudeFeature.Operation, extrudeFeature.TaperAngle.Value); break; } case PartFeatureExtentEnum.kToExtent: { ToExtent ToExtent = extrudeFeature.Extent as ToExtent; object ToEntity = FeatureUtilities.CopyFromToEntity(ToExtent.ToEntity, partCompDef, invTransfo); newFeature = partCompDef.Features.ExtrudeFeatures.AddByToExtent(partProfile, ToEntity, extrudeFeature.Operation, false, extrudeFeature.TaperAngle.Value); break; } case PartFeatureExtentEnum.kFromToExtent: { FromToExtent FromToExtent = extrudeFeature.Extent as FromToExtent; object FromEntity = FeatureUtilities.CopyFromToEntity(FromToExtent.FromFace, partCompDef, invTransfo); object ToEntity = FeatureUtilities.CopyFromToEntity(FromToExtent.ToFace, partCompDef, invTransfo); newFeature = partCompDef.Features.ExtrudeFeatures.AddByFromToExtent(partProfile, FromEntity, false, ToEntity, false, extrudeFeature.Operation, extrudeFeature.TaperAngle.Value); break; } default: break; } return(newFeature as PartFeature); } catch { return(null); } }