<%@language = "javascript" %>
<% /*
    $Revision$
    $Id$

    File:           dwf_verify_proc.asp
    Description:    Generate an PNG image
    Parameters:     dwf: bestandsnaam van de dwf
    Context:
    Note:
*/
var JSON_Result = true;
%>

<!--#include file='../Shared/common.inc'-->
<!--#include file="../SlnkDWF/Slnk2IMG.inc" -->
<%
user.checkAutorisation("WEB_PRSSYS");
if (Server.ScriptTimeout<600) Server.ScriptTimeout=600;

var concept = getQParamInt("concept", 0);
var dwf = getQParam("dwf", "");
var dwfPath = (concept==1?S("flexfilespath") + "/cad/concept/":concept==2?S("flexfilespath") + "/cad/symbols/":S("flexfilespath") + "/cad/") + safe.filename(dwf);

var shownolabel = getQParamInt("shownolabel", 1);
var showorigin = getQParamInt("showorigin", 0);

function myContourProcessor(cHandle)
{
    var minx,maxx,miny,maxy;
    for (var i2=0; i2 < cHandle.ContourCount; i2++)
    {
        var c = cHandle.ContourItem(i2);
        if (i2==0)
        {
            minx = c.Extents.min.DwgX;
            maxx = c.Extents.max.DwgX;
            miny = c.Extents.min.DwgY;
            maxy = c.Extents.max.DwgY;
        }
        else
        {
            minx = Math.min(c.Extents.min.DwgX, minx);
            maxx = Math.max(c.Extents.max.DwgX, maxx);
            miny = Math.min(c.Extents.min.DwgY, miny);
            maxy = Math.max(c.Extents.max.DwgY, maxy);
        }
        c.lineweight = S("fg_contourWeight") * S("fg_dwgscale") / 1000;
        if (c.Key)
        {
            c.Label = "[u][i]" + c.Key + (c.Area?"\n[c][s50]("+(c.Area / 1e6).toFixed(1) + "mē)":"");
            c.SetColor(0x00FF00, 32);
            if (c.Area)
                c.SetUrl("", "Contour {0} met {1} punten herkend".format(c.Key, c.PointCount)); // Tooltip
        }
        else if (shownolabel)
        {
            c.Label = "[s50]?? "+(c.Area / 1e6).toFixed(1) + "mē";
            c.SetUrl("", "Wel contour maar geen label gevonden");
            c.SetColor(0xFF0000);
        }
        //if (oLabel && oOpp)
    }
    if (concept==2)
    {
        // Facilitor doet er niets mee. Niet verwarrend maken dus
        var symbol = cHandle.AddSymbol(0, 0, "*SQUARE");
        symbol.scale = 0.05;
        symbol.contour.SetUrl("", "Origin (0, 0)");

        // On de centroid te achterhalen zou ik hem als symbool moeten definieren. Even te veel werk?
        //var symbol = cHandle.AddSymbol(c.Contour.Center.dwgX, c.Contour.Center.dwgX, "*STAR");
        //symbol.scale = 0.05;
        //symbol.contour.SetUrl("", "Centroid (default Facilitor insertion point)");
    }
    else if (showorigin)
    {
        var symbol = cHandle.AddSymbol(0, 0, "*SQUARE");
        symbol.scale = 2;
        symbol.contour.SetUrl("", "Origin (0, 0)");
    }

    // Zet een markering waar de limiet van de DWF ligt
    // Als je daar rechte van symbolen plaatst krijg je 'coordinate overflow'
    // Tijdelijk uitgeschakeld
    var oAbout = new ActiveXObject("SLNKDWF.About");
    if (0&&oAbout.VersionString >= "4,21") {
        var lim = cHandle.DwgLimits;
        // Een volledige contour komt niet in beeld, daarom doen we maar deellijnen
        //var cnt = cHandle.AddContour;
        //cnt.AddPoint(lim.min.DwgX+1000, lim.min.DwgY+1000);
        //cnt.AddPoint(lim.max.DwgX-1000, lim.min.DwgY+1000);
        //cnt.AddPoint(lim.max.DwgX-1000, lim.max.DwgY-1000);
        //cnt.AddPoint(lim.min.DwgX+1000, lim.max.DwgY-1000);
        //cnt.AddPoint(lim.min.DwgX+1000, lim.min.DwgY+1000);
        //cnt.setColor(0xff0000, 128);

        var cnt = cHandle.AddContour;
        cnt.SetoutlineColor(0xff0000);
        cnt.LineWeight = 250;
        cnt.AddPoint(lim.min.DwgX, miny);
        cnt.AddPoint(lim.min.DwgX, maxy);

        var cnt = cHandle.AddContour;
        cnt.SetoutlineColor(0xff0000);
        cnt.LineWeight = 250;
        var halfy = (maxy + miny) / 2;    // boxje voor het label/uitleg. Zou het voor alle lijnen kunnen doen maar in de praktijk
        cnt.AddPoint(lim.max.DwgX, miny); // zie ik alleen tekeningen met max-x problemen
        cnt.AddPoint(lim.max.DwgX, halfy - 1500);
        cnt.AddPoint(lim.max.DwgX - 1000, halfy - 1500);
        cnt.AddPoint(lim.max.DwgX - 1000, halfy + 1500);
        cnt.AddPoint(lim.max.DwgX, halfy + 1500);
        cnt.AddPoint(lim.max.DwgX, maxy);
        cnt.labelPosition = 2;
        cnt.labelRotation = 90;
        cnt.label = 'max-x';
        cnt.SetUrl("", "Harde x-limiet {0}: symbolen rechts hiervan geven problemen".format(Math.round(lim.max.DwgX))); // Tooltip

        var cnt = cHandle.AddContour;
        cnt.SetoutlineColor(0xff0000);
        cnt.LineWeight = 250;
        cnt.AddPoint(minx, lim.min.DwgY);
        cnt.AddPoint(maxx, lim.min.DwgY);

        var cnt = cHandle.AddContour;
        cnt.SetoutlineColor(0xff0000);
        cnt.LineWeight = 250;
        cnt.AddPoint(minx, lim.max.DwgY);
        cnt.AddPoint(maxx, lim.max.DwgY);
    }

    // cHandle.SetLabel("", "[u][i]"); // initieel originele ruimtenummer onderstreept
    cHandle.SetLabelFont("Arial", S("fg_inLabelSize") * S("fg_dwgscale") / 1000);

    ll = getQParamArray("layers", [".*"]);
    for (l in ll)
        ll[l] = ll[l].replace(/\|/g,"\\|");
    var llt = "{"+ll.join("}|{") +"}";
    cHandle.SetFilterLayers("{SLNK Labels}|{SLNK Contours}|" + llt);
    //cHandle.SetFilterLayers("{A--LSE--_ruimte element}");

    // Response.AddHeader("jgl", llt);

    //cHandle.SetColor("", S("fg_contourColor"), S("S("fg_contourAlpha")")); // Alle herkende ruimtes initieel transparant
    //cHandle.SetColor("", 0x00FF00, 32); // Alle herkende ruimtes initieel transparant
    //cHandle.HighlightUnrecognized(); // Deze worden rood
    //
}

function myImageProcessor(cHandle)
{
    cHandle.PaperColor = 0xE0E0FF;
}

if (dwfPath)
{
    var mySLNKDWF = new SLNKDWF({ dwfFile      : dwfPath,
                                  dwfProcessor : myContourProcessor,
                                  imgProcessor : myImageProcessor,
                                  contourLayers: getQParam("contLayer", "NOTEXIST"),
                                  labelLayers  : getQParam("labelLayer", "NOTEXIST"),
                                  minArea      : S("fg_contour_minArea"),
                                  minmergedistance: S("fg_minmergedistance"),
                                  tempFolder   : shared.tempFolder(),
                                  keepTemp     : getQParamInt("keeptemp", 0),
                                  markers      : getQParamInt("markers", 0),
                                  flags        : S("fg_slnkdwf_flags"),
                                  asciiTemp    : getQParamInt("keeptemp", 0)
                                });
    mySLNKDWF.Process();
};
%>
<% ASPPAGE_END(); %>
