示例#1
0
        internal Utf8Span TrimHelper(TrimType trimType)
        {
            ReadOnlySpan <byte> retSpan = Bytes;

            if ((trimType & TrimType.Head) != 0)
            {
                int indexOfFirstNonWhiteSpaceChar = Utf8Utility.GetIndexOfFirstNonWhiteSpaceChar(retSpan);
                Debug.Assert((uint)indexOfFirstNonWhiteSpaceChar <= (uint)retSpan.Length);

                // TODO_UTF8STRING: Can use an unsafe slicing routine below if we need a perf boost.

                retSpan = retSpan.Slice(indexOfFirstNonWhiteSpaceChar);
            }

            if ((trimType & TrimType.Tail) != 0)
            {
                int indexOfTrailingWhiteSpaceSequence = Utf8Utility.GetIndexOfTrailingWhiteSpaceSequence(retSpan);
                Debug.Assert((uint)indexOfTrailingWhiteSpaceSequence <= (uint)retSpan.Length);

                // TODO_UTF8STRING: Can use an unsafe slicing routine below if we need a perf boost.

                retSpan = retSpan.Slice(0, indexOfTrailingWhiteSpaceSequence);
            }

            return(UnsafeCreateWithoutValidation(retSpan));
        }
示例#2
0
        private MString TrimHelper(TrimType trimType)
        {
            int end   = this.Length - 1;
            int start = 0;

            if (((uint)trimType | (uint)TrimType.Left) != 0)
            {
                start = 0;
                while (start < this.Length)
                {
                    if (!char.IsWhiteSpace(this[start]))
                    {
                        break;
                    }
                    start++;
                }
            }
            if (((uint)trimType | (uint)TrimType.Right) != 0)
            {
                end = this.Length - 1;
                while (end >= start)
                {
                    if (!char.IsWhiteSpace(this[end]))
                    {
                        break;
                    }
                    end--;
                }
            }
            return(this.CreateTrimmedString(start, end));
        }
        // This function is used to prevent long quotations in error messages
        private static void AppendTrimmed(StringBuilder sb, string value, int startIndex, int count, TrimType trimType)
        {
            const int    TrimSize   = 32;
            const string TrimMarker = "...";

            if (count <= TrimSize) {
                sb.Append(value, startIndex, count);
            } else {
                switch (trimType) {
                case TrimType.Left:
                    sb.Append(TrimMarker);
                    sb.Append(value, startIndex + count - TrimSize, TrimSize);
                    break;
                case TrimType.Right:
                    sb.Append(value, startIndex, TrimSize);
                    sb.Append(TrimMarker);
                    break;
                case TrimType.Middle:
                    sb.Append(value, startIndex, TrimSize / 2);
                    sb.Append(TrimMarker);
                    sb.Append(value, startIndex + count - TrimSize / 2, TrimSize / 2);
                    break;
                }
            }
        }
示例#4
0
        private Utf8String TrimHelper(TrimType trimType)
        {
            Utf8Span trimmedSpan = this.AsSpan().TrimHelper(trimType);

            // Try to avoid allocating a new Utf8String instance if possible.
            // Otherwise, allocate a new substring wrapped around the resulting slice.

            return((trimmedSpan.Length == this.Length) ? this : trimmedSpan.ToUtf8String());
        }
示例#5
0
 public void SetPropertyValue(string property, string value)
 {
     if (property == "Type")
     {
         Type = (TrimType)Enum.Parse(typeof(TrimType), value.XOMLName());
     }
     else
     {
         throw new OwlKeywordException(KeywordsType.Trim, string.Format(ETexts.GT(ErrorType.XOMLEnumInvalid), property));
     }
 }
示例#6
0
 public TrimPath(
     string name,
     string matchName,
     TrimType trimPathType,
     Animatable <double> startPercent,
     Animatable <double> endPercent,
     Animatable <double> offsetDegrees)
     : base(name, matchName)
 {
     TrimPathType  = trimPathType;
     StartPercent  = startPercent;
     EndPercent    = endPercent;
     OffsetDegrees = offsetDegrees;
 }
示例#7
0
        public string Trim(TrimType trimType, string value)
        {
            switch (trimType)
            {
            case TrimType.Left:
                value = value.TrimStart();
                break;

            case TrimType.Right:
                value = value.TrimEnd();
                break;

            case TrimType.Both:
                value = value.Trim();
                break;
            }

            return(value);
        }
示例#8
0
    public void In(
        [FriendlyName("Target", "The target string to be trimmed.")]
        string Target,

        [FriendlyName("Trim Type", "Specify the side of the string that will be trimmed.")]
        [SocketState(false, false)]
        TrimType trimType,

        [FriendlyName("Characters", "(optional) Specify the characters to trim. If none are provided, whitespace will be trimmed by default.")]
        [SocketState(false, false)]
        string trimChars,

        [FriendlyName("Result", "Resulting trimmed string.")]
        out string Result
        )
    {
        char[] myChar;

        // Determine what to trim
        if (trimChars == "")
        {
            string whitespace = " ";
            myChar = whitespace.ToCharArray();
        }
        else
        {
            myChar = trimChars.ToCharArray();
        }

        // Trim string based on TrimType
        if (trimType == TrimType.Both)
        {
            Result = Target.Trim(myChar);
        }
        else if (trimType == TrimType.Left)
        {
            Result = Target.TrimStart(myChar);
        }
        else
        {
            Result = Target.TrimEnd(myChar);
        }
    }
        public static string TrimDuplicates(this string input, TrimType trimType)
        {
            string result = string.Empty;

            switch (trimType)
            {
            case TrimType.Comma:
                result = input.TrimCharacter(',');
                break;

            case TrimType.Pipe:
                result = input.TrimCharacter('|');
                break;

            case TrimType.Colon:
                result = input.TrimCharacter(':');
                break;
            }

            return(result);
        }
        static public bool BuildAtlas(TrimType trimType, List <SpriteElement> listSprite, Dictionary <string, EAPInfoAttachment> dicPivot, string texturePath, int padingSize, bool append = false)
        {
            try
            {
                //bool checkAppend=append;
                float prog = 0.2f;
                EditorUtility.DisplayCancelableProgressBar("Creating Spritesheet", "Auto Build Atlas Sprites", prog);
                Texture2D[] textArray = new Texture2D[listSprite.Count];
                for (int i = 0; i < textArray.Length; i++)
                {
                    textArray[i] = listSprite[i].texture;
                }
                Texture2D mainTexture = new Texture2D(8192, 8192);
                Rect[]    rects       = mainTexture.PackTextures(textArray, padingSize, 8192, false);
                mainTexture.Apply();
                //ImportTextureUtil.MaxImportSettings(mainTexture);
                int xmin        = 0;
                int ymin        = 0;
                int cacheWidth  = mainTexture.width;
                int cacheHeight = mainTexture.height;

                int       optimizeWidth  = cacheWidth;
                int       optimizeHeight = cacheHeight;
                Texture2D mainTexture2   = null;
                prog = 0.4f;
                EditorUtility.DisplayCancelableProgressBar("Creating Spritesheet", "Auto Build Atlas Sprites", prog);
                #region Trim to minimum Texture
                if (trimType == TrimType.TrimMinimum && rects.Length > 0)
                {
                    float rectMinX = rects[0].xMin;
                    float rectMinY = rects[0].yMin;
                    float rectMaxX = rects[0].xMax;
                    float rectMaxY = rects[0].yMax;
                    for (int i = 1; i < rects.Length; i++)
                    {
                        if (rects[i].xMin < rectMinX)
                        {
                            rectMinX = rects[i].xMin;
                        }
                        if (rects[i].yMin < rectMinY)
                        {
                            rectMinY = rects[i].yMin;
                        }
                        if (rects[i].xMax < rectMaxX)
                        {
                            rectMaxX = rects[i].xMax;
                        }
                        if (rects[i].yMax < rectMaxY)
                        {
                            rectMaxY = rects[i].yMax;
                        }
                    }
                    int intRectMinX = (int)(rectMinX * cacheWidth);
                    int intRectMinY = (int)(rectMinY * cacheHeight);
                    int intRectMaxX = (int)(rectMaxX * cacheWidth);
                    int intRectMaxY = (int)(rectMaxY * cacheHeight);

                    Color32[] pixels = mainTexture.GetPixels32();
                    xmin = mainTexture.width;
                    int xmax = 0;
                    ymin = mainTexture.height;
                    int ymax      = 0;
                    int oldWidth  = mainTexture.width;
                    int oldHeight = mainTexture.height;

                    // Trim solid pixels
                    for (int y = 0, yw = oldHeight; y < yw; ++y)
                    {
                        for (int x = 0, xw = oldWidth; x < xw; ++x)
                        {
                            Color32 c = pixels[y * xw + x];

                            if (c.a != 0)
                            {
                                if (y < ymin)
                                {
                                    ymin = y;
                                }
                                if (y > ymax - 1)
                                {
                                    ymax = y + 1;
                                }
                                if (x < xmin)
                                {
                                    xmin = x;
                                }
                                if (x > xmax - 1)
                                {
                                    xmax = x + 1;
                                }
                            }
                        }
                    }
                    if (xmin > intRectMinX)
                    {
                        xmin = intRectMinX;
                    }
                    if (ymin > intRectMinY)
                    {
                        ymin = intRectMinY;
                    }
                    if (xmax < intRectMaxX)
                    {
                        xmax = intRectMaxX;
                    }
                    if (ymax < intRectMaxY)
                    {
                        ymax = intRectMaxY;
                    }
                    if (xmax - xmin > 0 && ymax - ymin > 0)
                    {
                        optimizeWidth  = xmax - xmin;
                        optimizeHeight = ymax - ymin;
                        mainTexture2   = new Texture2D(xmax - xmin, ymax - ymin);
                        mainTexture2.SetPixels(mainTexture.GetPixels(xmin, ymin, xmax - xmin, ymax - ymin));
                        mainTexture2.Apply();
                        GameObject.DestroyImmediate(mainTexture);
                        mainTexture = mainTexture2;
                    }
                }

                #endregion

                prog = 0.5f;
                EditorUtility.DisplayCancelableProgressBar("Creating Spritesheet", "Auto Build Atlas Sprites", prog);
                #region Write New File
                byte[] byt = mainTexture.EncodeToPNG();
                if (texturePath != "")
                {
                    System.IO.File.WriteAllBytes(texturePath, byt);
                    AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                }
                AssetDatabase.ImportAsset(texturePath);
                #endregion
                EditorUtility.ClearProgressBar();
                prog = 0.6f;
                EditorUtility.DisplayCancelableProgressBar("Creating Spritesheet", "Auto Build Atlas Sprites", prog);
                mainTexture = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D;
                TextureImporter         ti       = AssetImporter.GetAtPath(texturePath) as TextureImporter;
                TextureImporterSettings settings = new TextureImporterSettings();
                ti.ReadTextureSettings(settings);
                SpriteMetaData[] lstMetaSprite = new SpriteMetaData[listSprite.Count];
                if (append)
                {
                    if (ti.spritesheet != null && ti.spritesheet.Length > 0)
                    {
                        append        = true;
                        lstMetaSprite = ti.spritesheet;
                    }
                    else
                    {
                        append = false;
                    }
                }
                for (int i = 0; i < lstMetaSprite.Length; i++)
                {
                    if (i < rects.Length)
                    {
                        SpriteMetaData metaSprite = new SpriteMetaData();
                        if (append)
                        {
                            metaSprite = lstMetaSprite[i];
                        }
                        metaSprite.name = listSprite[i].name;
                        Rect rectInfo = listSprite[i].GetSpriteRect();

                        Rect rect = new Rect(rects[i].x * cacheWidth - xmin, rects[i].y * cacheHeight - ymin, rectInfo.width, rectInfo.height);
                        if (rect.x + rect.width > optimizeWidth)
                        {
                            rect.width = optimizeWidth - rect.x;
                        }
                        if (rect.y + rect.height > optimizeHeight)
                        {
                            rect.height = optimizeHeight - rect.y;
                        }
                        metaSprite.rect = rect;
                        int oWidth  = listSprite[i].originalRect.width;
                        int oHeight = listSprite[i].originalRect.height;
                        if (oWidth < 1)
                        {
                            oWidth = 1;
                        }
                        if (oHeight < 1)
                        {
                            oHeight = 1;
                        }
                        int xLeft = listSprite[i].startX;
                        int yTop  = listSprite[i].startY;

                        if (listSprite[i].IsOptimize())
                        {
                            float pivotX = listSprite[i].pivot.x * listSprite[i].originalRect.width;
                            float pivotY = listSprite[i].pivot.y * listSprite[i].originalRect.height;
                            pivotX = pivotX - xLeft;
                            pivotY = pivotY - yTop;
                            pivotX = pivotX / listSprite[i].optimizeRect.width;
                            pivotY = pivotY / listSprite[i].optimizeRect.height;

                            listSprite[i].SetPivot(new Vector2(pivotX, pivotY));
                            metaSprite.pivot     = new Vector2(pivotX, pivotY);
                            metaSprite.alignment = ImportTextureUtil.GetAlignment(metaSprite.pivot);                          // listSprite[i].alignment;
                            if (dicPivot != null)
                            {
                                foreach (KeyValuePair <string, EAPInfoAttachment> pair in dicPivot)
                                {
                                    if (pair.Value.spriteName == metaSprite.name)
                                    {
                                        pair.Value.SetCache(xLeft, yTop, listSprite[i].originalRect, listSprite[i].optimizeRect);
                                    }
                                }
                            }
                        }
                        else
                        {
                            metaSprite.pivot     = listSprite[i].pivot;
                            metaSprite.alignment = ImportTextureUtil.GetAlignment(metaSprite.pivot);
                        }
                        lstMetaSprite[i] = metaSprite;
                    }
                }
                prog = 0.7f;
                EditorUtility.DisplayCancelableProgressBar("Creating Spritesheet", "Auto Build Atlas Sprites", prog);
                ti.isReadable                = true;
                ti.mipmapEnabled             = false;
                ti.spritesheet               = lstMetaSprite;
                ti.textureType               = TextureImporterType.Sprite;
                ti.spriteImportMode          = SpriteImportMode.Multiple;
                ti.spritePixelsPerUnit       = 100;
                settings.textureFormat       = TextureImporterFormat.ARGB32;
                settings.npotScale           = TextureImporterNPOTScale.None;
                settings.alphaIsTransparency = true;
                ti.SetTextureSettings(settings);
                ti.maxTextureSize   = 4096;
                ti.mipmapEnabled    = false;
                ti.spriteImportMode = SpriteImportMode.Multiple;
                AssetDatabase.ImportAsset(texturePath);
                EditorUtility.SetDirty(mainTexture);
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                AssetDatabase.ImportAsset(texturePath);
                prog = 1.0f;
                EditorUtility.DisplayCancelableProgressBar("Creating Spritesheet", "Auto Build Atlas Sprites", prog);
                EditorUtility.ClearProgressBar();

                // douple setting for fix Unity 5.5
                ti.textureType      = TextureImporterType.Sprite;
                ti.spriteImportMode = SpriteImportMode.Multiple;
                EditorUtility.SetDirty(mainTexture);
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                AssetDatabase.ImportAsset(texturePath);

                /*for(int i=0;i<listSprite.Count;i++)
                 * {
                 *      listSprite[i].FreeMemory();
                 * }*/
                System.GC.Collect();
                return(true);
            }
            catch (UnityException ex)
            {
                Debug.LogError("Error:" + ex.Message);
                EditorUtility.ClearProgressBar();
                return(false);
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error:" + ex.Message);
                EditorUtility.ClearProgressBar();
                return(false);
            }
        }
        static public bool AutoBuildAtlasFromListTexture(List <Texture2D> listTexture, List <DataAnimAnalytics> listJsonAnim, TrimType trimType, string texturePath, int pading)
        {
            float prog = 0.0f;

            EditorUtility.DisplayCancelableProgressBar("Collecting Textures", "Process...", prog);
            try
            {
                Dictionary <string, EAPInfoAttachment> dicPivot = new Dictionary <string, EAPInfoAttachment>();
                for (int i = 0; i < listJsonAnim.Count; i++)
                {
                    DataAnimAnalytics dataAnalytic = listJsonAnim[i];
                    foreach (KeyValuePair <string, EAPInfoAttachment> pair in dataAnalytic.jsonFinal.dicPivot)
                    {
                        dicPivot[pair.Value.spriteName] = pair.Value;
                    }
                }

                List <SpriteElement> listSprite = new List <SpriteElement>();
                for (int i = 0; i < listTexture.Count; i++)
                {
                    Object obj = listTexture[i];
                    if (obj is Texture2D)
                    {
                        Texture2D tex = (Texture2D)obj;

                        SpriteElement element = new SpriteElement(tex);
                        if (trimType == TrimType.Trim2nTexture || trimType == TrimType.TrimMinimum)
                        {
                            if (!element.TrimTexture())
                            {
                                element.CloneFromOriginTexture();
                            }
                        }
                        else
                        {
                            element.CloneFromOriginTexture();
                        }
                        foreach (KeyValuePair <string, EAPInfoAttachment> pair in dicPivot)
                        {
                            if (pair.Value.spriteName == tex.name)
                            {
                                //Debug.LogError(pair.Value.spriteName);
                                element.SetPivot(new Vector2(pair.Value.x, pair.Value.y));
                                break;
                            }
                        }
                        listSprite.Add(element);
                        prog = (float)(i + 1) / listTexture.Count;
                        EditorUtility.DisplayCancelableProgressBar("Collecting Textures", "Process...", prog);
                    }
                }
                if (listSprite.Count > 0)
                {
                    bool result = BuildAtlas(trimType, listSprite, dicPivot, texturePath, pading);
                    // GC memory
                    for (int i = 0; i < listSprite.Count; i++)
                    {
                        GameObject.DestroyImmediate(listSprite[i].texture);
                        listSprite[i] = null;
                    }
                    return(result);
                }
                return(false);
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error:" + ex.Message);
                EditorUtility.ClearProgressBar();
                return(false);
            }
        }
        // cutDownType values: ( PercentOfTrees, Volume, Area )
        // trimType values: ( ByTallest, BySmallest, Systematic )
        // value: (% de corta)
        public override void ApplyCutDown(Parcela oldPlot, Parcela newPlot, CutDownType cutDownType, TrimType trimType, float value)
        {
            newPlot.VAR_10      = value;
            newPlot.H_DOMINANTE = oldPlot.H_DOMINANTE.Value;
            double parA1, parA2,
                   parB0, parB1, parB2, parB3,
                   parC0, parC1, parC2, parC3,
                   parD1, parD2,
                   parA, parB, SEC_NORMAL, tpuBA;

            switch (trimType)
            {
            case TrimType.ByTallest:

                break;

            case  TrimType.BySmallest:
                if (cutDownType == CutDownType.Area)
                {
                    parC0 = 1.35;
                    parC1 = 0.979;
                    parC2 = 0.859;
                    tpuBA = value / 100;
                    newPlot.A_BASIMETRICA = oldPlot.A_BASIMETRICA.Value - tpuBA * oldPlot.A_BASIMETRICA.Value;

                    newPlot.N_PIESHA = newPlot.A_BASIMETRICA * 40000 / Math.Pow(oldPlot.D_CUADRATICO.Value, 2) * Math.PI;

                    newPlot.D_CUADRATICO = oldPlot.D_CUADRATICO.Value;

                    newPlot.VCC = Math.Exp((double)1.69 + 0.0604 * newPlot.SI.Value - 48.8 / newPlot.EDAD.Value + 0.982 * Math.Log(newPlot.A_BASIMETRICA.Value));
                }
                break;

            case  TrimType.Systematic:
                if (cutDownType == CutDownType.Area)
                {
                    parC0 = 1.35;
                    parC1 = 0.979;
                    parC2 = 0.859;
                    tpuBA = value / 100;
                    newPlot.A_BASIMETRICA = oldPlot.A_BASIMETRICA.Value - tpuBA * oldPlot.A_BASIMETRICA.Value;

                    newPlot.N_PIESHA = newPlot.A_BASIMETRICA * 40000 / Math.Pow(oldPlot.D_CUADRATICO.Value, 2) * Math.PI;

                    newPlot.D_CUADRATICO = oldPlot.D_CUADRATICO.Value;

                    newPlot.VCC = Math.Exp((double)1.69 + 0.0604 * newPlot.SI.Value - 48.8 / newPlot.EDAD.Value + 0.982 * Math.Log(newPlot.A_BASIMETRICA.Value));
                }
                break;
            }
        }
示例#13
0
        private void Screenshot_MouseMove(object sender, MouseEventArgs e)
        {
            long mouseMoveTimeStep = DateTime.Now.Ticks - lastMouseMoveTime;

            if (mouseMoveTimeStep > 200)
            {
                lastMouseMoveTime = DateTime.Now.Ticks;
                switch (screenshotStatus)
                {
                case ScreenshotStatus.SCREENSHOTSTART:
                    endPoint = e.Location;
                    break;

                case ScreenshotStatus.SCREENSHOTTRIM:
                    trim_X = trim_X == 0 ? e.X : trim_X;
                    trim_Y = trim_Y == 0 ? e.Y : trim_Y;
                    switch (trimType)
                    {
                    case TrimType.MOVE:
                        startPoint.Offset(e.X - trim_X, e.Y - trim_Y);
                        endPoint.Offset(e.X - trim_X, e.Y - trim_Y);
                        break;

                    case TrimType.TOP:
                        startPoint.Offset(0, e.Y - trim_Y);
                        break;

                    case TrimType.TOPLEFT:
                        startPoint.Offset(e.X - trim_X, e.Y - trim_Y);
                        break;

                    case TrimType.TOPRIGHT:
                        startPoint.Offset(0, e.Y - trim_Y);
                        endPoint.Offset(e.X - trim_X, 0);
                        break;

                    case TrimType.RIGHTR:
                        endPoint.Offset(e.X - trim_X, 0);
                        break;

                    case TrimType.BOTTOMRIGHT:
                        endPoint.Offset(e.X - trim_X, e.Y - trim_Y);
                        break;

                    case TrimType.BOTTOM:
                        endPoint.Offset(0, e.Y - trim_Y);
                        break;

                    case TrimType.BOTTOMLEFT:
                        startPoint.Offset(e.X - trim_X, 0);
                        endPoint.Offset(0, e.Y - trim_Y);
                        break;

                    case TrimType.LEFT:
                        startPoint.Offset(e.X - trim_X, 0);
                        break;
                    }
                    trim_X = e.X;
                    trim_Y = e.Y;
                    break;

                case ScreenshotStatus.SCREENSHOTEND:
                    if (cancelRect.Contains(e.Location))
                    {
                        inBtn = 1;
                    }
                    else if (completRect.Contains(e.Location))
                    {
                        inBtn = 2;
                    }
                    else
                    {
                        inBtn = 0;
                    }
                    if (blockDic.Count == 9)
                    {
                        foreach (KeyValuePair <int, Rectangle> pair in blockDic)
                        {
                            if ((pair.Value).Contains(e.Location))
                            {
                                switch (pair.Key)
                                {
                                case 0:
                                    if (Cursor != Cursors.SizeAll)
                                    {
                                        Cursor = Cursors.SizeAll;
                                    }
                                    trimType = TrimType.MOVE;
                                    break;

                                case 1:
                                    if (Cursor != Cursors.SizeNWSE)
                                    {
                                        Cursor = Cursors.SizeNWSE;
                                    }
                                    trimType = TrimType.TOPLEFT;
                                    break;

                                case 2:
                                    if (Cursor != Cursors.SizeNS)
                                    {
                                        Cursor = Cursors.SizeNS;
                                    }
                                    trimType = TrimType.TOP;
                                    break;

                                case 3:
                                    if (Cursor != Cursors.SizeNESW)
                                    {
                                        Cursor = Cursors.SizeNESW;
                                    }
                                    trimType = TrimType.TOPRIGHT;
                                    break;

                                case 4:
                                    if (Cursor != Cursors.SizeWE)
                                    {
                                        Cursor = Cursors.SizeWE;
                                    }
                                    trimType = TrimType.RIGHTR;
                                    break;

                                case 5:
                                    if (Cursor != Cursors.SizeNWSE)
                                    {
                                        Cursor = Cursors.SizeNWSE;
                                    }
                                    trimType = TrimType.BOTTOMRIGHT;
                                    break;

                                case 6:
                                    if (Cursor != Cursors.SizeNS)
                                    {
                                        Cursor = Cursors.SizeNS;
                                    }
                                    trimType = TrimType.BOTTOM;
                                    break;

                                case 7:
                                    if (Cursor != Cursors.SizeNESW)
                                    {
                                        Cursor = Cursors.SizeNESW;
                                    }
                                    trimType = TrimType.BOTTOMLEFT;
                                    break;

                                case 8:
                                    if (Cursor != Cursors.SizeWE)
                                    {
                                        Cursor = Cursors.SizeWE;
                                    }
                                    trimType = TrimType.LEFT;
                                    break;
                                }
                                break;
                            }
                            else
                            {
                                if (Cursor != Cursors.Default)
                                {
                                    Cursor = Cursors.Default;
                                }
                                trimType = TrimType.NONE;
                            }
                        }
                    }
                    break;
                }
                Invalidate();
            }
        }
示例#14
0
        // cutDownType values: ( PercentOfTrees, Volume, Area )
        // trimType values: ( ByTallest, BySmallest, Systematic )
        // value: (% de corta)
        public override void ApplyCutDown(Parcela oldPlot, Parcela newPlot, CutDownType cutDownType, TrimType trimType, float value)
        {
            newPlot.VAR_9 = value; // % de corta...
            double parA0, parB0, parB1, parB2, parB3;

            parA0      = 4.9272;
            parB0      = 1.3324;
            parB1      = 0.0559;
            parB2      = -22.7815;
            parB3      = 1.0394;
            newPlot.SI = oldPlot.SI.Value;
            double parC0, parC1, parC2, SEC_NORMAL;

            switch (cutDownType)
            {
            case CutDownType.PercentOfTrees:
                parC0                 = 0.531019;
                parC1                 = 0.989792;
                parC2                 = 0.517850;
                newPlot.N_PIESHA      = (1 - value / 100) * oldPlot.N_PIESHA.Value;
                newPlot.D_CUADRATICO  = parC0 + oldPlot.D_CUADRATICO.Value * (parC1 + parC2 * Math.Pow(value / 100, 2));
                SEC_NORMAL            = Math.PI * Math.Pow(newPlot.D_CUADRATICO.Value / 2, 2);
                newPlot.A_BASIMETRICA = SEC_NORMAL * newPlot.N_PIESHA.Value / 10000;
                newPlot.VCC           = Math.Exp((double)parB0 + parB1 * newPlot.SI.Value + parB2 / newPlot.EDAD.Value + parB3 * Math.Log(newPlot.A_BASIMETRICA.Value));
                break;

            case CutDownType.Volume:
                break;

            case CutDownType.Area:
                parC0 = 0.144915;
                parC1 = 0.969819;
                parC2 = 0.678010;
                newPlot.A_BASIMETRICA = (1 - value / 100) * oldPlot.A_BASIMETRICA.Value;
                newPlot.D_CUADRATICO  = Math.Pow(parC0 + parC1 * Math.Pow(oldPlot.D_CUADRATICO.Value, 0.5) + parC2 * (value / 100), 2);
                SEC_NORMAL            = Math.PI * Math.Pow(newPlot.D_CUADRATICO.Value / 200, 2);
                newPlot.N_PIESHA      = newPlot.A_BASIMETRICA.Value / SEC_NORMAL;
                newPlot.VCC           = Math.Exp((double)parB0 + parB1 * newPlot.SI.Value + parB2 / newPlot.EDAD.Value + parB3 * Math.Log(newPlot.A_BASIMETRICA.Value));
                break;
            }
        }
示例#15
0
        static private StringSlice Trim(string inString, int inStartIdx, int inLength, char[] inTrimChars, TrimType inTrimType)
        {
            if (inString == null)
            {
                return(StringSlice.Empty);
            }

            if (inTrimChars == null || inTrimChars.Length == 0 || inTrimType == TrimType.None)
            {
                return(new StringSlice(inString, inStartIdx, inLength));
            }

            int trimCount = inTrimChars.Length;

            int startIdx = inStartIdx;
            int endIdx   = startIdx + inLength - 1;

            if ((inTrimType & TrimType.Start) == TrimType.Start)
            {
                while (startIdx <= endIdx)
                {
                    int  i = 0;
                    char c = inString[startIdx];
                    for (i = 0; i < trimCount; ++i)
                    {
                        if (c == inTrimChars[i])
                        {
                            break;
                        }
                    }
                    if (i == trimCount)
                    {
                        break;
                    }

                    ++startIdx;
                }
            }

            if ((inTrimType & TrimType.End) == TrimType.End)
            {
                while (endIdx >= startIdx)
                {
                    int  i = 0;
                    char c = inString[endIdx];
                    for (i = 0; i < trimCount; ++i)
                    {
                        if (c == inTrimChars[i])
                        {
                            break;
                        }
                    }
                    if (i == trimCount)
                    {
                        break;
                    }

                    --endIdx;
                }
            }

            if (startIdx > endIdx)
            {
                return(StringSlice.Empty);
            }

            int newLength = endIdx - startIdx + 1;

            if (newLength == inLength)
            {
                return(new StringSlice(inString, inStartIdx, inLength));
            }

            return(new StringSlice(inString, startIdx, newLength));
        }
示例#16
0
        /// <summary>
        /// 元画像を指定の方法で加工した新しい画像を取得します。
        /// </summary>
        /// <param name="bitmap">元画像を設定します。</param>
        /// <param name="trimming">トリミングするかどうかを設定します。</param>
        /// <param name="trimmingType">トリミングの基準となる位置を設定します。</param>
        /// <param name="line200">200ライン画像とみなすかを設定します。</param>
        /// <param name="color8">8色画像とみなすかを設定します。</param>
        /// <returns>加工した新しい画像を返します。</returns>
        private BitmapSource ProcessImage(BitmapImage bitmap, bool trimming, TrimType trimmingType, bool line200, bool color8)
        {
            if (HasPalette && BitsPerPixel == 8 && CountUsedColor(bitmap) <= 16)
            {
                var wBmp = ShrinkBitsPerPixel(bitmap);

                if (line200 && wBmp.PixelHeight >= 2)
                {
                    // 200ライン
                    unsafe
                    {
                        wBmp.Lock();

                        var ptr = (byte *)wBmp.BackBuffer;

                        for (var y = 1; y < wBmp.PixelHeight; y += 2)
                        {
                            byte *sBuffer = ptr + (y - 1) * wBmp.BackBufferStride;
                            byte *dBuffer = ptr + y * wBmp.BackBufferStride;

                            for (var offset = 0; offset < wBmp.BackBufferStride; offset++)
                            {
                                dBuffer[offset] = sBuffer[offset];
                            }
                        }

                        wBmp.Unlock();
                    }
                }

                if (trimming)
                {
                    // トリミング
                    unsafe
                    {
                        wBmp.Lock();

                        int sx, sy, ex, ey, oColorIndex;
                        var width  = bitmap.PixelWidth;
                        var height = bitmap.PixelHeight;
                        var ptr    = (byte *)wBmp.BackBuffer;

                        // 左上 or 右下 のパレットを取得
                        byte *oPtr = ptr + (trimmingType == TrimType.LeftTop ? 0 : (bitmap.PixelHeight - 1) * wBmp.BackBufferStride + (width - 1) / 2);

                        // トリミングするカラーインデックスを取得
                        if ((width - 1) % 2 == 0)
                        {
                            oColorIndex = *oPtr >> 4;
                        }
                        else
                        {
                            oColorIndex = *oPtr & 0x0f;
                        }

                        // 上端取得
                        for (sy = 0; sy < height; sy++)
                        {
                            var check = false;
                            for (var x = 0; x < width; x++)
                            {
                                byte *pixel       = ptr + sy * wBmp.BackBufferStride + x / 2;
                                var   dColorIndex = (x % 2 == 0) ? *pixel >> 4 : *pixel & 0x0f;
                                if (dColorIndex != oColorIndex)
                                {
                                    check = true;
                                    break;
                                }
                            }

                            if (check)
                            {
                                break;
                            }
                        }

                        // 下端取得
                        for (ey = height - 1; ey >= 0; ey--)
                        {
                            var check = false;
                            for (var x = 0; x < width; x++)
                            {
                                byte *pixel       = ptr + ey * wBmp.BackBufferStride + x / 2;
                                var   dColorIndex = (x % 2 == 0) ? *pixel >> 4 : *pixel & 0x0f;
                                if (dColorIndex != oColorIndex)
                                {
                                    check = true;
                                    break;
                                }
                            }

                            if (check)
                            {
                                break;
                            }
                        }

                        // 左端取得
                        for (sx = 0; sx < width; sx++)
                        {
                            var check = false;
                            for (var y = 0; y < height; y++)
                            {
                                byte *pixel       = ptr + y * wBmp.BackBufferStride + sx / 2;
                                int   dColorIndex = (sx % 2 == 0) ? *pixel >> 4 : *pixel & 0x0f;
                                if (dColorIndex != oColorIndex)
                                {
                                    check = true;
                                    break;
                                }
                            }

                            if (check)
                            {
                                break;
                            }
                        }

                        // 右端取得
                        for (ex = width - 1; ex >= 0; ex--)
                        {
                            var check = false;
                            for (var y = 0; y < height; y++)
                            {
                                byte *pixel       = ptr + y * wBmp.BackBufferStride + ex / 2;
                                int   dColorIndex = (ex % 2 == 0) ? *pixel >> 4 : *pixel & 0x0f;
                                if (dColorIndex != oColorIndex)
                                {
                                    check = true;
                                    break;
                                }
                            }

                            if (check)
                            {
                                break;
                            }
                        }

                        wBmp.Unlock();

                        if (sx <= ex || sy <= ey)
                        {
                            return(new CroppedBitmap(wBmp, new Int32Rect(sx, sy, ex - sx + 1, ey - sy + 1)) as BitmapSource);
                        }
                    }
                }

                return(wBmp);
            }

            return(bitmap);
        }
示例#17
0
        // This function is used to prevent long quotations in error messages, SQLBUDT 222626
        private static void AppendTrimmed(StringBuilder sb, string value, int startIndex, int count, TrimType trimType)
        {
            const int    TrimSize   = 32;
            const string TrimMarker = "...";

            if (count <= TrimSize)
            {
                sb.Append(value, startIndex, count);
            }
            else
            {
                switch (trimType)
                {
                case TrimType.Left:
                    sb.Append(TrimMarker);
                    sb.Append(value, startIndex + count - TrimSize, TrimSize);
                    break;

                case TrimType.Right:
                    sb.Append(value, startIndex, TrimSize);
                    sb.Append(TrimMarker);
                    break;

                case TrimType.Middle:
                    sb.Append(value, startIndex, TrimSize / 2);
                    sb.Append(TrimMarker);
                    sb.Append(value, startIndex + count - TrimSize / 2, TrimSize / 2);
                    break;
                }
            }
        }
// cutDownType values: ( PercentOfTrees, Volume, Area )
// trimType values: ( ByTallest, BySmallest, Systematic )
// value: (% de corta)
        public override void ApplyCutDown(Parcela oldPlot, Parcela newPlot, CutDownType cutDownType, TrimType trimType, float value)
        {
            newPlot.VAR_9 = value;
            //Indice de calidad
            double IC = oldPlot.SI.Value / 10;
            // H_DOMINANTE:
            double parA17, parB17, parC17, parA29, parB29, parC29;

            parA17 = 1.9962;
            parB17 = 0.2642;
            parC17 = 0.46;
            parA29 = 3.1827;
            parB29 = 0.3431;
            parC29 = 0.3536;
            double H0_17 = 10 * parA17 * Math.Pow(1 - Math.Exp((double)-1 * parB17 * newPlot.EDAD.Value / 10), 1 / parC17);
            double H0_29 = 10 * parA29 * Math.Pow(1 - Math.Exp((double)-1 * parB29 * newPlot.EDAD.Value / 10), 1 / parC29);

            newPlot.VAR_2       = H0_17;
            newPlot.VAR_3       = H0_29;
            newPlot.H_DOMINANTE = H0_17 + (H0_29 - H0_17) * (IC - 1.7) / 1.2;
            // parametros de volumen y área basimétrica
            double parA0, parB0, parB1, parB2, parB3;

            parA0 = 5.103222;
            parB0 = 1.42706;
            parB1 = 0.388317;
            parB2 = -30.691629;
            parB3 = 1.034549;
            // parametros de corta
            double parC0, parC1, parC2, SEC_NORMAL, tpuN, tpuBA;

            switch (cutDownType)
            {
            case CutDownType.PercentOfTrees:
                parC0                 = 0.531019;
                parC1                 = 0.989792;
                parC2                 = 0.517850;
                tpuN                  = value / 100;
                newPlot.N_PIESHA      = (1 - tpuN) * oldPlot.N_PIESHA.Value;
                newPlot.D_CUADRATICO  = parC0 + parC1 * oldPlot.D_CUADRATICO + parC2 * oldPlot.D_CUADRATICO.Value * Math.Pow(tpuN, 2);
                SEC_NORMAL            = Math.PI * Math.Pow(newPlot.D_CUADRATICO.Value / 2, 2);
                newPlot.A_BASIMETRICA = SEC_NORMAL * newPlot.N_PIESHA.Value / 10000;
                newPlot.VCC           = Math.Exp((double)parB0 + parB1 * IC + parB2 / newPlot.EDAD.Value + parB3 * Math.Log(newPlot.A_BASIMETRICA.Value));
                break;

            case CutDownType.Volume:
                break;

            case CutDownType.Area:
                parC0 = 0.144915;
                parC1 = 0.969819;
                parC2 = 0.678010;
                tpuBA = value / 100;
                newPlot.A_BASIMETRICA = (1 - tpuBA) * oldPlot.A_BASIMETRICA.Value;
                newPlot.D_CUADRATICO  = Math.Pow(parC0 + parC1 * Math.Pow(oldPlot.D_CUADRATICO.Value, 0.5) + parC2 * (tpuBA), 2);
                SEC_NORMAL            = Math.PI * Math.Pow(newPlot.D_CUADRATICO.Value / 200, 2);
                newPlot.N_PIESHA      = newPlot.A_BASIMETRICA.Value / SEC_NORMAL;
                newPlot.VCC           = Math.Exp((double)parB0 + parB1 * IC + parB2 / newPlot.EDAD.Value + parB3 * Math.Log(newPlot.A_BASIMETRICA.Value));
                break;
            }
        }
        private void Trim(TrimType type)
        {
            string data = Singleton.Instance<SavedData>().Variables[_textActionData.SourceVar].GetValue();
            char ch;
            if (_searchString == "\\r")
                ch = '\r';
            else if (_searchString == "\\n")
                ch = '\n';
            else
                ch = Convert.ToChar(_searchString);

            if (type == TrimType.Trim)
                data = data.Trim(ch);
            else if (type == TrimType.TrimEnd)
                data = data.TrimEnd(ch);
            else if (type == TrimType.TrimStart)
                data = data.TrimStart(ch);

            Singleton.Instance<SavedData>().Variables[_textActionData.TargetVar].SetValue(data);
            ActionStatus = Enums.Status.Pass;
            AutoApp.Logger.WritePassLog(string.Format("{0} String Completed", type));
        }
示例#20
0
        /// <summary>
        /// 指定されたエンコーダーで画像を保存します。
        /// </summary>
        /// <param name="codec">エンコードするためのコーデック情報を設定します。</param>
        /// <param name="directory">保存するパスを設定します。</param>
        /// <param name="removeSource">元画像を削除するかどうかを設定します。</param>
        /// <param name="trimming">トリミングするかどうかを設定します。</param>
        /// <param name="trimmingType">トリミングの基準となる位置を設定します。</param>
        /// <param name="line200">200ライン画像とみなすかを設定します。</param>
        /// <param name="color8">8色画像とみなすかを設定します。</param>
        public SaveResult Save(CodecInfo codec, string directory, bool removeSource, bool trimming, TrimType trimmingType, bool line200, bool color8)
        {
            if (!IsProcessed)
            {
                var filename = $"{Path.GetFileNameWithoutExtension(Filename)}{codec.Extension}";
                var path     = Path.Combine(directory ?? Directory, filename);

                var bitmap  = LoadImage();
                var pBitmap = ProcessImage(bitmap, trimming, trimmingType, line200, color8);
                var encoder = (BitmapEncoder)Activator.CreateInstance(codec.EncoderType);
                encoder.Frames.Add(BitmapFrame.Create(pBitmap));

                using (var stream = File.OpenWrite(path))
                {
                    encoder.Save(stream);
                    stream.Close();
                }

                // 元画像削除オンで出力したファイル名が異なる場合は削除
                if (removeSource && Filename != filename)
                {
                    File.Delete(fullPath);
                }

                IsProcessed = true;
                return(SaveResult.Processed);
            }

            return(SaveResult.Skipped);
        }