public void NestPaths(VectorDocument doc, int size, uint sheet) { CutLibWrapper.CutTestResult res = new CutLibWrapper.CutTestResult(); CutLibWrapper.ResetSheet(sheet, size); doc.DocHeight = size; foreach (VectorPath pi in doc.Paths) { pi.Nested = false; } VectorPath p = null; while ((p = GetPathByMaxArea(doc)) != null) { res.resultOK = false; CutLibWrapper.TestShape(sheet, p.Shape, ref res, true, 0); if (res.resultOK) { CutLibWrapper.Plot(sheet, p.Shape, res.angle, res.x, res.y); p.SetPos(res.x, res.y); p.Rotate(res.angle); } p.Nested = true; } }
void UpdateDocInfo() { VectorDocument d = null; d = vectorView.Document; if (d != null) { docInfo.Text = ""; selInfo.Text = ""; docInfo.Text = string.Format("Tamanho do Desenho (mm): {3} por {4}", d.Paths.Count, d.OffsetX, d.OffsetY, d.DocWidth, d.DocHeight); RectangleF r = d.GetBoundRect(); float area = 0; foreach (VectorPath p in vectorView.Document.Selection) { area = p.Area; } if (!float.IsInfinity(r.Width)) { selInfo.Text = string.Format("Objeto - Tamanho (mm): {0:0.00} por {1:0.00} Área (em mm²): {2:0.00}", r.Width, r.Height, area); } } }
void UpdateDocInfo() { VectorDocument d = vvCorte.Document; if (d != null) { d.CalcMetrics(); lbTamanho.Text = string.Format("Largura: {0:0.00}m Comprimento: {1:0.00}m", d.DocHeight / 1000, d.GetMaxX() / 1000); lbAreaFilme.Text = string.Format("Filme total: {0:0.00}m\xB2", d.DocArea / 1000000); lbAreaUsada.Text = string.Format("Filme usado: {0:0.00}m\xB2 Eficiência: {1:0.00}%", d.UsedArea / 1000000, d.Efficiency * 100); } }
private void vvCorte_SelectionMoved(object sender, VectorEventArgs e) { //UpdateViewCorte(); if (vvCorte.Document != null) { VectorDocument doc = vvCorte.Document; } if (nestManager != null) { nestManager.Replot(vvCorte.Document.Paths); } UpdateDocInfo(); }
/// <summary> /// Builds vectors from selected features and feature weighting model /// </summary> /// <param name="context">The context.</param> /// <param name="log">The log.</param> public void VectorSpaceConstruction(OperationContext context, ILogBuilder log, Boolean constructCategories = false) { List <string> FV = context.SelectedFeatures.GetKeys(); //.entries.Select(x => x.name).ToList(); //FV.AddRange(); log.log("Preparing Weight model [" + weightModel.GetSignature() + "] - feature selection [" + FV.Count() + "]"); // preparing the model weightModel.PrepareTheModel(context.spaceModel, log); Int32 i = 0; Int32 s = context.spaceModel.documents.Count / 10; // building document VSM foreach (SpaceDocumentModel docModel in context.spaceModel.documents) { var wd = weightModel.GetWeights(FV, docModel, context.spaceModel); VectorDocument docVec = new VectorDocument(docModel.name); docVec.terms = wd; context.vectorSpace.documents.Add(docVec); if (i % s == 0) { Double r = i.GetRatio(context.spaceModel.documents.Count); log.log("[" + r.ToString("F2") + "]"); } i++; } if (constructCategories) { // logger.log(":: Creating VectorSpace instances for categories"); // building category VSM foreach (SpaceCategoryModel catModel in context.spaceModel.categories) { var wd = weightModel.GetWeights(FV, catModel, context.spaceModel); VectorLabel catVec = new VectorLabel(catModel.name); catVec.terms = wd; context.vectorSpace.labels.Add(catVec); } } }
public void NestPaths(VectorDocument doc, int size) { doc.DocHeight = size; foreach (VectorPath pi in doc.Paths) { pi.Nested = false; } VectorPath p = null; while ((p = GetPathByMaxArea(doc)) != null) { bool forceNest = false; try { forceNest = bool.Parse(Program.Config["forceAutoNest"]); } catch { } bool forceAngle = false; bool oldForceAngle = p.ForceAngle; if (forceNest) { forceAngle = false; // Isso vai fazer o autonest procurar em todos os ângulos } else { forceAngle = p.ForceAngle; // Respeita o que está defindo no cadastro. } p.ForceAngle = forceAngle; if (nestManager.NestPath(p)) { p.Nested = true; } p.ForceAngle = oldForceAngle; } }
public VectorPath GetPathByMaxArea(VectorDocument doc) { VectorPath p = null; foreach (VectorPath vi in doc.Paths) { if (!vi.Nested) { if (p == null) { p = vi; } else { if (vi.Area > p.Area) { p = vi; } } } } return(p); }
/// <summary> /// Builds vectors from selected features and feature weighting model /// </summary> /// <param name="context">The context.</param> /// <param name="log">The log.</param> public void VectorSpaceConstruction(OperationContext context, ILogBuilder log, Boolean constructCategories = false) { List <string> FV = context.SelectedFeatures.GetKeys(); //.entries.Select(x => x.name).ToList(); //FV.AddRange(); log.log("Preparing Weight model [" + weightModel.GetSignature() + "] - feature selection [" + FV.Count() + "] "); // preparing the model weightModel.PrepareTheModel(context.spaceModel, log); // blanking anything existing in vector space context.vectorSpace = new VectorSpace(); List <SpaceDocumentModel> toBlendIntoVectors = DocumentBlenderFunctionExtension.GetDocumentToBlend(blender.options, context.spaceModel.documents, log); Int32 i = 0; Int32 s = toBlendIntoVectors.Count() / 5; Dictionary <String, List <VectorDocument> > labelToDocumentSets = new Dictionary <String, List <VectorDocument> >(); foreach (SpaceCategoryModel catModel in context.spaceModel.categories) { labelToDocumentSets.Add(catModel.name, new List <VectorDocument>()); } Int32 unlabeled = 0; foreach (SpaceDocumentModel model in toBlendIntoVectors) { VectorDocument docVec = model.BlendToVector <VectorDocument>(weightModel, context.spaceModel, FV); //new VectorDocument(model.name); context.vectorSpace.documents.Add(docVec); if (constructCategories) { String l = model.labels.FirstOrDefault(); if (!l.isNullOrEmpty()) { if (labelToDocumentSets.ContainsKey(l)) { labelToDocumentSets[l].Add(docVec); } else { unlabeled++; // } } } if (i % s == 0) { Double r = i.GetRatio(context.spaceModel.documents.Count); log.log("Blending primary vectors [" + r.ToString("P2") + "] : [" + i + "/" + toBlendIntoVectors.Count + "]"); } i++; } if (constructCategories && (unlabeled > 0)) { log.log("Vectors [" + unlabeled + "] are unlabeled"); } if (constructCategories) { log.log(":: Creating VectorSpace instances for categories"); // building category VSM foreach (SpaceCategoryModel catModel in context.spaceModel.categories) { VectorLabel catVec = new VectorLabel(catModel.name); foreach (var docVec in labelToDocumentSets[catModel.name]) { catVec.terms.Merge(docVec.terms); } //= catModel.BlendToVector<VectorLabel>(weightModel, context.spaceModel, FV); //weightModel.GetWeights(FV, catModel, context.spaceModel); context.vectorSpace.labels.Add(catVec); } } if (weightModel != null) { weightModel.Dispose(); } }
/// <summary> /// Executes the plane method, invoking contained functions according to the settings /// </summary> /// <param name="inputContext">The input context - related to this plane.</param> /// <param name="generalContext">General execution context, attached to the <see cref="T:imbNLP.Toolkit.Planes.PlanesMethodDesign" /></param> /// <param name="logger">The logger.</param> /// <returns> /// Retur /// </returns> public IPlaneContext ExecutePlaneMethod(IPlaneContext inputContext, ExperimentModelExecutionContext generalContext, ILogBuilder logger) { notes.logStartPhase("[2] Corpus Plane - execution", ""); ICorpusPlaneContext context = (ICorpusPlaneContext)inputContext; VectorPlaneContext outputContext = new VectorPlaneContext(); outputContext.provider.StoreAndReceive(context); context.stemmContext = new StemmingContext(stemmer); Dictionary <String, SpaceDocumentModel> documentVsModel = new Dictionary <string, SpaceDocumentModel>(); // modelling the documents foreach (TextDocument doc in context.corpus_documents) { SpaceDocumentModel model = spaceConstructor.ConstructDocument(doc.content, doc.name, context.space, context.stemmContext, tokenizer); List <SpaceLabel> labels = spaceConstructor.GetLabels(doc.labels, context.space); Boolean isUnknownLabel = true; foreach (SpaceLabel label in labels) { if (label.name != SpaceLabel.UNKNOWN) { isUnknownLabel = false; } context.space.LabelToDocumentLinks.Add(label, model, 1); } context.space.documents.Add(model); if (!isUnknownLabel) { context.space.terms.MergeDictionary(model.terms); } documentVsModel.Add(doc.name, model); } if (generalContext.reportOptions.HasFlag(PlanesReportOptions.report_fold_textrender)) { foreach (TextDocument doc in context.corpus_documents) { String prefix = doc.labels.FirstOrDefault(); if (prefix.isNullOrEmpty()) { prefix = SpaceLabel.UNKNOWN; } String fn = prefix + "_" + doc.name; String pth = notes.folder_entity.pathFor(fn.getFilename("txt"), imbSCI.Data.enums.getWritableFileMode.overwrite, "Textual representation of website [" + doc.name + "], produced by rendering and blending settings", true); doc.content.saveStringToFile(pth, imbSCI.Data.enums.getWritableFileMode.overwrite); } } if (generalContext.reportOptions.HasFlag(PlanesReportOptions.report_fold_stats)) { foreach (WebSiteDocumentsSet ds in context.dataset) { DataTable dt = ds.MakeTable(documentVsModel); notes.SaveDataTable(dt, notes.folder_entity); } var dt_vsm = context.space.LabelToDocumentLinks.MakeTable("LabelToDocument", "Relationships between labels and documents in the primary Vector Space Model"); notes.SaveDataTable(dt_vsm, notes.folder_corpus); } if (generalContext.reportOptions.HasFlag(PlanesReportOptions.report_corpusDictionary)) { notes.SaveDataTable(context.space.terms.MakeTable("corpus_stats", "Training set dictionary, after stemming", generalContext.DictionaryReportLimit), notes.folder_corpus); } #region SELECTING THE FEATURES // forming corpus global weight context.SelectedFeatures = new WeightDictionary(); List <KeyValuePair <string, double> > filter_result = filter.SelectFeatures(context.space); List <string> FV = new List <string>(); FV.AddRange(filter_result.Select(x => x.Key)); if (filter_result.Any()) { foreach (var pair in filter_result) { context.SelectedFeatures.AddEntry(pair.Key, pair.Value); } if (generalContext.reportOptions.HasFlag(PlanesReportOptions.report_selectedFeatures)) { notes.SaveDataTable(context.SelectedFeatures.MakeTable("selected_features", "Features selected for BoW construction", new List <string>() { filter.function.shortName }, generalContext.DictionaryReportLimit), notes.folder_corpus); } } else { logger.log("-- Feature selection function returned zero set. All features [" + context.space.terms.Count + "] are therefore accepted as selected."); var tkns = context.space.terms.GetTokens(); foreach (var tkn in tkns) { context.SelectedFeatures.AddEntry(tkn, 1); } } #endregion notes.log("Selected features [" + context.SelectedFeatures.entries.Count + "] by [" + filter.functionSettings.functionName + "]"); //context.space = //weightModel.Deploy(); outputContext.vectorSpace = new Vectors.VectorSpace(); foreach (SpaceLabel label in context.space.labels) { var docs = context.space.LabelToDocumentLinks.GetAllLinked(label); if (label.name != SpaceLabel.UNKNOWN) { SpaceCategoryModel categoryModel = new SpaceCategoryModel(label, docs); context.space.LabelToCategoryLinks.Add(label, categoryModel, 1); context.space.categories.Add(categoryModel); notes.log("Class [" + categoryModel.name + "] BoW model created - terms[" + categoryModel.terms.Count + "] "); } } outputContext.LabelToDocumentLinks = context.space.LabelToDocumentLinks; // preparing the model weightModel.PrepareTheModel(context.space); // logger.log(":: Creating VectorSpace instances for documents"); // building document VSM foreach (SpaceDocumentModel docModel in context.space.documents) { var wd = weightModel.GetWeights(FV, docModel, context.space); VectorDocument docVec = new VectorDocument(docModel.name); docVec.terms = wd; if (generalContext.reportOptions.HasFlag(PlanesReportOptions.report_documentBoWModels)) { DataTable dt = wd.MakeTable("docVec_" + docModel.name, "Document vector model", null, 10000); notes.SaveDataTable(dt, notes.folder_vector); } outputContext.vectorSpace.documents.Add(docVec); } // logger.log(":: Creating VectorSpace instances for categories"); // building category VSM foreach (SpaceCategoryModel catModel in context.space.categories) { var wd = weightModel.GetWeights(FV, catModel, context.space); VectorLabel catVec = new VectorLabel(catModel.name); catVec.terms = wd; if (generalContext.reportOptions.HasFlag(PlanesReportOptions.report_documentBoWModels)) { DataTable dt = wd.MakeTable("catVec_" + catModel.name, "Document vector model", null, 10000); notes.SaveDataTable(dt, notes.folder_vector); } outputContext.vectorSpace.labels.Add(catVec); } if (generalContext.reportOptions.HasFlag(PlanesReportOptions.report_documentBoWModels)) { foreach (SpaceCategoryModel catModel in context.space.categories) { var dt = catModel.terms.MakeTable("cat_" + catModel.name, "Vector Space BoW weighted model, representing a category"); notes.SaveDataTable(dt, notes.folder_vector); } } notes.logEndPhase(); return(outputContext); }
private void btnGravar_Click(object sender, EventArgs e) { if (salvando) { return; } salvando = true; try { if (lbAnos.CheckedItems.Count <= 0) { MessageBox.Show("Nenhum ano selecionado", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } VectorDocument doc = vectorView.Document; pbDesenho.Value = 0; pbDesenho.Maximum = lbAnos.CheckedItems.Count; pbDesenho.Visible = true; Application.DoEvents(); if (doc != null) { string svg = null; if (doc != null && doc.Paths.Count > 0) { svg = doc.ToSVG(); } foreach (object i in lbAnos.CheckedItems) { ModeloAno v = (ModeloAno)i; DBManager.SalvarDesenho(Convert.ToInt32(v.Codigo_ano), svg, txtObs.Text, sel.TipoDesenho, imageData); pbDesenho.Value++; Application.DoEvents(); } Mensagens.Informacao("Desenho Salvo com Sucesso!"); pbDesenho.Visible = false; toolStripButton1_Click(sender, e); cbMarca.Focus(); } else { MessageBox.Show("Nenhum desenho carregado!", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Stop); } pbDesenho.Visible = false; lbAnos.Items.Clear(); rbEsquerda.Checked = false; rbDireita.Checked = false; tbEtiqueta.Text = ""; tbNomePeca.Text = ""; } catch { } finally { salvando = false; } }
private void btnExportar_Click(object sender, EventArgs e) { if (salvando) { return; } salvando = true; try { if (lbAnos.CheckedItems.Count <= 0) { MessageBox.Show("Nenhum ano selecionado. Selecione um ou mais anos para exportação", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } VectorDocument doc = vectorView.Document; FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { pbDesenho.Value = 0; pbDesenho.Maximum = lbAnos.CheckedItems.Count; pbDesenho.Visible = true; Application.DoEvents(); string baseName = fbd.SelectedPath + "\\" + string.Format("{0}-{1}", cbMarca.Text, cbModelo.Text).Replace('\\', '_'); foreach (object i in lbAnos.CheckedItems) { ModeloAno v = (ModeloAno)i; int codDesenho = 0; string ppv = null; string svg = DBManager.CarregarDesenho(Convert.ToInt32(v.Codigo_ano), out codDesenho, sel.TipoDesenho); string fname = string.Format("{0} {1}.svg", baseName, v.Ano); if (File.Exists(fname)) { File.Delete(fname); } File.WriteAllText(fname, svg, Encoding.UTF8); if (ppv != null) { fname = string.Format("{0} {1}-ppv.svg", baseName, v.Ano); if (File.Exists(fname)) { File.Delete(fname); } File.WriteAllText(fname, ppv, Encoding.UTF8); } pbDesenho.Value++; Application.DoEvents(); } Mensagens.Informacao("Desenho Exportado com Sucesso!"); pbDesenho.Visible = false; toolStripButton1_Click(sender, e); cbMarca.Focus(); pbDesenho.Visible = false; lbAnos.Items.Clear(); rbEsquerda.Checked = false; rbDireita.Checked = false; tbEtiqueta.Text = ""; tbNomePeca.Text = ""; } } catch { } finally { salvando = false; } }