天天看點

VectorDraw入門必備手冊(十九):如何解決操作過程中的小問題?

  VectorDraw Developer Framework(VDF)是一個用于應用程式可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地建立、編輯、管理、輸出、輸入和列印2D和3D圖形檔案。   

    在使用任何軟體過程中都不可避免的會遇到一些問題,VectorDraw Developer Framework(VDF)也是同樣的,本篇文章就将會解決幾個我們使用過程的小問題。

怎麼解決缺少SHX字型,檔案打開緩慢的問題?

問:

    我在使用過程中,由于缺少SHX字型,檔案打開緩慢,這種情況怎麼解決?

答:

    繪圖使用一些.SHX字型檔案作為預設VDF搜尋路徑中不存在的vdTextStyles,如果缺少,這會導緻這種現象。因為在這些文本樣式中,預設情況下,這些字型檔案将替換為Arial TrueType字型,因為Arial的字元過多且Arial的複雜性,這些字元要花費更多的時間來計算其圖形表示形式。

    為了加快此速度,繪圖所使用的shx字型檔案必須存在于VDF搜尋路徑中(例如,在繪圖檔案夾中-or-在vdDocument.SupportPath中定義的檔案夾中-或- 應用程式的路徑)。

     如果沒有這些SHX字型檔案,則還可以覆寫應用程式中的OnNoFileFind事件,以便用始終存在于應用程式路徑中的SHX檔案替換未引用的SHX字型檔案,如下所示:

//In this example we substitute all unreferenced shx files with txt.shx which must exist in the drawing folder or in the application path.

.... 
doc.OnNoFileFind += new vdDocument.NoFileFindEventHandler(ActiveDocument_OnNoFileFind);  // add the event handler
bool fontSubstitute = false; // a “public” variable to avoid recursion of event
....

        void ActiveDocument_OnNoFileFind(object sender, ref string fileName, ref bool success)
        {
            //Substitute shx font files with existing txt.shx font file.
            if (!fontSubstitute && fileName.EndsWith(".shx"))
            {
                fontSubstitute = true;//set it to true in order not to have recursion
                success = doc.FindFile("txt.shx", out fileName);
                fontSubstitute = false;
                if (success) return;

            }
            doc.Prompt("\r\n Can not find file: " + fileName);
            doc.Prompt(null);
        }
           

如何清除已删除的布局或塊項目?

問:

    如何清除已删除的布局或塊項目?

答:

    在下面,我們建立了兩個不同的示例,說明如何從布局或塊中清除已擦除的項目。

    示例1:清除已删除的活動布局項目。

var tempCol = [];
           var activelayout = vdcanvas.GetActiveLayout();
           for (var k = 0; k < activelayout.Entities.Items.length; k++) {
               var fig = vdcanvas.GetEntityItem(activelayout.Entities.Items[k]);
               if (!fig.Deleted) tempCol.push(activelayout.Entities.Items[k]);//If not an item is Deleted we push it in our tempCol
           }          
           activelayout.Entities.Items = tempCol;//update the active layout entities with the tempCol
           

    示例2:清除塊中已擦除的項目

var tempCol = []; 
           var blk = vdcanvas.AddBlock("myblock");//let's say that the block we want to update is the 'blk'
           for (var k = 0; k < blk.Entities.Items.length; k++) {
               var fig = vdcanvas.GetEntityItem(blk.Entities.Items[k]);
               if (!fig.Deleted) tempCol.push(blk.Entities.Items[k]);//If not an item is Deleted we push it in our tempCol
           }        
           blk.Entities.Items = tempCol;//update the block entities with the tempCol
           

如何擷取要複制或移動的對象?

問:

    我想在複制/移動動作結束之前擷取要複制或移動的對象的新位置,以便在新位置有效的情況下進行一些計算。如何執行此操作?

答:

    當動作為ActionGetTranfromSelection時,可以使用OnActionDraw事件,并使用動作的GetMatrix并檢查諸如以下的對象:

void doc_OnActionDraw(object sender, object action, bool isHideMode, ref bool cancel)
 {
     if (action != null && action is VectorDraw.Professional.CommandActions.ActionGetTranfromSelection)
     {
         VectorDraw.Professional.CommandActions.ActionGetTranfromSelection trans = action as VectorDraw.Professional.CommandActions.ActionGetTranfromSelection;
         vdSelection sel = trans.Layout.Document.Selections.FindName("VDRAW_PREVIOUS_SELSET");// sel contains the object that are moved/copied/rotated etc.
         if (sel == null || sel.Count == 0) return;
         // this.Text = sel.Count.ToString(); /// for debugging
         Matrix mat = trans.GetMatrix(); // this is the matrix that is applied to the source object by the action
         foreach (vdFigure item in sel)
         {
             vdFigure tempfig = item.Clone(item.Document) as vdFigure; // get a coly of this object being transformed (copied/moved etc)
             tempfig.Transformby(mat);    // transform this with the action’s GetMatrix
             // this tempfig is the temporary figure rendered by action copy/move etc
             // using this tempfig object you can do your calid position check, using bounding box etc
         }
     }
 }
           

活動激活時如何使用滑鼠中鍵進行平移

問:

活動激活時如何使用滑鼠中鍵進行平移?

答:

    您可以通過使用vdmoudown和vdmouseup事件來執行此操作,因為要這樣做,您必須在要平移時暫停活動操作,然後将其恢複到目前指令。一旦使用滑鼠中鍵進行平移,而不是使用左鍵完成指令,就可能發生這種情況。

    在下面,您可以看到一個示例:

var vdcanvas = vdmanager.AttachCanvas('canvas');
       vdcanvas.vdmousedown = _vdmousedown; //set to the initialize page load
       vdcanvas.vdmouseup = _vdmouseup;
       vdcanvas.ActiveAction().PanMouseButton = vdConst.MouseMiddleButton; // set the middle mouse button for panning procedure

       function _vdmousedown(e) {
            var code = e.mousebutton; //get the mouse button code
            if (code === 2)vdcanvas.ActiveAction().Pause(); // middle mouse code is 2           
        }

        function _vdmouseup(e) { //resume the action when finishing the panning
            var code = e.mousebutton;
            if (code === 2)vdcanvas.ActiveAction().Resume();                             
        }
           

    對于以上問答,如果您有任何的疑惑都可以在評論區留言,我們會及時回複。此系列的問答教程我們會持續更新,如果您感興趣,可以多多關注本教程。

繼續閱讀