Business Extensions to Handlers
CADViewer has a number of supporting infrastructure components to connect the back-end CAD Converters with the front-end CADViewer on various platforms, please see the section Platform Handlers.
Each of these Handlers/Connectors implements the CADViewer RESTful API for communication and transfer of files between the CAD Converter back-end and the front-end CADViewer instance.
The actual request-response call for a file transfer will need a URL end-point to connect to the REST API server. The REST API End-points supported by CADViewer server scripts on the various platforms are:
URL End-points to REST API
Platform | End-Point |
---|---|
NodeJS | /callapiconversion |
PHP | /call-Api_Conversion.php |
Tomcat Servlets | /callApiConversionServlet |
dotNet | /callApiConversionHandler.ashx |
dotNetCore | /callApiConversion |
Download
Each of these End-points are implemented in the Platform Handlers and can be Downloaded.
Handlers written in PHP, NodeJS, dotNet and dotNetCore are included with source code as part of our Downloads, for Source Code for the Tomcat - Servlets please Contact us, as Servlets are compiled code.
Implementation
The various callapiconversion end-point scripts, all follows the same CADViewer RESTful API process:
- 1: Receive a REST Conversion Request.
- 2: Pick up the file descriptor from the JSON Request.
- 3: Save the file to a temporary Fxxxxx.dwg (if dwg) in the /cadviewer/converters/files/ folder.
- 4: Convert the file to Fxxxxx.svg in the /cadviewer/converters/files/ folder.
- 5: Serve the converted file back up to CADViewer in a JSON Response.
The Application Programmer should therefore locate the point 2) in the process and add their own DataBase or blob handler to pass over their own files to the /converters/files/ folder, for the script to complete the conversion process .
Rest API Call Controls
The CADViewer REST API provides a Request Key ‘customConversionEndpointExtension’ for users to add control to the back-end process, see Request - Response in the CADViewer RESTful API.
In the CADViewer front-end the setting is controlled with the API call:
// Set user control of conversions in the /callapiconversion end-point
cvjs_setCustomConversionEndpointExtension(true); // false default, set to true to control endpoint
The application programmers can with this setting set an end-point for content loading that will be handled on the server. CADViewer will pass over conversion parameters and the end-point for processing on the server.
// Set user control of conversions in the /callapiconversion end-point
EndPoint = "http://myendpoint.com:8055/assets/143555d9-f637-471d-870e-945f226d7df7";
cadviewer.cvjs_LoadDrawing("floorPlan", EndPoint );
The end-point in the front-end is assumed to be AutoCAD DWG on the back-end, but the application programmer can add the tag ftype to set a different file format. The back-end custom code in the exposed handlers are set up to parse a direct load of a svg file or to do a conversion of the format specified by ftype. Obviously the application programmer may change this code.
// Set user control of conversions in the /callapiconversion end-point
EndPoint = "http://myendpoint.com:8055/assets/143555d9-f637-471d-870e-945f226d7df7&ftype=svg";
cadviewer.cvjs_LoadDrawing("floorPlan", EndPoint );
/* or */
// Set user control of conversions in the /callapiconversion end-point
EndPoint = "http://myendpoint.com:8055/assets/143555d9-f637-471d-870e-945f226d7df7&ftype=dwg";
cadviewer.cvjs_LoadDrawing("floorPlan", EndPoint );
NodeJS CADServer End-Point Extension
In the NodeJS CAD Conversion Server, when the ‘customConversionEndpointExtension’ is set to ’true’, then the Implementation point 2: above “Pick up the file descriptor from the JSON Request”, has been moved to an external method cvjs_customConversionEndpointExtension in the file /routes/cvjs_customConversionEndpointExtension_6.9.xx.
The application programmer can in this method freely add specific content that should not be exposed such as Bearer Tokens etv., pull the file/blob, and then pass back over to CADViewer server for processing through the call callapiconversion.cvjs_standard_CV_AX_processing().
There are two call-back methods:
- cvjs_standard_CV_AX_processing() - conversion of file and REST call-back to CADViewer
- SVG_callback() - REST call-back with SVG file to CADViewer
See code in: cvjs_customConversionEndpointExtension
Front-End
Load when processing a DWG for Space Objects
Once the conversion is done and the converted drawing is sent up to CADViewer using the REST API , the application programmer can fetch the SVG for storage or other processing using the CADViewer API command:
There are three API for this:
-
cvjs_extractSVGfromCanvas() - extracts the actual canvas including any objects
-
cvjs_returnNonPreprocessedSVG() - returns the loaded SVG prior to any pre-processing
-
cvjs_restAPI_getSVGContentData() - provide an endpoint for user to load SVG from server, this can be a svg or an compressed svgz
function cvjs_OnLoadEnd(){
// generic callback method, called when the drawing is loaded
// here you fill in your stuff, call DB, set up arrays, etc..
// this method MUST be retained as a dummy method! - if not implemeted -
// capture processed SVG for storage or processing.
var mySVG = cadviewer.cvjs_extractSVGfromCanvas("floorPlan");
// download as SVG file
cadviewer.cvjs_downloadObjectAsFile("testSVGprocessed.svg", mySVG);
// download non processed SVG file
var mySVGnotprocessed = cadviewer.cvjs_returnNonPreprocessedSVG();
cadviewer.cvjs_downloadObjectAsFile("testSVGnotprocessed.svg", mySVGnotprocessed);
// get the data content link for svg/svgz file
// pull from server, false delete after pull, true remain on server
var mySVGzlink = cvjs_restAPI_getSVGContentData(true);
window.alert(mySVGzlink);
// do somethng with my loaded file, can be svg or compressed svgz
// get all space objects
var SpaceObjects = cadviewer.cvjs_returnAllSpaceObjects()
cadviewer.cvjs_downloadObjectAsFile("testSpaceObjects.json", JSON.stringify(SpaceObjects));
}
Loading SVG without processing and adding Space Object overlay
When a drawing has been processed and the SpaceObjects has been processed and extracted, for example using cvjs_returnAllSpaceObjects(), then it is not needed to fire off the back-end converter again and the SpaceObject content can be overlaid to the bare SVG drawing (for example extrated through cvjs_returnNonPreprocessedSVG())
When subsequently loading the SVG, you need to tell the system not to do any pre-procssing of that SVG, as you will add that yourself.
cadviewer.cvjs_setSpaceObjectProcessing(false);
// before calling cvjs_LoadDrawing(*.svg)
and then in callback insert your JSON objects.
function cvjs_OnLoadEnd(){
// generic callback method, called when the drawing is loaded
// here you fill in your stuff, call DB, set up arrays, etc..
// this method MUST be retained as a dummy method! - if not implemeted -
// overlay the SVG with Space Objects, for example>
cadviewer.cvjs_loadSpaceObjectsDirect("floorPlan", "http://localhost:3000/content/SpaceObjects/testSpaceObjects.json")
}