Skip to content

Commit

Permalink
Bug resolved: importing only a part of the series was not working if …
Browse files Browse the repository at this point in the history
…the increment was different to 1
  • Loading branch information
b-deville committed Mar 26, 2013
1 parent cba07b8 commit 28049a9
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions PrintingLayout/Sources/PLLayoutView.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,49 +241,49 @@ - (IBAction)importPartialSeries:(id)sender
}
}

- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(DCMView *)contextInfo
{
DCMView *dicomView =(DCMView*)contextInfo;
DCMView *dicomView = contextInfo;
PLWindowController *wc = self.window.windowController;
NSUInteger start = wc.importStart - 1;
NSUInteger increment = wc.importInterval;

NSUInteger nbImages = (wc.importEnd - wc.importStart + 1) / increment;
NSUInteger imgPerPage = wc.importWidth * wc.importHeight;

NSUInteger nbPages = nbImages % imgPerPage ? 1 + nbImages / imgPerPage : nbImages / imgPerPage;
NSUInteger start = wc.importStart - 1;
NSUInteger increment = wc.importInterval;
NSUInteger imgPerPage = wc.importWidth * wc.importHeight;
NSUInteger newHeight = wc.importHeight,
newWidth = wc.importWidth;

// Create enough pages to import all desired images and resize them to the desired layout
// Resize the current page to the desired layout
if (![self updateLayoutViewWidth:newWidth height:newHeight])
return;

PLDocumentView *motherView = (PLDocumentView*)self.superview;
NSUInteger currentPage = motherView.currentPageIndex;
if (nbPages > 1)
{
for (NSUInteger i = 1; i < nbPages; ++i)
{
NSUInteger pageIndex = currentPage + i;
[motherView insertPageAtIndex:pageIndex];
PLLayoutView *pageToFill = [motherView.subviews objectAtIndex:pageIndex];

if (![pageToFill updateLayoutViewWidth:newWidth height:newHeight])
return;
}
}
NSUInteger page = motherView.currentPageIndex;

// Import images
for (NSUInteger i = 0; i < nbPages; ++i)
NSUInteger currentImg = start;
NSUInteger currentPage = page;
NSUInteger currentThumb = 0;
while (currentImg < wc.importEnd)
{
PLLayoutView *pageToFill = [motherView.subviews objectAtIndex:i + currentPage];
PLLayoutView *pageToFill = [motherView.subviews objectAtIndex:currentPage];
PLThumbnailView *thumb = [[pageToFill subviews] objectAtIndex:currentThumb];

if ([thumb fillView:currentThumb withDCMView:dicomView atIndex:currentImg])
pageToFill.filledThumbs++;

currentImg += increment;
currentThumb++;

for (NSUInteger j = 0; j < imgPerPage; ++j)
if (currentThumb == imgPerPage) // The current page is full
{
PLThumbnailView *thumb = [[pageToFill subviews] objectAtIndex:j];
if ([thumb fillView:j withDCMView:dicomView atIndex:start + j + imgPerPage * i])
pageToFill.filledThumbs++;
currentPage++;
currentThumb = 0;
// Create a new page and resize it to the desired layout
[motherView insertPageAtIndex:currentPage];
PLLayoutView *pageToFill = [motherView.subviews objectAtIndex:currentPage];

if (![pageToFill updateLayoutViewWidth:newWidth height:newHeight])
return;
}
}

Expand Down

0 comments on commit 28049a9

Please sign in to comment.