RectSelection::RectSelection (Coord l, Coord b, Coord r, Coord t, Graphic* gs) : (gs) { myname = "Rect"; Append(new IFillRect(l, b, r, t)); Append(new Rect(l, b, r, t)); } // RectSelection reads data to initialize its graphic state and create // its filled interior and outline. RectSelection::RectSelection (istream& from, State* state) : (nil) { myname = "Rect"; ReadGS(from, state); Skip(from); Coord l, b, r, t; from >> l >> b >> r >> t; Append(new IFillRect(l, b, r, t)); Append(new Rect(l, b, r, t)); } // Copy returns a copy of the RectSelection. Graphic* RectSelection::Copy () { Coord l, b, r, t; GetOriginal2(l, b, r, t); return new RectSelection(l, b, r, t, this); } // GetOriginal2 returns the two corners that were passed to the // RectSelection's constructor. void RectSelection::GetOriginal2 (Coord& l, Coord& b, Coord& r, Coord& t) { ((Rect*) Last())->GetOriginal(l, b, r, t); }
EllipseSelection::EllipseSelection (Coord x0, Coord y0, int rx, int ry, Graphic* gs) : (gs) { Append(new IFillEllipse(x0, y0, rx, ry)); Append(new Ellipse(x0, y0, rx, ry)); } // EllipseSelection reads data to initialize its graphic state and // create its filled interior and outline. EllipseSelection::EllipseSelection (istream& from, State* state) : (nil) { ReadGS(from, state); Skip(from); Coord x0, y0; int rx, ry; from >> x0 >> y0 >> rx >> ry; Append(new IFillEllipse(x0, y0, rx, ry)); Append(new Ellipse(x0, y0, rx, ry)); } // Copy returns a copy of the EllipseSelection. Graphic* EllipseSelection::Copy () { Coord x0, y0; int rx, ry; GetOriginal(x0, y0, rx, ry); return new EllipseSelection(x0, y0, rx, ry, this); } // GetOriginal returns the center point and the x and y radii lengths // that were passed to the EllipseSelection's constructor. void EllipseSelection::GetOriginal (Coord& x0, Coord& y0, int& rx, int& ry) { ((Ellipse*) Last())->GetOriginal(x0, y0, rx, ry); }
CircleSelection::CircleSelection (Coord x0, Coord y0, int r, Graphic* gs) : (gs) { Append(new IFillCircle(x0, y0, r)); Append(new Circle(x0, y0, r)); } // CircleSelection reads data to initialize its graphic state and // create its filled interior and outline. CircleSelection::CircleSelection (istream& from, State* state) : (nil) { ReadGS(from, state); Skip(from); Coord x0, y0; int r; from >> x0 >> y0 >> r; Append(new IFillCircle(x0, y0, r)); Append(new Circle(x0, y0, r)); } // Copy returns a copy of the CircleSelection. Graphic* CircleSelection::Copy () { Coord x0, y0; int r; GetOriginal(x0, y0, r); return new CircleSelection(x0, y0, r, this); } // GetOriginal returns the center point and radius length that were // passed to the CircleSelection's constructor. void CircleSelection::GetOriginal (Coord& x0, Coord& y0, int& r) { ((Circle*) Last())->GetOriginal(x0, y0, r, r); }
ClosedBSplineSelection::ClosedBSplineSelection (Coord* x, Coord* y, int n, Graphic* gs) : (gs) { myname = "CBSpl"; Append(new IFillClosedBSpline(x, y, n)); Append(new ClosedBSpline(x, y, n)); } // ClosedBSplineSelection reads data to initialize its graphic state // and create the closed B-spline's filled interior and outline. ClosedBSplineSelection::ClosedBSplineSelection (istream& from, State* state) : (nil) { myname = "CBSpl"; ReadGS(from, state); Coord* x; Coord* y; int n; ReadPoints(from, x, y, n); Append(new IFillClosedBSpline(x, y, n)); Append(new ClosedBSpline(x, y, n)); } // Copy returns a copy of the ClosedBSplineSelection. Graphic* ClosedBSplineSelection::Copy () { Coord* x; Coord* y; int n; GetOriginal(x, y, n); Graphic* copy = new ClosedBSplineSelection(x, y, n, this); delete x; delete y; return copy; } // GetOriginal returns the control points that were passed to the // ClosedBSplineSelection's constructor. void ClosedBSplineSelection::GetOriginal (Coord*& x, Coord*& y, int& n) { ((ClosedBSpline*) Last())->GetOriginal(x, y, n); }
PolygonSelection::PolygonSelection (Coord* x, Coord* y, int n, Graphic* gs) : (gs) { myname = "Poly"; Append(new IFillPolygon(x, y, n)); Append(new Polygon(x, y, n)); } // PolygonSelection reads data to initialize its graphic state and // create its filled interior and outline. PolygonSelection::PolygonSelection (istream& from, State* state) : (nil) { myname = "Poly"; ReadGS(from, state); Coord* x; Coord* y; int n; ReadPoints(from, x, y, n); Append(new IFillPolygon(x, y, n)); Append(new Polygon(x, y, n)); } // Copy returns a copy of the PolygonSelection. Graphic* PolygonSelection::Copy () { Coord* x; Coord* y; int n; GetOriginal(x, y, n); Graphic* copy = new PolygonSelection(x, y, n, this); delete x; delete y; return copy; } // GetOriginal returns the vertices that were passed to the // PolygonSelection's constructor. void PolygonSelection::GetOriginal (Coord*& x, Coord*& y, int& n) { ((Polygon*) Last())->GetOriginal(x, y, n); }
BSplineSelection::BSplineSelection (Coord* x, Coord* y, int n, Graphic* gs) : (gs) { Init(x, y, n); } // BSplineSelection reads data to initialize its graphic state and // create its components. BSplineSelection::BSplineSelection (istream& from, State* state) : (nil) { bspline = nil; ReadGS(from, state); Coord* x; Coord* y; int n; ReadPoints(from, x, y, n); Init(x, y, n); } // Copy returns a copy of the BSplineSelection. Graphic* BSplineSelection::Copy () { Coord* x; Coord* y; int n; GetOriginal(x, y, n); Graphic* copy = new BSplineSelection(x, y, n, this); delete x; delete y; return copy; } // GetOriginal returns the control points that were passed to the // BSplineSelection's constructor. void BSplineSelection::GetOriginal (Coord*& x, Coord*& y, int& n) { ((BSpline*) bspline)->GetOriginal(x, y, n); }
KS_E_ERROR ks_file_read(KS_FILE_PTR file_ptr, LongWord position, LongWord data_size, Pointer data_buffer) { /* ************************************************************** * * Local declarations: * * ************************************************************** */ KS_E_ERROR error; /* Holds error codes for subroutine*/ /* calls */ LongWord data_offset; /* Offset into the buffer to return*/ LongWord remaining_space; /* Space remaining in file buffer */ LongWord buffer_request; /* Size of each copy from the */ /* file buffer */ ROUTINE_ENTER(); /* ************************************************************** * * Verify the structure ID passed in is the correct one. * * ************************************************************** */ if (file_ptr->struct_id != KS_FILE_ID) { KS_ERROR(KS_E_INVALID_STRUCT_ID, KS_FILE_ID); }; /* ************************************************************** * * Zero the number of bytes transfered in the KS_FILE structure. * * ************************************************************** */ file_ptr->data_size = 0; /* ************************************************************** * * If there is a buffer, then lets get data from the file buffer.* * ************************************************************** */ if (file_ptr->buffer_size != NULL) { /* ********************************************************** * * If we hit the end of file last time, then we have no * * choice but to return an error. * * ********************************************************** */ if (file_ptr->end_of_file == TRUE) { error = eofEncountered; goto EXIT_NOW; }; /* ********************************************************** * * Loop till we satisfy the request (or take an error) * * ********************************************************** */ data_offset = 0; while (data_size > 0) { /* ****************************************************** * * Calculate the remaining space in the buffer. If * * there is any space left in the buffer then lets copy * * as much as we need to into the output buffer. * * ****************************************************** */ remaining_space = (file_ptr->buffer_available) - (file_ptr->buffer_offset); if (remaining_space > 0) { buffer_request = MIN(data_size, remaining_space); /* ************************************************** * * Copy the available bytes (or the required bytes) * * to the target buffer (if one was supplied). * * ************************************************** */ if (data_buffer != NULL) { COPY_BYTES(file_ptr->buffer, file_ptr->buffer_offset, data_buffer, data_offset, buffer_request); }; /* ************************************************** * * Now modify the parameters of the buffers by: * * * * 1) Adding the size of the request to the file * * buffer ofset and the data offset (IE: Indices to * * the file buffer and the read request buffer). * * * * 2) Subtracting the request size from the read * * request size and the remaining number of * * characters in the file buffer. * * ************************************************** */ file_ptr->buffer_offset = file_ptr->buffer_offset + buffer_request; data_offset = data_offset + buffer_request; file_ptr->data_size = data_offset; data_size = data_size - buffer_request; remaining_space = remaining_space - buffer_request; }; /* ****************************************************** * * If isn't anything in the file buffer, the we have to * * re-fill it. The problem is that the buffer size may * * have changed due to what our user wants (users are * * bound to be the end of all computing...). This means * * that we'll junp through a few hoops if we must change * * buffer sizes - so expect some weirdness here. * * ****************************************************** */ if (remaining_space == 0) { /* ************************************************** * * This is the above mentioned weirdness - if the * * user specified a different size buffer we will * * no comply with their wishes. * * ************************************************** */ if (file_ptr->buffer_size != KSf_FileBufferSize) { KS_MEMORY_DEALLOCATE(file_ptr->buffer_handle, error); if (error != KS_E_SUCCESS) { goto EXIT_NOW; }; KS_MEMORY_ALLOCATE(attrFixed + attrLocked, KSf_FileBufferSize, BUFFER_USERID, file_ptr->buffer_handle, error); if (error != KS_E_SUCCESS) { goto EXIT_NOW; }; file_ptr->buffer = (Byte *) *(file_ptr->buffer_handle); file_ptr->buffer_size = KSf_FileBufferSize; file_ptr->buffer_available = KSf_FileBufferSize; }; /* ************************************************** * * Issue a Read to the file into our buffer. * * ************************************************** */ KSf_pkts.IO.pCount = 4; KSf_pkts.IO.refNum = file_ptr->refNum; KSf_pkts.IO.dataBuffer = TO_POINTER(file_ptr->buffer); KSf_pkts.IO.requestCount = file_ptr->buffer_size; ReadGS(&KSf_pkts.IO); /* ************************************************** * * Now for the error processing. * * * * Any error means we return to our caller. * * * * The end of file error (eofEncountered or $4c) is * * special. At EOF we mark the KS_FILE structure * * so the next READ call will return EOF right away. * * We will return SUCCESS in this case because the * * user will be able to find some data in the input * * buffer (total amount == ). * ************************************************** */ if ((error = GET_ERROR()) != KS_E_SUCCESS) { if (error == eofEncountered) { error = KS_E_SUCCESS; file_ptr->end_of_file = TRUE; } goto EXIT_NOW; }; file_ptr->buffer_available = KSf_pkts.IO.transferCount; file_ptr->buffer_offset = 0; }; /* End if there is no remaining buffer space */ }; /* End while there are characters to be read... */ KS_SUCCESS(); }; /* End if we are doing buffer I/O from the file */ /* ************************************************************** * * Ok, we've done enough buffering... lets do some real input... * * * * Position the 'mark' (where we will read from) in the file. * * Note: We'll move the mark only if our user asks us to. * * ************************************************************** */ if (position != KS_NEXT_FILE_POSITION) { KSf_pkts.position.pCount = 3; KSf_pkts.position.refNum = file_ptr->refNum; KSf_pkts.position.base = startPlus; KSf_pkts.position.displacement = position; SetMarkGS(&KSf_pkts.position); if ((error = GET_ERROR()) != KS_E_SUCCESS) { goto EXIT_NOW; }; }; /* End if we must change the file position */ /* ************************************************************** * * Setup the I/O packet and read what our user is asking for. * * ************************************************************** */ KSf_pkts.IO.pCount = 4; KSf_pkts.IO.refNum = file_ptr->refNum; KSf_pkts.IO.dataBuffer = data_buffer; KSf_pkts.IO.requestCount = data_size; ReadGS(&KSf_pkts.IO); if ((error = GET_ERROR()) != KS_E_SUCCESS) { goto EXIT_NOW; }; /* ************************************************************** * * Save the number of bytes transfered in the KS_FILE structure. * * ************************************************************** */ file_ptr->data_size = KSf_pkts.IO.transferCount; /* ************************************************************** * * Return the status back to our caller. * * ************************************************************** */ EXIT_NOW: if (error != KS_E_SUCCESS) { KS_ERROR(error, KS_FILE_ID); }; KS_SUCCESS(); } /* End of ks_file_read() */